123 lines
5.1 KiB
JavaScript
123 lines
5.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 api_order = require("../../api/order.js");
|
|
const utils_request = require("../../utils/request.js");
|
|
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
|
|
__name: "submit",
|
|
setup(__props) {
|
|
const cartStore = store_cart.useCartStore();
|
|
const statusBarHeight = common_vendor.ref(0);
|
|
const navBarHeight = common_vendor.ref(44);
|
|
const receiverName = common_vendor.ref("");
|
|
const receiverPhone = common_vendor.ref("");
|
|
const receiverAddress = common_vendor.ref("");
|
|
const remark = common_vendor.ref("");
|
|
const agreed = common_vendor.ref(false);
|
|
const submitting = common_vendor.ref(false);
|
|
function fullUrl(path) {
|
|
if (!path)
|
|
return "";
|
|
if (path.startsWith("http"))
|
|
return path;
|
|
return utils_request.BASE_URL + path;
|
|
}
|
|
function goBack() {
|
|
common_vendor.index.navigateBack();
|
|
}
|
|
const orderItems = common_vendor.computed(() => cartStore.checkedItems);
|
|
const totalPrice = common_vendor.computed(
|
|
() => orderItems.value.reduce((sum, item) => sum + item.specData.totalPrice * item.quantity, 0)
|
|
);
|
|
const canSubmit = common_vendor.computed(() => agreed.value && !submitting.value);
|
|
async function handleSubmit() {
|
|
if (!canSubmit.value)
|
|
return;
|
|
if (!receiverName.value.trim()) {
|
|
common_vendor.index.showToast({ title: "请输入收货人姓名", icon: "none" });
|
|
return;
|
|
}
|
|
if (!receiverPhone.value.trim()) {
|
|
common_vendor.index.showToast({ title: "请输入联系电话", icon: "none" });
|
|
return;
|
|
}
|
|
if (!receiverAddress.value.trim()) {
|
|
common_vendor.index.showToast({ title: "请输入收货地址", icon: "none" });
|
|
return;
|
|
}
|
|
submitting.value = true;
|
|
try {
|
|
const order = await api_order.createOrder({
|
|
items: orderItems.value.map((item) => ({
|
|
productId: item.productId,
|
|
specDataId: item.specDataId,
|
|
quantity: item.quantity,
|
|
unitPrice: item.specData.totalPrice
|
|
})),
|
|
receiverName: receiverName.value.trim(),
|
|
receiverPhone: receiverPhone.value.trim(),
|
|
receiverAddress: receiverAddress.value.trim()
|
|
});
|
|
for (const item of orderItems.value) {
|
|
cartStore.removeFromCart(item.id);
|
|
}
|
|
common_vendor.index.redirectTo({ url: `/pages/order/detail?id=${order.id}` });
|
|
} catch {
|
|
common_vendor.index.showToast({ title: "提交订单失败,请重试", icon: "none" });
|
|
} finally {
|
|
submitting.value = false;
|
|
}
|
|
}
|
|
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;
|
|
});
|
|
return (_ctx, _cache) => {
|
|
return {
|
|
a: common_assets._imports_0$2,
|
|
b: common_vendor.o(goBack),
|
|
c: navBarHeight.value + "px",
|
|
d: statusBarHeight.value + "px",
|
|
e: statusBarHeight.value + navBarHeight.value + "px",
|
|
f: common_assets._imports_1$1,
|
|
g: common_assets._imports_2$3,
|
|
h: receiverName.value,
|
|
i: common_vendor.o(($event) => receiverName.value = $event.detail.value),
|
|
j: receiverPhone.value,
|
|
k: common_vendor.o(($event) => receiverPhone.value = $event.detail.value),
|
|
l: receiverAddress.value,
|
|
m: common_vendor.o(($event) => receiverAddress.value = $event.detail.value),
|
|
n: remark.value,
|
|
o: common_vendor.o(($event) => remark.value = $event.detail.value),
|
|
p: common_assets._imports_3,
|
|
q: common_vendor.f(orderItems.value, (item, k0, i0) => {
|
|
var _a;
|
|
return {
|
|
a: fullUrl(item.product.thumb || ((_a = item.product.bannerImages) == null ? void 0 : _a[0]) || ""),
|
|
b: common_vendor.t(item.product.name),
|
|
c: common_vendor.t(item.specData.modelName || "B2022"),
|
|
d: common_vendor.t(item.specData.fineness || "2606"),
|
|
e: common_vendor.t(item.specData.fineness || "30"),
|
|
f: common_vendor.t(item.specData.mainStone || "13.00#"),
|
|
g: common_vendor.t(item.specData.ringSize || "13.00#"),
|
|
h: common_vendor.t(item.specData.goldTotalWeight || "236"),
|
|
i: common_vendor.t(item.specData.totalPrice),
|
|
j: item.id
|
|
};
|
|
}),
|
|
r: agreed.value ? "/static/ic_check_s.png" : "/static/ic_check.png",
|
|
s: common_vendor.o(($event) => agreed.value = !agreed.value),
|
|
t: common_vendor.t(totalPrice.value),
|
|
v: !canSubmit.value ? 1 : "",
|
|
w: common_vendor.o(handleSubmit)
|
|
};
|
|
};
|
|
}
|
|
});
|
|
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-c3fa8b8a"]]);
|
|
wx.createPage(MiniProgramPage);
|
|
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/order/submit.js.map
|