cart.vue 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415
  1. <template>
  2. <!-- 商品分类第三种布局样式 -->
  3. <view class="goodCate">
  4. <!-- #ifdef MP || APP-PLUS -->
  5. <view class="mp-header">
  6. <view class="sys-head" :style="{ height: sysHeight }"></view>
  7. <view class="serch-box" style="height: 43px;">
  8. <view class="serch-wrapper acea-row row-middle">
  9. <navigator url="/pages/goods/goods_search/index" class="input acea-row row-center-wrapper" hover-class="none">
  10. <text class="iconfont icon-xiazai5"></text>
  11. 搜索商品信息
  12. </navigator>
  13. </view>
  14. </view>
  15. <!-- 门店地址详情 -->
  16. <!-- <view class="store-address">
  17. <view class="address acea-row row-middle" @click="goMap()">
  18. <view class="name line1">{{info.name || '暂无门店'}}</view>
  19. <text class="iconfont icon-xiangyou" />
  20. </view>
  21. <view class="distance">
  22. 门店距您{{info.range||0}}km
  23. </view>
  24. <view class="time">
  25. 营业时间:{{info.day_time || '-'}}
  26. </view>
  27. <view class="switch acea-row row-between-wrapper">
  28. <view class="title" :class="{'on': switchNum == item.key,'onLeft':switchNum != 1}"
  29. v-for="(item, index) in deliveryList" :key="item.key" @click="swithFn(item.key)">{{item.name}}</view>
  30. </view>
  31. </view> -->
  32. <!-- 门店详情 -->
  33. </view>
  34. <!-- #endif -->
  35. <!-- #ifdef H5 -->
  36. <view class="header acea-row row-center-wrapper">
  37. <navigator url="/pages/goods/goods_search/index" class="search acea-row row-middle" hover-class="none">
  38. <text class="iconfont icon-sousuo5"></text>
  39. 搜索商品信息
  40. </navigator>
  41. <view class="store-address">
  42. <view class="address acea-row row-middle" @click="goMap()">
  43. <view class="name line1">{{info.name || '暂无门店'}}</view>
  44. <text class="iconfont icon-xiangyou" />
  45. </view>
  46. <view class="distance">
  47. 门店距您{{info.range||0}}km
  48. </view>
  49. <view class="time">
  50. 营业时间:{{info.day_time || '-'}}
  51. </view>
  52. <view class="switch acea-row row-between-wrapper">
  53. <view class="title" :class="{'on': switchNum == item.key,'onLeft':switchNum != 1}"
  54. v-for="(item, index) in deliveryList" :key="item.key" @click="swithFn(item.key)">{{item.name}}</view>
  55. </view>
  56. </view>
  57. </view>
  58. <view class="conter">
  59. <!-- #endif -->
  60. <!-- #ifndef H5 -->
  61. <view class="conter" :style="'padding-top:'+marTop+'px'">
  62. <!-- #endif -->
  63. <!-- #ifndef H5 -->
  64. <view class='aside' :style="'top:'+marTop+'px'">
  65. <!-- #endif -->
  66. <!-- #ifdef H5 -->
  67. <view class='aside'>
  68. <!-- #endif -->
  69. <view class='item acea-row row-center-wrapper' :class='index==navActive?"on":""'
  70. v-for="(item,index) in categoryList" :key="index" @click="tapNav(index,item)">
  71. <text>{{item.cate_name}}</text>
  72. </view>
  73. </view>
  74. <view class="wrapper">
  75. <view class="bgcolor" v-if="iSlong">
  76. <!-- #ifndef H5 -->
  77. <view class="longTab acea-row row-middle" :style="'top:'+marTop+'px'">
  78. <!-- #endif -->
  79. <!-- #ifdef H5 -->
  80. <view class="longTab acea-row row-middle">
  81. <!-- #endif -->
  82. <scroll-view scroll-x="true" style="white-space: nowrap; display: flex;height:44rpx;"
  83. scroll-with-animation :scroll-left="tabLeft" show-scrollbar="true">
  84. <view class="longItem" :style='"width:"+isWidth+"px"' :class="index===tabClick?'click':''"
  85. v-for="(item,index) in categoryErList" :key="index" @click="longClick(index)">
  86. {{item.cate_name}}
  87. </view>
  88. </scroll-view>
  89. </view>
  90. <!-- #ifndef H5 -->
  91. <view class="openList" :style="'top:'+marTop+'px'" @click="openTap"><text
  92. class="iconfont icon-xiangxia"></text></view>
  93. <!-- #endif -->
  94. <!-- #ifdef H5 -->
  95. <view class="openList" @click="openTap"><text class="iconfont icon-xiangxia"></text></view>
  96. <!-- #endif -->
  97. </view>
  98. <view v-else>
  99. <!-- #ifndef H5 -->
  100. <view class="downTab" :style="'margin-top:'+marTop+'px'">
  101. <!-- #endif -->
  102. <!-- #ifdef H5 -->
  103. <view class="downTab">
  104. <!-- #endif -->
  105. <view class="title acea-row row-between-wrapper">
  106. <view>{{categoryTitle}}</view>
  107. <view class="closeList" @click="closeTap"><text class="iconfont icon-xiangxia"></text>
  108. </view>
  109. </view>
  110. <view class="children">
  111. <view class="acea-row row-middle">
  112. <view class="item line1" :class="index===tabClick?'click':''"
  113. v-for="(item,index) in categoryErList" :key="index" @click="longClick(index)">
  114. {{item.cate_name}}
  115. </view>
  116. </view>
  117. </view>
  118. </view>
  119. <view class="mask" @click="closeTap"></view>
  120. </view>
  121. <!--商品列表 -->
  122. <goodClass :tempArr="tempArr" :isLogin="isLogin" @gocartduo="goCartDuo" @gocartdan="goCartDan"
  123. @ChangeCartNumDan="ChangeCartNumDan" @detail="goDetail"></goodClass>
  124. <view class='loadingicon acea-row row-center-wrapper'>
  125. <text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadTitle}}
  126. </view>
  127. </view>
  128. </view>
  129. <view class="footer acea-row row-between-wrapper" :class="isFooter?'':'on'">
  130. <view class="cartIcon acea-row row-center-wrapper" @click="getCartList(0)" v-if="cartNum>0">
  131. <!-- <view class="iconfont icon-gouwuche-yangshi2"></view>
  132. <text class="num">{{cartNum}}</text> -->
  133. <uni-badge class="uni-badge-left-margin" :text="cartNum" absolute="rightTop">
  134. <view class="iconfont icon-gouwuche-yangshi2"></view>
  135. </uni-badge>
  136. </view>
  137. <view class="cartIcon acea-row row-center-wrapper noCart" v-else>
  138. <view class="iconfont icon-gouwuche-yangshi2"></view>
  139. </view>
  140. <view class="acea-row row-middle" :class="cartNum>0?'':'noCart'">
  141. <view class="money">¥<text class="num">{{totalPrice}}</text></view>
  142. <view class="bnt" @click="subOrder">提交订单</view>
  143. </view>
  144. </view>
  145. <!-- 分类购物车下拉列表 -->
  146. <cartList :cartData="cartData" :isFooter='isFooter' @closeList="closeList" @ChangeCartNumDan="ChangeCartList"
  147. @ChangeSubDel="ChangeSubDel" @ChangeOneDel="ChangeOneDel"></cartList>
  148. <!-- 产品属性组件 -->
  149. <productWindow :attr="attr" :isShow='1' :iSplus='1' :iScart='1' @myevent="onMyEvent"
  150. @ChangeAttr="ChangeAttr" @ChangeCartNum="ChangeCartNumDuo" @attrVal="attrVal" @iptCartNum="iptCartNum"
  151. @goCat="goCatNum" :is_vip="is_vip" id='product-window'></productWindow>
  152. <!-- #ifdef MP -->
  153. <!-- <authorize v-if="isShowAuth" @authColse="authColse" @onLoadFun="onLoadFun"></authorize> -->
  154. <!-- #endif -->
  155. </view>
  156. </template>
  157. <script>
  158. let sysHeight = uni.getSystemInfoSync().statusBarHeight + 'px';
  159. import {
  160. vcartList,
  161. // getCartCounts,
  162. cartDel
  163. } from '@/api/order.js';
  164. import {
  165. getCategoryList,
  166. getAttr,
  167. postCartNum,
  168. getCartCount,
  169. getCateList,
  170. addTableCate,
  171. placeOrder,
  172. emptyTableData,
  173. } from '@/api/store.js';
  174. import {
  175. getProducts,
  176. getCustomerList,
  177. getStoreCategory,
  178. getStoreBrand
  179. } from '@/api/new_store.js';
  180. import productWindow from '@/components/productWindow/index';
  181. import goodClass from '@/components/goodClass';
  182. import cartList from '@/components/cartList';
  183. import {
  184. mapState,
  185. mapGetters
  186. } from 'vuex';
  187. import {
  188. goShopDetail
  189. } from '@/libs/order.js';
  190. import {
  191. toLogin
  192. } from '@/libs/login.js';
  193. export default {
  194. computed: {
  195. ...mapGetters(['isLogin', 'uid'])
  196. },
  197. components: {
  198. productWindow,
  199. goodClass,
  200. cartList
  201. },
  202. props: {
  203. isFooter: {
  204. type: Boolean,
  205. default: false
  206. },
  207. info: {
  208. type: Object,
  209. default: {}
  210. },
  211. pageVisible: {
  212. type: Boolean,
  213. default: true
  214. }
  215. },
  216. data() {
  217. return {
  218. deliveryList:[
  219. {name:'配送',key:1},
  220. {name:'自提',key:2}
  221. ],
  222. marTop: 0,
  223. switchNum: 1,
  224. sysHeight: sysHeight,
  225. categoryList: [],
  226. navActive: 0,
  227. categoryTitle: '',
  228. categoryErList: [],
  229. tabLeft: 0,
  230. isWidth: 0, //每个导航栏占位
  231. tabClick: 0, //导航栏被点击
  232. iSlong: true,
  233. tempArr: [],
  234. loading: false,
  235. loadend: false,
  236. loadTitle: '加载更多',
  237. page: 1,
  238. limit: 10,
  239. cid: 0, //一级分类
  240. sid: 0, //二级分类
  241. delivery_type:3, // 配送方式
  242. isAuto: false, //没有授权的不会自动授权
  243. isShowAuth: false, //是否隐藏授权
  244. attr: {
  245. cartAttr: false,
  246. productAttr: [],
  247. productSelect: {}
  248. },
  249. productValue: [],
  250. attrValue: '', //已选属性
  251. storeName: '', //多属性产品名称
  252. id: 0,
  253. cartData: {
  254. cartList: [],
  255. iScart: false
  256. },
  257. totalPrice: 0.00,
  258. lengthCart: 0,
  259. is_vip: 0, //是否是会员
  260. cart_num: 0,
  261. storeInfo: {},
  262. cartNum: 0
  263. }
  264. },
  265. watch: {
  266. pageVisible(value) {
  267. if (value) {
  268. return;
  269. }
  270. if (!this.timer || this.timer.constructor.name != 'Object') {
  271. return;
  272. }
  273. Object.values(this.timer).forEach(this.clearTimer);
  274. },
  275. info: {
  276. handler(value) {
  277. if (!value.store_id || !value.tableId) {
  278. return;
  279. }
  280. this.getCartNum();
  281. this.getCartList(1);
  282. },
  283. deep: true
  284. }
  285. },
  286. mounted() {
  287. let that = this;
  288. // 获取设备宽度
  289. uni.getSystemInfo({
  290. success(e) {
  291. that.isWidth = e.windowWidth / 5
  292. }
  293. });
  294. },
  295. methods: {
  296. // 取消定时器
  297. clearTimer(timerID) {
  298. if (timerID) {
  299. clearTimeout(timerID);
  300. }
  301. },
  302. // 设置定时器
  303. setTimer(timerID, callback) {
  304. if (typeof callback != 'function') {
  305. return;
  306. }
  307. if (!this.timer || this.timer.constructor.name != 'Object') {
  308. this.timer = {};
  309. }
  310. this.clearTimer(this.timer[timerID]);
  311. this.timer[timerID] = setTimeout(callback, 5000);
  312. },
  313. // 重载商品数据
  314. reloadProducts() {
  315. getProducts({
  316. page: 1,
  317. limit: this.tempArr.length,
  318. type: 1,
  319. cid: this.cid,
  320. sid: this.sid,
  321. store_id: this.info.id,
  322. delivery_type: '',
  323. collate_code_id: this.info.tableId,
  324. }).then(res => {
  325. this.$set(this, 'tempArr', res.data);
  326. this.setTimer('reloadProducts', this.reloadProducts);
  327. });
  328. },
  329. // 授权回调
  330. onLoadFun() {
  331. setTimeout(function(){
  332. this.isShowAuth = false;
  333. },10)
  334. },
  335. // 授权关闭
  336. authColse: function(e) {
  337. this.isShowAuth = e
  338. },
  339. updateFun(e) {
  340. if (e.cartNum) {
  341. this.tempArr.forEach((item) => {
  342. if (item.id == e.id) {
  343. item.cart_num = e.cartNum
  344. }
  345. })
  346. }
  347. },
  348. // 商品列表
  349. getProducts() {
  350. let that = this;
  351. if (that.loadend) return;
  352. if (that.loading) return;
  353. that.loading = true;
  354. getProducts({
  355. page: that.page,
  356. limit: that.limit,
  357. type: 1,
  358. cid: that.cid,
  359. sid: that.sid,
  360. store_id: that.info.id,
  361. delivery_type:'',
  362. collate_code_id:that.info.tableId,
  363. }).then(res => {
  364. console.log(res,'res')
  365. let list = res.data,
  366. loadend = list.length < that.limit;
  367. that.tempArr = that.$util.SplitArray(list, that.tempArr);
  368. that.$set(that, 'tempArr', that.tempArr);
  369. that.loading = false;
  370. that.loadend = loadend;
  371. that.loadTitle = loadend ? "没有更多内容啦~" : "加载更多";
  372. that.page = that.page + 1;
  373. this.setTimer('reloadProducts', this.reloadProducts);
  374. }).catch(err => {
  375. that.loading = false;
  376. that.loadTitle = '加载更多'
  377. });
  378. },
  379. // 切换自提方式
  380. swithFn(num) {
  381. switch (num) {
  382. case 1:
  383. this.switchNum = 1
  384. this.delivery_type = '3'
  385. break;
  386. case 2:
  387. this.switchNum = 2
  388. this.delivery_type='2'
  389. break;
  390. }
  391. this.page = 1;
  392. this.loadend = false;
  393. this.tempArr = []
  394. this.getProducts()
  395. },
  396. // 跳转到门店列表
  397. goMap() {
  398. uni.navigateTo({
  399. url: "/pages/store/store_list/index?storeFrom=1&type=1&storeId="+this.info.id,
  400. success(res) {
  401. console.log('成功啦', res);
  402. },
  403. fail(err) {
  404. console.log('失败啦', err);
  405. }
  406. })
  407. },
  408. getMarTop() {
  409. // #ifdef MP || APP-PLUS
  410. let that = this;
  411. setTimeout(() => {
  412. // 获取小程序头部高度
  413. let info = uni.createSelectorQuery().in(this).select(".mp-header");
  414. info.boundingClientRect(function(data) {
  415. that.marTop = data.height
  416. }).exec()
  417. }, 100)
  418. // #endif
  419. },
  420. // 生成订单;
  421. subOrder: function() {
  422. placeOrder({
  423. tableId: this.info.tableId,
  424. storeId: this.info.store_id,
  425. }).then(() => {
  426. uni.navigateTo({
  427. url: `/pages/store/table_confirm/index?tableId=${this.info.tableId}`
  428. });
  429. }).catch(err => {
  430. this.$util.Tips({
  431. title: err
  432. });
  433. });
  434. },
  435. // 计算总价;
  436. getTotalPrice: function() {
  437. let that = this,
  438. list = that.cartData.cartList,
  439. totalPrice = 0.00;
  440. list.forEach(item => {
  441. if (item.attrStatus && item.status) {
  442. totalPrice = that.$util.$h.Add(totalPrice, that.$util.$h.Mul(item.cart_num, item
  443. .truePrice));
  444. }
  445. })
  446. that.$set(that, 'totalPrice', totalPrice);
  447. },
  448. ChangeSubDel: function(event) {
  449. uni.showModal({
  450. title: '确定要清空吗?',
  451. content: '清空后,已点的商品会被删除',
  452. success: (res) => {
  453. if (res.confirm) {
  454. emptyTableData({
  455. tableId: this.info.tableId
  456. }).then(res => {
  457. this.$util.Tips({
  458. title: '清空成功'
  459. });
  460. this.getCartNum();
  461. this.getCartList(1);
  462. });
  463. }
  464. }
  465. });
  466. },
  467. ChangeOneDel: function(id, index) {
  468. let that = this,
  469. list = that.cartData.cartList,
  470. storeId = uni.getStorageSync('user_store_id');
  471. cartDel(id.toString(),storeId).then(res => {
  472. list.splice(index, 1);
  473. if (!list.length) {
  474. that.cartData.iScart = false;
  475. that.page = 1;
  476. that.loadend = false;
  477. that.tempArr = [];
  478. that.getProducts();
  479. };
  480. that.getCartNum();
  481. if (!cart) {
  482. that.getCartList(1);
  483. }
  484. })
  485. },
  486. getCartList(iSshow) {
  487. let that = this;
  488. let { store_id, tableId } = this.info;
  489. getCateList({ store_id, tableId }).then(res => {
  490. that.$set(that.cartData, 'cartList', res.data);
  491. if (res.data.length) {
  492. that.$set(that.cartData, 'iScart', iSshow ? false : !that.cartData.iScart);
  493. } else {
  494. that.$set(that.cartData, 'iScart', false);
  495. }
  496. that.getTotalPrice();
  497. });
  498. },
  499. closeList(e) {
  500. this.$set(this.cartData, 'iScart', e);
  501. },
  502. // 获取购物车商品数量
  503. getCartNum: function() {
  504. let { store_id, tableId } = this.info;
  505. getCartCount({ store_id, tableId }).then(res => {
  506. this.cartNum = res.data.count;
  507. this.setTimer('getCartNum', this.getCartNum);
  508. });
  509. },
  510. onMyEvent: function() {
  511. this.$set(this.attr, 'cartAttr', false);
  512. },
  513. /**
  514. * 默认选中属性
  515. *
  516. */
  517. DefaultSelect: function() {
  518. let productAttr = this.attr.productAttr;
  519. let value = [];
  520. for (let key in this.productValue) {
  521. if (this.productValue[key].stock > 0) {
  522. value = this.attr.productAttr.length ? key.split(",") : [];
  523. break;
  524. }
  525. }
  526. for (let i = 0; i < productAttr.length; i++) {
  527. this.$set(productAttr[i], "index", value[i]);
  528. }
  529. //sort();排序函数:数字-英文-汉字;
  530. let productSelect = this.productValue[value.join(",")];
  531. if (productSelect && productAttr.length) {
  532. this.$set(
  533. this.attr.productSelect,
  534. "store_name",
  535. this.storeName
  536. );
  537. this.$set(this.attr.productSelect, "image", productSelect.image);
  538. this.$set(this.attr.productSelect, "price", productSelect.price);
  539. this.$set(this.attr.productSelect, "stock", productSelect.stock);
  540. this.$set(this.attr.productSelect, "unique", productSelect.unique);
  541. this.$set(this.attr.productSelect, "cart_num", 1);
  542. this.$set(this.attr.productSelect, 'vip_price', productSelect.vip_price);
  543. this.$set(this, "attrValue", value.join(","));
  544. } else if (!productSelect && productAttr.length) {
  545. this.$set(
  546. this.attr.productSelect,
  547. "store_name",
  548. this.storeName
  549. );
  550. this.$set(this.attr.productSelect, "image", this.storeInfo.image);
  551. this.$set(this.attr.productSelect, "price", this.storeInfo.price);
  552. this.$set(this.attr.productSelect, "stock", 0);
  553. this.$set(this.attr.productSelect, "unique", "");
  554. this.$set(this.attr.productSelect, "cart_num", 0);
  555. this.$set(this, "attrValue", "");
  556. this.$set(this.attr.productSelect, 'vip_price', this.storeInfo.vip_price);
  557. } else if (!productSelect && !productAttr.length) {
  558. this.$set(
  559. this.attr.productSelect,
  560. "store_name",
  561. this.storeName
  562. );
  563. this.$set(this.attr.productSelect, "image", this.storeInfo.image);
  564. this.$set(this.attr.productSelect, "price", this.storeInfo.price);
  565. this.$set(this.attr.productSelect, "stock", this.storeInfo.stock);
  566. this.$set(
  567. this.attr.productSelect,
  568. "unique",
  569. this.storeInfo.unique || ""
  570. );
  571. this.$set(this.attr.productSelect, "cart_num", 1);
  572. this.$set(this, "attrValue", "");
  573. this.$set(this.attr.productSelect, 'vip_price', this.storeInfo.vip_price);
  574. }
  575. },
  576. /**
  577. * 属性变动赋值
  578. *
  579. */
  580. ChangeAttr: function(res) {
  581. let productSelect = this.productValue[res];
  582. if (productSelect && productSelect.stock > 0) {
  583. this.$set(this.attr.productSelect, "image", productSelect.image);
  584. this.$set(this.attr.productSelect, "price", productSelect.price);
  585. this.$set(this.attr.productSelect, "stock", productSelect.stock);
  586. this.$set(this.attr.productSelect, "unique", productSelect.unique);
  587. this.$set(this.attr.productSelect, 'vip_price', productSelect.vip_price);
  588. this.$set(this.attr.productSelect, "cart_num", 1);
  589. this.$set(this, "attrValue", res);
  590. } else if (productSelect && productSelect.stock == 0) {
  591. this.$set(this.attr.productSelect, "image", productSelect.image);
  592. this.$set(this.attr.productSelect, "price", productSelect.price);
  593. this.$set(this.attr.productSelect, "stock", 0);
  594. this.$set(this.attr.productSelect, "unique", "");
  595. this.$set(this.attr.productSelect, 'vip_price', productSelect.vip_price);
  596. this.$set(this.attr.productSelect, "cart_num", 0);
  597. this.$set(this, "attrValue", "");
  598. } else {
  599. this.$set(this.attr.productSelect, "image", this.storeInfo.image);
  600. this.$set(this.attr.productSelect, "price", this.storeInfo.price);
  601. this.$set(this.attr.productSelect, "stock", 0);
  602. this.$set(this.attr.productSelect, "unique", "");
  603. this.$set(this.attr.productSelect, 'vip_price', this.storeInfo.vip_price);
  604. this.$set(this.attr.productSelect, "cart_num", 0);
  605. this.$set(this, "attrValue", "");
  606. }
  607. },
  608. attrVal(val) {
  609. this.$set(this.attr.productAttr[val.indexw], 'index', this.attr.productAttr[val.indexw].attr_values[val
  610. .indexn]);
  611. },
  612. /**
  613. * 购物车手动填写
  614. *
  615. */
  616. iptCartNum: function(e) {
  617. this.$set(this.attr.productSelect, 'cart_num', e);
  618. },
  619. // 点击默认单属性购物车
  620. goCartDan(item, index) {
  621. if (!this.isLogin) {
  622. this.getIsLogin();
  623. } else {
  624. this.tempArr[index].cart_num = 1;
  625. this.$set(this, 'tempArr', this.tempArr);
  626. this.goCat(0, item.id, 1);
  627. }
  628. },
  629. // 改变单属性购物车
  630. ChangeCartNumDan(changeValue, index, item) {
  631. let num = this.tempArr[index];
  632. let stock = this.tempArr[index].stock;
  633. this.ChangeCartNum(changeValue, num, stock, 0, item.id);
  634. },
  635. // 改变多属性购物车
  636. ChangeCartNumDuo(changeValue) {
  637. //获取当前变动属性
  638. let productSelect = this.productValue[this.attrValue];
  639. //如果没有属性,赋值给商品默认库存
  640. if (productSelect === undefined && !this.attr.productAttr.length)
  641. productSelect = this.attr.productSelect;
  642. //无属性值即库存为0;不存在加减;
  643. if (productSelect === undefined) return;
  644. let stock = productSelect.stock || 0;
  645. let num = this.attr.productSelect;
  646. this.ChangeCartNum(changeValue, num, stock, 1, this.id);
  647. },
  648. // 已经加入购物车时的购物加减;
  649. ChangeCartList(changeValue, index) {
  650. let list = this.cartData.cartList;
  651. let num = list[index];
  652. let stock = list[index].trueStock;
  653. this.ChangeCartNum(changeValue, num, stock, 0, num.product_id, index, 1);
  654. if (!list.length) {
  655. this.cartData.iScart = false;
  656. this.page = 1;
  657. this.loadend = false;
  658. this.tempArr = [];
  659. this.getProducts();
  660. }
  661. },
  662. // 购物车加减计算函数
  663. ChangeCartNum(changeValue, num, stock, isDuo, id, index, cart) {
  664. if (changeValue) {
  665. num.cart_num++;
  666. if (num.cart_num > stock) {
  667. if (isDuo) {
  668. this.$set(this.attr.productSelect, "cart_num", stock ? stock : 1);
  669. this.$set(this, "cart_num", stock ? stock : 1);
  670. } else {
  671. num.cart_num = stock ? stock : 0;
  672. this.$set(this, 'tempArr', this.tempArr);
  673. this.$set(this.cartData, 'cartList', this.cartData.cartList);
  674. }
  675. return this.$util.Tips({
  676. title: "该产品没有更多库存了"
  677. });
  678. } else {
  679. if (!isDuo) {
  680. if (cart) {
  681. this.goCat(0, id, 1, 1, num.product_attr_unique);
  682. this.getTotalPrice();
  683. this.tempArr.forEach((item) => {
  684. if (item.id == id) {
  685. item.cart_num++;
  686. }
  687. })
  688. } else {
  689. this.goCat(0, id, 1);
  690. }
  691. } else {
  692. this.tempArr.forEach((item) => {
  693. if (item.id == id) {
  694. item.cart_num++;
  695. }
  696. })
  697. }
  698. }
  699. } else {
  700. num.cart_num--;
  701. if (num.cart_num == 0) {
  702. this.cartData.cartList.splice(index, 1);
  703. if (isDuo) {
  704. this.$set(this.attr.productSelect, "cart_num", 1);
  705. this.$set(this, "cart_num", 1);
  706. }
  707. }
  708. if (num.cart_num < 0) {
  709. if (isDuo) {
  710. this.$set(this.attr.productSelect, "cart_num", 1);
  711. this.$set(this, "cart_num", 1);
  712. } else {
  713. num.cart_num = 0;
  714. this.$set(this, 'tempArr', this.tempArr);
  715. this.$set(this.cartData, 'cartList', this.cartData.cartList);
  716. }
  717. } else {
  718. if (!isDuo) {
  719. if (cart) {
  720. this.goCat(0, id, 0, 1, num.product_attr_unique);
  721. this.getTotalPrice();
  722. this.tempArr.forEach((item) => {
  723. if (item.id == id) {
  724. item.cart_num--;
  725. }
  726. })
  727. } else {
  728. this.goCat(0, id, 0);
  729. }
  730. } else {
  731. this.tempArr.forEach((item) => {
  732. if (item.id == id) {
  733. item.cart_num--;
  734. }
  735. })
  736. }
  737. }
  738. }
  739. },
  740. // 多规格加入购物车;
  741. goCatNum() {
  742. this.goCat(1, this.id, 1);
  743. },
  744. /*
  745. * 加入购物车
  746. */
  747. goCat: function(duo, id, type, cart, unique) {
  748. let that = this;
  749. if (duo) {
  750. let productSelect = that.productValue[this.attrValue];
  751. //如果有属性,没有选择,提示用户选择
  752. if (
  753. that.attr.productAttr.length &&
  754. productSelect === undefined
  755. )
  756. return that.$util.Tips({
  757. title: "产品库存不足,请选择其它属性"
  758. });
  759. }
  760. let q = {
  761. productId: id,
  762. cartNum: duo ? that.attr.productSelect.cart_num : 1,
  763. isAdd: type,
  764. uniqueId: duo ? that.attr.productSelect.unique : cart ? unique : "",
  765. tableId: this.info.tableId,
  766. storeId: this.info.id,
  767. };
  768. addTableCate(q).then(res => {
  769. if (duo) {
  770. that.attr.cartAttr = false;
  771. that.$util.Tips({
  772. title: "添加购物车成功"
  773. });
  774. // that.page = 1;
  775. // that.loadend = false;
  776. that.tempArr.forEach((item, index) => {
  777. if (item.id == that.id) {
  778. let arrtStock = that.attr.productSelect.stock
  779. let objNum = parseInt(item.cart_num) + parseInt(that.attr.productSelect.cart_num);
  780. item.cart_num = objNum > arrtStock ? arrtStock : objNum
  781. }
  782. })
  783. // that.productslist();
  784. }
  785. that.getCartNum();
  786. if (!cart) {
  787. that.getCartList(1);
  788. }
  789. }).catch(err => {
  790. that.$util.Tips({
  791. title: err
  792. });
  793. });
  794. },
  795. goCartDuo(item) {
  796. if (!this.isLogin) {
  797. this.getIsLogin();
  798. } else {
  799. // uni.showLoading({
  800. // title: '加载中'
  801. // });
  802. this.storeName = item.store_name;
  803. this.getAttrs(item.id);
  804. this.$set(this, 'id', item.id);
  805. this.$set(this.attr, 'cartAttr', true);
  806. }
  807. },
  808. getIsLogin() {
  809. toLogin();
  810. },
  811. // 商品详情接口;
  812. getAttrs(id) {
  813. let that = this;
  814. getAttr(id, 0).then(res => {
  815. // uni.hideLoading();
  816. that.$set(that.attr, 'productAttr', res.data.productAttr);
  817. that.$set(that, 'productValue', res.data.productValue);
  818. that.$set(that, 'is_vip', res.data.storeInfo.is_vip);
  819. that.$set(that, 'storeInfo', res.data.storeInfo);
  820. that.DefaultSelect();
  821. })
  822. },
  823. // 去详情页
  824. goDetail(item) {
  825. goShopDetail(item, this.uid).then(res => {
  826. uni.navigateTo({
  827. url: `/pages/goods_details/index?id=${item.id}&fromType=1`
  828. });
  829. });
  830. },
  831. openTap() {
  832. this.iSlong = false
  833. },
  834. closeTap() {
  835. this.iSlong = true
  836. },
  837. // 分类数据
  838. getAllCategory: function() {
  839. let that = this;
  840. getStoreCategory().then(res => {
  841. let data = res.data;
  842. data.forEach(item => {
  843. item.children.unshift({
  844. 'id': 0,
  845. 'cate_name': '全部'
  846. })
  847. })
  848. that.categoryTitle = data[0].cate_name;
  849. that.cid = data[0].id;
  850. that.sid = 0;
  851. that.navActive = 0;
  852. that.tabClick = 0;
  853. that.categoryList = data;
  854. that.categoryErList = res.data[0].children ? res.data[0].children : [];
  855. that.page = 1;
  856. that.loadend = false;
  857. that.tempArr = [];
  858. that.getProducts();
  859. })
  860. },
  861. tapNav(index, item) {
  862. uni.pageScrollTo({
  863. duration: 0,
  864. scrollTop: 0
  865. })
  866. let list = this.categoryList[index];
  867. this.navActive = index;
  868. this.categoryTitle = list.cate_name;
  869. this.categoryErList = item.children ? item.children : [];
  870. this.tabClick = 0;
  871. this.tabLeft = 0;
  872. this.cid = list.id;
  873. this.sid = 0;
  874. this.page = 1;
  875. this.loadend = false;
  876. this.tempArr = [];
  877. this.getProducts();
  878. },
  879. // 导航栏点击
  880. longClick(index) {
  881. if (this.categoryErList.length > 3) {
  882. this.tabLeft = (index - 1) * (this.isWidth + 6) //设置下划线位置
  883. };
  884. this.tabClick = index; //设置导航点击了哪一个
  885. this.iSlong = true;
  886. this.sid = this.categoryErList[index].id;
  887. this.page = 1;
  888. this.loadend = false;
  889. this.tempArr = [];
  890. this.getProducts();
  891. },
  892. },
  893. onReachBottom: function() {
  894. this.getProducts();
  895. }
  896. }
  897. </script>
  898. <style lang="scss">
  899. /* #ifdef MP || APP-PLUS */
  900. .mp-header {
  901. z-index: 30;
  902. position: fixed;
  903. left: 0;
  904. top: 0;
  905. width: 100%;
  906. background: #fff;
  907. border-bottom: 1px solid #F0F0F0;
  908. .serch-wrapper {
  909. height: 100%;
  910. /* #ifdef MP */
  911. padding: 0 220rpx 0 53rpx;
  912. /* #endif */
  913. /* #ifdef APP-PLUS */
  914. padding: 0 50rpx 0 40rpx;
  915. /* #endif */
  916. .input {
  917. flex: 1;
  918. height: 55rpx;
  919. padding: 0 0 0 30rpx;
  920. background: #F8F8F8;
  921. color: #ADADAD;
  922. font-size: 26rpx;
  923. /* #ifdef MP */
  924. width: 70%;
  925. /* #endif */
  926. /* #ifdef APP-PLUS */
  927. width: 100%;
  928. /* #endif */
  929. border-radius: 50rpx;
  930. .iconfont {
  931. margin-right: 20rpx;
  932. }
  933. }
  934. }
  935. }
  936. /* #endif */
  937. page {
  938. background-color: #fff;
  939. }
  940. /deep/.product-window.joinCart {
  941. z-index: 999;
  942. }
  943. ::-webkit-scrollbar {
  944. width: 0;
  945. height: 0;
  946. color: transparent;
  947. display: none;
  948. }
  949. .goodCate {
  950. /deep/.mask {
  951. z-index: 99;
  952. }
  953. /deep/.attrProduct {
  954. .mask {
  955. z-index: 100;
  956. }
  957. }
  958. .header {
  959. position: fixed;
  960. background-color: #fff;
  961. top: 0;
  962. left: 0;
  963. width: 100%;
  964. z-index: 99;
  965. border-bottom: 1px solid #F0F0F0;
  966. /* #ifdef H5 */
  967. padding-top: 20rpx;
  968. /* #endif */
  969. .pageIndex {
  970. width: 68rpx;
  971. height: 68rpx;
  972. border-radius: 50%;
  973. background-color: #F7F7F7;
  974. .iconfont {
  975. color: #666666;
  976. font-size: 30rpx;
  977. }
  978. // image{
  979. // width: 29rpx;
  980. // height: 30rpx;
  981. // }
  982. }
  983. .search {
  984. width: 690rpx;
  985. height: 68rpx;
  986. border-radius: 36rpx;
  987. background-color: #F7F7F7;
  988. font-size: 26rpx;
  989. color: #cccccc;
  990. padding: 0 30rpx;
  991. box-sizing: border-box;
  992. .iconfont {
  993. font-size: 30rpx;
  994. margin-right: 18rpx;
  995. color: #666666;
  996. }
  997. }
  998. }
  999. .conter {
  1000. /* #ifdef H5 */
  1001. padding-top: 288rpx;
  1002. /* #endif */
  1003. height: 100vh;
  1004. background-color: #fff;
  1005. .aside {
  1006. position: fixed;
  1007. width: 23%;
  1008. left: 0;
  1009. bottom: 0;
  1010. /* #ifdef H5 */
  1011. top: 288rpx;
  1012. /* #endif */
  1013. background-color: #F7F7F7;
  1014. overflow-y: auto;
  1015. overflow-x: hidden;
  1016. /* #ifdef H5 */
  1017. // margin-top: 128rpx;
  1018. /* #endif */
  1019. z-index: 99;
  1020. padding-bottom: 194rpx;
  1021. .item {
  1022. height: 100rpx;
  1023. width: 100%;
  1024. font-size: 26rpx;
  1025. color: #333333;
  1026. &.on {
  1027. background-color: #FFFFFF;
  1028. width: 100%;
  1029. text-align: center;
  1030. color: var(--view-theme);
  1031. font-weight: 500;
  1032. position: relative;
  1033. &::after {
  1034. content: "";
  1035. position: absolute;
  1036. width: 6rpx;
  1037. height: 46rpx;
  1038. background: var(--view-theme);
  1039. border-radius: 0 4rpx 4rpx 0;
  1040. left: 0
  1041. }
  1042. }
  1043. }
  1044. }
  1045. .wrapper {
  1046. margin-top: 104rpx;
  1047. padding-bottom: 250rpx;
  1048. /* #ifdef H5 */
  1049. padding-bottom: 200rpx;
  1050. /* #endif */
  1051. width: 77%;
  1052. float: right;
  1053. background-color: #FFFFFF;
  1054. // padding-bottom: 240rpx;
  1055. .bgcolor {
  1056. width: 100%;
  1057. background-color: #FFFFFF;
  1058. }
  1059. // .goodsList {
  1060. // margin-top: 0 !important;
  1061. // }
  1062. .mask {
  1063. z-index: 9;
  1064. }
  1065. .longTab {
  1066. width: 65%;
  1067. position: fixed;
  1068. /* #ifdef H5 */
  1069. top: 288rpx;
  1070. /* #endif */
  1071. height: 100rpx;
  1072. z-index: 99;
  1073. background-color: #FFFFFF;
  1074. .longItem {
  1075. height: 44rpx;
  1076. display: inline-block;
  1077. line-height: 44rpx;
  1078. text-align: center;
  1079. font-size: 26rpx;
  1080. overflow: hidden;
  1081. text-overflow: ellipsis;
  1082. white-space: nowrap;
  1083. color: #333333;
  1084. background-color: #F7F7F7;
  1085. border-radius: 22rpx;
  1086. margin-left: 12rpx;
  1087. &.click {
  1088. font-weight: bold;
  1089. background-color: var(--view-theme);
  1090. color: #ffffff;
  1091. }
  1092. }
  1093. .underlineBox {
  1094. height: 3px;
  1095. width: 20%;
  1096. display: flex;
  1097. align-content: center;
  1098. justify-content: center;
  1099. transition: .5s;
  1100. .underline {
  1101. width: 33rpx;
  1102. height: 4rpx;
  1103. background-color: #FFFFFF;
  1104. }
  1105. }
  1106. }
  1107. .openList {
  1108. width: 12%;
  1109. height: 100rpx;
  1110. background-color: #FFFFFF;
  1111. line-height: 100rpx;
  1112. padding-left: 30rpx;
  1113. position: fixed;
  1114. right: 0;
  1115. /* #ifdef H5 */
  1116. top: 288rpx;
  1117. /* #endif */
  1118. z-index: 99;
  1119. .iconfont {
  1120. font-size: 22rpx;
  1121. color: #666666;
  1122. }
  1123. }
  1124. .downTab {
  1125. width: 78%;
  1126. position: fixed;
  1127. top: 0rpx;
  1128. /* #ifdef H5 */
  1129. top: 288rpx;
  1130. /* #endif */
  1131. z-index: 102;
  1132. background-color: #FFFFFF;
  1133. .title {
  1134. height: 100rpx;
  1135. font-size: 26rpx;
  1136. color: #999999;
  1137. padding-left: 20rpx;
  1138. .closeList {
  1139. width: 90rpx;
  1140. height: 100%;
  1141. line-height: 100rpx;
  1142. padding-left: 30rpx;
  1143. transform: rotate(180deg);
  1144. .iconfont {
  1145. font-size: 22rpx;
  1146. color: #666666;
  1147. }
  1148. }
  1149. }
  1150. .children {
  1151. max-height: 500rpx;
  1152. overflow-x: hidden;
  1153. overflow-y: auto;
  1154. padding-bottom: 20rpx;
  1155. .item {
  1156. height: 60rpx;
  1157. background-color: #F7F7F7;
  1158. border-radius: 30rpx;
  1159. line-height: 60rpx;
  1160. padding: 0 15rpx;
  1161. margin: 0 0 20rpx 20rpx;
  1162. width: 165rpx;
  1163. text-align: center;
  1164. &.click {
  1165. font-weight: bold;
  1166. background-color: var(--view-theme);
  1167. color: #ffffff;
  1168. }
  1169. }
  1170. }
  1171. }
  1172. .goodsList {
  1173. margin-top: 0rpx;
  1174. padding: 0 30rpx 0 20rpx;
  1175. /deep/.item {
  1176. margin-bottom: 33rpx !important;
  1177. .text {
  1178. font-size: 26rpx;
  1179. }
  1180. .bottom {
  1181. .sales {
  1182. .money {
  1183. font-size: 34rpx;
  1184. text {
  1185. font-size: 26rpx;
  1186. }
  1187. }
  1188. }
  1189. .cart {
  1190. .pictrue {
  1191. width: 50rpx;
  1192. height: 50rpx;
  1193. }
  1194. }
  1195. }
  1196. }
  1197. }
  1198. }
  1199. }
  1200. .store-address {
  1201. width: 100%;
  1202. margin-top: 15rpx;
  1203. position: relative;
  1204. padding: 12rpx 30rpx 0 30rpx;
  1205. height: 185rpx;
  1206. background-color: #fff;
  1207. .address {
  1208. font-size: 32rpx;
  1209. font-weight: 500;
  1210. color: #333333;
  1211. .name{
  1212. max-width: 400rpx;
  1213. }
  1214. .icon-xiangyou {
  1215. font-size: 24rpx;
  1216. margin-left: 10rpx;
  1217. }
  1218. }
  1219. .distance {
  1220. margin-top: 16rpx;
  1221. font-size: 24rpx;
  1222. font-weight: 400;
  1223. color: #999999;
  1224. }
  1225. .time {
  1226. margin-top: 16rpx;
  1227. font-size: 24rpx;
  1228. font-weight: 400;
  1229. color: #333333;
  1230. }
  1231. .switch {
  1232. position: absolute;
  1233. top: 15rpx;
  1234. /* #ifdef H5 */
  1235. top: 20rpx;
  1236. /* #endif */
  1237. right: 30rpx;
  1238. width: 194rpx;
  1239. height: 58rpx;
  1240. background: #F5F5F5;
  1241. border-radius: 33rpx;
  1242. .title {
  1243. width: 82rpx;
  1244. height: 100%;
  1245. line-height: 58rpx;
  1246. border-radius: 33rpx;
  1247. text-align: center;
  1248. padding-right: 20rpx;
  1249. &.onLeft {
  1250. padding-left: 20rpx;
  1251. padding-right: 0;
  1252. }
  1253. &.on {
  1254. width: 100rpx;
  1255. background-color: var(--view-theme) !important;
  1256. color: #fff;
  1257. padding: 0 !important;
  1258. }
  1259. }
  1260. }
  1261. }
  1262. .footer {
  1263. width: 100%;
  1264. position: fixed;
  1265. left: 0;
  1266. background-color: #fff;
  1267. box-shadow: 0px -3px 16px rgba(36, 12, 12, 0.05);
  1268. z-index: 100;
  1269. padding-left: 30rpx;
  1270. box-sizing: border-box;
  1271. height: 100rpx;
  1272. // #ifdef H5
  1273. bottom: 94rpx;
  1274. bottom: calc(94rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  1275. bottom: calc(94rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  1276. // #endif
  1277. // #ifndef H5
  1278. bottom: 98rpx;
  1279. bottom: calc(98rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  1280. bottom: calc(98rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  1281. // #endif
  1282. &.on {
  1283. // #ifndef H5
  1284. bottom: 0rpx;
  1285. // #endif
  1286. }
  1287. .cartIcon {
  1288. width: 80rpx;
  1289. height: 80rpx;
  1290. border-radius: 50%;
  1291. position: relative;
  1292. margin-top: -36rpx;
  1293. .iconfont {
  1294. font-size: 94rpx;
  1295. margin-top: 12rpx;
  1296. color: var(--view-theme);
  1297. }
  1298. &.noCart {
  1299. .iconfont {
  1300. color: #CBCBCB;
  1301. }
  1302. }
  1303. .num {
  1304. min-width: 14rpx;
  1305. background-color: #fff;
  1306. color: var(--view-theme);
  1307. border-radius: 15px;
  1308. position: absolute;
  1309. right: -10rpx;
  1310. top: 20rpx;
  1311. font-size: 20rpx;
  1312. padding: 0 10rpx;
  1313. border: 1px solid var(--view-theme);
  1314. }
  1315. }
  1316. .money {
  1317. font-size: 26rpx;
  1318. font-weight: bold;
  1319. color: var(--view-priceColor);
  1320. margin-right: 34rpx;
  1321. .num {
  1322. font-size: 34rpx;
  1323. }
  1324. }
  1325. .bnt {
  1326. width: 192rpx;
  1327. height: 76rpx;
  1328. background-color: var(--view-theme);
  1329. border-radius: 46px;
  1330. line-height: 76rpx;
  1331. text-align: center;
  1332. color: #fff;
  1333. font-size: 28rpx;
  1334. margin-right: 30rpx;
  1335. }
  1336. .noCart {
  1337. .money {
  1338. color: #CBCBCB;
  1339. }
  1340. .bnt {
  1341. background-color: #CBCBCB;
  1342. }
  1343. }
  1344. }
  1345. }
  1346. </style>