goods_cate3.vue 28 KB

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