goods_cate3.vue 29 KB

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