goods_cate3.vue 30 KB

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