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

main
huyuanxiang 2 years ago
parent 2df1d14c50
commit 2ad63130e8

@ -108,15 +108,13 @@ export default {
}, },
methods: { methods: {
handlerChangeNum() { handlerChangeNum() {
debounce(() => { // debounce(() => {
const num = Number(this.number)
if (num < 1 || !num) { // }, 5000)
this.number = 1 const num = Number(this.number)
} if (num > this.stock) {
if (num > this.stock) { this.number = this.stock
this.number = this.stock }
}
}, 500)
}, },
moveHandle(){ moveHandle(){
@ -241,7 +239,8 @@ export default {
}, },
onChangeNum(type = 'reduce') { 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 (type === 'add') {
if (num >= this.stock) { if (num >= this.stock) {
return return
@ -284,6 +283,8 @@ export default {
} }
const data = this.goods const data = this.goods
const selectedSku = [] 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 => { Object.keys(this.currentArr).forEach(key => {
const item = this.currentArr[key] const item = this.currentArr[key]
if (item) { if (item) {

@ -58,10 +58,12 @@
<block v-if="item.state == 2"> <block v-if="item.state == 2">
<!-- <view class="pay" @tap="onConfirmOrder(item)" :style="'color:#fff;background:' + colors+ ';border-color:' + colors">确认收货</view> --> <!-- <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="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>
<view class="pay shouhou" @tap="jumpDetails(item)"></view> <view class="pay shouhou" @tap="jumpDetails(item)"></view>
</block> </block>
<block v-if="item.state == 3"> <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>
<view class="pay shouhou" @tap="jumpDetails(item)"></view> <view class="pay shouhou" @tap="jumpDetails(item)"></view>
</block> </block>
@ -86,7 +88,8 @@
import loading from "../../commponent/public/loading"; import loading from "../../commponent/public/loading";
import navBar from '../../commponent/public/navBar.vue' import navBar from '../../commponent/public/navBar.vue'
import { ORDER_NAVS } from '@/config/order.js' import { ORDER_NAVS } from '@/config/order.js'
import { getUserInfo, setSalesGoods } from '@/utils/auth'; import { getUserInfo, setSalesGoods, getCart,
resetCart, } from '@/utils/auth';
const app = getApp(); const app = getApp();
let timer = null let timer = null
export default { export default {
@ -181,6 +184,60 @@ import { getUserInfo, setSalesGoods } from '@/utils/auth';
*/ */
onShareAppMessage: function() {}, onShareAppMessage: function() {},
methods: { 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() { handleLoadMore() {
if (this.isNoMore) return if (this.isNoMore) return
this.pageNo++ this.pageNo++

@ -55,8 +55,8 @@
<input <input
v-model="item.number" v-model="item.number"
type="number" type="number"
@blur="handlerChangeNum(item, 'blur')" @blur="handlerChangeNum(item, index,'blur')"
@input="handlerChangeNum(item, 'input')" @input="handlerChangeNum(item, index, 'input')"
max="99999"></input> max="99999"></input>
</view> </view>
<view class="add" @tap="onChangeNum(item,index, 'add')">+</view> <view class="add" @tap="onChangeNum(item,index, 'add')">+</view>
@ -266,7 +266,9 @@
current: '99999' 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 (type === 'blur') {
if (!item.number) { if (!item.number) {
item.number = 1 item.number = 1
@ -283,14 +285,13 @@
item.number = 1 item.number = 1
} }
}, 1) }, 1)
}, },
onChangeNum(item, index, type = 'add') { onChangeNum(item, index, type = 'add') {
if (item.status == 1) { // if (item.status == 1) { //
return 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 (type === 'add') {
// //
if (num >= this.stock) { if (num >= this.stock) {
@ -298,7 +299,6 @@
return return
} }
item.number = num + 1 item.number = num + 1
} else { } else {
if (num <= 1) { if (num <= 1) {
return return
@ -343,9 +343,7 @@
} else { } else {
sumPrice += resetNum(v.price * v.number) sumPrice += resetNum(v.price * v.number)
} }
}) })
this.sum = list.length this.sum = list.length
this.sumPrice = resetNum(sumPrice, 'end') this.sumPrice = resetNum(sumPrice, 'end')
}, },
@ -387,7 +385,6 @@
this.$toast('您还没选择商品') this.$toast('您还没选择商品')
return return
} }
// //
uni.showLoading({ uni.showLoading({
title: '提交中...' title: '提交中...'

Loading…
Cancel
Save