goods_cate3.vue 30 KB

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