goods_cate3.vue 29 KB

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