"use strict";
|
const common_vendor = require("../../common/vendor.js");
|
const apiservice_apiService = require("../../apiservice/apiService.js");
|
const stores_user = require("../../stores/user.js");
|
const userStore = stores_user.useUserStore();
|
const _sfc_main = {
|
setup() {
|
const tabs = ["已预约", "已使用", "已取消", "已过期"];
|
const currentTab = common_vendor.ref(0);
|
let sitebooking = common_vendor.ref([]);
|
const loading = common_vendor.ref(false);
|
const fetchsitebooking = async () => {
|
loading.value = true;
|
try {
|
const res = await apiservice_apiService.apiService.bookingListByUuid(userStore.uuid);
|
if (res.code === 1e3) {
|
sitebooking.value = res.data;
|
} else {
|
common_vendor.index.__f__("warn", "at pages/ucenter/my-booking.vue:109", "查询失败:", res.message);
|
}
|
} catch (error) {
|
common_vendor.index.__f__("error", "at pages/ucenter/my-booking.vue:113", "获取预约信息错误:", error);
|
common_vendor.index.showToast({
|
title: "网络错误",
|
icon: "none"
|
});
|
} finally {
|
loading.value = false;
|
}
|
};
|
const filteredsitebooking = common_vendor.computed(() => {
|
return sitebooking.value.filter((item) => item.status === tabs[currentTab.value]);
|
});
|
const getNowString = () => {
|
const now = /* @__PURE__ */ new Date();
|
const pad = (n) => n.toString().padStart(2, "0");
|
return `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())} ${pad(now.getHours())}:${pad(now.getMinutes())}:${pad(now.getSeconds())}`;
|
};
|
const onTabChange = (e) => {
|
currentTab.value = e.currentIndex;
|
};
|
const cancelReservation = async (item) => {
|
common_vendor.index.showModal({
|
title: "提示",
|
content: "确定取消预约吗?",
|
success: async (res) => {
|
if (res.confirm) {
|
try {
|
common_vendor.index.__f__("log", "at pages/ucenter/my-booking.vue:148", item);
|
const cancelRes = await apiservice_apiService.apiService.bookingCancel({
|
id: item.id,
|
canceltime: getNowString(),
|
status: "已取消"
|
});
|
common_vendor.index.__f__("log", "at pages/ucenter/my-booking.vue:156", cancelRes);
|
if (cancelRes.code === 1e3) {
|
common_vendor.index.showToast({
|
title: "预约已取消",
|
icon: "success"
|
});
|
await fetchsitebooking();
|
} else {
|
common_vendor.index.showToast({
|
title: cancelRes.message || "取消失败",
|
icon: "none"
|
});
|
}
|
} catch (error) {
|
common_vendor.index.__f__("error", "at pages/ucenter/my-booking.vue:172", "取消预约错误:", error);
|
common_vendor.index.showToast({
|
title: "取消失败,请重试",
|
icon: "none"
|
});
|
}
|
}
|
}
|
});
|
};
|
const verifyReservation = async (item) => {
|
try {
|
common_vendor.index.__f__("log", "at pages/ucenter/my-booking.vue:185", item);
|
const scanRes = await new Promise((resolve, reject) => {
|
common_vendor.index.scanCode({
|
scanType: ["qrCode"],
|
success: resolve,
|
fail: reject
|
});
|
});
|
common_vendor.index.__f__("log", "at pages/ucenter/my-booking.vue:194", scanRes.result);
|
const match = scanRes.result.match(/farm\.evcc\.top.*?sitename=([^&]+)/);
|
if (!match) {
|
common_vendor.index.showToast({
|
title: "二维码无效,请扫描正确的核销码",
|
icon: "none"
|
});
|
return;
|
}
|
const qrSitename = decodeURIComponent(match[1]);
|
const now = /* @__PURE__ */ new Date();
|
const todayStr = now.toISOString().split("T")[0];
|
const currentHour = now.getHours();
|
const isAm = !!item.visittimeam && item.visittimeam !== "";
|
let message = "";
|
if (qrSitename !== item.sitename) {
|
message = `二维码场馆不匹配(扫码场馆:${qrSitename})`;
|
} else if (item.visitdate !== todayStr) {
|
message = `未到预约日期(预约日期:${item.visitdate})`;
|
} else if (isAm && currentHour >= 12) {
|
message = "上午时段已过,无法核销";
|
} else if (!isAm && currentHour < 12) {
|
message = "还未到下午时段,请稍后核销";
|
}
|
if (message) {
|
common_vendor.index.showModal({
|
title: "无法核销",
|
content: message,
|
showCancel: false,
|
confirmText: "我知道了"
|
});
|
return;
|
}
|
const verifyRes = await apiservice_apiService.apiService.bookingUse({
|
id: item.id,
|
usedtime: getNowString(),
|
status: "已使用"
|
});
|
if (verifyRes.code === 1e3) {
|
common_vendor.index.showModal({
|
title: "核销成功",
|
content: "预约已核销,请工作人员确认",
|
showCancel: false,
|
confirmText: "确定",
|
success: async () => {
|
await fetchsitebooking();
|
}
|
});
|
} else {
|
common_vendor.index.showToast({
|
title: verifyRes.message || "核销失败",
|
icon: "none"
|
});
|
}
|
} catch (error) {
|
common_vendor.index.__f__("error", "at pages/ucenter/my-booking.vue:259", "核销错误:", error);
|
common_vendor.index.showToast({
|
title: "核销失败,请重试",
|
icon: "none"
|
});
|
}
|
};
|
common_vendor.onMounted(() => {
|
fetchsitebooking();
|
});
|
return {
|
tabs,
|
currentTab,
|
sitebooking,
|
filteredsitebooking,
|
loading,
|
onTabChange,
|
cancelReservation,
|
verifyReservation
|
};
|
}
|
};
|
if (!Array) {
|
const _easycom_uni_segmented_control2 = common_vendor.resolveComponent("uni-segmented-control");
|
_easycom_uni_segmented_control2();
|
}
|
const _easycom_uni_segmented_control = () => "../../uni_modules/uni-segmented-control/components/uni-segmented-control/uni-segmented-control.js";
|
if (!Math) {
|
_easycom_uni_segmented_control();
|
}
|
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
return common_vendor.e({
|
a: common_vendor.o($setup.onTabChange),
|
b: common_vendor.p({
|
current: $setup.currentTab,
|
values: $setup.tabs,
|
["style-type"]: "button",
|
["active-color"]: "#3b82f6"
|
}),
|
c: $setup.loading
|
}, $setup.loading ? {} : {}, {
|
d: common_vendor.f($setup.filteredsitebooking, (item, index, i0) => {
|
return common_vendor.e({
|
a: item.status === "已预约"
|
}, item.status === "已预约" ? {
|
b: common_vendor.o(($event) => $setup.cancelReservation(item), index)
|
} : {}, {
|
c: common_vendor.t(item.sitename),
|
d: item.status != "已预约"
|
}, item.status != "已预约" ? {
|
e: common_vendor.t(item.status)
|
} : {}, {
|
f: common_vendor.t(item.visitdate),
|
g: common_vendor.t(item.visittimeam && item.visittimeam !== "" ? "上午(09:00-12:00)" : "下午(13:00-17:00)"),
|
h: common_vendor.t(item.contactperson),
|
i: common_vendor.t(item.contactphone),
|
j: common_vendor.t(item.personcount),
|
k: item.status === "已使用"
|
}, item.status === "已使用" ? {
|
l: common_vendor.t(item.usedtime)
|
} : {}, {
|
m: item.status === "已取消"
|
}, item.status === "已取消" ? {
|
n: common_vendor.t(item.canceltime)
|
} : {}, {
|
o: item.status === "已预约"
|
}, item.status === "已预约" ? {
|
p: common_vendor.o(($event) => $setup.verifyReservation(item), index)
|
} : {}, {
|
q: index
|
});
|
}),
|
e: !$setup.filteredsitebooking.length
|
}, !$setup.filteredsitebooking.length ? {
|
f: common_vendor.t($setup.tabs[$setup.currentTab])
|
} : {});
|
}
|
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
|
wx.createPage(MiniProgramPage);
|
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/ucenter/my-booking.js.map
|