zhxy-jzd/src/utils/pageUtil.ts
2025-09-26 19:58:38 +08:00

183 lines
4.6 KiB
TypeScript
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.

import { checkXsXkApi, checkXkTfApi } from "@/api/base/xkApi";
import { useUserStore } from "@/store/modules/user";
import { useDataStore } from "@/store/modules/data";
const userStore = useUserStore();
const dataStore = useDataStore();
// TODO: 记住测试的时候才默认使用第一个
const devFlag = false;
/**
* 页面工具类,主要在于处理抢课、就餐等页面逻辑跳转的处理
*/
export const PageUtils = {
/**
* 跳转逻辑
* @param lxId 类型( JC: 就餐816059832: 俱乐部962488654: 兴趣课)
* @param action 动作jf: 缴费tf: 退费)
*/
async toHome(lxId: string, action: string) {
// 没有类型,则跳转首页
if (!lxId) {
uni.reLaunch({
url: "/pages/base/home/index",
});
return;
}
// 判断当前学生列表如果大于1则跳转学生选择页面
const xsList = userStore.getUser.xsList;
if (devFlag) {
userStore.setCurXs(xsList[0]);
} else {
if (xsList && xsList.length > 1
&& (dataStore.getGlobal && dataStore.getGlobal.from == 'launch')) {
uni.reLaunch({
url: "/pages/base/home/xsXz",
});
return;
}
}
try {
// 判断业务逻辑,并跳转界面
await this.checkLogicPage(lxId, action);
} catch (error) {
console.error("逻辑校验失败:", error);
uni.reLaunch({
url: "/pages/base/home/xsXz",
});
}
},
/**
* 判断业务逻辑,并跳转界面
*/
async checkLogicPage(lxId: string, action: string) {
switch (lxId) {
// 就餐逻辑单独处理
case "JC": {
if (action === "jf") {
await this.checkJcLogic();
} else if (action === "tf") {
await this.checkJcTfLogic();
}
} break;
// 默认当作 选课的选课类型IDxkLxId处理
default: {
if (action === "jf") {
await this.checkQkLogic(lxId);
} else if (action === "tf") {
await this.checkXkTfLogic(lxId);
}
}
}
},
/**
* 判断抢课逻辑
* @param xklxId
*/
async checkQkLogic(xklxId: string) {
const res: any = await checkXsXkApi({
xsId: userStore.getCurXs.id,
njmcId: userStore.getCurXs.njmcId,
xklxId: xklxId,
});
console.log('checkQkLogic', res);
if (res.resultCode != 1) {
uni.showToast({
title: res.message,
icon: 'none'
});
uni.reLaunch({
url: "/pages/base/home/xsXz",
});
return;
}
const result = res.result || {};
// 记录到缓存数据中
dataStore.setQk(result);
// 状态判断
switch (result.xsXkStatus) {
case 'WFB': { // KQK可抢课
uni.reLaunch({
url: "/pages/base/xk/qk/wks?xklxId=" + xklxId,
});
} break;
case 'KQK': { // KQK可抢课
uni.reLaunch({
url: "/pages/base/gzs/index?lxId=" + xklxId,
});
} break;
case 'QKZ': { // QKZ抢课中
uni.reLaunch({
url: "/pages/base/xk/qk/index?xklxId=" + xklxId,
});
} break;
case 'YQK': { // YQK已选课
uni.reLaunch({
url: "/pages/base/xk/pay/index?xklxId=" + xklxId,
});
} break;
case 'DZF': { // DZF待支付
uni.reLaunch({
url: "/pages/base/xk/pay/index?xklxId=" + xklxId,
});
} break;
case 'YZF': { // YZF已支付
uni.reLaunch({
url: "/pages/base/xk/pay/success?xklxId=" + xklxId,
});
} break;
}
},
// 判断退费页面切换逻辑
async checkXkTfLogic(xklxId: string) {
const res = await checkXkTfApi({
xsId: userStore.getCurXs.id,
njmcId: userStore.getCurXs.njmcId,
xklxId: xklxId,
});
console.log('checkXkTfLogic', res);
if (res.resultCode != 1) {
uni.showToast({
title: res.message,
icon: 'none',
duration: 2000,
});
uni.reLaunch({
url: "/pages/base/home/index",
});
return;
}
const result = res.result || {};
// 记录到缓存数据中
dataStore.setTf(result);
// 状态判断
switch (result.status) {
case 'KTF': { // KTF可退费
uni.reLaunch({
url: "/pages/base/gzs/tf?lxId=" + xklxId,
});
} break;
case 'TFZ': { // TFZ退费中
uni.reLaunch({
url: "/pages/base/xk/tf/detail?xklxId=" + xklxId,
});
} break;
}
},
// 判断就餐逻辑
async checkJcLogic() {
uni.reLaunch({
url: "/pages/base/jc/bm",
});
},
// 判断就餐退费逻辑
async checkJcTfLogic() {
},
}