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