195 lines
7.1 KiB
JavaScript
195 lines
7.1 KiB
JavaScript
"use strict";
|
|
var __async = (__this, __arguments, generator) => {
|
|
return new Promise((resolve, reject) => {
|
|
var fulfilled = (value) => {
|
|
try {
|
|
step(generator.next(value));
|
|
} catch (e) {
|
|
reject(e);
|
|
}
|
|
};
|
|
var rejected = (value) => {
|
|
try {
|
|
step(generator.throw(value));
|
|
} catch (e) {
|
|
reject(e);
|
|
}
|
|
};
|
|
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
});
|
|
};
|
|
const common_vendor = require("../../../common/vendor.js");
|
|
const modules_mall_sheep_index = require("../sheep/index.js");
|
|
const modules_mall_sheep_hooks_useGoods = require("../sheep/hooks/useGoods.js");
|
|
if (!Array) {
|
|
const _easycom_s_empty2 = common_vendor.resolveComponent("s-empty");
|
|
const _easycom_su_number_box2 = common_vendor.resolveComponent("su-number-box");
|
|
const _easycom_s_goods_item2 = common_vendor.resolveComponent("s-goods-item");
|
|
const _easycom_su_fixed2 = common_vendor.resolveComponent("su-fixed");
|
|
const _easycom_s_layout2 = common_vendor.resolveComponent("s-layout");
|
|
const _component_layout_default_uni = common_vendor.resolveComponent("layout-default-uni");
|
|
(_easycom_s_empty2 + _easycom_su_number_box2 + _easycom_s_goods_item2 + _easycom_su_fixed2 + _easycom_s_layout2 + _component_layout_default_uni)();
|
|
}
|
|
const _easycom_s_empty = () => "../sheep/components/s-empty/s-empty.js";
|
|
const _easycom_su_number_box = () => "../sheep/ui/su-number-box/su-number-box.js";
|
|
const _easycom_s_goods_item = () => "../sheep/components/s-goods-item/s-goods-item.js";
|
|
const _easycom_su_fixed = () => "../sheep/ui/su-fixed/su-fixed.js";
|
|
const _easycom_s_layout = () => "../sheep/components/s-layout/s-layout.js";
|
|
if (!Math) {
|
|
(_easycom_s_empty + _easycom_su_number_box + _easycom_s_goods_item + _easycom_su_fixed + _easycom_s_layout)();
|
|
}
|
|
const _sfc_main = {
|
|
__name: "cart",
|
|
setup(__props) {
|
|
common_vendor.useCssVars((_ctx) => ({
|
|
"69da5d77": common_vendor.unref(sys_navBar)
|
|
}));
|
|
const sys_navBar = modules_mall_sheep_index.sheep.$platform.navbar;
|
|
const cart = modules_mall_sheep_index.sheep.$store("cart");
|
|
const state = common_vendor.reactive({
|
|
editMode: false,
|
|
list: common_vendor.computed(() => cart.list),
|
|
selectedList: [],
|
|
selectedIds: common_vendor.computed(() => cart.selectedIds),
|
|
isAllSelected: common_vendor.computed(() => cart.isAllSelected),
|
|
totalPriceSelected: common_vendor.computed(() => cart.totalPriceSelected)
|
|
});
|
|
function onSelectSingle(id) {
|
|
cart.selectSingle(id);
|
|
}
|
|
function onSelectAll() {
|
|
cart.selectAll(!state.isAllSelected);
|
|
}
|
|
function onConfirm() {
|
|
const items = [];
|
|
const goods_list = [];
|
|
state.selectedList = state.list.filter((item) => state.selectedIds.includes(item.id));
|
|
state.selectedList.map((item) => {
|
|
items.push({
|
|
skuId: item.sku.id,
|
|
count: item.count,
|
|
cartId: item.id,
|
|
categoryId: item.spu.categoryId
|
|
});
|
|
goods_list.push({
|
|
// goods_id: item.goods_id,
|
|
goods_id: item.spu.id,
|
|
// goods_num: item.goods_num,
|
|
goods_num: item.count
|
|
// 商品价格id真没有
|
|
// goods_sku_price_id: item.goods_sku_price_id,
|
|
});
|
|
});
|
|
if (goods_list.length === 0) {
|
|
modules_mall_sheep_index.sheep.$helper.toast("请选择商品");
|
|
return;
|
|
}
|
|
modules_mall_sheep_index.sheep.$router.go("/modules/mall/order/confirm", {
|
|
data: JSON.stringify({
|
|
items
|
|
})
|
|
});
|
|
}
|
|
function onNumberChange(e, cartItem) {
|
|
if (e === 0) {
|
|
cart.delete(cartItem.id);
|
|
return;
|
|
}
|
|
if (cartItem.goods_num === e)
|
|
return;
|
|
cartItem.goods_num = e;
|
|
cart.update({
|
|
goods_id: cartItem.id,
|
|
goods_num: e,
|
|
goods_sku_price_id: cartItem.goods_sku_price_id
|
|
});
|
|
}
|
|
function onDelete() {
|
|
return __async(this, null, function* () {
|
|
cart.delete(state.selectedIds);
|
|
});
|
|
}
|
|
return (_ctx, _cache) => {
|
|
var _a;
|
|
return common_vendor.e({
|
|
a: state.list.length === 0
|
|
}, state.list.length === 0 ? {
|
|
b: common_vendor.p({
|
|
text: "购物车空空如也,快去逛逛吧~",
|
|
icon: "/static/cart-empty.png"
|
|
})
|
|
} : {}, {
|
|
c: state.list.length
|
|
}, state.list.length ? common_vendor.e({
|
|
d: common_vendor.t(state.list.length),
|
|
e: state.editMode
|
|
}, state.editMode ? {
|
|
f: common_vendor.o(($event) => state.editMode = false)
|
|
} : {
|
|
g: common_vendor.o(($event) => state.editMode = true)
|
|
}, {
|
|
h: common_vendor.f(state.list, (item, k0, i0) => {
|
|
return common_vendor.e({
|
|
a: state.selectedIds.includes(item.id),
|
|
b: common_vendor.o(($event) => onSelectSingle(item.id), item.id),
|
|
c: common_vendor.o(($event) => onSelectSingle(item.id), item.id)
|
|
}, !state.editMode ? {
|
|
d: common_vendor.o(($event) => onNumberChange($event, item), item.id),
|
|
e: "31203116-4-" + i0 + "," + ("31203116-3-" + i0),
|
|
f: common_vendor.o(($event) => item.count = $event, item.id),
|
|
g: common_vendor.p({
|
|
min: 0,
|
|
max: item.sku.stock,
|
|
step: 1,
|
|
modelValue: item.count
|
|
})
|
|
} : {}, {
|
|
h: "31203116-3-" + i0 + ",31203116-1",
|
|
i: common_vendor.p({
|
|
title: item.spu.name,
|
|
img: item.spu.picUrl || item.goods.image,
|
|
price: item.sku.price,
|
|
skuText: item.sku.properties.length > 1 ? item.sku.properties.reduce((items2, items) => items2.valueName + " " + items.valueName) : item.sku.properties[0].valueName,
|
|
priceColor: "#FF3000",
|
|
titleWidth: 400
|
|
}),
|
|
j: item.id
|
|
});
|
|
}),
|
|
i: !state.editMode,
|
|
j: state.list.length > 0
|
|
}, state.list.length > 0 ? common_vendor.e({
|
|
k: state.isAllSelected,
|
|
l: common_vendor.o(onSelectAll),
|
|
m: common_vendor.o(onSelectAll),
|
|
n: common_vendor.t(common_vendor.unref(modules_mall_sheep_hooks_useGoods.fen2yuan)(state.totalPriceSelected)),
|
|
o: state.editMode
|
|
}, state.editMode ? {
|
|
p: common_vendor.o(onDelete)
|
|
} : {
|
|
q: common_vendor.t(((_a = state.selectedIds) == null ? void 0 : _a.length) ? `(${state.selectedIds.length})` : ""),
|
|
r: common_vendor.o(onConfirm)
|
|
}, {
|
|
s: common_vendor.p({
|
|
bottom: true,
|
|
val: 48,
|
|
placeholder: true,
|
|
isInset: false
|
|
})
|
|
}) : {}) : {}, {
|
|
t: common_vendor.p({
|
|
title: "购物车",
|
|
tabbar: "/modules/mall/index/cart",
|
|
bgStyle: {
|
|
color: "#fff"
|
|
}
|
|
}),
|
|
v: common_vendor.s(_ctx.__cssVars())
|
|
});
|
|
};
|
|
}
|
|
};
|
|
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-31203116"]]);
|
|
wx.createPage(MiniProgramPage);
|