goods_cate2.vue 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088
  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. <navigator open-type="switchTab" url="/pages/index/index" class="pageIndex" hover-class="none" @click="jumpIndex">
  7. <text class="iconfont icon-shouye3"></text>
  8. </navigator>
  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, isCartPop) {
  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. }
  495. if (num.cart_num == 0) {
  496. this.cartData.cartList.splice(index, 1);
  497. }
  498. if (num.cart_num < 0) {
  499. if (isDuo) {
  500. this.$set(this.attr.productSelect, 'cart_num', this.storeInfo.min_qty);
  501. this.$set(this, 'cart_num', this.storeInfo.min_qty);
  502. } else {
  503. num.cart_num = 0;
  504. this.$set(this, 'tempArr', this.tempArr);
  505. this.$set(this.cartData, 'cartList', this.cartData.cartList);
  506. }
  507. } else {
  508. if (!isDuo) {
  509. if (cart) {
  510. this.goCat(0, id, 0, 1, num.product_attr_unique, num);
  511. this.getTotalPrice();
  512. } else {
  513. this.goCat(0, id, 0, 0, false, num);
  514. }
  515. }
  516. }
  517. }
  518. },
  519. // 多规格加入购物车;
  520. goCatNum() {
  521. this.goCat(1, this.id, 1);
  522. },
  523. /*
  524. * 加入购物车
  525. */
  526. goCat: function (duo, id, type, cart, unique, data) {
  527. let that = this;
  528. if (duo) {
  529. let productSelect = that.productValue[this.attrValue];
  530. //如果有属性,没有选择,提示用户选择
  531. if (that.attr.productAttr.length && productSelect === undefined) {
  532. return that.$util.Tips({
  533. title: that.$t(`该产品没有更多库存了`)
  534. });
  535. }
  536. if (that.attr.productSelect.cart_num <= 0) {
  537. return that.$util.Tips({
  538. title: that.$t(`最少添加 1 件商品`)
  539. });
  540. }
  541. }
  542. let q = {
  543. product_id: id,
  544. type: type,
  545. unique: duo ? that.attr.productSelect.unique : cart ? unique : ''
  546. };
  547. data && data.cart_num < data.min_qty ? (q.num = data.min_qty) : '';
  548. if (!that.cartData.iScart) q.num = duo ? that.attr.productSelect.cart_num : this.storeInfo.min_qty;
  549. postCartNum(q)
  550. .then(function (res) {
  551. if (duo) {
  552. that.attr.cartAttr = false;
  553. that.$util.Tips({
  554. title: that.$t(`添加成功`)
  555. });
  556. // that.page = 1;
  557. // that.loadend = false;
  558. that.tempArr.forEach((item, index) => {
  559. if (item.id == that.id) {
  560. let arrtStock = that.attr.productSelect.stock;
  561. let objNum = parseInt(item.cart_num) + parseInt(that.attr.productSelect.cart_num);
  562. item.cart_num = objNum > arrtStock ? arrtStock : objNum;
  563. }
  564. });
  565. // that.productslist();
  566. }
  567. that.getCartNum();
  568. if (!cart) {
  569. that.getCartList(1);
  570. }
  571. })
  572. .catch((err) => {
  573. return that.$util.Tips({
  574. title: err
  575. });
  576. });
  577. },
  578. // 点击默认单属性购物车
  579. goCartDan(item, index) {
  580. if (!this.isLogin) {
  581. this.getIsLogin();
  582. } else {
  583. if (!item.cart_button) {
  584. goShopDetail(item, this.uid).then((res) => {
  585. uni.navigateTo({
  586. url: `/pages/goods_details/index?id=${item.id}`
  587. });
  588. });
  589. return;
  590. }
  591. item.cart_num = item.min_qty;
  592. this.$set(this, 'tempArr', this.tempArr);
  593. this.goCat(0, item.id, 1);
  594. }
  595. },
  596. goCartDuo(item) {
  597. if (!this.isLogin) {
  598. this.getIsLogin();
  599. } else {
  600. if (!item.cart_button) {
  601. goShopDetail(item, this.uid).then((res) => {
  602. uni.navigateTo({
  603. url: `/pages/goods_details/index?id=${item.id}`
  604. });
  605. });
  606. return;
  607. }
  608. uni.showLoading({
  609. title: this.$t(`正在加载中`)
  610. });
  611. this.storeName = item.store_name;
  612. this.getAttrs(item.id);
  613. this.$set(this, 'id', item.id);
  614. this.$set(this.attr, 'cartAttr', true);
  615. }
  616. },
  617. getIsLogin() {
  618. toLogin();
  619. },
  620. // 商品详情接口;
  621. getAttrs(id) {
  622. let that = this;
  623. getAttr(id, 0).then((res) => {
  624. uni.hideLoading();
  625. that.$set(that.attr, 'productAttr', res.data.productAttr);
  626. that.$set(that, 'productValue', res.data.productValue);
  627. that.$set(that, 'is_vip', res.data.storeInfo.is_vip);
  628. that.$set(that, 'storeInfo', res.data.storeInfo);
  629. that.DefaultSelect();
  630. });
  631. },
  632. // 去详情页
  633. goDetail(item) {
  634. goShopDetail(item, this.uid).then((res) => {
  635. uni.navigateTo({
  636. url: `/pages/goods_details/index?id=${item.id}`
  637. });
  638. });
  639. },
  640. openTap() {
  641. this.iSlong = false;
  642. },
  643. closeTap() {
  644. this.iSlong = true;
  645. },
  646. getAllCategory: function (type) {
  647. let that = this;
  648. if (type || !uni.getStorageSync('CAT2_DATA')) {
  649. getCategoryList().then((res) => {
  650. uni.setStorageSync('CAT2_DATA', res.data);
  651. let data = res.data;
  652. data.forEach((item) => {
  653. item.children.unshift({
  654. id: 0,
  655. cate_name: that.$t(`全部`)
  656. });
  657. });
  658. that.categoryTitle = data[0].cate_name;
  659. that.cid = data[0].id;
  660. that.sid = 0;
  661. that.navActive = 0;
  662. that.tabClick = 0;
  663. that.categoryList = data;
  664. that.page = 1;
  665. that.loadend = false;
  666. that.tempArr = [];
  667. that.categoryErList = res.data[0].children ? res.data[0].children : [];
  668. that.productslist();
  669. });
  670. } else {
  671. let data = uni.getStorageSync('CAT2_DATA');
  672. data.forEach((item) => {
  673. item.children.unshift({
  674. id: 0,
  675. cate_name: that.$t(`全部`)
  676. });
  677. });
  678. if (!that.cid) {
  679. that.categoryTitle = data[0].cate_name;
  680. that.cid = data[0].id;
  681. that.sid = 0;
  682. that.navActive = 0;
  683. that.tabClick = 0;
  684. that.categoryList = data;
  685. that.categoryErList = data[0].children ? data[0].children : [];
  686. that.page = 1;
  687. that.loadend = false;
  688. that.tempArr = [];
  689. }
  690. that.productslist();
  691. }
  692. },
  693. tapNav(index, item) {
  694. let list = this.categoryList[index];
  695. this.navActive = index;
  696. this.categoryTitle = list.cate_name;
  697. this.categoryErList = item.children ? item.children : [];
  698. this.tabClick = 0;
  699. this.tabLeft = 0;
  700. this.cid = list.id;
  701. this.sid = 0;
  702. this.page = 1;
  703. this.loadend = false;
  704. this.tempArr = [];
  705. this.productslist();
  706. },
  707. // 导航栏点击
  708. longClick(index) {
  709. if (this.categoryErList.length > 3) {
  710. this.tabLeft = (index - 1) * (this.isWidth + 6); //设置下划线位置
  711. }
  712. this.tabClick = index; //设置导航点击了哪一个
  713. this.iSlong = true;
  714. this.sid = this.categoryErList[index].id;
  715. this.page = 1;
  716. this.loadend = false;
  717. this.tempArr = [];
  718. this.productslist();
  719. }
  720. },
  721. onReachBottom() {
  722. this.productslist();
  723. }
  724. };
  725. </script>
  726. <style lang="scss">
  727. .scroll-Y {
  728. height: 100vh;
  729. }
  730. page {
  731. background-color: #fff;
  732. }
  733. /deep/.product-window.joinCart {
  734. z-index: 999;
  735. }
  736. ::-webkit-scrollbar {
  737. width: 0;
  738. height: 0;
  739. color: transparent;
  740. display: none;
  741. }
  742. .goodCate {
  743. .mask {
  744. z-index: 99;
  745. }
  746. /deep/.attrProduct {
  747. .mask {
  748. z-index: 100;
  749. }
  750. }
  751. .header {
  752. position: fixed;
  753. height: 128rpx;
  754. background-color: #fff;
  755. top: 0;
  756. left: 0;
  757. width: 100%;
  758. z-index: 99;
  759. border-bottom: 1px solid #f0f0f0;
  760. .pageIndex {
  761. width: 68rpx;
  762. height: 68rpx;
  763. border-radius: 50%;
  764. background-color: var(--view-theme);
  765. text-align: center;
  766. line-height: 68rpx;
  767. .iconfont {
  768. color: #fff;
  769. font-size: 30rpx;
  770. }
  771. }
  772. .search {
  773. width: 600rpx;
  774. height: 68rpx;
  775. border-radius: 36rpx;
  776. background-color: #f8f8f8;
  777. font-size: 26rpx;
  778. color: #adadad;
  779. margin-left: 22rpx;
  780. .iconfont {
  781. font-size: 30rpx;
  782. margin: 4rpx 16rpx 0 0;
  783. }
  784. }
  785. }
  786. .conter {
  787. margin-top: 128rpx;
  788. // height: 100vh;
  789. background-color: #fff;
  790. .aside {
  791. position: fixed;
  792. width: 23%;
  793. left: 0;
  794. bottom: 100rpx;
  795. top: 0;
  796. background-color: #f7f7f7;
  797. overflow-y: auto;
  798. overflow-x: hidden;
  799. margin-top: 128rpx;
  800. z-index: 99;
  801. .item {
  802. height: 100rpx;
  803. width: 100%;
  804. font-size: 26rpx;
  805. color: #424242;
  806. &.on {
  807. background-color: #fff;
  808. width: 100%;
  809. text-align: center;
  810. color: var(--view-theme);
  811. font-weight: 500;
  812. position: relative;
  813. &::after {
  814. content: '';
  815. position: absolute;
  816. width: 6rpx;
  817. height: 46rpx;
  818. background: var(--view-theme);
  819. border-radius: 0 4rpx 4rpx 0;
  820. left: 0;
  821. }
  822. }
  823. }
  824. }
  825. .wrapper {
  826. margin-top: 104rpx;
  827. width: 77%;
  828. float: right;
  829. background-color: #fff;
  830. .bgcolor {
  831. width: 100%;
  832. background-color: #fff;
  833. }
  834. .goodsList {
  835. margin-top: 0 !important;
  836. }
  837. .mask {
  838. z-index: 9;
  839. }
  840. .longTab {
  841. width: 65%;
  842. position: fixed;
  843. top: 0;
  844. margin-top: 128rpx;
  845. height: 100rpx;
  846. z-index: 99;
  847. background-color: #fff;
  848. .longItem {
  849. height: 44rpx;
  850. display: inline-block;
  851. line-height: 44rpx;
  852. text-align: center;
  853. font-size: 26rpx;
  854. overflow: hidden;
  855. text-overflow: ellipsis;
  856. white-space: nowrap;
  857. color: #989898;
  858. background-color: #f7f7f7;
  859. border-radius: 22rpx;
  860. margin-left: 12rpx;
  861. &.click {
  862. font-weight: bold;
  863. background-color: var(--view-minorColorT);
  864. color: var(--view-theme);
  865. }
  866. }
  867. .underlineBox {
  868. height: 3px;
  869. width: 20%;
  870. display: flex;
  871. align-content: center;
  872. justify-content: center;
  873. transition: 0.5s;
  874. .underline {
  875. width: 33rpx;
  876. height: 4rpx;
  877. background-color: white;
  878. }
  879. }
  880. }
  881. .openList {
  882. width: 12%;
  883. height: 100rpx;
  884. background-color: #fff;
  885. line-height: 100rpx;
  886. padding-left: 30rpx;
  887. position: fixed;
  888. right: 0;
  889. top: 128rpx;
  890. z-index: 99;
  891. .iconfont {
  892. font-size: 22rpx;
  893. color: #989898;
  894. }
  895. }
  896. .downTab {
  897. width: 77%;
  898. position: fixed;
  899. top: 0;
  900. margin-top: 128rpx;
  901. z-index: 99;
  902. background-color: #fff;
  903. right: 0;
  904. .title {
  905. height: 100rpx;
  906. font-size: 26rpx;
  907. color: #adadad;
  908. padding-left: 20rpx;
  909. .closeList {
  910. width: 90rpx;
  911. height: 100%;
  912. line-height: 100rpx;
  913. padding-left: 30rpx;
  914. transform: rotate(180deg);
  915. .iconfont {
  916. font-size: 22rpx;
  917. color: #989898;
  918. }
  919. }
  920. }
  921. .children {
  922. max-height: 500rpx;
  923. overflow-x: hidden;
  924. overflow-y: auto;
  925. padding-bottom: 20rpx;
  926. .item {
  927. height: 60rpx;
  928. background-color: #f7f7f7;
  929. border-radius: 30rpx;
  930. line-height: 60rpx;
  931. padding: 0 15rpx;
  932. margin: 0 0 20rpx 20rpx;
  933. width: 165rpx;
  934. text-align: center;
  935. &.click {
  936. font-weight: bold;
  937. background-color: var(--view-minorColorT);
  938. color: var(--view-theme);
  939. }
  940. }
  941. }
  942. }
  943. .goodsList {
  944. margin-top: 228rpx;
  945. padding: 0 30rpx 0 20rpx;
  946. /deep/.item {
  947. margin-bottom: 33rpx !important;
  948. .pictrue {
  949. // height: 216rpx;
  950. }
  951. .text {
  952. font-size: 26rpx;
  953. }
  954. .bottom {
  955. .sales {
  956. .money {
  957. font-size: 34rpx;
  958. text {
  959. font-size: 26rpx;
  960. }
  961. }
  962. }
  963. .cart {
  964. .pictrue {
  965. width: 50rpx;
  966. height: 50rpx;
  967. }
  968. }
  969. }
  970. }
  971. }
  972. }
  973. }
  974. .footer {
  975. position: fixed;
  976. left: 0;
  977. bottom: 0;
  978. width: 100%;
  979. background-color: #fff;
  980. box-shadow: 0px -3rpx 16rpx rgba(36, 12, 12, 0.05);
  981. z-index: 101;
  982. padding: 12rpx 30rpx;
  983. box-sizing: border-box;
  984. padding-bottom: calc(12rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  985. padding-bottom: calc(12rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  986. .cartIcon {
  987. width: 96rpx;
  988. height: 96rpx;
  989. border-radius: 50%;
  990. position: relative;
  991. margin-top: -36rpx;
  992. .iconfont {
  993. font-size: 115rpx;
  994. margin-top: -5px;
  995. color: var(--view-theme);
  996. }
  997. &.noCart {
  998. .iconfont {
  999. color: #cbcbcb;
  1000. }
  1001. }
  1002. .num {
  1003. background-color: var(--view-priceColor);
  1004. min-width: 12rpx;
  1005. color: #fff;
  1006. border-radius: 15px;
  1007. position: absolute;
  1008. right: -6rpx;
  1009. top: -10rpx;
  1010. font-size: 22rpx;
  1011. padding: 0 10rpx;
  1012. height: 34rpx;
  1013. line-height: 34rpx;
  1014. }
  1015. }
  1016. .money {
  1017. color: var(--view-priceColor);
  1018. font-size: 28rpx;
  1019. font-weight: bold;
  1020. .num {
  1021. font-size: 42rpx;
  1022. }
  1023. .bnt {
  1024. width: 222rpx;
  1025. height: 76rpx;
  1026. background: var(--view-theme);
  1027. border-radius: 46rpx;
  1028. line-height: 76rpx;
  1029. text-align: center;
  1030. color: #fff;
  1031. margin-left: 24rpx;
  1032. }
  1033. }
  1034. }
  1035. }
  1036. </style>