修改购物车样式和逻辑
This commit is contained in:
parent
e1014ef6ef
commit
c15528bcde
@ -76,6 +76,12 @@
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.goodsItem_tit{
|
||||
margin: 20rpx 0 0 20rpx;
|
||||
font-size: 35rpx;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.goodsItem {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
@ -28,46 +28,51 @@
|
||||
当日达
|
||||
</view>
|
||||
<view class="goodsList">
|
||||
<view class="goodsItem" v-for="(item, index) in isDayCarList" :key="item.id">
|
||||
|
||||
<view class="goodsItem_left" @click="DayChecked(item, index)">
|
||||
<image v-if="!item.checked"
|
||||
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/com_check1.png">
|
||||
</image>
|
||||
<image v-if="item.checked"
|
||||
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/com_check2.png">
|
||||
</image>
|
||||
<view v-for="(carItem, carIndex) in isDayCarList" :key="carItem.id" :index="carIndex">
|
||||
<view class="goodsItem_tit">
|
||||
{{ carItem.supplier_name }}
|
||||
</view>
|
||||
<view class="goodsItem_right">
|
||||
<view class="goodsItem_msg">
|
||||
<view class="goodsItem_msg_img">
|
||||
<view class="tag tag-img">当日达</view>
|
||||
<image :src="picUrl + item.commodity_goods_info.commodity_pic">
|
||||
</image>
|
||||
</view>
|
||||
<view class="goodsItem_msg_right">
|
||||
<view class="goodsItem_msg_right_tit">
|
||||
{{ item.commodity_goods_info.goods_name }}
|
||||
<view class="goodsItem" v-for="(item, index) in carItem.commodity_cart_and_goods_model"
|
||||
:key="item.id">
|
||||
<view class="goodsItem_left" @click="DayChecked(item)">
|
||||
<image v-if="!item.checked"
|
||||
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/com_check1.png">
|
||||
</image>
|
||||
<image v-if="item.checked"
|
||||
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/com_check2.png">
|
||||
</image>
|
||||
</view>
|
||||
<view class="goodsItem_right">
|
||||
<view class="goodsItem_msg">
|
||||
<view class="goodsItem_msg_img">
|
||||
<view class="tag tag-img">当日达</view>
|
||||
<image :src="picUrl + item.commodity_goods_info.commodity_pic">
|
||||
</image>
|
||||
</view>
|
||||
<view class="goodsItem_msg_right_subTit">
|
||||
{{ item.commodity_goods_info.goods_intro }}
|
||||
</view>
|
||||
<view class="goodsItem_msg_right_msg">
|
||||
<view class="goodsItem_msg_right_msg_left">
|
||||
<span>¥</span>{{ item.commodity_goods_info.sales_price }}
|
||||
<span>/{{ item.commodity_goods_info.goods_unit }}</span>
|
||||
<view class="goodsItem_msg_right">
|
||||
<view class="goodsItem_msg_right_tit">
|
||||
{{ item.commodity_goods_info.goods_name }}
|
||||
</view>
|
||||
<view class="goodsItem_msg_right_msg_right">
|
||||
<u-number-box v-model="item.count" :asyncChange="true" min="0">
|
||||
<view slot="minus" class="minus" @click="minus(item, index)">
|
||||
<u-icon name="minus" size="32" bold></u-icon>
|
||||
</view>
|
||||
<text slot="input" style="width: 80rpx; text-align: center"
|
||||
class="input">{{ item.count }}</text>
|
||||
<view slot="plus" class="plus" @click="add(item, index)">
|
||||
<u-icon name="plus" color="#FFFFFF" size="32" bold></u-icon>
|
||||
</view>
|
||||
</u-number-box>
|
||||
<view class="goodsItem_msg_right_subTit">
|
||||
{{ item.commodity_goods_info.goods_intro }}
|
||||
</view>
|
||||
<view class="goodsItem_msg_right_msg">
|
||||
<view class="goodsItem_msg_right_msg_left">
|
||||
<span>¥</span>{{ item.commodity_goods_info.sales_price }}
|
||||
<span>/{{ item.commodity_goods_info.goods_unit }}</span>
|
||||
</view>
|
||||
<view class="goodsItem_msg_right_msg_right">
|
||||
<u-number-box v-model="item.count" :asyncChange="true" min="0">
|
||||
<view slot="minus" class="minus" @click="minus(carItem, index)">
|
||||
<u-icon name="minus" size="32" bold></u-icon>
|
||||
</view>
|
||||
<text slot="input" style="width: 80rpx; text-align: center"
|
||||
class="input">{{ item.count }}</text>
|
||||
<view slot="plus" class="plus" @click="add(carItem, index)">
|
||||
<u-icon name="plus" color="#FFFFFF" size="32" bold></u-icon>
|
||||
</view>
|
||||
</u-number-box>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@ -90,46 +95,51 @@
|
||||
包邮
|
||||
</view>
|
||||
<view class="goodsList">
|
||||
<view class="goodsItem" v-for="(item, index) in shopCarList" :key="item.id">
|
||||
|
||||
<view class="goodsItem_left" @click="changeChecked(item, index)">
|
||||
<image v-if="!item.checked"
|
||||
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/com_check1.png">
|
||||
</image>
|
||||
<image v-if="item.checked"
|
||||
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/com_check2.png">
|
||||
</image>
|
||||
<view v-for="(carItem, carIndex) in shopCarList" :key="carItem.id" :index="carIndex">
|
||||
<view class="goodsItem_tit">
|
||||
{{ carItem.supplier_name }}
|
||||
</view>
|
||||
<view class="goodsItem_right">
|
||||
<view class="goodsItem_msg">
|
||||
<view class="goodsItem_msg_img">
|
||||
<view class="goodsItem" v-for="(item, index) in carItem.commodity_cart_and_goods_model"
|
||||
:key="item.id">
|
||||
<view class="goodsItem_left" @click="changeChecked(item)">
|
||||
<image v-if="!item.checked"
|
||||
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/com_check1.png">
|
||||
</image>
|
||||
<image v-if="item.checked"
|
||||
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/com_check2.png">
|
||||
</image>
|
||||
</view>
|
||||
<view class="goodsItem_right">
|
||||
<view class="goodsItem_msg">
|
||||
<view class="goodsItem_msg_img">
|
||||
|
||||
<image :src="picUrl + item.commodity_goods_info.commodity_pic">
|
||||
</image>
|
||||
</view>
|
||||
<view class="goodsItem_msg_right">
|
||||
<view class="goodsItem_msg_right_tit">
|
||||
{{ item.commodity_goods_info.goods_name }}
|
||||
<image :src="picUrl + item.commodity_goods_info.commodity_pic">
|
||||
</image>
|
||||
</view>
|
||||
<view class="goodsItem_msg_right_subTit">
|
||||
{{ item.commodity_goods_info.goods_intro }}
|
||||
</view>
|
||||
<view class="goodsItem_msg_right_msg">
|
||||
<view class="goodsItem_msg_right_msg_left">
|
||||
<span>¥</span>{{ item.commodity_goods_info.sales_price }}
|
||||
<span>/{{ item.commodity_goods_info.goods_unit }}</span>
|
||||
<view class="goodsItem_msg_right">
|
||||
<view class="goodsItem_msg_right_tit">
|
||||
{{ item.commodity_goods_info.goods_name }}
|
||||
</view>
|
||||
<view class="goodsItem_msg_right_msg_right">
|
||||
<u-number-box v-model="item.count" :asyncChange="true" min="0">
|
||||
<view slot="minus" class="minus" @click="minus(item, index)">
|
||||
<u-icon name="minus" size="32" bold></u-icon>
|
||||
</view>
|
||||
<text slot="input" style="width: 80rpx; text-align: center"
|
||||
class="input">{{ item.count }}</text>
|
||||
<view slot="plus" class="plus" @click="add(item, index)">
|
||||
<u-icon name="plus" color="#FFFFFF" size="32" bold></u-icon>
|
||||
</view>
|
||||
</u-number-box>
|
||||
<view class="goodsItem_msg_right_subTit">
|
||||
{{ item.commodity_goods_info.goods_intro }}
|
||||
</view>
|
||||
<view class="goodsItem_msg_right_msg">
|
||||
<view class="goodsItem_msg_right_msg_left">
|
||||
<span>¥</span>{{ item.commodity_goods_info.sales_price }}
|
||||
<span>/{{ item.commodity_goods_info.goods_unit }}</span>
|
||||
</view>
|
||||
<view class="goodsItem_msg_right_msg_right">
|
||||
<u-number-box v-model="item.count" :asyncChange="true" min="0">
|
||||
<view slot="minus" class="minus" @click="minus(item, index)">
|
||||
<u-icon name="minus" size="32" bold></u-icon>
|
||||
</view>
|
||||
<text slot="input" style="width: 80rpx; text-align: center"
|
||||
class="input">{{ item.count }}</text>
|
||||
<view slot="plus" class="plus" @click="add(item, index)">
|
||||
<u-icon name="plus" color="#FFFFFF" size="32" bold></u-icon>
|
||||
</view>
|
||||
</u-number-box>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@ -175,281 +185,363 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
apiArr
|
||||
} from "../../../api/shop";
|
||||
import {
|
||||
picUrl,
|
||||
menuButtonInfo,
|
||||
request,
|
||||
NavgateTo
|
||||
} from "../../../utils";
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
picUrl,
|
||||
top: "",
|
||||
localHeight: "",
|
||||
value: 3,
|
||||
type: "error",
|
||||
shopCarList: [],
|
||||
isDayCarList: [],
|
||||
shopCarTotal: 0,
|
||||
shopMoney: 0,
|
||||
isAllchecked: false, // 全选
|
||||
isDaychecked: false, // 当日达
|
||||
isDayshow: false,
|
||||
isParcelPostchecked: false,
|
||||
parcelPostshow: false,
|
||||
import {
|
||||
apiArr
|
||||
} from "../../../api/shop";
|
||||
import {
|
||||
picUrl,
|
||||
menuButtonInfo,
|
||||
request,
|
||||
NavgateTo
|
||||
} from "../../../utils";
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
picUrl,
|
||||
top: "",
|
||||
localHeight: "",
|
||||
value: 3,
|
||||
type: "error",
|
||||
shopCarList: [],
|
||||
isDayCarList: [],
|
||||
shopCarTotal: 0,
|
||||
shopMoney: 0,
|
||||
isAllchecked: false, // 全选
|
||||
isDaychecked: false, // 当日达
|
||||
isDayshow: false,
|
||||
isParcelPostchecked: false,
|
||||
parcelPostshow: false,
|
||||
|
||||
};
|
||||
};
|
||||
},
|
||||
// watch: {
|
||||
// // console.log(this.isDaychecked);
|
||||
// isDaychecked(e) {
|
||||
// console.log('当日达状态', e);
|
||||
// },
|
||||
// isParcelPostchecked(e) {
|
||||
// console.log('包邮状态', e);
|
||||
// }
|
||||
// isAllchecked(e) {
|
||||
// console.log('全选状态', e);
|
||||
// }
|
||||
// },
|
||||
methods: {
|
||||
back() {
|
||||
NavgateTo("1");
|
||||
},
|
||||
// watch: {
|
||||
// // console.log(this.isDaychecked);
|
||||
// isDaychecked(e) {
|
||||
// console.log('当日达状态', e);
|
||||
// },
|
||||
// isParcelPostchecked(e) {
|
||||
// console.log('包邮状态', e);
|
||||
// }
|
||||
// isAllchecked(e) {
|
||||
// console.log('全选状态', e);
|
||||
// }
|
||||
// },
|
||||
methods: {
|
||||
back() {
|
||||
NavgateTo("1");
|
||||
},
|
||||
|
||||
// 结算
|
||||
submitOrder() {
|
||||
let arr = [];
|
||||
this.shopCarList.forEach((item) => {
|
||||
if (item.checked) {
|
||||
arr.push(item);
|
||||
// 结算
|
||||
submitOrder() {
|
||||
let arr = [];
|
||||
console.log("🚀 ~ submitOrder ~ this.shopCarList:", this.shopCarList)
|
||||
// 收集包邮购物车中选中的商品
|
||||
this.shopCarList.forEach((item) => {
|
||||
item.commodity_cart_and_goods_model.forEach((ite) => {
|
||||
if (ite.checked) {
|
||||
arr.push(ite);
|
||||
}
|
||||
});
|
||||
})
|
||||
});
|
||||
// 收集当日达购物车中选中的商品
|
||||
this.isDayCarList.forEach((item) => {
|
||||
item.commodity_cart_and_goods_model.forEach((ite) => {
|
||||
if (ite.checked) {
|
||||
arr.push(ite);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
// NavgateTo(`../submitOrder/index?shopCarList=${JSON.stringify(arr)}`);
|
||||
NavgateTo(`../groupPurchaseSubmit/index?shopCarList=${JSON.stringify(arr)}`);
|
||||
},
|
||||
// NavgateTo(`../submitOrder/index?shopCarList=${JSON.stringify(arr)}`);
|
||||
NavgateTo(`../groupPurchaseSubmit/index?shopCarList=${JSON.stringify(arr)}`);
|
||||
},
|
||||
|
||||
// 获取购物车列表
|
||||
getShopCar() {
|
||||
request(apiArr.getCar, "POST", {}).then((res) => {
|
||||
console.log(res.total);
|
||||
// res.commodity_cart_list.forEach((item) => {
|
||||
// 获取购物车列表
|
||||
getShopCar() {
|
||||
request(apiArr.getCar, "POST", {}).then((res) => {
|
||||
if (res.normal_cart_list.length > 0) {
|
||||
res.normal_cart_list.forEach((item) => {
|
||||
console.log(item.commodity_cart_and_goods_model);
|
||||
if(item.is_support_same_day == false) {
|
||||
this.isDayshow = false;
|
||||
this.parcelPostshow = true;
|
||||
this.shopCarList = item.commodity_cart_and_goods_model;
|
||||
item.checked = false;
|
||||
} else {
|
||||
this.isDayshow = true;
|
||||
this.parcelPostshow = false;
|
||||
this.isDayCarList = item.commodity_cart_and_goods_model;
|
||||
item.checked = false;
|
||||
}
|
||||
});
|
||||
item.checked = false;
|
||||
this.parcelPostshow = true;
|
||||
})
|
||||
this.shopCarList = res.normal_cart_list
|
||||
} else {
|
||||
res.normal_cart_list.forEach((item) => {
|
||||
item.checked = false;
|
||||
this.parcelPostshow = false;
|
||||
})
|
||||
}
|
||||
|
||||
// this.shopCarList = res.commodity_cart_list;
|
||||
// this.shopCarList = res.normal_cart_list[0].commodity_cart_and_goods_model;
|
||||
this.shopCarTotal = res.total;
|
||||
if (res.same_day_cart_list.length > 0) {
|
||||
res.same_day_cart_list.forEach((item) => {
|
||||
item.checked = false;
|
||||
this.isDayshow = true;
|
||||
})
|
||||
this.isDayCarList = res.same_day_cart_list
|
||||
} else {
|
||||
res.normal_cart_list.forEach((item) => {
|
||||
item.checked = false;
|
||||
this.isDayshow = false;
|
||||
})
|
||||
}
|
||||
|
||||
// res.normal_cart_list.forEach((item) => {
|
||||
// if (item.is_support_same_day == false) {
|
||||
// this.isDayshow = false;
|
||||
// this.parcelPostshow = true;
|
||||
// this.shopCarList = item.commodity_cart_and_goods_model;
|
||||
// item.checked = false;
|
||||
// } else {
|
||||
// this.isDayshow = true;
|
||||
// this.parcelPostshow = false;
|
||||
// this.isDayCarList = item.commodity_cart_and_goods_model;
|
||||
// item.checked = false;
|
||||
// }
|
||||
// });
|
||||
|
||||
this.shopCarTotal = res.total;
|
||||
});
|
||||
},
|
||||
|
||||
// 单个修改
|
||||
changeChecked(item) {
|
||||
item.checked = !item.checked;
|
||||
this.calcTotal();
|
||||
// 检查当日达是否全选
|
||||
this.isDaychecked = this.isDayCarList.every(carItem =>
|
||||
carItem.commodity_cart_and_goods_model.every(goods => goods.checked)
|
||||
);
|
||||
// 检查包邮是否全选
|
||||
this.isParcelPostchecked = this.shopCarList.every(carItem =>
|
||||
carItem.commodity_cart_and_goods_model.every(goods => goods.checked)
|
||||
);
|
||||
// 检查全选状态
|
||||
this.isAllchecked = this.isDaychecked && this.isParcelPostchecked;
|
||||
},
|
||||
DayChecked(item) {
|
||||
item.checked = !item.checked;
|
||||
this.calcTotal();
|
||||
// 检查当日达是否全选
|
||||
this.isDaychecked = this.isDayCarList.every(carItem =>
|
||||
carItem.commodity_cart_and_goods_model.every(goods => goods.checked)
|
||||
);
|
||||
// 检查包邮是否全选
|
||||
this.isParcelPostchecked = this.shopCarList.every(carItem =>
|
||||
carItem.commodity_cart_and_goods_model.every(goods => goods.checked)
|
||||
);
|
||||
// 检查全选状态
|
||||
this.isAllchecked = this.isDaychecked && this.isParcelPostchecked;
|
||||
},
|
||||
// 全选
|
||||
allChecked() {
|
||||
this.isAllchecked = !this.isAllchecked;
|
||||
this.isDaychecked = this.isAllchecked;
|
||||
this.isParcelPostchecked = this.isAllchecked;
|
||||
|
||||
// 设置当日达购物车商品选中状态
|
||||
this.isDayCarList.forEach(carItem => {
|
||||
carItem.commodity_cart_and_goods_model.forEach(goods => {
|
||||
goods.checked = this.isAllchecked;
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
// ceshi() {
|
||||
// console.log(this.shopCarTotal);
|
||||
// 设置包邮购物车商品选中状态
|
||||
this.shopCarList.forEach(carItem => {
|
||||
carItem.commodity_cart_and_goods_model.forEach(goods => {
|
||||
goods.checked = this.isAllchecked;
|
||||
});
|
||||
});
|
||||
|
||||
// console.log(this.shopCarList);
|
||||
// },
|
||||
this.calcTotal();
|
||||
},
|
||||
|
||||
// 单个修改
|
||||
changeChecked(item, index) {
|
||||
this.shopCarList[index].checked = !this.shopCarList[index].checked;
|
||||
this.calcTotal();
|
||||
this.isParcelPostchecked = this.shopCarList.every((item) => item.checked);
|
||||
if(this.isDayshow == false) {
|
||||
this.isAllchecked = this.shopCarList.every((item) => item.checked);
|
||||
}
|
||||
},
|
||||
DayChecked(item, index) {
|
||||
this.isDayCarList[index].checked = !this.isDayCarList[index].checked;
|
||||
this.calcTotal();
|
||||
this.isDaychecked = this.isDayCarList.every((item) => item.checked);
|
||||
if(this.parcelPostshow == false) {
|
||||
this.isAllchecked = this.isDayCarList.every((item) => item.checked);
|
||||
}
|
||||
},
|
||||
// 全选
|
||||
allChecked() {
|
||||
this.isAllchecked = !this.isAllchecked;
|
||||
// this.isDaychecked = !this.isDaychecked;
|
||||
// this.isParcelPostchecked = !this.isParcelPostchecked;
|
||||
// Bug 修复:将 !this.allChecked 改为 !this.isAllchecked
|
||||
if (this.isAllchecked) {
|
||||
this.isDaychecked = true;
|
||||
this.isParcelPostchecked = true;
|
||||
this.shopCarList.forEach((item) => {
|
||||
item.checked = true;
|
||||
});
|
||||
} else {
|
||||
this.isDaychecked = false;
|
||||
this.isParcelPostchecked = false;
|
||||
this.shopCarList.forEach((item) => {
|
||||
item.checked = false;
|
||||
});
|
||||
}
|
||||
this.calcTotal();
|
||||
},
|
||||
// 全选当日达
|
||||
is_day_checked() {
|
||||
this.isDaychecked = !this.isDaychecked;
|
||||
|
||||
// 全选当日达
|
||||
is_day_checked() {
|
||||
this.isDaychecked = !this.isDaychecked;
|
||||
this.isAllchecked = !this.isAllchecked
|
||||
if (this.isDaychecked) {
|
||||
this.isDayCarList.forEach((item) => {
|
||||
item.checked = true;
|
||||
});
|
||||
} else {
|
||||
this.isDayCarList.forEach((item) => {
|
||||
item.checked = false;
|
||||
});
|
||||
}
|
||||
this.calcTotal();
|
||||
// 设置当日达购物车商品选中状态
|
||||
this.isDayCarList.forEach(carItem => {
|
||||
carItem.commodity_cart_and_goods_model.forEach(goods => {
|
||||
goods.checked = this.isDaychecked;
|
||||
});
|
||||
});
|
||||
|
||||
// 更新全选状态
|
||||
this.isAllchecked = this.isDaychecked && this.isParcelPostchecked;
|
||||
|
||||
console.log("全选当日达");
|
||||
},
|
||||
this.calcTotal();
|
||||
},
|
||||
|
||||
// 全选包邮
|
||||
parcel_post_checked() {
|
||||
this.isParcelPostchecked = !this.isParcelPostchecked;
|
||||
this.isAllchecked = !this.isAllchecked
|
||||
console.log(this.isParcelPostchecked);
|
||||
if (this.isParcelPostchecked) {
|
||||
this.shopCarList.forEach((item) => {
|
||||
item.checked = true;
|
||||
});
|
||||
} else {
|
||||
this.shopCarList.forEach((item) => {
|
||||
item.checked = false;
|
||||
});
|
||||
}
|
||||
// 全选包邮
|
||||
parcel_post_checked() {
|
||||
this.isParcelPostchecked = !this.isParcelPostchecked;
|
||||
|
||||
this.calcTotal();
|
||||
// 设置包邮购物车商品选中状态
|
||||
this.shopCarList.forEach(carItem => {
|
||||
carItem.commodity_cart_and_goods_model.forEach(goods => {
|
||||
goods.checked = this.isParcelPostchecked;
|
||||
});
|
||||
});
|
||||
|
||||
// 更新全选状态
|
||||
this.isAllchecked = this.isDaychecked && this.isParcelPostchecked;
|
||||
|
||||
console.log("全选包邮");
|
||||
},
|
||||
this.calcTotal();
|
||||
},
|
||||
|
||||
// 计算金额
|
||||
calcTotal() {
|
||||
let total = 0;
|
||||
this.shopCarList.forEach((item) => {
|
||||
console.log(item);
|
||||
// 计算金额
|
||||
calcTotal() {
|
||||
let total = 0;
|
||||
|
||||
if (item.checked) {
|
||||
total += item.commodity_goods_info.sales_price * item.count;
|
||||
// 计算当日达购物车金额
|
||||
this.isDayCarList.forEach(carItem => {
|
||||
carItem.commodity_cart_and_goods_model.forEach(goods => {
|
||||
if (goods.checked) {
|
||||
total += goods.commodity_goods_info.sales_price * goods.count;
|
||||
}
|
||||
});
|
||||
this.shopMoney = total;
|
||||
},
|
||||
});
|
||||
|
||||
// 减少数量
|
||||
minus(item, index) {
|
||||
let that = this;
|
||||
if (item.count === 1) {
|
||||
request(apiArr.deleteCar, "POST", {
|
||||
ids: [item.id],
|
||||
}).then((res) => {
|
||||
that.shopCarList.splice(index, 1);
|
||||
that.calcTotal();
|
||||
});
|
||||
}
|
||||
this.shopCarTotal = this.shopCarTotal - 1
|
||||
this.shopCarList[index].count = this.shopCarList[index].count - 1;
|
||||
this.handleQuantityChange(this.shopCarList[index].count, this.shopCarList[index])
|
||||
// 计算包邮购物车金额
|
||||
this.shopCarList.forEach(carItem => {
|
||||
carItem.commodity_cart_and_goods_model.forEach(goods => {
|
||||
if (goods.checked) {
|
||||
total += goods.commodity_goods_info.sales_price * goods.count;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
this.shopMoney = total;
|
||||
},
|
||||
|
||||
// 减少数量
|
||||
minus(carItem, goodsIndex) {
|
||||
let that = this;
|
||||
const item = carItem.commodity_cart_and_goods_model;
|
||||
|
||||
if (carItem.count === 1) {
|
||||
request(apiArr.deleteCar, "POST", {
|
||||
ids: [item.id],
|
||||
}).then((res) => {
|
||||
carItem.commodity_cart_and_goods_model.splice(goodsIndex, 1);
|
||||
// 如果商家没有商品了,移除该商家
|
||||
if (carItem.commodity_cart_and_goods_model.length === 0) {
|
||||
const carIndex = this.shopCarList.indexOf(carItem);
|
||||
if (carIndex !== -1) {
|
||||
this.shopCarList.splice(carIndex, 1);
|
||||
}
|
||||
}
|
||||
that.calcTotal();
|
||||
that.shopCarTotal = that.shopCarTotal - 1;
|
||||
});
|
||||
} else {
|
||||
this.shopCarTotal = this.shopCarTotal - 1;
|
||||
carItem.count = carItem.count - 1;
|
||||
this.handleQuantityChange(carItem.count, carItem);
|
||||
this.calcTotal();
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
// 添加数量
|
||||
add(item, index) {
|
||||
this.shopCarTotal = this.shopCarTotal + 1
|
||||
this.shopCarList[index].count = this.shopCarList[index].count + 1;
|
||||
this.handleQuantityChange(this.shopCarList[index].count, this.shopCarList[index])
|
||||
this.calcTotal();
|
||||
},
|
||||
// 添加数量
|
||||
add(carItem, goodsIndex) {
|
||||
const item = carItem.commodity_cart_and_goods_model;
|
||||
this.shopCarTotal = this.shopCarTotal + 1;
|
||||
carItem.count = carItem.count + 1;
|
||||
this.handleQuantityChange(carItem.count, carItem);
|
||||
this.calcTotal();
|
||||
},
|
||||
|
||||
// 删除
|
||||
deleteItem() {
|
||||
let that = this;
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
content: "确定删除所选商品吗",
|
||||
success: function(res) {
|
||||
if (res.confirm) {
|
||||
let ids = [];
|
||||
that.shopCarList.forEach((item) => {
|
||||
if (item.checked) {
|
||||
ids.push(item.id);
|
||||
item.checked = false;
|
||||
// 删除
|
||||
deleteItem() {
|
||||
let that = this;
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
content: "确定删除所选商品吗",
|
||||
success: function (res) {
|
||||
if (res.confirm) {
|
||||
let ids = [];
|
||||
|
||||
// 收集当日达购物车中选中的商品ID
|
||||
that.isDayCarList.forEach(carItem => {
|
||||
carItem.commodity_cart_and_goods_model.forEach(goods => {
|
||||
if (goods.checked) {
|
||||
ids.push(goods.id);
|
||||
goods.checked = false;
|
||||
}
|
||||
});
|
||||
request(apiArr.deleteCar, "POST", {
|
||||
ids,
|
||||
})
|
||||
.then((res) => {
|
||||
uni.showToast({
|
||||
title: "删除成功",
|
||||
duration: 2000,
|
||||
});
|
||||
that.getShopCar();
|
||||
that.calcTotal();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
} else if (res.cancel) {
|
||||
console.log("用户点击取消");
|
||||
});
|
||||
|
||||
// 收集包邮购物车中选中的商品ID
|
||||
that.shopCarList.forEach(carItem => {
|
||||
carItem.commodity_cart_and_goods_model.forEach(goods => {
|
||||
if (goods.checked) {
|
||||
ids.push(goods.id);
|
||||
goods.checked = false;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (ids.length === 0) {
|
||||
uni.showToast({
|
||||
title: "请选择要删除的商品",
|
||||
icon: "none",
|
||||
duration: 2000,
|
||||
});
|
||||
return;
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
//商品数量变化
|
||||
handleQuantityChange(val, item) {
|
||||
|
||||
const params = {
|
||||
user_id: uni.getStorageSync("userId"),
|
||||
goods_id_and_count: [{
|
||||
goods_id: item.goods_id,
|
||||
count: val,
|
||||
}, ],
|
||||
};
|
||||
request(apiArr.updateCar, "POST", params).then((res) => {
|
||||
console.log(res);
|
||||
uni.showToast({
|
||||
title: "操作成功!",
|
||||
success() {},
|
||||
});
|
||||
});
|
||||
},
|
||||
request(apiArr.deleteCar, "POST", {
|
||||
ids,
|
||||
})
|
||||
.then((res) => {
|
||||
uni.showToast({
|
||||
title: "删除成功",
|
||||
duration: 2000,
|
||||
});
|
||||
that.getShopCar();
|
||||
that.calcTotal();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
} else if (res.cancel) {
|
||||
console.log("用户点击取消");
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
//商品数量变化
|
||||
handleQuantityChange(val, item) {
|
||||
|
||||
onLoad(options) {
|
||||
const meun = menuButtonInfo();
|
||||
this.top = meun.top;
|
||||
this.localHeight = meun.height;
|
||||
this.getShopCar();
|
||||
const params = {
|
||||
user_id: uni.getStorageSync("userId"),
|
||||
goods_id_and_count: [{
|
||||
goods_id: item.goods_id,
|
||||
count: val,
|
||||
},],
|
||||
};
|
||||
request(apiArr.updateCar, "POST", params).then((res) => {
|
||||
console.log(res);
|
||||
uni.showToast({
|
||||
title: "操作成功!",
|
||||
success() { },
|
||||
});
|
||||
});
|
||||
},
|
||||
onReachBottom() {},
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
const meun = menuButtonInfo();
|
||||
this.top = meun.top;
|
||||
this.localHeight = meun.height;
|
||||
this.getShopCar();
|
||||
},
|
||||
onReachBottom() { },
|
||||
|
||||
|
||||
};
|
||||
};
|
||||
</script>
|
||||
|
||||
<style>
|
||||
@import url("./index.css");
|
||||
@import url("./index.css");
|
||||
</style>
|
||||
Loading…
x
Reference in New Issue
Block a user