购物车:接入修改数量 API

pull/1/MERGE
YunaiV 2023-08-29 23:58:33 +08:00
parent f579101f7c
commit 92cb6252ae
1 changed files with 77 additions and 75 deletions

View File

@ -114,8 +114,8 @@
<text class='checkAll'>全选({{selectValue.length}})</text>
</checkbox-group>
</view>
<view class='money acea-row row-middle' v-if="footerswitch==true">
<text class='font-color'>{{selectCountPrice}}</text>
<view class='money acea-row row-middle' v-if="footerswitch">
<text class='font-color'>{{ fen2yuan(selectCountPrice) }}</text>
<form @submit="subOrder" report-submit='true'>
<button class='placeOrder bg-color' formType="submit">立即下单</button>
</form>
@ -140,7 +140,7 @@
<script>
let sysHeight = 0
import { getCartCounts, changeCartNum, cartDel, getResetCart} from '@/api/order.js';
import { cartDel, getResetCart } from '@/api/order.js';
import { getProductHot, collectAll, getProductDetail } from '@/api/store.js';
import { toLogin } from '@/libs/login.js';
import { mapGetters } from "vuex";
@ -155,7 +155,6 @@
},
data() {
return {
cartCount: 0,
goodsHidden: false,
footerswitch: true,
hostProduct: [],
@ -163,13 +162,14 @@
hotLimit: 10,
hotScroll: false,
cartList: {
valid: [],
invalid: []
cartList: { //
valid: [], //
invalid: [] //
},
isAllSelect: false, //
selectValue: [], //
selectCountPrice: 0.00,
selectCountPrice: 0.00, //
cartCount: 0, //
loading: false,
loadTitle: '加载更多', //
@ -211,13 +211,11 @@
valid: [],
invalid: []
};
this.isAllSelect = false; //
this.selectValue = []; //
this.selectCountPrice = 0.00;
this.cartCount = 0;
this.getCartList();
this.isAllSelect = false; //
this.selectValue = []; //
this.selectCountPrice = 0.00;
// TODO
this.cartCount = 0;
}
},
methods: {
@ -250,7 +248,6 @@
that.loadend = false;
that.cartList.valid = [];
that.getCartList();
that.getCartNum();
}
});
})
@ -425,7 +422,6 @@
that.loadend = false;
that.cartList.valid = [];
that.getCartList();
that.getCartNum();
});
else
return that.$util.Tips({
@ -443,7 +439,7 @@
productId.push(validList[index].productId);
}
}
};
}
return productId;
},
subCollect: function(event) {
@ -563,31 +559,27 @@
that.selectValue = value;
that.switchSelect();
},
inArray: function(search, array) {
for (let i in array) {
if (array[i] == search) {
return true;
}
}
return false;
},
/**
* 合计金额数量
*/
switchSelect: function() {
let that = this;
let validList = that.cartList.valid;
let selectValue = that.selectValue;
let selectCountPrice = 0.00;
const validList = this.cartList.valid;
const selectValue = this.selectValue;
if (selectValue.length < 1) {
that.selectCountPrice = selectCountPrice;
} else {
for (let index in validList) {
if (that.inArray(validList[index].id, selectValue)) {
selectCountPrice = that.$util.$h.Add(selectCountPrice, that.$util.$h.Mul(validList[index]
.cartNum, validList[
index].price))
}
}
that.selectCountPrice = selectCountPrice;
this.selectCountPrice = 0.00;
return;
}
//
let selectCountPrice = 0.00;
let cartCount = 0
for (let index in validList) {
if (this.inArray(validList[index].id, selectValue)) {
selectCountPrice = this.$util.$h.Add(selectCountPrice, this.$util.$h.Mul(validList[index].count, validList[index].sku.price))
cartCount += validList[index].count
}
}
this.selectCountPrice = selectCountPrice;
this.cartCount = cartCount;
},
/**
* 购物车手动填写
@ -606,55 +598,57 @@
this.$set(this.cartList, 'valid', this.cartList.valid)
}
},
/**
* 减少购买数量
*/
subCart: function(index) {
let that = this;
let status = false;
let item = that.cartList.valid[index];
item.cartNum = Number(item.cartNum) - 1;
if (item.cartNum < 1) status = true;
if (item.cartNum <= 1) {
item.cartNum = 1;
let item = this.cartList.valid[index];
if (item.count < 1) {
this.$util.Tips({
title: '商品数量不能减少!'
});
return;
}
//
item.count = Number(item.count) - 1;
if (item.count <= 1) {
item.count = 1;
item.numSub = true;
} else {
item.numSub = false;
item.numAdd = false;
}
if (false == status) {
that.setCartNum(item.id, item.cartNum, function(data) {
that.cartList.valid[index] = item;
that.switchSelect();
that.getCartNum();
});
}
//
this.setCartNum(item.id, item.count);
},
/**
* 增加购买数量
*/
addCart: function(index) {
let that = this;
let item = that.cartList.valid[index];
item.cartNum = Number(item.cartNum) + 1;
if (item.cartNum >= item.stock) {
item.cartNum = item.stock;
//
let item = this.cartList.valid[index];
item.count = Number(item.count) + 1
if (item.count >= item.sku.stock) {
item.count = item.sku.stock;
item.numAdd = true;
item.numSub = false;
} else {
item.numAdd = false;
item.numSub = false;
}
that.setCartNum(item.id, item.cartNum, function(data) {
that.cartList.valid[index] = item;
that.switchSelect();
that.getCartNum();
});
//
this.setCartNum(item.id, item.count);
},
setCartNum(cartId, cartNum, successCallback) {
let that = this;
changeCartNum(cartId, cartNum).then(res => {
successCallback && successCallback(res.data);
});
},
getCartNum: function() {
let that = this;
getCartCounts(true, 'sum').then(res => {
that.cartCount = res.data.count;
/**
* 修改购物项为指定数量
*/
setCartNum(cartId, cartNum) {
TradeCartApi.updateCart({
id: cartId,
count: cartNum
}).then(res => {
//
this.getCartList()
});
},
getCartData() {
@ -688,7 +682,7 @@
validList[index].numSub = validList[index].cartNum === 1;
//
const sku = validList[index].sku;
validList[index].numAdd = !!(sku && validList[index].count === sku.stock);
validList[index].numAdd = sku && validList[index].count < sku.stock;
// selectValue
// why SPU SKU invalidList SPU
if (sku && sku.stock > 0) {
@ -779,7 +773,15 @@
fen2yuan(price) {
return Util.fen2yuan(price)
}
},
inArray: function(search, array) {
for (let i in array) {
if (array[i] === search) {
return true;
}
}
return false;
},
},
onReachBottom() {
// TODO