xiaokuaisong-xiaochengxu/uniapp04/unpackage/dist/dev/mp-weixin/pages/account/account.js
2025-04-11 14:42:29 +08:00

130 lines
4.5 KiB
JavaScript

"use strict";
const common_vendor = require("../../common/vendor.js");
const API_api = require("../../API/api.js");
if (!Array) {
const _easycom_uni_collapse_item2 = common_vendor.resolveComponent("uni-collapse-item");
_easycom_uni_collapse_item2();
}
const _easycom_uni_collapse_item = () => "../../uni_modules/uni-collapse/components/uni-collapse-item/uni-collapse-item.js";
if (!Math) {
_easycom_uni_collapse_item();
}
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
__name: "account",
setup(__props) {
const address = common_vendor.ref("哈尔滨华德学院二公寓");
const { safeAreaInsets } = common_vendor.index.getSystemInfoSync();
const buyerMessage = common_vendor.ref("");
const totalAmount = common_vendor.ref();
const getMerchantIdFromUrl = () => {
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
if (currentPage && currentPage.options && currentPage.options.totalAmount) {
let value = currentPage.options.totalAmount;
if (typeof value === "string" && value.trim() !== "") {
totalAmount.value = Number(value);
if (isNaN(totalAmount.value)) {
console.error("Failed to parse totalAmount as a number:", value);
} else {
console.log(`totalAmount received: ${totalAmount.value}`);
common_vendor.index.setStorageSync("totalAmount", totalAmount.value);
}
} else {
console.error("totalAmount is not a valid string:", value);
}
} else {
console.error("Could not retrieve totalAmount from URL.");
}
};
common_vendor.onMounted(() => {
getMerchantIdFromUrl();
});
common_vendor.watch(totalAmount, (newValue) => {
common_vendor.index.$emit("totalAmountChanged", newValue);
});
const business = common_vendor.ref([]);
const loadCartItems = () => {
const storedCartItems = common_vendor.index.getStorageSync("cartItems");
if (storedCartItems) {
business.value = storedCartItems;
console.log(business.value);
}
business.value.forEach((item) => {
console.log(`dishesImage: ${item.dishesImage}, dishesName: ${item.dishesName}, dishesId: ${item.id},quantity:${item.quantity}`);
});
};
common_vendor.onMounted(() => {
loadCartItems();
});
common_vendor.ref(common_vendor.index.getStorageSync("totalAmount"));
const Code = () => {
const data = {
businessId: 1830063677349658600,
// notes: "",
// orderDetailAddRequest: [
// {
// attributeNames: "小份",
// dishesId: 82,
// quantity: 1
// }
// ],
notes: buyerMessage.value,
orderDetailAddRequest: business.value.map((item) => ({
attributeNames: "小份",
// 假设attributeNames是一个可选属性
dishesId: item.id,
quantity: item.quantity
})),
payMethod: 0,
phone: "13613639360",
pickupMethod: 0,
pickupTime: "",
totalPrice: 13.99,
userName: "用户名称"
};
common_vendor.index.request({
url: API_api.apiImageUrl + "/api/orders/add",
method: "POST",
data,
header: {
"cookie": common_vendor.index.getStorageSync("cookie") || ""
},
success(res) {
console.log("Success:", res.data);
common_vendor.index.setStorageSync("orderInfo", res.data);
common_vendor.index.navigateTo({
url: "/pages/orderSettlement/orderSettlement"
});
},
fail() {
console.error("Error:", "请求失败");
}
});
};
return (_ctx, _cache) => {
var _a;
return {
a: common_vendor.t(address.value),
b: common_vendor.f(business.value, (item, index, i0) => {
return {
a: item.dishesImage,
b: common_vendor.t(item.dishesName),
c: common_vendor.t(item.dishesPrice),
d: index
};
}),
c: common_vendor.t(totalAmount.value),
d: buyerMessage.value,
e: common_vendor.o(($event) => buyerMessage.value = $event.detail.value),
f: common_vendor.p({
title: "费用明细"
}),
g: common_vendor.t(totalAmount.value),
h: common_vendor.o(Code),
i: ((_a = common_vendor.unref(safeAreaInsets)) == null ? void 0 : _a.bottom) + "px"
};
};
}
});
wx.createPage(_sfc_main);