修改购物车样式和逻辑

This commit is contained in:
赵毅 2025-08-25 11:19:09 +08:00
parent e1014ef6ef
commit c15528bcde
2 changed files with 428 additions and 330 deletions

View File

@ -21,13 +21,13 @@
.searchBox_right { .searchBox_right {
opacity: 0; opacity: 0;
flex: 1; flex: 1;
} }
.isDay { .isDay {
position: absolute; position: absolute;
} }
.tag { .tag {
background-color: #ff7d00; background-color: #ff7d00;
color: white; color: white;
@ -38,14 +38,14 @@
.tag-img { .tag-img {
position: absolute; position: absolute;
/* top: 1; */ /* top: 1; */
bottom: 1; bottom: 1;
left: 10; left: 10;
z-index: 1; z-index: 1;
} }
.is_day { .is_day {
margin-left: 20rpx; margin-left: 20rpx;
} }
.empty { .empty {
@ -76,6 +76,12 @@
justify-content: flex-end; justify-content: flex-end;
} }
.goodsItem_tit{
margin: 20rpx 0 0 20rpx;
font-size: 35rpx;
font-weight: bold;
}
.goodsItem { .goodsItem {
display: flex; display: flex;
align-items: center; align-items: center;

View File

@ -28,46 +28,51 @@
当日达 当日达
</view> </view>
<view class="goodsList"> <view class="goodsList">
<view class="goodsItem" v-for="(item, index) in isDayCarList" :key="item.id"> <view v-for="(carItem, carIndex) in isDayCarList" :key="carItem.id" :index="carIndex">
<view class="goodsItem_tit">
<view class="goodsItem_left" @click="DayChecked(item, index)"> {{ carItem.supplier_name }}
<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>
<view class="goodsItem_right"> <view class="goodsItem" v-for="(item, index) in carItem.commodity_cart_and_goods_model"
<view class="goodsItem_msg"> :key="item.id">
<view class="goodsItem_msg_img"> <view class="goodsItem_left" @click="DayChecked(item)">
<view class="tag tag-img">当日达</view> <image v-if="!item.checked"
<image :src="picUrl + item.commodity_goods_info.commodity_pic"> src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/com_check1.png">
</image> </image>
</view> <image v-if="item.checked"
<view class="goodsItem_msg_right"> src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/com_check2.png">
<view class="goodsItem_msg_right_tit"> </image>
{{ item.commodity_goods_info.goods_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>
<view class="goodsItem_msg_right_subTit"> <view class="goodsItem_msg_right">
{{ item.commodity_goods_info.goods_intro }} <view class="goodsItem_msg_right_tit">
</view> {{ item.commodity_goods_info.goods_name }}
<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>
<view class="goodsItem_msg_right_msg_right"> <view class="goodsItem_msg_right_subTit">
<u-number-box v-model="item.count" :asyncChange="true" min="0"> {{ item.commodity_goods_info.goods_intro }}
<view slot="minus" class="minus" @click="minus(item, index)"> </view>
<u-icon name="minus" size="32" bold></u-icon> <view class="goodsItem_msg_right_msg">
</view> <view class="goodsItem_msg_right_msg_left">
<text slot="input" style="width: 80rpx; text-align: center" <span></span>{{ item.commodity_goods_info.sales_price }}
class="input">{{ item.count }}</text> <span>/{{ item.commodity_goods_info.goods_unit }}</span>
<view slot="plus" class="plus" @click="add(item, index)"> </view>
<u-icon name="plus" color="#FFFFFF" size="32" bold></u-icon> <view class="goodsItem_msg_right_msg_right">
</view> <u-number-box v-model="item.count" :asyncChange="true" min="0">
</u-number-box> <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> </view>
</view> </view>
@ -76,7 +81,7 @@
</view> </view>
</view> </view>
</view> </view>
<view class="is_day" v-if="parcelPostshow" style="margin-top: 20rpx;"> <view class="is_day" v-if="parcelPostshow" style="margin-top: 20rpx;">
<view class="footer_all" @click="parcel_post_checked" <view class="footer_all" @click="parcel_post_checked"
@ -90,46 +95,51 @@
包邮 包邮
</view> </view>
<view class="goodsList"> <view class="goodsList">
<view class="goodsItem" v-for="(item, index) in shopCarList" :key="item.id"> <view v-for="(carItem, carIndex) in shopCarList" :key="carItem.id" :index="carIndex">
<view class="goodsItem_tit">
<view class="goodsItem_left" @click="changeChecked(item, index)"> {{ carItem.supplier_name }}
<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>
<view class="goodsItem_right"> <view class="goodsItem" v-for="(item, index) in carItem.commodity_cart_and_goods_model"
<view class="goodsItem_msg"> :key="item.id">
<view class="goodsItem_msg_img"> <view class="goodsItem_left" @click="changeChecked(item)">
<image v-if="!item.checked"
<image :src="picUrl + item.commodity_goods_info.commodity_pic"> src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/com_check1.png">
</image> </image>
</view> <image v-if="item.checked"
<view class="goodsItem_msg_right"> src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/com_check2.png">
<view class="goodsItem_msg_right_tit"> </image>
{{ item.commodity_goods_info.goods_name }} </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>
<view class="goodsItem_msg_right_subTit"> <view class="goodsItem_msg_right">
{{ item.commodity_goods_info.goods_intro }} <view class="goodsItem_msg_right_tit">
</view> {{ item.commodity_goods_info.goods_name }}
<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>
<view class="goodsItem_msg_right_msg_right"> <view class="goodsItem_msg_right_subTit">
<u-number-box v-model="item.count" :asyncChange="true" min="0"> {{ item.commodity_goods_info.goods_intro }}
<view slot="minus" class="minus" @click="minus(item, index)"> </view>
<u-icon name="minus" size="32" bold></u-icon> <view class="goodsItem_msg_right_msg">
</view> <view class="goodsItem_msg_right_msg_left">
<text slot="input" style="width: 80rpx; text-align: center" <span></span>{{ item.commodity_goods_info.sales_price }}
class="input">{{ item.count }}</text> <span>/{{ item.commodity_goods_info.goods_unit }}</span>
<view slot="plus" class="plus" @click="add(item, index)"> </view>
<u-icon name="plus" color="#FFFFFF" size="32" bold></u-icon> <view class="goodsItem_msg_right_msg_right">
</view> <u-number-box v-model="item.count" :asyncChange="true" min="0">
</u-number-box> <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> </view>
</view> </view>
@ -138,11 +148,11 @@
</view> </view>
</view> </view>
</view> </view>
<view class="footer"> <view class="footer">
<view class="footer_left"> <view class="footer_left">
@ -175,281 +185,363 @@
</template> </template>
<script> <script>
import { import {
apiArr apiArr
} from "../../../api/shop"; } from "../../../api/shop";
import { import {
picUrl, picUrl,
menuButtonInfo, menuButtonInfo,
request, request,
NavgateTo NavgateTo
} from "../../../utils"; } from "../../../utils";
export default { export default {
data() { data() {
return { return {
picUrl, picUrl,
top: "", top: "",
localHeight: "", localHeight: "",
value: 3, value: 3,
type: "error", type: "error",
shopCarList: [], shopCarList: [],
isDayCarList: [], isDayCarList: [],
shopCarTotal: 0, shopCarTotal: 0,
shopMoney: 0, shopMoney: 0,
isAllchecked: false, // isAllchecked: false, //
isDaychecked: false, // isDaychecked: false, //
isDayshow: false, isDayshow: false,
isParcelPostchecked: false, isParcelPostchecked: false,
parcelPostshow: 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() { submitOrder() {
let arr = []; let arr = [];
this.shopCarList.forEach((item) => { console.log("🚀 ~ submitOrder ~ this.shopCarList:", this.shopCarList)
if (item.checked) { //
arr.push(item); 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(`../submitOrder/index?shopCarList=${JSON.stringify(arr)}`);
NavgateTo(`../groupPurchaseSubmit/index?shopCarList=${JSON.stringify(arr)}`); NavgateTo(`../groupPurchaseSubmit/index?shopCarList=${JSON.stringify(arr)}`);
}, },
// //
getShopCar() { getShopCar() {
request(apiArr.getCar, "POST", {}).then((res) => { request(apiArr.getCar, "POST", {}).then((res) => {
console.log(res.total); if (res.normal_cart_list.length > 0) {
// res.commodity_cart_list.forEach((item) => {
res.normal_cart_list.forEach((item) => { res.normal_cart_list.forEach((item) => {
console.log(item.commodity_cart_and_goods_model); item.checked = false;
if(item.is_support_same_day == false) { this.parcelPostshow = true;
this.isDayshow = false; })
this.parcelPostshow = true; this.shopCarList = res.normal_cart_list
this.shopCarList = item.commodity_cart_and_goods_model; } else {
item.checked = false; res.normal_cart_list.forEach((item) => {
} else { item.checked = false;
this.isDayshow = true; this.parcelPostshow = false;
this.parcelPostshow = false; })
this.isDayCarList = item.commodity_cart_and_goods_model; }
item.checked = false;
} if (res.same_day_cart_list.length > 0) {
}); res.same_day_cart_list.forEach((item) => {
item.checked = false;
// this.shopCarList = res.commodity_cart_list; this.isDayshow = true;
// this.shopCarList = res.normal_cart_list[0].commodity_cart_and_goods_model; })
this.shopCarTotal = res.total; 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) { is_day_checked() {
this.shopCarList[index].checked = !this.shopCarList[index].checked; this.isDaychecked = !this.isDaychecked;
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.isDayCarList.forEach(carItem => {
this.isDaychecked = !this.isDaychecked; carItem.commodity_cart_and_goods_model.forEach(goods => {
this.isAllchecked = !this.isAllchecked goods.checked = this.isDaychecked;
if (this.isDaychecked) { });
this.isDayCarList.forEach((item) => { });
item.checked = true;
});
} else {
this.isDayCarList.forEach((item) => {
item.checked = false;
});
}
this.calcTotal();
//
this.isAllchecked = this.isDaychecked && this.isParcelPostchecked;
console.log("全选当日达"); this.calcTotal();
}, },
// //
parcel_post_checked() { parcel_post_checked() {
this.isParcelPostchecked = !this.isParcelPostchecked; 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;
});
}
this.calcTotal();
//
this.shopCarList.forEach(carItem => {
carItem.commodity_cart_and_goods_model.forEach(goods => {
goods.checked = this.isParcelPostchecked;
});
});
console.log("全选包邮"); //
}, this.isAllchecked = this.isDaychecked && this.isParcelPostchecked;
// this.calcTotal();
calcTotal() { },
let total = 0;
this.shopCarList.forEach((item) => {
console.log(item);
if (item.checked) { //
total += item.commodity_goods_info.sales_price * item.count; calcTotal() {
let total = 0;
//
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) { this.shopCarList.forEach(carItem => {
let that = this; carItem.commodity_cart_and_goods_model.forEach(goods => {
if (item.count === 1) { if (goods.checked) {
request(apiArr.deleteCar, "POST", { total += goods.commodity_goods_info.sales_price * goods.count;
ids: [item.id], }
}).then((res) => { });
that.shopCarList.splice(index, 1); });
that.calcTotal();
}); this.shopMoney = total;
} },
this.shopCarTotal = this.shopCarTotal - 1
this.shopCarList[index].count = this.shopCarList[index].count - 1; //
this.handleQuantityChange(this.shopCarList[index].count, this.shopCarList[index]) 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(); this.calcTotal();
}, }
},
// //
add(item, index) { add(carItem, goodsIndex) {
this.shopCarTotal = this.shopCarTotal + 1 const item = carItem.commodity_cart_and_goods_model;
this.shopCarList[index].count = this.shopCarList[index].count + 1; this.shopCarTotal = this.shopCarTotal + 1;
this.handleQuantityChange(this.shopCarList[index].count, this.shopCarList[index]) carItem.count = carItem.count + 1;
this.calcTotal(); this.handleQuantityChange(carItem.count, carItem);
}, this.calcTotal();
},
// //
deleteItem() { deleteItem() {
let that = this; let that = this;
uni.showModal({ uni.showModal({
title: "提示", title: "提示",
content: "确定删除所选商品吗", content: "确定删除所选商品吗",
success: function(res) { success: function (res) {
if (res.confirm) { if (res.confirm) {
let ids = []; let ids = [];
that.shopCarList.forEach((item) => {
if (item.checked) { // ID
ids.push(item.id); that.isDayCarList.forEach(carItem => {
item.checked = false; carItem.commodity_cart_and_goods_model.forEach(goods => {
if (goods.checked) {
ids.push(goods.id);
goods.checked = false;
} }
}); });
request(apiArr.deleteCar, "POST", { });
ids,
}) // ID
.then((res) => { that.shopCarList.forEach(carItem => {
uni.showToast({ carItem.commodity_cart_and_goods_model.forEach(goods => {
title: "删除成功", if (goods.checked) {
duration: 2000, ids.push(goods.id);
}); goods.checked = false;
that.getShopCar(); }
that.calcTotal(); });
}) });
.catch((err) => {
console.log(err); if (ids.length === 0) {
}); uni.showToast({
} else if (res.cancel) { title: "请选择要删除的商品",
console.log("用户点击取消"); icon: "none",
duration: 2000,
});
return;
} }
},
});
},
//
handleQuantityChange(val, item) {
const params = { request(apiArr.deleteCar, "POST", {
user_id: uni.getStorageSync("userId"), ids,
goods_id_and_count: [{ })
goods_id: item.goods_id, .then((res) => {
count: val, uni.showToast({
}, ], title: "删除成功",
}; duration: 2000,
request(apiArr.updateCar, "POST", params).then((res) => { });
console.log(res); that.getShopCar();
uni.showToast({ that.calcTotal();
title: "操作成功!", })
success() {}, .catch((err) => {
}); console.log(err);
}); });
}, } else if (res.cancel) {
console.log("用户点击取消");
}
},
});
}, },
//
handleQuantityChange(val, item) {
onLoad(options) { const params = {
const meun = menuButtonInfo(); user_id: uni.getStorageSync("userId"),
this.top = meun.top; goods_id_and_count: [{
this.localHeight = meun.height; goods_id: item.goods_id,
this.getShopCar(); 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> </script>
<style> <style>
@import url("./index.css"); @import url("./index.css");
</style> </style>