JewelryMall/miniprogram/unpackage/dist/dev/mp-weixin/pages/cart/index.js
2026-02-25 23:47:19 +08:00

83 lines
4.1 KiB
JavaScript

"use strict";
const common_vendor = require("../../common/vendor.js");
const common_assets = require("../../common/assets.js");
const store_cart = require("../../store/cart.js");
const utils_request = require("../../utils/request.js");
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
__name: "index",
setup(__props) {
function fullUrl(path) {
if (!path)
return "";
if (path.startsWith("http"))
return path;
return utils_request.BASE_URL + path;
}
const cartStore = store_cart.useCartStore();
const statusBarHeight = common_vendor.ref(0);
const navBarHeight = common_vendor.ref(44);
const isAllChecked = common_vendor.computed(
() => cartStore.items.length > 0 && cartStore.items.every((item) => item.checked)
);
common_vendor.onMounted(() => {
const sysInfo = common_vendor.index.getSystemInfoSync();
statusBarHeight.value = sysInfo.statusBarHeight || 0;
const menuBtn = common_vendor.index.getMenuButtonBoundingClientRect();
navBarHeight.value = menuBtn.height + (menuBtn.top - (sysInfo.statusBarHeight || 0)) * 2;
cartStore.fetchCart();
});
function handleSettle() {
if (cartStore.checkedItems.length === 0) {
common_vendor.index.showToast({ title: "请先选择商品", icon: "none" });
return;
}
const token = common_vendor.index.getStorageSync("token");
if (!token) {
common_vendor.index.navigateTo({ url: "/pages/login/index" });
return;
}
common_vendor.index.navigateTo({ url: "/pages/order/submit" });
}
return (_ctx, _cache) => {
return common_vendor.e({
a: navBarHeight.value + "px",
b: statusBarHeight.value + "px",
c: statusBarHeight.value + navBarHeight.value + "px",
d: common_vendor.unref(cartStore).items.length > 0
}, common_vendor.unref(cartStore).items.length > 0 ? {
e: common_vendor.f(common_vendor.unref(cartStore).items, (item, k0, i0) => {
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
return {
a: item.checked ? "/static/ic_check_s.png" : "/static/ic_check.png",
b: common_vendor.o(($event) => common_vendor.unref(cartStore).toggleCheck(item.id), item.id),
c: fullUrl(((_a = item.product) == null ? void 0 : _a.thumb) || ((_c = (_b = item.product) == null ? void 0 : _b.bannerImages) == null ? void 0 : _c[0]) || ""),
d: common_vendor.t(((_d = item.product) == null ? void 0 : _d.name) || ((_e = item.specData) == null ? void 0 : _e.modelName)),
e: common_vendor.t((_f = item.product) == null ? void 0 : _f.styleNo),
f: common_vendor.t((_g = item.specData) == null ? void 0 : _g.modelName),
g: common_vendor.t((_h = item.specData) == null ? void 0 : _h.ringSize),
h: common_vendor.t((_i = item.specData) == null ? void 0 : _i.ringSize),
i: common_vendor.t((_j = item.specData) == null ? void 0 : _j.goldTotalWeight),
j: common_vendor.t((_k = item.specData) == null ? void 0 : _k.fineness),
k: common_vendor.t(((_l = item.specData) == null ? void 0 : _l.totalPrice) || 0),
l: common_vendor.o(($event) => common_vendor.unref(cartStore).removeFromCart(item.id), item.id),
m: item.id
};
})
} : {
f: common_assets._imports_0$1
}, {
g: common_vendor.unref(cartStore).items.length > 0
}, common_vendor.unref(cartStore).items.length > 0 ? {
h: isAllChecked.value ? "/static/ic_check_s.png" : "/static/ic_check.png",
i: common_vendor.o(($event) => common_vendor.unref(cartStore).toggleCheckAll()),
j: common_vendor.t(common_vendor.unref(cartStore).totalAmount.toFixed(2)),
k: common_vendor.unref(cartStore).checkedItems.length === 0 ? 1 : "",
l: common_vendor.o(handleSettle)
} : {});
};
}
});
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-8039fbf1"]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/cart/index.js.map