购物车:接入修改数量 API
parent
f579101f7c
commit
92cb6252ae
|
@ -114,8 +114,8 @@
|
||||||
<text class='checkAll'>全选({{selectValue.length}})</text>
|
<text class='checkAll'>全选({{selectValue.length}})</text>
|
||||||
</checkbox-group>
|
</checkbox-group>
|
||||||
</view>
|
</view>
|
||||||
<view class='money acea-row row-middle' v-if="footerswitch==true">
|
<view class='money acea-row row-middle' v-if="footerswitch">
|
||||||
<text class='font-color'>¥{{selectCountPrice}}</text>
|
<text class='font-color'>¥{{ fen2yuan(selectCountPrice) }}</text>
|
||||||
<form @submit="subOrder" report-submit='true'>
|
<form @submit="subOrder" report-submit='true'>
|
||||||
<button class='placeOrder bg-color' formType="submit">立即下单</button>
|
<button class='placeOrder bg-color' formType="submit">立即下单</button>
|
||||||
</form>
|
</form>
|
||||||
|
@ -140,7 +140,7 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
let sysHeight = 0
|
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 { getProductHot, collectAll, getProductDetail } from '@/api/store.js';
|
||||||
import { toLogin } from '@/libs/login.js';
|
import { toLogin } from '@/libs/login.js';
|
||||||
import { mapGetters } from "vuex";
|
import { mapGetters } from "vuex";
|
||||||
|
@ -155,7 +155,6 @@
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
cartCount: 0,
|
|
||||||
goodsHidden: false,
|
goodsHidden: false,
|
||||||
footerswitch: true,
|
footerswitch: true,
|
||||||
hostProduct: [],
|
hostProduct: [],
|
||||||
|
@ -163,13 +162,14 @@
|
||||||
hotLimit: 10,
|
hotLimit: 10,
|
||||||
hotScroll: false,
|
hotScroll: false,
|
||||||
|
|
||||||
cartList: {
|
cartList: { // 购物车列表
|
||||||
valid: [],
|
valid: [], // 有效
|
||||||
invalid: []
|
invalid: [] // 无效
|
||||||
},
|
},
|
||||||
isAllSelect: false, // 是否全选
|
isAllSelect: false, // 是否全选
|
||||||
selectValue: [], // 选中的数据
|
selectValue: [], // 选中的数据
|
||||||
selectCountPrice: 0.00,
|
selectCountPrice: 0.00, // 选中的金额
|
||||||
|
cartCount: 0, // 选中的商品数量
|
||||||
|
|
||||||
loading: false,
|
loading: false,
|
||||||
loadTitle: '加载更多', //提示语
|
loadTitle: '加载更多', //提示语
|
||||||
|
@ -211,13 +211,11 @@
|
||||||
valid: [],
|
valid: [],
|
||||||
invalid: []
|
invalid: []
|
||||||
};
|
};
|
||||||
|
this.isAllSelect = false; // 全选
|
||||||
|
this.selectValue = []; // 选中的数据
|
||||||
|
this.selectCountPrice = 0.00;
|
||||||
|
this.cartCount = 0;
|
||||||
this.getCartList();
|
this.getCartList();
|
||||||
this.isAllSelect = false; //全选
|
|
||||||
this.selectValue = []; //选中的数据
|
|
||||||
this.selectCountPrice = 0.00;
|
|
||||||
|
|
||||||
// TODO 芋艿:
|
|
||||||
this.cartCount = 0;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
@ -250,7 +248,6 @@
|
||||||
that.loadend = false;
|
that.loadend = false;
|
||||||
that.cartList.valid = [];
|
that.cartList.valid = [];
|
||||||
that.getCartList();
|
that.getCartList();
|
||||||
that.getCartNum();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
@ -425,7 +422,6 @@
|
||||||
that.loadend = false;
|
that.loadend = false;
|
||||||
that.cartList.valid = [];
|
that.cartList.valid = [];
|
||||||
that.getCartList();
|
that.getCartList();
|
||||||
that.getCartNum();
|
|
||||||
});
|
});
|
||||||
else
|
else
|
||||||
return that.$util.Tips({
|
return that.$util.Tips({
|
||||||
|
@ -443,7 +439,7 @@
|
||||||
productId.push(validList[index].productId);
|
productId.push(validList[index].productId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
return productId;
|
return productId;
|
||||||
},
|
},
|
||||||
subCollect: function(event) {
|
subCollect: function(event) {
|
||||||
|
@ -563,31 +559,27 @@
|
||||||
that.selectValue = value;
|
that.selectValue = value;
|
||||||
that.switchSelect();
|
that.switchSelect();
|
||||||
},
|
},
|
||||||
inArray: function(search, array) {
|
/**
|
||||||
for (let i in array) {
|
* 合计金额、数量
|
||||||
if (array[i] == search) {
|
*/
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
switchSelect: function() {
|
switchSelect: function() {
|
||||||
let that = this;
|
const validList = this.cartList.valid;
|
||||||
let validList = that.cartList.valid;
|
const selectValue = this.selectValue;
|
||||||
let selectValue = that.selectValue;
|
|
||||||
let selectCountPrice = 0.00;
|
|
||||||
if (selectValue.length < 1) {
|
if (selectValue.length < 1) {
|
||||||
that.selectCountPrice = selectCountPrice;
|
this.selectCountPrice = 0.00;
|
||||||
} else {
|
return;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
// 合计金额
|
||||||
|
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)
|
this.$set(this.cartList, 'valid', this.cartList.valid)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* 减少购买数量
|
||||||
|
*/
|
||||||
subCart: function(index) {
|
subCart: function(index) {
|
||||||
let that = this;
|
let item = this.cartList.valid[index];
|
||||||
let status = false;
|
if (item.count < 1) {
|
||||||
let item = that.cartList.valid[index];
|
this.$util.Tips({
|
||||||
item.cartNum = Number(item.cartNum) - 1;
|
title: '商品数量不能减少!'
|
||||||
if (item.cartNum < 1) status = true;
|
});
|
||||||
if (item.cartNum <= 1) {
|
return;
|
||||||
item.cartNum = 1;
|
}
|
||||||
|
// 本地先修改状态
|
||||||
|
item.count = Number(item.count) - 1;
|
||||||
|
if (item.count <= 1) {
|
||||||
|
item.count = 1;
|
||||||
item.numSub = true;
|
item.numSub = true;
|
||||||
} else {
|
} else {
|
||||||
item.numSub = false;
|
item.numSub = false;
|
||||||
item.numAdd = false;
|
item.numAdd = false;
|
||||||
}
|
}
|
||||||
if (false == status) {
|
// 提交修改
|
||||||
that.setCartNum(item.id, item.cartNum, function(data) {
|
this.setCartNum(item.id, item.count);
|
||||||
that.cartList.valid[index] = item;
|
|
||||||
that.switchSelect();
|
|
||||||
that.getCartNum();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* 增加购买数量
|
||||||
|
*/
|
||||||
addCart: function(index) {
|
addCart: function(index) {
|
||||||
let that = this;
|
// 本地先修改状态
|
||||||
let item = that.cartList.valid[index];
|
let item = this.cartList.valid[index];
|
||||||
item.cartNum = Number(item.cartNum) + 1;
|
item.count = Number(item.count) + 1
|
||||||
if (item.cartNum >= item.stock) {
|
if (item.count >= item.sku.stock) {
|
||||||
item.cartNum = item.stock;
|
item.count = item.sku.stock;
|
||||||
item.numAdd = true;
|
item.numAdd = true;
|
||||||
item.numSub = false;
|
item.numSub = false;
|
||||||
} else {
|
} else {
|
||||||
item.numAdd = false;
|
item.numAdd = false;
|
||||||
item.numSub = false;
|
item.numSub = false;
|
||||||
}
|
}
|
||||||
that.setCartNum(item.id, item.cartNum, function(data) {
|
// 提交修改
|
||||||
that.cartList.valid[index] = item;
|
this.setCartNum(item.id, item.count);
|
||||||
that.switchSelect();
|
|
||||||
that.getCartNum();
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
setCartNum(cartId, cartNum, successCallback) {
|
/**
|
||||||
let that = this;
|
* 修改购物项为指定数量
|
||||||
changeCartNum(cartId, cartNum).then(res => {
|
*/
|
||||||
successCallback && successCallback(res.data);
|
setCartNum(cartId, cartNum) {
|
||||||
});
|
TradeCartApi.updateCart({
|
||||||
},
|
id: cartId,
|
||||||
getCartNum: function() {
|
count: cartNum
|
||||||
let that = this;
|
}).then(res => {
|
||||||
getCartCounts(true, 'sum').then(res => {
|
// 加载最新状态
|
||||||
that.cartCount = res.data.count;
|
this.getCartList()
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getCartData() {
|
getCartData() {
|
||||||
|
@ -688,7 +682,7 @@
|
||||||
validList[index].numSub = validList[index].cartNum === 1;
|
validList[index].numSub = validList[index].cartNum === 1;
|
||||||
// 设置是否可添加(到顶,不可添加)
|
// 设置是否可添加(到顶,不可添加)
|
||||||
const sku = validList[index].sku;
|
const sku = validList[index].sku;
|
||||||
validList[index].numAdd = !!(sku && validList[index].count === sku.stock);
|
validList[index].numAdd = sku && validList[index].count < sku.stock;
|
||||||
// 设置为选中,并添加到 selectValue 数组中
|
// 设置为选中,并添加到 selectValue 数组中
|
||||||
// why?库存不足时,可以引导选择该 SPU 对应的其它 SKU。而 invalidList 是 SPU 不存在或者库存彻底不足
|
// why?库存不足时,可以引导选择该 SPU 对应的其它 SKU。而 invalidList 是 SPU 不存在或者库存彻底不足
|
||||||
if (sku && sku.stock > 0) {
|
if (sku && sku.stock > 0) {
|
||||||
|
@ -779,7 +773,15 @@
|
||||||
|
|
||||||
fen2yuan(price) {
|
fen2yuan(price) {
|
||||||
return Util.fen2yuan(price)
|
return Util.fen2yuan(price)
|
||||||
}
|
},
|
||||||
|
inArray: function(search, array) {
|
||||||
|
for (let i in array) {
|
||||||
|
if (array[i] === search) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
onReachBottom() {
|
onReachBottom() {
|
||||||
// TODO 芋艿:临时禁用
|
// TODO 芋艿:临时禁用
|
||||||
|
|
Loading…
Reference in New Issue