修复bug
This commit is contained in:
parent
b1a6e58a6f
commit
edb9ee5c38
@ -27,8 +27,10 @@ import { confirm, hideLoading, loading, toast } from "@/utils/widget";
|
||||
import { normalizeCorpId } from "@/utils/api-base-config";
|
||||
import FullPage from "@/components/full-page.vue";
|
||||
|
||||
const env = __VITE_ENV__;
|
||||
const appid = env.MP_WX_APP_ID;
|
||||
const { account } = storeToRefs(useAccount());
|
||||
const { login } = useAccount();
|
||||
const { getTeams, login } = useAccount();
|
||||
|
||||
const corpId = ref("");
|
||||
const issueId = ref("");
|
||||
@ -78,9 +80,8 @@ async function loadIssueDetail() {
|
||||
return true;
|
||||
}
|
||||
|
||||
async function hasBoundArchive() {
|
||||
const openid = account.value?.openid || "";
|
||||
if (!openid || !corpId.value || !memberId.value) return false;
|
||||
async function getIssueCustomer() {
|
||||
if (!corpId.value || !memberId.value) return null;
|
||||
|
||||
try {
|
||||
const detail = await api(
|
||||
@ -91,21 +92,114 @@ async function hasBoundArchive() {
|
||||
const customer = detail?.data || null;
|
||||
const teamIds = Array.isArray(customer?.teamId) ? customer.teamId : [customer?.teamId];
|
||||
bindingTeamId.value = teamIds.find(Boolean) || "";
|
||||
return Boolean(customer && String(customer.miniAppId || "") === String(openid));
|
||||
return customer;
|
||||
} catch (e) {
|
||||
console.warn("getCustomerByCustomerId failed", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async function hasBoundArchive() {
|
||||
const openid = account.value?.openid || "";
|
||||
if (!openid) return false;
|
||||
|
||||
const customer = await getIssueCustomer();
|
||||
return Boolean(customer && String(customer.miniAppId || "") === String(openid));
|
||||
}
|
||||
|
||||
function buildClaimUrl() {
|
||||
const params = [
|
||||
`corpId=${encodeURIComponent(corpId.value || "")}`,
|
||||
`issueId=${encodeURIComponent(issueId.value || "")}`,
|
||||
memberId.value ? `memberId=${encodeURIComponent(memberId.value)}` : "",
|
||||
].filter(Boolean).join("&");
|
||||
return `/pages/experience-coupon/claim?${params}`;
|
||||
}
|
||||
|
||||
async function ensurePhoneAuthorized() {
|
||||
if (account.value?.mobile) return true;
|
||||
|
||||
tip.value = "请先授权手机号后再领取体验券";
|
||||
uni.navigateTo({
|
||||
url: `/pages/login/login?redirectUrl=${encodeURIComponent(buildClaimUrl())}`,
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
async function ensureTeamAdded() {
|
||||
const customer = await getIssueCustomer();
|
||||
if (!customer || !bindingTeamId.value) {
|
||||
tip.value = "体验券发放档案缺少所属团队,暂无法领取";
|
||||
return false;
|
||||
}
|
||||
|
||||
const teams = await getTeams();
|
||||
const linked = (teams || []).some(
|
||||
(team) =>
|
||||
normalizeCorpId(team.corpId) === corpId.value &&
|
||||
String(team.teamId) === String(bindingTeamId.value)
|
||||
);
|
||||
if (linked) return true;
|
||||
|
||||
tip.value = "请先添加体验券所属团队后再领取";
|
||||
try {
|
||||
await confirm("请先添加体验券所属团队后再领取", {
|
||||
title: "提示",
|
||||
confirmText: "添加团队",
|
||||
cancelText: "取消",
|
||||
});
|
||||
const res = await api(
|
||||
"bindWxappWithTeam",
|
||||
{
|
||||
appid,
|
||||
corpId: corpId.value,
|
||||
teamId: bindingTeamId.value,
|
||||
openid: account.value?.openid || "",
|
||||
},
|
||||
false
|
||||
);
|
||||
if (!res?.success) {
|
||||
toast(res?.message || "添加团队失败");
|
||||
return false;
|
||||
}
|
||||
await getTeams();
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function goBindArchive() {
|
||||
const params = [
|
||||
`corpId=${encodeURIComponent(corpId.value || "")}`,
|
||||
`teamId=${encodeURIComponent(bindingTeamId.value || "")}`,
|
||||
].join("&");
|
||||
uni.navigateTo({
|
||||
url: `/pages/archive/edit-archive?${params}`,
|
||||
});
|
||||
async function bindIssueArchive() {
|
||||
if (!memberId.value) {
|
||||
toast("体验券发放档案不存在");
|
||||
return;
|
||||
}
|
||||
|
||||
loading("绑定档案中...");
|
||||
try {
|
||||
const res = await api(
|
||||
"bindMiniAppArchive",
|
||||
{
|
||||
id: memberId.value,
|
||||
corpId: corpId.value,
|
||||
teamId: bindingTeamId.value,
|
||||
miniAppId: account.value?.openid || "",
|
||||
},
|
||||
false
|
||||
);
|
||||
if (!res?.success) {
|
||||
tip.value = res?.message || "绑定档案失败";
|
||||
toast(tip.value);
|
||||
return;
|
||||
}
|
||||
|
||||
toast("档案绑定成功");
|
||||
tip.value = "";
|
||||
autoPrompted.value = false;
|
||||
await promptClaim();
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
function isExpiredIssue() {
|
||||
@ -183,7 +277,7 @@ async function promptClaim() {
|
||||
confirmText: "去绑定",
|
||||
cancelText: "取消",
|
||||
});
|
||||
goBindArchive();
|
||||
await bindIssueArchive();
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
@ -201,6 +295,10 @@ async function bootstrap() {
|
||||
if (!okLogin) return;
|
||||
const okDetail = await loadIssueDetail();
|
||||
if (!okDetail) return;
|
||||
const phoneAuthorized = await ensurePhoneAuthorized();
|
||||
if (!phoneAuthorized) return;
|
||||
const teamAdded = await ensureTeamAdded();
|
||||
if (!teamAdded) return;
|
||||
await promptClaim();
|
||||
} finally {
|
||||
hideLoading();
|
||||
|
||||
@ -86,8 +86,14 @@ function formatDate(ts) {
|
||||
return `${y}-${m}-${day}`;
|
||||
}
|
||||
|
||||
function pickCorpName(team = {}) {
|
||||
return team.licenseHospitalName || team.leaderCorp || team.corpName || "-";
|
||||
async function loadCorpName() {
|
||||
if (!corpId.value) {
|
||||
corpName.value = "";
|
||||
return;
|
||||
}
|
||||
const res = await api("getCorpInfo", { corpId: corpId.value }, false);
|
||||
const corp = Array.isArray(res?.data) ? res.data[0] : null;
|
||||
corpName.value = corp?.corp_name || corp?.corpName || "";
|
||||
}
|
||||
|
||||
const groups = computed(() => {
|
||||
@ -139,16 +145,6 @@ function applySelection(selection = {}) {
|
||||
teamId.value = selection.teamId || teamId.value || "";
|
||||
customerId.value = selection.customerId || selection.memberId || customerId.value || "";
|
||||
customerName.value = selection.name || customerName.value || "";
|
||||
if (selection.corpName) {
|
||||
corpName.value = selection.corpName;
|
||||
return;
|
||||
}
|
||||
const matched = teams.value.find(
|
||||
(team) =>
|
||||
normalizeCorpId(team.corpId) === corpId.value &&
|
||||
(!teamId.value || team.teamId === teamId.value)
|
||||
);
|
||||
corpName.value = pickCorpName(matched || {});
|
||||
}
|
||||
|
||||
async function resolveContext(options = {}) {
|
||||
@ -181,7 +177,7 @@ async function resolveContext(options = {}) {
|
||||
|
||||
if (!corpId.value) corpId.value = normalizeCorpId(matched?.corpId || "");
|
||||
if (!teamId.value) teamId.value = matched?.teamId || "";
|
||||
if (!corpName.value) corpName.value = pickCorpName(matched || {});
|
||||
await loadCorpName();
|
||||
|
||||
if (customerId.value) return true;
|
||||
|
||||
@ -240,6 +236,7 @@ async function syncSelectedProfile() {
|
||||
if (!selected) return false;
|
||||
remove(RIGHTS_SELECTION_CACHE_KEY);
|
||||
applySelection(selected);
|
||||
await loadCorpName();
|
||||
await loadRights();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -41,7 +41,6 @@ import FullPage from "@/components/full-page.vue";
|
||||
const HOME_CURRENT_TEAM_CACHE_KEY = "home-current-team-info";
|
||||
const RIGHTS_SELECTION_CACHE_KEY = "experience-coupon-rights-selection";
|
||||
const { account } = storeToRefs(useAccount());
|
||||
const { getTeams } = useAccount();
|
||||
|
||||
const loading = ref(false);
|
||||
const options = ref([]);
|
||||
@ -106,32 +105,17 @@ async function loadArchives() {
|
||||
|
||||
loading.value = true;
|
||||
try {
|
||||
const teams = (await getTeams()) || [];
|
||||
const currentTeam = get(HOME_CURRENT_TEAM_CACHE_KEY) || {};
|
||||
const selectedCorpId = normalizeCorpId(currentTeam.corpId || currentCorpId.value);
|
||||
const selectedTeamId = currentTeam.teamId || currentTeamId.value;
|
||||
const selectedTeam = teams.find(
|
||||
(team) =>
|
||||
normalizeCorpId(team.corpId) === selectedCorpId &&
|
||||
(!selectedTeamId || team.teamId === selectedTeamId)
|
||||
);
|
||||
|
||||
if (!selectedCorpId || !selectedTeam) {
|
||||
if (!selectedCorpId) {
|
||||
options.value = [];
|
||||
return;
|
||||
}
|
||||
|
||||
const [corpRes, customerRes] = await Promise.all([
|
||||
api("getCorpInfo", { corpId: selectedCorpId }, false),
|
||||
api(
|
||||
"getTeamCustomers",
|
||||
{
|
||||
miniAppId,
|
||||
corpId: selectedCorpId,
|
||||
teamId: selectedTeam.teamId,
|
||||
},
|
||||
false
|
||||
),
|
||||
api("getCorpMiniAppCustomers", { miniAppId, corpId: selectedCorpId }, false),
|
||||
]);
|
||||
const corp = Array.isArray(corpRes?.data) ? corpRes.data[0] : null;
|
||||
const archiveCorpName = corp?.corp_name || corp?.corpName || "-";
|
||||
@ -140,7 +124,7 @@ async function loadArchives() {
|
||||
.map((customer) => ({
|
||||
key: `${selectedCorpId}_${customer._id}`,
|
||||
corpId: selectedCorpId,
|
||||
teamId: selectedTeam.teamId || "",
|
||||
teamId: currentTeam.teamId || currentTeamId.value || "",
|
||||
customerId: customer._id || "",
|
||||
name: customer.name || "",
|
||||
relationship: customer.relationship || "",
|
||||
|
||||
@ -86,6 +86,16 @@ const statusMap = {
|
||||
const avatarText = computed(() => (customerName.value || "档案").slice(0, 1));
|
||||
const monthText = computed(() => selectedMonth.value.replace("-", "年") + "月");
|
||||
|
||||
async function loadCorpName() {
|
||||
if (!corpId.value) {
|
||||
corpName.value = "";
|
||||
return;
|
||||
}
|
||||
const res = await api("getCorpInfo", { corpId: corpId.value }, false);
|
||||
const corp = Array.isArray(res?.data) ? res.data[0] : null;
|
||||
corpName.value = corp?.corp_name || corp?.corpName || "";
|
||||
}
|
||||
|
||||
function pad(value) {
|
||||
return String(value).padStart(2, "0");
|
||||
}
|
||||
@ -242,8 +252,8 @@ onLoad(async (options = {}) => {
|
||||
teamId.value = options.teamId || "";
|
||||
customerId.value = options.customerId || options.id || "";
|
||||
customerName.value = options.name ? decodeURIComponent(options.name) : "";
|
||||
corpName.value = options.corpName ? decodeURIComponent(options.corpName) : "";
|
||||
if (options.month) selectedMonth.value = options.month;
|
||||
await loadCorpName();
|
||||
await loadStaffNameMap();
|
||||
await loadRecords();
|
||||
});
|
||||
|
||||
@ -88,6 +88,16 @@ const refreshing = ref(false);
|
||||
const avatarText = computed(() => (customerName.value || "档案").slice(0, 1));
|
||||
const monthText = computed(() => selectedMonth.value.replace("-", "年") + "月");
|
||||
|
||||
async function loadCorpName() {
|
||||
if (!corpId.value) {
|
||||
corpName.value = "";
|
||||
return;
|
||||
}
|
||||
const res = await api("getCorpInfo", { corpId: corpId.value }, false);
|
||||
const corp = Array.isArray(res?.data) ? res.data[0] : null;
|
||||
corpName.value = corp?.corp_name || corp?.corpName || "";
|
||||
}
|
||||
|
||||
function pad(value) {
|
||||
return String(value).padStart(2, "0");
|
||||
}
|
||||
@ -211,8 +221,8 @@ onLoad(async (options = {}) => {
|
||||
teamId.value = options.teamId || "";
|
||||
customerId.value = options.customerId || options.id || "";
|
||||
customerName.value = options.name ? decodeURIComponent(options.name) : "";
|
||||
corpName.value = options.corpName ? decodeURIComponent(options.corpName) : "";
|
||||
if (options.month) selectedMonth.value = options.month;
|
||||
await loadCorpName();
|
||||
await loadStaffNameMap();
|
||||
await loadRecords();
|
||||
});
|
||||
|
||||
@ -63,6 +63,7 @@ const urlsConfig = {
|
||||
getExperienceCouponIssueDetail: "getExperienceCouponIssueDetail",
|
||||
getExperienceCouponIssueList: "getExperienceCouponIssueList",
|
||||
getMiniAppCustomers: 'getMiniAppCustomers',
|
||||
getCorpMiniAppCustomers: 'getCorpMiniAppCustomers',
|
||||
getTeamCustomers: 'getTeamCustomers',
|
||||
getTreatmentRecord: "getTreatmentRecord",
|
||||
getDeductRecord: "getDeductRecord",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user