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

344 lines
12 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use strict";
const common_vendor = require("../../common/vendor.js");
const API_api = require("../../API/api.js");
if (!Array) {
const _easycom_uni_notice_bar2 = common_vendor.resolveComponent("uni-notice-bar");
const _easycom_uni_data_checkbox2 = common_vendor.resolveComponent("uni-data-checkbox");
const _component_template = common_vendor.resolveComponent("template");
const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
(_easycom_uni_notice_bar2 + _easycom_uni_data_checkbox2 + _component_template + _easycom_uni_icons2)();
}
const _easycom_uni_notice_bar = () => "../../uni_modules/uni-notice-bar/components/uni-notice-bar/uni-notice-bar.js";
const _easycom_uni_data_checkbox = () => "../../uni_modules/uni-data-checkbox/components/uni-data-checkbox/uni-data-checkbox.js";
const _easycom_uni_icons = () => "../../uni_modules/uni-icons/components/uni-icons/uni-icons.js";
if (!Math) {
(_easycom_uni_notice_bar + _easycom_uni_data_checkbox + DistributionBox + _easycom_uni_icons)();
}
const DistributionBox = () => "./distributionBox.js";
const paymentTimeout = 15 * 60 * 1e3;
const _sfc_main = {
__name: "goToPay",
setup(__props) {
common_vendor.onUnload(() => {
common_vendor.index.reLaunch({
url: "/pages/index/index"
});
});
const radio1 = common_vendor.ref(0);
const statusId = common_vendor.ref(null);
const array = common_vendor.ref(["1公寓", "2公寓", "3公寓", "4公寓", "5公寓", "6公寓", "7公寓", "8公寓", "9公寓", "10公寓", "11公寓", "12公寓", "育才大厦"]);
const index = common_vendor.ref(0);
const sex = common_vendor.ref([
{
text: "堂食",
value: 0
},
{
text: "自提",
value: 1
},
{
text: "跑腿",
value: 2
}
]);
function bindPickerChange(e) {
const selectedIndex = e.detail.value;
console.log("picker发送选择改变携带值为", selectedIndex);
index.value = selectedIndex;
const selectedApartment = array.value[selectedIndex];
console.log("您选择了:", selectedApartment);
selectedApartmentName.value = selectedApartment;
}
const selectedApartmentName = common_vendor.ref("");
common_vendor.index.$on("updateRemark", (newRemark) => {
orderItem.value.notes = newRemark;
});
const orderItem = common_vendor.ref(null);
const getOrder = () => {
const notPay = common_vendor.index.getStorageSync("notPay");
common_vendor.index.request({
url: API_api.apiImageUrl + "/api/orders/get/my",
method: "GET",
data: {
id: notPay
//id:133
},
header: {
"Content-Type": "application/json",
// 确保设置正确的 Content-Type
"cookie": common_vendor.index.getStorageSync("cookie") || ""
},
success(res) {
console.log("获取订单成功");
if (res.data && res.data.data) {
orderItem.value = res.data.data;
console.log(orderItem.value);
if (orderItem.value.pickupMethod !== void 0) {
radio1.value = orderItem.value.pickupMethod;
}
}
},
fail() {
console.log("获取订单失败");
}
});
};
const isoStart = common_vendor.ref("");
const isoEnd = common_vendor.ref("");
const submitOrder = () => {
var _a;
console.log(
"我选择的radio1的值:",
radio1.value,
"我选择的公寓:",
selectedApartmentName.value,
"我选择的时间:",
sendTime.value
);
const notPay = common_vendor.index.getStorageSync("notPay");
common_vendor.index.request({
url: `${API_api.apiImageUrl}/api/orders/updateOrder`,
method: "POST",
data: {
location: selectedApartmentName.value,
notes: ((_a = orderItem.value) == null ? void 0 : _a.notes) || "",
// 使用订单中的备注,如果不存在则为空字符串
orderId: notPay,
pickupMethod: radio1.value,
// 使用当前选中的配送方式
pickupStartTime: isoStart.value,
// 注意这里使用的是 .value
pickupEndTime: isoEnd.value
// 注意这里使用的是 .value
},
header: {
"Content-Type": "application/json",
// 确保设置正确的 Content-Type
"cookie": common_vendor.index.getStorageSync("cookie") || ""
},
success(res) {
console.log("更新订单成功", res);
orderItem.value.pickupMethod = radio1.value;
goToPayment();
},
fail(err) {
console.log("更新订单失败", err);
}
});
};
common_vendor.onMounted(() => {
getOrder();
});
common_vendor.onActivated(() => {
getOrder();
});
const goToPayment = () => {
const notPay = common_vendor.index.getStorageSync("notPay");
my.request({
url: API_api.apiImageUrl + "/api/Alipay/payment/create",
method: "GET",
data: {
id: notPay
},
header: {
"Content-Type": "application/json",
"cookie": common_vendor.index.getStorageSync("cookie") || ""
},
success: function(result) {
console.log("reasaaaaaaaaaa");
console.log(result);
console.log("tradeNo的值为");
console.log(result.data.data);
my.tradePay({
tradeNO: result.data.data,
success: (res) => {
console.log("成功调用");
console.log(res);
if (res.resultCode == 9e3) {
common_vendor.index.setStorageSync("orderId", notPay);
common_vendor.index.navigateTo({
url: "/pages/testFive/testFive"
});
common_vendor.index.removeStorageSync("cartItems");
}
},
fail: (res) => {
my.alert({
content: JSON.stringify(res)
});
console.log("失败");
console.log(res);
}
});
}
});
};
const orderCreateTime = Date.now();
const updateTimer = () => {
const elapsedTime = Date.now() - orderCreateTime;
if (elapsedTime > paymentTimeout) {
console.log("超时啦");
clearInterval(intervalId);
formattedTime.value = "已超时";
} else {
const remainingTime = paymentTimeout - elapsedTime;
const minutes = Math.floor(remainingTime % (1e3 * 60 * 60) / (1e3 * 60));
const seconds = Math.floor(remainingTime % (1e3 * 60) / 1e3);
formattedTime.value = `待支付,${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`;
}
};
const formattedTime = common_vendor.ref("待支付剩余14:48");
const intervalId = common_vendor.ref(null);
common_vendor.onMounted(() => {
intervalId.value = setInterval(updateTimer, 1e3);
updateTimer();
});
setTimeout(() => {
if (!formattedTime.value.includes("已超时")) {
console.log("超时啦");
clearInterval(intervalId.value);
common_vendor.index.showToast({
title: "支付已超时",
duration: 2e3
});
const orderItemId = orderItem.value.id;
const tradeNo = common_vendor.index.getStorageSync("tradeNo");
common_vendor.index.request({
url: API_api.apiImageUrl + "/api/Alipay/test/close",
method: "GET",
data: {
orderId: orderItemId,
out_trade_no: tradeNo
},
success(res) {
console.log("成功");
console.log(res);
},
fail() {
console.log("失败");
}
});
common_vendor.index.showToast({
title: "订单超时,已为您自动取消喽",
duration: 2e3
});
formattedTime.value = "已超时";
}
}, paymentTimeout);
const closeOrder = () => {
const orderItemId = orderItem.value.id;
const tradeNo = common_vendor.index.getStorageSync("tradeNo");
common_vendor.index.request({
url: API_api.apiImageUrl + "/api/Alipay/test/close",
method: "GET",
data: {
orderId: orderItemId,
out_trade_no: tradeNo
},
success(res) {
console.log("成功");
console.log(res);
},
fail() {
console.log("失败");
}
});
};
const goToRemark = () => {
common_vendor.index.navigateTo({
url: "/pages/goToRemark/goToRemark"
});
};
const sendTime = common_vendor.ref("");
const dsbonBox = common_vendor.ref(null);
const showTime = () => {
if (dsbonBox.value) {
dsbonBox.value.showBox();
}
};
const handleTimeSelected = (time) => {
console.log("Selected Time:", time);
const [date, duration] = time.split(" ");
const [startHour, endHour] = duration.split("-");
isoStart.value = `${date}T${startHour}:00+08:00`;
isoEnd.value = `${date}T${endHour}:00+08:00`;
new Date(isoStart.value);
new Date(isoEnd.value);
console.log("Start Time in ISO format:", isoStart.value);
console.log("End Time in ISO format:", isoEnd.value);
sendTime.value = time;
};
return (_ctx, _cache) => {
var _a, _b;
return common_vendor.e({
a: common_vendor.p({
["show-icon"]: true,
scrollable: true,
text: "15分钟内未支付,订单将自动取消"
}),
b: common_vendor.t(formattedTime.value),
c: statusId.value,
d: common_vendor.o(($event) => radio1.value = $event),
e: common_vendor.p({
localdata: sex.value,
modelValue: radio1.value
}),
f: radio1.value === 2
}, radio1.value === 2 ? {
g: common_vendor.t(selectedApartmentName.value ? selectedApartmentName.value : "请选择公寓"),
h: common_vendor.o(bindPickerChange),
i: index.value,
j: array.value,
k: common_vendor.t(sendTime.value || "请选择配送时间"),
l: common_vendor.o(showTime),
m: common_vendor.sr(dsbonBox, "71a06cb4-2", {
"k": "dsbonBox"
}),
n: common_vendor.o(handleTimeSelected),
o: common_vendor.p({
["get-time"]: sendTime.value
})
} : {}, {
p: common_vendor.t(orderItem.value.totalPrice),
q: common_vendor.o(submitOrder),
r: common_vendor.p({
type: "calendar-filled",
size: "30"
}),
s: common_vendor.p({
type: "calendar-filled",
size: "30"
}),
t: common_vendor.p({
type: "calendar-filled",
size: "30"
}),
v: common_vendor.o(closeOrder),
w: (_a = orderItem.value.businessVO) == null ? void 0 : _a.businessImages,
x: common_vendor.t((_b = orderItem.value.businessVO) == null ? void 0 : _b.businessName),
y: common_vendor.f(orderItem.value.orderDetailsVOList, (item, k0, i0) => {
return {
a: item.dishesVO.dishesImage,
b: common_vendor.t(item.dishesVO.dishesName),
c: common_vendor.t(item.quantity),
d: common_vendor.t(item.dishesVO.dishesName),
e: common_vendor.t(item.dishesVO.dishesPrice)
};
}),
z: radio1.value === 1 || radio1.value === 2
}, radio1.value === 1 || radio1.value === 2 ? {} : {}, {
A: radio1.value === 2
}, radio1.value === 2 ? {} : {}, {
B: common_vendor.t(orderItem.value.totalPrice),
C: common_vendor.t(orderItem.value.notes ? orderItem.value.notes : "去备注"),
D: common_vendor.o(goToRemark),
E: common_vendor.t(orderItem.value.phone),
F: common_vendor.t(orderItem.value.pickupCode)
});
};
}
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-71a06cb4"]]);
wx.createPage(MiniProgramPage);