goods_cate3.vue 31 KB

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