goods_cate3.vue 31 KB

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