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

main
huyuanxiang 2 years ago
parent 2df1d14c50
commit 2ad63130e8

@ -18,21 +18,21 @@
</view> </view>
</view> </view>
<block v-if="goods._skus.length > 0"> <block v-if="goods._skus.length > 0">
<view v-for="(item, index) in goods._skus" <view v-for="(item, index) in goods._skus"
:key="index" :key="index"
class="sku_list"> class="sku_list">
<view class="sku_name"> <view class="sku_name">
{{item.skuname}} {{item.skuname}}
</view> </view>
<view class="sku_tag"> <view class="sku_tag">
<view v-for="(row, sIndex) in item.child" <view v-for="(row, sIndex) in item.child"
:key="row.id" :key="row.id"
class="tag_s" class="tag_s"
:class="[currentArr['' + index] == row.id ? ' active' : '']" :class="[currentArr['' + index] == row.id ? ' active' : '']"
@tap="setTag(item, index, sIndex, row)" @tap="setTag(item, index, sIndex, row)"
> >
{{row.tagname}} {{row.tagname}}
</view> </view>
</view> </view>
</view> </view>
@ -41,8 +41,8 @@
<view class="n_left">购买数量</view> <view class="n_left">购买数量</view>
<view class="n_right"> <view class="n_right">
<text class="jian" @tap="onChangeNum('reduce')"></text> <text class="jian" @tap="onChangeNum('reduce')"></text>
<input v-model="number" <input v-model="number"
type="number" max="99999" type="number" max="99999"
@input="handlerChangeNum" @input="handlerChangeNum"
min="1" min="1"
class="inputs"></input> class="inputs"></input>
@ -72,7 +72,7 @@ export default {
issku: false ,// issku: false ,//
update: true, update: true,
nowList:{}, nowList:{},
stock: 99999 stock: 99999
}; };
}, },
@ -104,50 +104,48 @@ export default {
this.$set(this.currentArr, index, v.child[0].id) this.$set(this.currentArr, index, v.child[0].id)
}) })
this.number = 1 // this.number = 1 //
} }
}, },
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(){
return return
}, },
setTag(items, current, indexs,row) { setTag(items, current, indexs,row) {
console.log(items, current, indexs,row) console.log(items, current, indexs,row)
// //
let that = this let that = this
let item = items let item = items
let pid = items.sku_id let pid = items.sku_id
let isChecked = true; // or let isChecked = true; // or
// const findIndex = this.currentArr.findIndex(v => v === row.id) // const findIndex = this.currentArr.findIndex(v => v === row.id)
// if (findIndex > -1) { // if (findIndex > -1) {
// this.currentArr.splice(findIndex, 1, ''); // this.currentArr.splice(findIndex, 1, '');
// isChecked = false // isChecked = false
// } else { // } else {
// this.$set(this.currentArr, current, row.id) // this.$set(this.currentArr, current, row.id)
// } // }
// this.currentArr[current + ''] = row.id // this.currentArr[current + ''] = row.id
this.$set(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() // let newSku = this.getAllSku() //
that.skulength = chooseSkuId.length that.skulength = chooseSkuId.length
if(chooseSkuId.length == that.nowList.sku.length && newSku.length){ if(chooseSkuId.length == that.nowList.sku.length && newSku.length){
// //
that.currentSku = newSku[0] that.currentSku = newSku[0]
@ -160,7 +158,7 @@ export default {
}, },
changeDisabled(isChecked=false,skuId=0, pid=0){ // changeDisabled(isChecked=false,skuId=0, pid=0){ //
let newSku = [] let newSku = []
if (isChecked) { if (isChecked) {
for(let key of this.skuArr){ // for(let key of this.skuArr){ //
if(key.stock <= 0){ //0 if(key.stock <= 0){ //0
continue continue
@ -197,7 +195,7 @@ export default {
// } // }
// }); // });
} }
// //
let chooseSkuKey = []; let chooseSkuKey = [];
if (!isChecked) { if (!isChecked) {
@ -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
@ -255,7 +254,7 @@ export default {
num -= 1 num -= 1
} }
this.number = num this.number = num
}, },
onsubmit(value) { onsubmit(value) {
// //
@ -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) {
@ -317,7 +318,7 @@ export default {
colCart = [data] colCart = [data]
} }
resetCart(colCart) resetCart(colCart)
// //
uni.showToast({ uni.showToast({
title: '加入购物车成功 !', title: '加入购物车成功 !',
@ -327,7 +328,7 @@ export default {
* 模拟获取购物车的数量 getCart * 模拟获取购物车的数量 getCart
*/ */
let cartNum = getCartNumber() let cartNum = getCartNumber()
setTabBarBadge(cartNum) setTabBarBadge(cartNum)
}else{ // }else{ //
let goods = [] let goods = []
@ -537,4 +538,4 @@ export default {
background-color: #F9F9F9; background-color: #F9F9F9;
opacity: 0.5; opacity: 0.5;
} }
</style> </style>

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

@ -4,19 +4,19 @@
<div class="status-bar" :style="{height:statusBarHeight+'px'}"></div> <div class="status-bar" :style="{height:statusBarHeight+'px'}"></div>
<!-- #endif --> <!-- #endif -->
<block v-if="cartList.length > 0 "> <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> @click="clearInvalid">购物车</view>
<!-- <view class="clearCart" :style="{color:colors,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 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)" @longpress.stop="onshowDel(item,index)"
@touchend="ontouchend"> @touchend="ontouchend">
<view class="checkbox-box" @tap="setCurrent(item,index)"> <view class="checkbox-box" @tap="setCurrent(item,index)">
<view class="checkbox text-xxl" style="border: 0px;" v-if="item.status !== 1 "> <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> :class="item.current == true ? 'text-green':'text-gray'" ></text>
</view> </view>
<view class="checkbox" style="border-color:#ccc" v-else> <view class="checkbox" style="border-color:#ccc" v-else>
<view></view> <view></view>
@ -52,11 +52,11 @@
<view class="right_btn"> <view class="right_btn">
<view class="sub" @tap="onChangeNum(item,index, 'sub')" :style="'color:' + (item.num == 1?'#ccc':'')">-</view> <view class="sub" @tap="onChangeNum(item,index, 'sub')" :style="'color:' + (item.num == 1?'#ccc':'')">-</view>
<view class="input"> <view class="input">
<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>
@ -79,7 +79,7 @@
<view class="left"> <view class="left">
<view class="checkbox-box" @tap="setAllCurrent"> <view class="checkbox-box" @tap="setAllCurrent">
<view class="checkbox text-xxl" :style="'border-color:' + colors"> <view class="checkbox text-xxl" :style="'border-color:' + colors">
<view class="cuIcon-roundcheckfill " <view class="cuIcon-roundcheckfill "
:class="allCurrent ? 'text-green':'text-gray'" ></view> :class="allCurrent ? 'text-green':'text-gray'" ></view>
</view> </view>
<view class="text" style="margin-left: 8upx;">全选</view> <view class="text" style="margin-left: 8upx;">全选</view>
@ -147,15 +147,15 @@
// #ifdef APP-PLUS // #ifdef APP-PLUS
this.showHeader = true //APP this.showHeader = true //APP
// #endif // #endif
}, },
/** /**
* 生命周期函数--监听页面初次渲染完成 * 生命周期函数--监听页面初次渲染完成
*/ */
onReady: function() { onReady: function() {
}, },
/** /**
@ -180,7 +180,7 @@
}); });
setTabBarBadge(cartList.length) setTabBarBadge(cartList.length)
this.setAllCurrent(false) this.setAllCurrent(false)
}, },
/** /**
@ -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: '提交中...'
@ -761,7 +758,7 @@
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: flex-end; align-items: flex-end;
} }
.bottom_all .rights view { .bottom_all .rights view {

Loading…
Cancel
Save