From 2ad63130e8bc50a1604a7302a2e5169e66bf4472 Mon Sep 17 00:00:00 2001 From: huyuanxiang <273637057@qq.com> Date: Wed, 12 Jul 2023 10:24:37 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=E5=86=8D=E6=AC=A1=E4=B8=8B=E5=8D=95?= =?UTF-8?q?=EF=BC=8C=E8=B4=AD=E7=89=A9=E8=BD=A6=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/commponent/public/sku.vue | 71 +++++++++++++++++---------------- pages/views/order/orderList.vue | 59 ++++++++++++++++++++++++++- pages/views/tabBar/cart.vue | 41 +++++++++---------- 3 files changed, 113 insertions(+), 58 deletions(-) diff --git a/pages/commponent/public/sku.vue b/pages/commponent/public/sku.vue index eb5c217..4840d8d 100644 --- a/pages/commponent/public/sku.vue +++ b/pages/commponent/public/sku.vue @@ -18,21 +18,21 @@ - {{item.skuname}} - {{row.tagname}} - + @@ -41,8 +41,8 @@ 购买数量 - @@ -72,7 +72,7 @@ export default { issku: false ,//判断当前商品是否存在规格 update: true, nowList:{}, - + stock: 99999 }; }, @@ -104,50 +104,48 @@ export default { this.$set(this.currentArr, index, v.child[0].id) }) this.number = 1 //初始数量 - } + } }, methods: { handlerChangeNum() { - debounce(() => { - const num = Number(this.number) - if (num < 1 || !num) { - this.number = 1 - } - if (num > this.stock) { - this.number = this.stock - } - }, 500) - + // debounce(() => { + + // }, 5000) + const num = Number(this.number) + if (num > this.stock) { + this.number = this.stock + } + }, moveHandle(){ - return + return }, setTag(items, current, indexs,row) { - + console.log(items, current, indexs,row) //选择规格 let that = this let item = items let pid = items.sku_id let isChecked = true; // 选中 or 取消选中 - + // const findIndex = this.currentArr.findIndex(v => v === row.id) // if (findIndex > -1) { // this.currentArr.splice(findIndex, 1, ''); // isChecked = false - + // } else { // this.$set(this.currentArr, current, row.id) // } // this.currentArr[current + ''] = row.id this.$set(this.currentArr, current, row.id) - - const chooseSkuId = Object.values(this.currentArr).filter(v => !!v); + + const chooseSkuId = Object.values(this.currentArr).filter(v => !!v); let newSku = this.getAllSku() //获取符合条件的规格数据 that.skulength = chooseSkuId.length - + if(chooseSkuId.length == that.nowList.sku.length && newSku.length){ //如果所有的规格类都被选中了 设置当前选中项商品的信息 that.currentSku = newSku[0] @@ -160,7 +158,7 @@ export default { }, changeDisabled(isChecked=false,skuId=0, pid=0){ //改变禁用状态 let newSku = [] - if (isChecked) { + if (isChecked) { for(let key of this.skuArr){ //遍历可用规格数组 if(key.stock <= 0){ //如果规格现有的库存小于等于0 continue @@ -197,7 +195,7 @@ export default { // } // }); } - + // 当前已选择的规格大类 let chooseSkuKey = []; if (!isChecked) { @@ -241,7 +239,8 @@ export default { }, onChangeNum(type = 'reduce') { - let num = Number(this.number) + const total = Math.floor(Number(this.number)) + let num = total < 1 ? 1 : total > this.stock ? this.stock : total if (type === 'add') { if (num >= this.stock) { return @@ -255,7 +254,7 @@ export default { num -= 1 } this.number = num - + }, onsubmit(value) { // 此处应该判断是否登录 如果没登录 跳转到登录页 @@ -284,6 +283,8 @@ export default { } const data = this.goods const selectedSku = [] + const total = Math.floor(Number(this.number)) + this.number = total < 1 ? 1 : total > this.stock ? this.stock : total Object.keys(this.currentArr).forEach(key => { const item = this.currentArr[key] if (item) { @@ -317,7 +318,7 @@ export default { colCart = [data] } resetCart(colCart) - + // 存储商品数据 uni.showToast({ title: '加入购物车成功 !', @@ -327,7 +328,7 @@ export default { * 模拟获取购物车的数量 getCart */ let cartNum = getCartNumber() - + setTabBarBadge(cartNum) }else{ //如果是购买商品 let goods = [] @@ -537,4 +538,4 @@ export default { background-color: #F9F9F9; opacity: 0.5; } - \ No newline at end of file + diff --git a/pages/views/order/orderList.vue b/pages/views/order/orderList.vue index 312e682..d324884 100644 --- a/pages/views/order/orderList.vue +++ b/pages/views/order/orderList.vue @@ -58,10 +58,12 @@ + 再次下单 订单评价 申请售后 + 再次下单 订单评价 申请售后 @@ -86,7 +88,8 @@ import loading from "../../commponent/public/loading"; import navBar from '../../commponent/public/navBar.vue' import { ORDER_NAVS } from '@/config/order.js' -import { getUserInfo, setSalesGoods } from '@/utils/auth'; +import { getUserInfo, setSalesGoods, getCart, + resetCart, } from '@/utils/auth'; const app = getApp(); let timer = null export default { @@ -181,6 +184,60 @@ import { getUserInfo, setSalesGoods } from '@/utils/auth'; */ onShareAppMessage: function() {}, methods: { + handleRepeatOrder(item) { + const cartList = getCart().map(v => { + v.current = false + return v + }) + const goodsList = item.orderDetailList.map(v => { + v.imgList = v.url.split(',') + v.number = 1 + v.id = v.goodsId + v.current = true + v._selectedSku = [{ + id: v.goodsId, + imgs: '', + money: v.price, + number: 1, + tagname: v.goodsName + }] + v._skus = [ + { + sku_id: v.goodsId, + skuname: '规格', + child: [ + { + id: 1, + imgs: '', + money: v.price, + number: 1, + tagname: v.goodsName + } + ] + } + ] + return v + }) + const cartIds = cartList.map(v => v.id) + const goodsIds = goodsList.map(v => v.id) + + const goodsNotHasCart = goodsList.filter(v => !cartIds.includes(v.id)) + const cartHasGoodsList = cartList.filter(v => goodsIds.includes(v.id)).map(v => { + v.number += 1 + v.current = true + return v + }) + const cartNotHasGoodsList = cartList.filter(v => !goodsIds.includes(v.id)) + const lastList = [...goodsNotHasCart, ...cartHasGoodsList, ...cartNotHasGoodsList] + resetCart(lastList) + this.$toast('添加成功') + setTimeout(() => { + uni.switchTab({ + url: '/pages/views/tabBar/cart' + }) + }, 1000) + + }, handleLoadMore() { if (this.isNoMore) return this.pageNo++ diff --git a/pages/views/tabBar/cart.vue b/pages/views/tabBar/cart.vue index 7bbd0d8..40f1992 100644 --- a/pages/views/tabBar/cart.vue +++ b/pages/views/tabBar/cart.vue @@ -4,19 +4,19 @@
- 购物车 - + - - - + @@ -52,11 +52,11 @@ - - + @@ -79,7 +79,7 @@ - 全选 @@ -147,15 +147,15 @@ // #ifdef APP-PLUS this.showHeader = true //在APP端对样式进行调整 // #endif - - + + }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function() { - + }, /** @@ -180,7 +180,7 @@ }); setTabBarBadge(cartList.length) this.setAllCurrent(false) - + }, /** @@ -266,7 +266,9 @@ current: '99999' }); }, - handlerChangeNum(item, type = 'input') { + handlerChangeNum(item, index, type = 'input') { + const total = Math.floor(Number(item.number)) + item.number = total < 1 ? 1 : total > this.stock ? this.stock : total if (type === 'blur') { if (!item.number) { item.number = 1 @@ -283,14 +285,13 @@ item.number = 1 } }, 1) - }, onChangeNum(item, index, type = 'add') { if (item.status == 1) { //已失效商品不做操作 return } - const num = Number(item.number) - + const total = Math.floor(Number(item.number)) + let num = total < 1 ? 1 : total > this.stock ? this.stock : total if (type === 'add') { //增加 if (num >= this.stock) { @@ -298,7 +299,6 @@ return } item.number = num + 1 - } else { if (num <= 1) { return @@ -343,9 +343,7 @@ } else { sumPrice += resetNum(v.price * v.number) } - }) - this.sum = list.length this.sumPrice = resetNum(sumPrice, 'end') }, @@ -387,7 +385,6 @@ this.$toast('您还没选择商品') return } - // 计算出被选中的数据 uni.showLoading({ title: '提交中...' @@ -761,7 +758,7 @@ display: flex; flex-direction: column; align-items: flex-end; - + } .bottom_all .rights view {