guyu/unpackage/dist/dev/mp-weixin/pages/bags/bags-page.js

156 lines
4.3 KiB
JavaScript

"use strict";
const common_vendor = require("../../common/vendor.js");
const common_assets = require("../../common/assets.js");
const _sfc_main = {
data() {
return {
checkNum: 0,
//选中几个
sumPrice: 0,
//总价
selectAll: false,
dataList: [
{
imgurl: "",
title: "坂本日常 吧唧",
name: "坂本",
price: 20,
num: 1,
isCheck: false,
type: "库存紧张"
},
{
imgurl: "",
title: "坂本日常 吧唧",
name: "坂本",
price: 20,
num: 1,
isCheck: false,
type: "库存紧张"
},
{
imgurl: "",
title: "坂本日常 吧唧",
name: "坂本",
price: 20,
num: 1,
isCheck: false,
type: "库存紧张"
},
{
imgurl: "",
title: "坂本日常 吧唧",
name: "坂本",
price: 20,
num: 1,
isCheck: false,
type: "库存紧张"
},
{
imgurl: "",
title: "坂本日常 吧唧",
name: "坂本",
price: 20,
num: 1,
isCheck: false,
type: "库存紧张"
},
{
imgurl: "",
title: "坂本日常 吧唧",
name: "坂本",
price: 20,
num: 1,
isCheck: false,
type: "库存紧张"
},
{
imgurl: "",
title: "坂本日常 吧唧",
name: "坂本",
price: 20,
num: 1,
isCheck: false,
type: "库存紧张"
}
]
};
},
methods: {
// 切换单个项目的选中状态
toggleItem(index) {
this.dataList[index].isCheck = !this.dataList[index].isCheck;
this.updateSelectAllStatus();
},
// 全选/取消全选
toggleSelectAll() {
this.selectAll = !this.selectAll;
this.dataList.forEach((item) => {
item.isCheck = this.selectAll;
});
this.selectedCount();
this.totalPrice();
},
// 更新全选状态(当手动选择所有项时自动勾选全选)
updateSelectAllStatus() {
this.selectAll = this.dataList.every((item) => item.isCheck);
this.selectedCount();
this.totalPrice();
},
// 增加数量
increase(index) {
this.dataList[index].num++;
this.selectedCount();
this.totalPrice();
},
// 减少数量
decrease(index) {
if (this.dataList[index].num > 1) {
this.dataList[index].num--;
}
this.selectedCount();
this.totalPrice();
},
// 选中的商品总数量
selectedCount() {
this.checkNum = this.dataList.reduce((total, item) => {
return total + (item.isCheck ? item.num : 0);
}, 0);
},
// 选中的商品总价格
totalPrice() {
this.sumPrice = this.dataList.reduce((total, item) => {
return total + (item.isCheck ? item.price * item.num : 0);
}, 0);
}
}
};
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return {
a: common_vendor.f($data.dataList, (item, index, i0) => {
return {
a: item.isCheck ? "/static/ic_check_s.png" : "/static/ic_check.png",
b: common_vendor.o(($event) => $options.toggleItem(index)),
c: item.imgurl,
d: common_vendor.t(item.title),
e: common_vendor.t(item.name),
f: common_vendor.t(item.price),
g: common_vendor.o(($event) => $options.decrease(index)),
h: common_vendor.t(item.num),
i: common_vendor.o(($event) => $options.increase(index))
};
}),
b: common_assets._imports_10,
c: common_assets._imports_11,
d: common_assets._imports_2$1,
e: common_vendor.t($data.checkNum),
f: common_vendor.t($data.sumPrice),
g: common_vendor.t($data.checkNum),
h: $data.selectAll ? "/static/ic_check_s.png" : "/static/ic_check.png",
i: common_vendor.o((...args) => $options.toggleSelectAll && $options.toggleSelectAll(...args))
};
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/bags/bags-page.js.map