[fix]再次下单,购物车调整

main
huyuanxiang 2 years ago
parent 2df1d14c50
commit 2ad63130e8

@ -108,15 +108,13 @@ export default {
},
methods: {
handlerChangeNum() {
debounce(() => {
// debounce(() => {
// }, 5000)
const num = Number(this.number)
if (num < 1 || !num) {
this.number = 1
}
if (num > this.stock) {
this.number = this.stock
}
}, 500)
},
moveHandle(){
@ -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
@ -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) {

@ -58,10 +58,12 @@
<block v-if="item.state == 2">
<!-- <view class="pay" @tap="onConfirmOrder(item)" :style="'color:#fff;background:' + colors+ ';border-color:' + colors">确认收货</view> -->
<!-- <view class="pay shouhou" @tap="onRefund(item)">退</view> -->
<view class="pay shouhou" @tap="handleRepeatOrder(item)"></view>
<view class="pay shouhou" @tap="jumpDetails(item)"></view>
<view class="pay shouhou" @tap="jumpDetails(item)"></view>
</block>
<block v-if="item.state == 3">
<view class="pay shouhou" @tap="handleRepeatOrder(item)"></view>
<view class="pay shouhou" @tap="jumpDetails(item)"></view>
<view class="pay shouhou" @tap="jumpDetails(item)"></view>
</block>
@ -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++

@ -55,8 +55,8 @@
<input
v-model="item.number"
type="number"
@blur="handlerChangeNum(item, 'blur')"
@input="handlerChangeNum(item, 'input')"
@blur="handlerChangeNum(item, index,'blur')"
@input="handlerChangeNum(item, index, 'input')"
max="99999"></input>
</view>
<view class="add" @tap="onChangeNum(item,index, 'add')">+</view>
@ -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: '提交中...'

Loading…
Cancel
Save