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

main
huyuanxiang 1 year ago
parent 2df1d14c50
commit 2ad63130e8

@ -18,21 +18,21 @@
</view>
</view>
<block v-if="goods._skus.length > 0">
<view v-for="(item, index) in goods._skus"
:key="index"
<view v-for="(item, index) in goods._skus"
:key="index"
class="sku_list">
<view class="sku_name">
{{item.skuname}}
</view>
<view class="sku_tag">
<view v-for="(row, sIndex) in item.child"
:key="row.id"
class="tag_s"
<view v-for="(row, sIndex) in item.child"
:key="row.id"
class="tag_s"
:class="[currentArr['' + index] == row.id ? ' active' : '']"
@tap="setTag(item, index, sIndex, row)"
@tap="setTag(item, index, sIndex, row)"
>
{{row.tagname}}
</view>
</view>
</view>
@ -41,8 +41,8 @@
<view class="n_left">购买数量</view>
<view class="n_right">
<text class="jian" @tap="onChangeNum('reduce')"></text>
<input v-model="number"
type="number" max="99999"
<input v-model="number"
type="number" max="99999"
@input="handlerChangeNum"
min="1"
class="inputs"></input>
@ -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;
}
</style>
</style>

@ -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++

@ -4,19 +4,19 @@
<div class="status-bar" :style="{height:statusBarHeight+'px'}"></div>
<!-- #endif -->
<block v-if="cartList.length > 0 ">
<view class="clearCart" :style="{top:showHeader==true?statusBarHeight+'px':'0upx'}"
<view class="clearCart" :style="{top:showHeader==true?statusBarHeight+'px':'0upx'}"
@click="clearInvalid">购物车</view>
<!-- <view class="clearCart" :style="{color:colors,top:showHeader==true?statusBarHeight+'px':'0upx'}" @click="clearInvalid"></view> -->
<view class="cart_box">
<view v-for="(item, index) in cartList" :key="index" class="cart_list"
<view v-for="(item, index) in cartList" :key="index" class="cart_list"
@longpress.stop="onshowDel(item,index)"
@touchend="ontouchend">
<view class="checkbox-box" @tap="setCurrent(item,index)">
<view class="checkbox text-xxl" style="border: 0px;" v-if="item.status !== 1 ">
<text class="cuIcon-roundcheckfill "
<text class="cuIcon-roundcheckfill "
:class="item.current == true ? 'text-green':'text-gray'" ></text>
</view>
<view class="checkbox" style="border-color:#ccc" v-else>
<view></view>
@ -52,11 +52,11 @@
<view class="right_btn">
<view class="sub" @tap="onChangeNum(item,index, 'sub')" :style="'color:' + (item.num == 1?'#ccc':'')">-</view>
<view class="input">
<input
<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>
@ -79,7 +79,7 @@
<view class="left">
<view class="checkbox-box" @tap="setAllCurrent">
<view class="checkbox text-xxl" :style="'border-color:' + colors">
<view class="cuIcon-roundcheckfill "
<view class="cuIcon-roundcheckfill "
:class="allCurrent ? 'text-green':'text-gray'" ></view>
</view>
<view class="text" style="margin-left: 8upx;">全选</view>
@ -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 {

Loading…
Cancel
Save