goods_cate2.vue 30 KB

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