goods_cate3.vue 29 KB

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