|
@@ -26,7 +26,8 @@
|
|
|
{{item.supplier.name}}
|
|
|
</checkbox>
|
|
|
</view>
|
|
|
- <checkbox-group name="checkbox" @change="goodsChange">
|
|
|
+ <checkbox-group name="checkbox" @change="goodsChange
|
|
|
+ ">
|
|
|
<view class="content" v-for="gs in item.list" :key="gs.specs._id">
|
|
|
<view class="box">
|
|
|
<checkbox :value="gs.specs._id" :checked="gs.check" />
|
|
@@ -52,7 +53,7 @@
|
|
|
:max="gs.specs.num" v-model="gs.num" />
|
|
|
</view>
|
|
|
<view class="del" v-if="num==1">
|
|
|
- <text class="iconfont icon-del-copy" @click="toDel(gs)"></text>
|
|
|
+ <text class="iconfont icon-icon-cross-empty" @click="toDel(gs)"></text>
|
|
|
</view>
|
|
|
</view>
|
|
|
</checkbox-group>
|
|
@@ -230,94 +231,73 @@
|
|
|
// 加减商品数量
|
|
|
async changeValue(value) {
|
|
|
const that = this;
|
|
|
- that.$nextTick(async () => {
|
|
|
- let res;
|
|
|
- const {
|
|
|
- goodsSpec_id: goodsSpecId,
|
|
|
- num,
|
|
|
- cart_id: cartId
|
|
|
- } = value
|
|
|
- res = await that.$api(`/cart/checkGoodsNum`, 'GET', {
|
|
|
- cartId,
|
|
|
- goodsSpecId,
|
|
|
- num
|
|
|
- });
|
|
|
- if (res.errcode === 0) {
|
|
|
- const {
|
|
|
- enough,
|
|
|
- total
|
|
|
- } = res.data
|
|
|
- if (!enough) {
|
|
|
+ let user = that.user;
|
|
|
+ if (user && user._id) {
|
|
|
+ this.$nextTick(async () => {
|
|
|
+ let res;
|
|
|
+ const obj = {
|
|
|
+ num: value.num,
|
|
|
+ money: that.$multiply(value.specs.money, value.num)
|
|
|
+ }
|
|
|
+ res = await that.$api(`/Cart/${value.cart_id}`, 'POST', obj)
|
|
|
+ if (res.errcode == '0') {
|
|
|
+ uni.showToast({
|
|
|
+ title: `加入购物车成功`,
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ that.searchMarket();
|
|
|
+ } else {
|
|
|
uni.showToast({
|
|
|
- title: `库存最大为${total}`,
|
|
|
- icon: 'error',
|
|
|
- });
|
|
|
- // 将该商品的库存量修改为最大值
|
|
|
- value.num = total;
|
|
|
+ title: res.errmsg,
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
}
|
|
|
- }
|
|
|
- // 计算总额
|
|
|
- that.countMoney();
|
|
|
- })
|
|
|
+ // 计算总额
|
|
|
+ that.countMoney();
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ uni.navigateTo({
|
|
|
+ url: `/pages/login/index`
|
|
|
+ })
|
|
|
+ }
|
|
|
},
|
|
|
// 删除, 接口,购物车删除,然后将该数据移除
|
|
|
async toDel(e) {
|
|
|
- const that = this;
|
|
|
- let list = that.list;
|
|
|
- let set_list = [];
|
|
|
- let goods_list = [];
|
|
|
+ let list = this.list;
|
|
|
+ let goodsList = [];
|
|
|
uni.showModal({
|
|
|
title: '提示',
|
|
|
content: '请选择要删除的商品',
|
|
|
success: async (res) => {
|
|
|
if (!res.confirm) return
|
|
|
if (e?.cart_id) {
|
|
|
- const result = await that.$api(`/cart/${e.cart_id}`, 'Delete');
|
|
|
+ const result = await this.$api(`/Cart/${e.cart_id}`, 'Delete');
|
|
|
if (result.errcode === 0) {
|
|
|
- // 判断是套装还是正常商品
|
|
|
- set_list = list.filter(i => i.is_set == '0')
|
|
|
- goods_list = list.filter(i => i.is_set !== '0')
|
|
|
- set_list = set_list.filter(i => i.cart_id !== e.cart_id)
|
|
|
- goods_list = goods_list.map(i => ({
|
|
|
+ goodsList = list.map(i => ({
|
|
|
...i,
|
|
|
- goods: i.goods.filter(f => f.cart_id !== e.cart_id)
|
|
|
+ list: i.list.filter(f => f.cart_id !== e.cart_id)
|
|
|
}))
|
|
|
- that.$set(that, `list`, [...set_list, ...goods_list]);
|
|
|
+ this.$set(this, `list`, goodsList);
|
|
|
// 检查店铺内是否还有商品
|
|
|
- that.checkShopGoodsExist();
|
|
|
+ this.checkShopGoodsExist();
|
|
|
// 计算总额
|
|
|
- that.countMoney();
|
|
|
+ this.countMoney();
|
|
|
}
|
|
|
} else {
|
|
|
- let goodsList = [];
|
|
|
let cartIds = [];
|
|
|
- for (let val of this.list) {
|
|
|
- // 判断是套装还是正常商品
|
|
|
- if (val.is_set == '0') goodsList.push(val)
|
|
|
- else goodsList.push(val.goods)
|
|
|
- }
|
|
|
- for (let val of goodsList) {
|
|
|
- // 判断是套装还是正常商品
|
|
|
- if (val.is_set == '0') {
|
|
|
- if (val.check) cartIds.push(val.cart_id)
|
|
|
- } else {
|
|
|
- for (let set of val) {
|
|
|
- if (set.check) cartIds.push(set.cart_id)
|
|
|
- }
|
|
|
+ for (let val of list) {
|
|
|
+ for (let s of val.list) {
|
|
|
+ if (s.check) cartIds.push(s.cart_id)
|
|
|
}
|
|
|
}
|
|
|
- set_list = list.filter(i => i.is_set == '0')
|
|
|
- goods_list = list.filter(i => i.is_set !== '0')
|
|
|
for (let val of cartIds) {
|
|
|
- const result = await this.$api(`/cart/${val}`, 'Delete');
|
|
|
+ const result = await this.$api(`/Cart/${val}`, 'Delete');
|
|
|
if (result.errcode === 0) {
|
|
|
- // 判断是套装还是正常商品
|
|
|
- set_list = set_list.filter(i => i.cart_id !== val)
|
|
|
- goods_list = goods_list.map(i => ({
|
|
|
+ goodsList = list.map(i => ({
|
|
|
...i,
|
|
|
- goods: i.goods.filter(f => f.cart_id !== val)
|
|
|
+ list: i.list.filter(f => f.cart_id !== val)
|
|
|
}))
|
|
|
- this.$set(this, `list`, [...set_list, ...goods_list]);
|
|
|
+ this.$set(this, `list`, goodsList);
|
|
|
// 检查店铺内是否还有商品
|
|
|
this.checkShopGoodsExist();
|
|
|
// 计算总额
|
|
@@ -331,8 +311,7 @@
|
|
|
//检查店铺内是否还有商品
|
|
|
checkShopGoodsExist() {
|
|
|
const that = this;
|
|
|
- let list = that.list;
|
|
|
- list = list.filter(f => f.list && f.list.length > 0)
|
|
|
+ const list = that.list.filter(f => f.list && f.list.length > 0)
|
|
|
that.$set(that `list`, list);
|
|
|
},
|
|
|
// 计算总额
|
|
@@ -341,7 +320,7 @@
|
|
|
const list = that.list;
|
|
|
let totalMoney = 0;
|
|
|
// 渲染结束执行下面方法
|
|
|
- that.$nextTick(() => {
|
|
|
+ this.$nextTick(() => {
|
|
|
for (const val of list) {
|
|
|
for (let as of val.list) {
|
|
|
if (as.check == true) {
|
|
@@ -356,23 +335,24 @@
|
|
|
// 显示图片处理
|
|
|
getFile(data) {
|
|
|
let file
|
|
|
- if (data.specs.file) file = data.specs.file
|
|
|
+ if (data.specs.file && data.specs.file.length > 0) file = data.specs.file
|
|
|
else file = data.goods.file;
|
|
|
if (!file) return '';
|
|
|
if (file.length && file.length > 0) return file[0].url
|
|
|
},
|
|
|
// 去结算
|
|
|
async toSettle() {
|
|
|
+ const that = this;
|
|
|
// 将选中的购物车放到数组中,传回服务端进行检查.然后拿着key去订单页请求数据
|
|
|
let goodsList = [];
|
|
|
let cartIds = [];
|
|
|
- for (let val of this.list) {
|
|
|
+ for (let val of that.list) {
|
|
|
goodsList.push(val)
|
|
|
}
|
|
|
for (let val of goodsList) {
|
|
|
if (val.check) cartIds.push(val.cart_id)
|
|
|
}
|
|
|
- const res = await this.$api(`/util/checkCartBuy`, 'POST', {
|
|
|
+ const res = await that.$api(`/util/checkCartBuy`, 'POST', {
|
|
|
cartIds
|
|
|
});
|
|
|
if (res.errcode == '0') {
|
|
@@ -389,7 +369,8 @@
|
|
|
},
|
|
|
// 是否选中商品,控制提交订单按钮
|
|
|
hasCheck() {
|
|
|
- return this.list.some(e => e.list.some(eg => eg.check))
|
|
|
+ const that = this;
|
|
|
+ return that.list.some(e => e.list.some(eg => eg.check))
|
|
|
},
|
|
|
// 公共跳转
|
|
|
toCommon(route, e) {
|