goods_cate2.vue 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087
  1. <template>
  2. <view class="goodCate">
  3. <!-- <view>
  4. <scroll-view scroll-y="true" class="scroll-Y"> -->
  5. <view class="header acea-row row-center-wrapper">
  6. <view class="pageIndex" hover-class="none" @click="jumpIndex">
  7. <text class="iconfont icon-shouye3"></text>
  8. </view>
  9. <navigator url="/pages/goods/goods_search/index" class="search acea-row row-center-wrapper" hover-class="none">
  10. <text class="iconfont icon-xiazai5"></text>
  11. {{ $t(`搜索商品名称`) }}
  12. </navigator>
  13. </view>
  14. <view class="conter">
  15. <view class="aside">
  16. <scroll-view scroll-y="true" scroll-with-animation="true" style="height: calc(100% - 100rpx)">
  17. <view class="item acea-row row-center-wrapper" :class="index == navActive ? 'on' : ''" v-for="(item, index) in categoryList" :key="index" @click="tapNav(index, item)">
  18. <text>{{ $t(item.cate_name) }}</text>
  19. </view>
  20. </scroll-view>
  21. </view>
  22. <view class="wrapper">
  23. <view class="bgcolor" v-if="iSlong">
  24. <view class="longTab acea-row row-middle">
  25. <scroll-view scroll-x="true" style="white-space: nowrap; display: flex; height: 44rpx" scroll-with-animation :scroll-left="tabLeft" show-scrollbar="true">
  26. <view
  27. class="longItem"
  28. :style="'width:' + isWidth + 'px'"
  29. :class="index === tabClick ? 'click' : ''"
  30. v-for="(item, index) in categoryErList"
  31. :key="index"
  32. @click="longClick(index)"
  33. >
  34. {{ $t(item.cate_name) }}
  35. </view>
  36. </scroll-view>
  37. </view>
  38. <view class="openList" @click="openTap"><text class="iconfont icon-xiala"></text></view>
  39. </view>
  40. <view v-else>
  41. <view class="downTab">
  42. <view class="title acea-row row-between-wrapper">
  43. <view>{{ categoryTitle }}</view>
  44. <view class="closeList" @click="closeTap"><text class="iconfont icon-xiala"></text></view>
  45. </view>
  46. <view class="children">
  47. <view class="acea-row row-middle">
  48. <view class="item line1" :class="index === tabClick ? 'click' : ''" v-for="(item, index) in categoryErList" :key="index" @click="longClick(index)">
  49. {{ $t(item.cate_name) }}
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. <view class="mask" @click="closeTap"></view>
  55. </view>
  56. <scroll-view
  57. scroll-y="true"
  58. scroll-with-animation="true"
  59. :scroll-top="scrollTop"
  60. @scroll="scroll"
  61. style="height: calc(100vh - 324rpx)"
  62. :lower-threshold="50"
  63. @scrolltolower="productslist"
  64. >
  65. <goodList
  66. ref="d_goodClass"
  67. :tempArr="tempArr"
  68. :isLogin="isLogin"
  69. @gocartduo="goCartDuo"
  70. @gocartdan="goCartDan"
  71. @ChangeCartNumDan="ChangeCartNumDan"
  72. @detail="goDetail"
  73. ></goodList>
  74. <view class="loadingicon acea-row row-center-wrapper">
  75. <text class="loading iconfont icon-jiazai" :hidden="loading == false"></text>
  76. {{ loadTitle }}
  77. </view>
  78. </scroll-view>
  79. </view>
  80. </view>
  81. <view class="footer acea-row row-between-wrapper">
  82. <view class="cartIcon acea-row row-center-wrapper" @click="getCartList(0)" v-if="cartCount">
  83. <view class="iconfont icon-gouwuche-yangshi2"></view>
  84. <view class="num">{{ cartCount }}</view>
  85. </view>
  86. <view class="cartIcon acea-row row-center-wrapper noCart" v-else>
  87. <view class="iconfont icon-gouwuche-yangshi2"></view>
  88. </view>
  89. <view class="money acea-row row-middle">
  90. <view>
  91. {{ $t(`¥`) }}
  92. <text class="num">{{ totalPrice }}</text>
  93. </view>
  94. <view class="bnt" @click="subOrder">{{ $t(`去付款`) }}</view>
  95. </view>
  96. </view>
  97. <cartList :cartData="cartData" @closeList="closeList" @ChangeCartNumDan="ChangeCartList" @ChangeSubDel="ChangeSubDel" @ChangeOneDel="ChangeOneDel"></cartList>
  98. <productWindow
  99. :attr="attr"
  100. :isShow="1"
  101. :iSplus="1"
  102. :iScart="1"
  103. :minQty="storeInfo.min_qty"
  104. @myevent="onMyEvent"
  105. @ChangeAttr="ChangeAttr"
  106. @ChangeCartNum="ChangeCartNumDuo"
  107. @attrVal="attrVal"
  108. @iptCartNum="iptCartNum"
  109. @goCat="goCatNum"
  110. id="product-window"
  111. :is_vip="is_vip"
  112. ></productWindow>
  113. <!-- </scroll-view>
  114. </view> -->
  115. </view>
  116. </template>
  117. <script>
  118. import { getCategoryList, getProductslist, getAttr, postCartNum } from '@/api/store.js';
  119. import { vcartList, getCartCounts, cartDel } from '@/api/order.js';
  120. import productWindow from '@/components/productWindow';
  121. import goodList from '@/components/catGoodList';
  122. import cartList from '@/components/cartList';
  123. import { mapGetters } from 'vuex';
  124. import { goShopDetail } from '@/libs/order.js';
  125. import { toLogin } from '@/libs/login.js';
  126. export default {
  127. computed: mapGetters(['isLogin', 'uid']),
  128. components: {
  129. productWindow,
  130. goodList,
  131. cartList
  132. },
  133. data() {
  134. return {
  135. categoryList: [],
  136. navActive: 0,
  137. categoryTitle: '',
  138. categoryErList: [],
  139. tabLeft: 0,
  140. scrollTop: 0,
  141. old: {
  142. scrollTop: 0
  143. },
  144. isWidth: 0, //每个导航栏占位
  145. tabClick: 0, //导航栏被点击
  146. iSlong: true,
  147. tempArr: [],
  148. loading: false,
  149. loadend: false,
  150. loadTitle: this.$t(`加载更多`),
  151. page: 1,
  152. limit: 10,
  153. cid: 0, //一级分类
  154. sid: 0, //二级分类
  155. isAuto: false, //没有授权的不会自动授权
  156. isShowAuth: false, //是否隐藏授权
  157. attr: {
  158. cartAttr: false,
  159. productAttr: [],
  160. productSelect: {}
  161. },
  162. productValue: [],
  163. attrValue: '', //已选属性
  164. storeName: '', //多属性产品名称
  165. id: 0,
  166. cartData: {
  167. cartList: [],
  168. iScart: false
  169. },
  170. cartCount: 0,
  171. totalPrice: 0.0,
  172. is_vip: 0, //是否是会员
  173. cart_num: 0,
  174. storeInfo: {}
  175. };
  176. },
  177. mounted() {
  178. let that = this;
  179. // 获取设备宽度
  180. uni.getSystemInfo({
  181. success(e) {
  182. that.isWidth = e.windowWidth / 5;
  183. }
  184. });
  185. if (!that.categoryList.length) {
  186. this.getAllCategory(1);
  187. this.getCartNum();
  188. this.getCartList(1);
  189. }
  190. uni.$on('uploadCatData', () => {
  191. this.getAllCategory(1);
  192. this.getCartNum();
  193. });
  194. },
  195. methods: {
  196. jumpIndex() {
  197. this.$emit('jumpIndex');
  198. },
  199. // 生成订单;
  200. subOrder: function () {
  201. let that = this,
  202. list = that.cartData.cartList,
  203. ids = [];
  204. if (list.length) {
  205. list.forEach((item) => {
  206. ids.push(item.id);
  207. });
  208. uni.navigateTo({
  209. url: '/pages/goods/order_confirm/index?cartId=' + ids.join(',')
  210. });
  211. that.cartData.iScart = false;
  212. } else {
  213. return that.$util.Tips({
  214. title: this.$t(`请选择产品`)
  215. });
  216. }
  217. },
  218. // 计算总价;
  219. getTotalPrice: function () {
  220. let that = this,
  221. list = that.cartData.cartList,
  222. totalPrice = 0.0;
  223. list.forEach((item) => {
  224. if (item.attrStatus && item.status) {
  225. totalPrice = that.$util.$h.Add(totalPrice, that.$util.$h.Mul(item.cart_num, item.truePrice));
  226. }
  227. });
  228. that.$set(that, 'totalPrice', totalPrice);
  229. },
  230. ChangeSubDel: function (event) {
  231. let that = this,
  232. list = that.cartData.cartList,
  233. ids = [];
  234. list.forEach((item) => {
  235. ids.push(item.id);
  236. });
  237. cartDel(ids.join(',')).then((res) => {
  238. that.$set(that.cartData, 'cartList', []);
  239. that.cartData.iScart = false;
  240. that.totalPrice = 0.0;
  241. that.page = 1;
  242. that.loadend = false;
  243. that.tempArr = [];
  244. that.productslist();
  245. that.getCartNum();
  246. });
  247. },
  248. ChangeOneDel: function (id, index) {
  249. let that = this,
  250. list = that.cartData.cartList;
  251. cartDel(id.toString()).then((res) => {
  252. list.splice(index, 1);
  253. if (!list.length) {
  254. that.cartData.iScart = false;
  255. that.page = 1;
  256. that.loadend = false;
  257. that.tempArr = [];
  258. that.productslist();
  259. }
  260. that.getCartNum();
  261. });
  262. },
  263. getCartList(iSshow) {
  264. let that = this;
  265. vcartList().then((res) => {
  266. that.$set(that.cartData, 'cartList', res.data);
  267. if (res.data.length) {
  268. that.$set(that.cartData, 'iScart', iSshow ? false : !that.cartData.iScart);
  269. } else {
  270. that.$set(that.cartData, 'iScart', false);
  271. }
  272. that.getTotalPrice();
  273. });
  274. },
  275. closeList(e) {
  276. this.$set(this.cartData, 'iScart', e);
  277. this.page = 1;
  278. this.loadend = false;
  279. this.tempArr = [];
  280. this.productslist();
  281. },
  282. getCartNum() {
  283. let that = this;
  284. getCartCounts().then((res) => {
  285. that.cartCount = res.data.count;
  286. that.$refs.d_goodClass.addIng = false;
  287. });
  288. },
  289. onMyEvent: function () {
  290. this.$set(this.attr, 'cartAttr', false);
  291. },
  292. /**
  293. * 默认选中属性
  294. *
  295. */
  296. DefaultSelect: function () {
  297. let productAttr = this.attr.productAttr;
  298. let value = [];
  299. for (let key in this.productValue) {
  300. if (this.productValue[key].stock > 0) {
  301. value = this.attr.productAttr.length ? key.split(',') : [];
  302. break;
  303. }
  304. }
  305. for (let i = 0; i < productAttr.length; i++) {
  306. this.$set(productAttr[i], 'index', value[i]);
  307. }
  308. //sort();排序函数:数字-英文-汉字;
  309. let productSelect = this.productValue[value.join(',')];
  310. if (productSelect && productAttr.length) {
  311. this.$set(this.attr.productSelect, 'store_name', this.storeName);
  312. this.$set(this.attr.productSelect, 'image', productSelect.image);
  313. this.$set(this.attr.productSelect, 'price', productSelect.price);
  314. this.$set(this.attr.productSelect, 'stock', productSelect.stock);
  315. this.$set(this.attr.productSelect, 'unique', productSelect.unique);
  316. this.$set(this.attr.productSelect, 'cart_num', this.storeInfo.min_qty);
  317. this.$set(this.attr.productSelect, 'vip_price', productSelect.vip_price);
  318. this.$set(this, 'attrValue', value.join(','));
  319. } else if (!productSelect && productAttr.length) {
  320. this.$set(this.attr.productSelect, 'store_name', this.storeName);
  321. this.$set(this.attr.productSelect, 'image', this.storeInfo.image);
  322. this.$set(this.attr.productSelect, 'price', this.storeInfo.price);
  323. this.$set(this.attr.productSelect, 'stock', 0);
  324. this.$set(this.attr.productSelect, 'unique', '');
  325. this.$set(this.attr.productSelect, 'cart_num', 0);
  326. this.$set(this.attr.productSelect, 'vip_price', this.storeInfo.vip_price);
  327. this.$set(this, 'attrValue', '');
  328. } else if (!productSelect && !productAttr.length) {
  329. this.$set(this.attr.productSelect, 'store_name', this.storeName);
  330. this.$set(this.attr.productSelect, 'image', this.storeInfo.image);
  331. this.$set(this.attr.productSelect, 'price', this.storeInfo.price);
  332. this.$set(this.attr.productSelect, 'stock', this.storeInfo.stock);
  333. this.$set(this.attr.productSelect, 'unique', this.storeInfo.unique || '');
  334. this.$set(this.attr.productSelect, 'cart_num', this.storeInfo.min_qty);
  335. this.$set(this, 'attrValue', '');
  336. this.$set(this.attr.productSelect, 'vip_price', this.storeInfo.vip_price);
  337. }
  338. },
  339. /**
  340. * 属性变动赋值
  341. *
  342. */
  343. ChangeAttr: function (res) {
  344. let productSelect = this.productValue[res];
  345. if (productSelect && productSelect.stock > 0) {
  346. this.$set(this.attr.productSelect, 'image', productSelect.image);
  347. this.$set(this.attr.productSelect, 'price', productSelect.price);
  348. this.$set(this.attr.productSelect, 'stock', productSelect.stock);
  349. this.$set(this.attr.productSelect, 'unique', productSelect.unique);
  350. this.$set(this.attr.productSelect, 'vip_price', productSelect.vip_price);
  351. this.$set(this.attr.productSelect, 'cart_num', this.storeInfo.min_qty);
  352. this.$set(this, 'attrValue', res);
  353. } else if (productSelect && productSelect.stock == 0) {
  354. this.$set(this.attr.productSelect, 'image', productSelect.image);
  355. this.$set(this.attr.productSelect, 'price', productSelect.price);
  356. this.$set(this.attr.productSelect, 'stock', 0);
  357. this.$set(this.attr.productSelect, 'unique', '');
  358. this.$set(this.attr.productSelect, 'vip_price', productSelect.vip_price);
  359. this.$set(this.attr.productSelect, 'cart_num', 0);
  360. this.$set(this, 'attrValue', '');
  361. } else {
  362. this.$set(this.attr.productSelect, 'image', this.storeInfo.image);
  363. this.$set(this.attr.productSelect, 'price', this.storeInfo.price);
  364. this.$set(this.attr.productSelect, 'stock', 0);
  365. this.$set(this.attr.productSelect, 'unique', '');
  366. this.$set(this.attr.productSelect, 'vip_price', this.storeInfo.vip_price);
  367. this.$set(this.attr.productSelect, 'cart_num', 0);
  368. this.$set(this, 'attrValue', '');
  369. }
  370. },
  371. attrVal(val) {
  372. this.$set(this.attr.productAttr[val.indexw], 'index', this.attr.productAttr[val.indexw].attr_values[val.indexn]);
  373. },
  374. /**
  375. * 购物车手动填写
  376. *
  377. */
  378. iptCartNum: function (e) {
  379. // this.$set(this.attr.productSelect, 'cart_num', e);
  380. if (e) {
  381. let number = this.storeInfo.min_qty;
  382. if (Number.isInteger(parseInt(e)) && parseInt(e) >= this.storeInfo.min_qty) {
  383. number = parseInt(e);
  384. }
  385. this.$nextTick((e) => {
  386. this.$set(this.attr.productSelect, 'cart_num', e < 0 ? this.storeInfo.min_qty : number);
  387. });
  388. }
  389. },
  390. onLoadFun() {},
  391. // 产品列表
  392. productslist: function () {
  393. let that = this;
  394. if (that.loadend) return;
  395. if (that.loading) return;
  396. that.loading = true;
  397. that.loadTitle = '';
  398. getProductslist({
  399. page: that.page,
  400. limit: that.limit,
  401. type: 1,
  402. cid: that.cid,
  403. sid: that.sid
  404. })
  405. .then((res) => {
  406. let list = res.data,
  407. loadend = list.length < that.limit;
  408. that.tempArr = that.$util.SplitArray(list, that.tempArr);
  409. that.$set(that, 'tempArr', that.tempArr);
  410. that.loading = false;
  411. that.loadend = loadend;
  412. that.loadTitle = loadend ? that.$t(`没有更多内容啦~`) : that.$t(`加载更多`);
  413. that.page == 1 && this.goTop();
  414. that.page = that.page + 1;
  415. })
  416. .catch((err) => {
  417. (that.loading = false), (that.loadTitle = that.$t(`加载更多`));
  418. });
  419. },
  420. scroll(e) {
  421. this.old.scrollTop = e.detail.scrollTop;
  422. },
  423. goTop(e) {
  424. // 解决view层不同步的问题
  425. this.scrollTop = this.old.scrollTop;
  426. this.$nextTick(() => {
  427. this.scrollTop = 0;
  428. });
  429. },
  430. // 改变单属性购物车
  431. ChangeCartNumDan(changeValue, index, item) {
  432. let num = this.tempArr[index];
  433. let stock = this.tempArr[index].stock;
  434. this.ChangeCartNum(changeValue, num, stock, 0, item.id);
  435. },
  436. // 改变多属性购物车
  437. ChangeCartNumDuo(changeValue) {
  438. //获取当前变动属性
  439. let productSelect = this.productValue[this.attrValue];
  440. //如果没有属性,赋值给商品默认库存
  441. if (productSelect === undefined && !this.attr.productAttr.length) productSelect = this.attr.productSelect;
  442. //无属性值即库存为0;不存在加减;
  443. if (productSelect === undefined) return;
  444. let stock = productSelect.stock || 0;
  445. let num = this.attr.productSelect;
  446. this.ChangeCartNum(changeValue, num, stock, 1, this.id);
  447. },
  448. // 已经加入购物车时的购物加减;
  449. ChangeCartList(changeValue, index) {
  450. let list = this.cartData.cartList;
  451. let num = list[index];
  452. let stock = list[index].trueStock;
  453. this.ChangeCartNum(changeValue, num, stock, 0, num.product_id, index, 1);
  454. if (!list.length) {
  455. this.cartData.iScart = false;
  456. this.page = 1;
  457. this.loadend = false;
  458. this.tempArr = [];
  459. this.productslist();
  460. }
  461. },
  462. // 购物车加减计算函数
  463. ChangeCartNum(changeValue, num, stock, isDuo, id, index, cart) {
  464. this.$refs.d_goodClass.addIng = false;
  465. if (changeValue) {
  466. num.cart_num++;
  467. if (num.cart_num > stock) {
  468. if (isDuo) {
  469. this.$set(this.attr.productSelect, 'cart_num', stock ? stock : 1);
  470. this.$set(this, 'cart_num', stock ? stock : 1);
  471. } else {
  472. num.cart_num = stock ? stock : 0;
  473. this.$set(this, 'tempArr', this.tempArr);
  474. this.$set(this.cartData, 'cartList', this.cartData.cartList);
  475. }
  476. return this.$util.Tips({
  477. title: this.$t(`该产品没有更多库存了`)
  478. });
  479. } else {
  480. if (!isDuo) {
  481. if (cart) {
  482. this.goCat(0, id, 1, 1, num.product_attr_unique, num);
  483. this.getTotalPrice();
  484. } else {
  485. this.goCat(0, id, 1, 0, false, num);
  486. }
  487. }
  488. }
  489. } else {
  490. num.cart_num--;
  491. if (num.cart_num < num.min_qty) {
  492. this.cartData.cartList.splice(index, 1);
  493. num.cart_num = 0;
  494. } else if (num.cart_num == 0) {
  495. this.cartData.cartList.splice(index, 1);
  496. }
  497. if (num.cart_num < 0) {
  498. if (isDuo) {
  499. this.$set(this.attr.productSelect, 'cart_num', this.storeInfo.min_qty);
  500. this.$set(this, 'cart_num', this.storeInfo.min_qty);
  501. } else {
  502. num.cart_num = 0;
  503. this.$set(this, 'tempArr', this.tempArr);
  504. this.$set(this.cartData, 'cartList', this.cartData.cartList);
  505. }
  506. } else {
  507. if (!isDuo) {
  508. if (cart) {
  509. this.goCat(0, id, 0, 1, num.product_attr_unique, num);
  510. this.getTotalPrice();
  511. } else {
  512. this.goCat(0, id, 0, 0, false, num);
  513. }
  514. }
  515. }
  516. }
  517. },
  518. // 多规格加入购物车;
  519. goCatNum() {
  520. this.goCat(1, this.id, 1);
  521. },
  522. /*
  523. * 加入购物车
  524. */
  525. goCat: function (duo, id, type, cart, unique, data) {
  526. let that = this;
  527. if (duo) {
  528. let productSelect = that.productValue[this.attrValue];
  529. //如果有属性,没有选择,提示用户选择
  530. if (that.attr.productAttr.length && productSelect === undefined) {
  531. return that.$util.Tips({
  532. title: that.$t(`该产品没有更多库存了`)
  533. });
  534. }
  535. if (that.attr.productSelect.cart_num <= 0) {
  536. return that.$util.Tips({
  537. title: that.$t(`最少添加 1 件商品`)
  538. });
  539. }
  540. }
  541. let q = {
  542. product_id: id,
  543. type: type,
  544. unique: duo ? that.attr.productSelect.unique : cart ? unique : ''
  545. };
  546. data && data.cart_num < data.min_qty ? (q.num = data.min_qty) : '';
  547. if (!that.cartData.iScart) q.num = duo ? that.attr.productSelect.cart_num : this.storeInfo.min_qty;
  548. postCartNum(q)
  549. .then(function (res) {
  550. if (duo) {
  551. that.attr.cartAttr = false;
  552. that.$util.Tips({
  553. title: that.$t(`添加成功`)
  554. });
  555. // that.page = 1;
  556. // that.loadend = false;
  557. that.tempArr.forEach((item, index) => {
  558. if (item.id == that.id) {
  559. let arrtStock = that.attr.productSelect.stock;
  560. let objNum = parseInt(item.cart_num) + parseInt(that.attr.productSelect.cart_num);
  561. item.cart_num = objNum > arrtStock ? arrtStock : objNum;
  562. }
  563. });
  564. // that.productslist();
  565. }
  566. that.getCartNum();
  567. if (!cart) {
  568. that.getCartList(1);
  569. }
  570. })
  571. .catch((err) => {
  572. return that.$util.Tips({
  573. title: err
  574. });
  575. });
  576. },
  577. // 点击默认单属性购物车
  578. goCartDan(item, index) {
  579. if (!this.isLogin) {
  580. this.getIsLogin();
  581. } else {
  582. if (!item.cart_button) {
  583. goShopDetail(item, this.uid).then((res) => {
  584. uni.navigateTo({
  585. url: `/pages/goods_details/index?id=${item.id}`
  586. });
  587. });
  588. return;
  589. }
  590. item.cart_num = item.min_qty;
  591. this.$set(this, 'tempArr', this.tempArr);
  592. this.goCat(0, item.id, 1);
  593. }
  594. },
  595. goCartDuo(item) {
  596. if (!this.isLogin) {
  597. this.getIsLogin();
  598. } else {
  599. if (!item.cart_button) {
  600. goShopDetail(item, this.uid).then((res) => {
  601. uni.navigateTo({
  602. url: `/pages/goods_details/index?id=${item.id}`
  603. });
  604. });
  605. return;
  606. }
  607. uni.showLoading({
  608. title: this.$t(`正在加载中`)
  609. });
  610. this.storeName = item.store_name;
  611. this.getAttrs(item.id);
  612. this.$set(this, 'id', item.id);
  613. this.$set(this.attr, 'cartAttr', true);
  614. }
  615. },
  616. getIsLogin() {
  617. toLogin();
  618. },
  619. // 商品详情接口;
  620. getAttrs(id) {
  621. let that = this;
  622. getAttr(id, 0).then((res) => {
  623. uni.hideLoading();
  624. that.$set(that.attr, 'productAttr', res.data.productAttr);
  625. that.$set(that, 'productValue', res.data.productValue);
  626. that.$set(that, 'is_vip', res.data.storeInfo.is_vip);
  627. that.$set(that, 'storeInfo', res.data.storeInfo);
  628. that.DefaultSelect();
  629. });
  630. },
  631. // 去详情页
  632. goDetail(item) {
  633. goShopDetail(item, this.uid).then((res) => {
  634. uni.navigateTo({
  635. url: `/pages/goods_details/index?id=${item.id}`
  636. });
  637. });
  638. },
  639. openTap() {
  640. this.iSlong = false;
  641. },
  642. closeTap() {
  643. this.iSlong = true;
  644. },
  645. getAllCategory: function (type) {
  646. let that = this;
  647. if (type || !uni.getStorageSync('CAT2_DATA')) {
  648. getCategoryList().then((res) => {
  649. uni.setStorageSync('CAT2_DATA', res.data);
  650. let data = res.data;
  651. data.forEach((item) => {
  652. item.children.unshift({
  653. id: 0,
  654. cate_name: that.$t(`全部`)
  655. });
  656. });
  657. that.categoryTitle = data[0].cate_name;
  658. that.cid = data[0].id;
  659. that.sid = 0;
  660. that.navActive = 0;
  661. that.tabClick = 0;
  662. that.categoryList = data;
  663. that.page = 1;
  664. that.loadend = false;
  665. that.tempArr = [];
  666. that.categoryErList = res.data[0].children ? res.data[0].children : [];
  667. that.productslist();
  668. });
  669. } else {
  670. let data = uni.getStorageSync('CAT2_DATA');
  671. data.forEach((item) => {
  672. item.children.unshift({
  673. id: 0,
  674. cate_name: that.$t(`全部`)
  675. });
  676. });
  677. if (!that.cid) {
  678. that.categoryTitle = data[0].cate_name;
  679. that.cid = data[0].id;
  680. that.sid = 0;
  681. that.navActive = 0;
  682. that.tabClick = 0;
  683. that.categoryList = data;
  684. that.categoryErList = data[0].children ? data[0].children : [];
  685. that.page = 1;
  686. that.loadend = false;
  687. that.tempArr = [];
  688. }
  689. that.productslist();
  690. }
  691. },
  692. tapNav(index, item) {
  693. let list = this.categoryList[index];
  694. this.navActive = index;
  695. this.categoryTitle = list.cate_name;
  696. this.categoryErList = item.children ? item.children : [];
  697. this.tabClick = 0;
  698. this.tabLeft = 0;
  699. this.cid = list.id;
  700. this.sid = 0;
  701. this.page = 1;
  702. this.loadend = false;
  703. this.tempArr = [];
  704. this.productslist();
  705. },
  706. // 导航栏点击
  707. longClick(index) {
  708. if (this.categoryErList.length > 3) {
  709. this.tabLeft = (index - 1) * (this.isWidth + 6); //设置下划线位置
  710. }
  711. this.tabClick = index; //设置导航点击了哪一个
  712. this.iSlong = true;
  713. this.sid = this.categoryErList[index].id;
  714. this.page = 1;
  715. this.loadend = false;
  716. this.tempArr = [];
  717. this.productslist();
  718. }
  719. },
  720. onReachBottom() {
  721. this.productslist();
  722. }
  723. };
  724. </script>
  725. <style lang="scss">
  726. .scroll-Y {
  727. height: 100vh;
  728. }
  729. page {
  730. background-color: #fff;
  731. }
  732. /deep/.product-window.joinCart {
  733. z-index: 999;
  734. }
  735. ::-webkit-scrollbar {
  736. width: 0;
  737. height: 0;
  738. color: transparent;
  739. display: none;
  740. }
  741. .goodCate {
  742. .mask {
  743. z-index: 99;
  744. }
  745. /deep/.attrProduct {
  746. .mask {
  747. z-index: 100;
  748. }
  749. }
  750. .header {
  751. position: fixed;
  752. height: 128rpx;
  753. background-color: #fff;
  754. top: 0;
  755. left: 0;
  756. width: 100%;
  757. z-index: 99;
  758. border-bottom: 1px solid #f0f0f0;
  759. .pageIndex {
  760. width: 68rpx;
  761. height: 68rpx;
  762. border-radius: 50%;
  763. background-color: var(--view-theme);
  764. text-align: center;
  765. line-height: 68rpx;
  766. .iconfont {
  767. color: #fff;
  768. font-size: 30rpx;
  769. }
  770. }
  771. .search {
  772. width: 600rpx;
  773. height: 68rpx;
  774. border-radius: 36rpx;
  775. background-color: #f8f8f8;
  776. font-size: 26rpx;
  777. color: #adadad;
  778. margin-left: 22rpx;
  779. .iconfont {
  780. font-size: 30rpx;
  781. margin: 4rpx 16rpx 0 0;
  782. }
  783. }
  784. }
  785. .conter {
  786. margin-top: 128rpx;
  787. // height: 100vh;
  788. background-color: #fff;
  789. .aside {
  790. position: fixed;
  791. width: 23%;
  792. left: 0;
  793. bottom: 100rpx;
  794. top: 0;
  795. background-color: #f7f7f7;
  796. overflow-y: auto;
  797. overflow-x: hidden;
  798. margin-top: 128rpx;
  799. z-index: 99;
  800. .item {
  801. height: 100rpx;
  802. width: 100%;
  803. font-size: 26rpx;
  804. color: #424242;
  805. &.on {
  806. background-color: #fff;
  807. width: 100%;
  808. text-align: center;
  809. color: var(--view-theme);
  810. font-weight: 500;
  811. position: relative;
  812. &::after {
  813. content: '';
  814. position: absolute;
  815. width: 6rpx;
  816. height: 46rpx;
  817. background: var(--view-theme);
  818. border-radius: 0 4rpx 4rpx 0;
  819. left: 0;
  820. }
  821. }
  822. }
  823. }
  824. .wrapper {
  825. margin-top: 104rpx;
  826. width: 77%;
  827. float: right;
  828. background-color: #fff;
  829. .bgcolor {
  830. width: 100%;
  831. background-color: #fff;
  832. }
  833. .goodsList {
  834. margin-top: 0 !important;
  835. }
  836. .mask {
  837. z-index: 9;
  838. }
  839. .longTab {
  840. width: 65%;
  841. position: fixed;
  842. top: 0;
  843. margin-top: 128rpx;
  844. height: 100rpx;
  845. z-index: 99;
  846. background-color: #fff;
  847. .longItem {
  848. height: 44rpx;
  849. display: inline-block;
  850. line-height: 44rpx;
  851. text-align: center;
  852. font-size: 26rpx;
  853. overflow: hidden;
  854. text-overflow: ellipsis;
  855. white-space: nowrap;
  856. color: #989898;
  857. background-color: #f7f7f7;
  858. border-radius: 22rpx;
  859. margin-left: 12rpx;
  860. &.click {
  861. font-weight: bold;
  862. background-color: var(--view-minorColorT);
  863. color: var(--view-theme);
  864. }
  865. }
  866. .underlineBox {
  867. height: 3px;
  868. width: 20%;
  869. display: flex;
  870. align-content: center;
  871. justify-content: center;
  872. transition: 0.5s;
  873. .underline {
  874. width: 33rpx;
  875. height: 4rpx;
  876. background-color: white;
  877. }
  878. }
  879. }
  880. .openList {
  881. width: 12%;
  882. height: 100rpx;
  883. background-color: #fff;
  884. line-height: 100rpx;
  885. padding-left: 30rpx;
  886. position: fixed;
  887. right: 0;
  888. top: 128rpx;
  889. z-index: 99;
  890. .iconfont {
  891. font-size: 22rpx;
  892. color: #989898;
  893. }
  894. }
  895. .downTab {
  896. width: 77%;
  897. position: fixed;
  898. top: 0;
  899. margin-top: 128rpx;
  900. z-index: 99;
  901. background-color: #fff;
  902. right: 0;
  903. .title {
  904. height: 100rpx;
  905. font-size: 26rpx;
  906. color: #adadad;
  907. padding-left: 20rpx;
  908. .closeList {
  909. width: 90rpx;
  910. height: 100%;
  911. line-height: 100rpx;
  912. padding-left: 30rpx;
  913. transform: rotate(180deg);
  914. .iconfont {
  915. font-size: 22rpx;
  916. color: #989898;
  917. }
  918. }
  919. }
  920. .children {
  921. max-height: 500rpx;
  922. overflow-x: hidden;
  923. overflow-y: auto;
  924. padding-bottom: 20rpx;
  925. .item {
  926. height: 60rpx;
  927. background-color: #f7f7f7;
  928. border-radius: 30rpx;
  929. line-height: 60rpx;
  930. padding: 0 15rpx;
  931. margin: 0 0 20rpx 20rpx;
  932. width: 165rpx;
  933. text-align: center;
  934. &.click {
  935. font-weight: bold;
  936. background-color: var(--view-minorColorT);
  937. color: var(--view-theme);
  938. }
  939. }
  940. }
  941. }
  942. .goodsList {
  943. margin-top: 228rpx;
  944. padding: 0 30rpx 0 20rpx;
  945. /deep/.item {
  946. margin-bottom: 33rpx !important;
  947. .pictrue {
  948. // height: 216rpx;
  949. }
  950. .text {
  951. font-size: 26rpx;
  952. }
  953. .bottom {
  954. .sales {
  955. .money {
  956. font-size: 34rpx;
  957. text {
  958. font-size: 26rpx;
  959. }
  960. }
  961. }
  962. .cart {
  963. .pictrue {
  964. width: 50rpx;
  965. height: 50rpx;
  966. }
  967. }
  968. }
  969. }
  970. }
  971. }
  972. }
  973. .footer {
  974. position: fixed;
  975. left: 0;
  976. bottom: 0;
  977. width: 100%;
  978. background-color: #fff;
  979. box-shadow: 0px -3rpx 16rpx rgba(36, 12, 12, 0.05);
  980. z-index: 101;
  981. padding: 12rpx 30rpx;
  982. box-sizing: border-box;
  983. padding-bottom: calc(12rpx + constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  984. padding-bottom: calc(12rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  985. .cartIcon {
  986. width: 96rpx;
  987. height: 96rpx;
  988. border-radius: 50%;
  989. position: relative;
  990. margin-top: -36rpx;
  991. .iconfont {
  992. font-size: 115rpx;
  993. margin-top: -5px;
  994. color: var(--view-theme);
  995. }
  996. &.noCart {
  997. .iconfont {
  998. color: #cbcbcb;
  999. }
  1000. }
  1001. .num {
  1002. background-color: var(--view-priceColor);
  1003. min-width: 12rpx;
  1004. color: #fff;
  1005. border-radius: 15px;
  1006. position: absolute;
  1007. right: -6rpx;
  1008. top: -10rpx;
  1009. font-size: 22rpx;
  1010. padding: 0 10rpx;
  1011. height: 34rpx;
  1012. line-height: 34rpx;
  1013. }
  1014. }
  1015. .money {
  1016. color: var(--view-priceColor);
  1017. font-size: 28rpx;
  1018. font-weight: bold;
  1019. .num {
  1020. font-size: 42rpx;
  1021. }
  1022. .bnt {
  1023. width: 222rpx;
  1024. height: 76rpx;
  1025. background: var(--view-theme);
  1026. border-radius: 46rpx;
  1027. line-height: 76rpx;
  1028. text-align: center;
  1029. color: #fff;
  1030. margin-left: 24rpx;
  1031. }
  1032. }
  1033. }
  1034. }
  1035. </style>