goods_cate2.vue 28 KB

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