goods_cate3.vue 29 KB

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