fix(aihr): expose enabled scenarios to supervisors
This commit is contained in:
@@ -122,7 +122,7 @@ import { onLoad, onShow } from '@dcloudio/uni-app';
|
||||
import type { PracticeAlert, PracticeAssignment } from '@/types/api';
|
||||
import { clearAuth, isLoggedIn, rememberLoginRedirect } from '@/services/auth';
|
||||
import { resetPageScroll } from '@/services/navigation';
|
||||
import { createPracticeAssignment, getPracticeAlerts, getPracticeTeamSnapshot } from '@/services/practice';
|
||||
import { createPracticeAssignment, getPracticeAlerts, getPracticeScenarios, getPracticeTeamSnapshot } from '@/services/practice';
|
||||
import SupervisorTabBar from '@/components/SupervisorTabBar.vue';
|
||||
import {
|
||||
createAsyncGenerationGuard,
|
||||
@@ -130,6 +130,7 @@ import {
|
||||
isSupervisorAccessDenied,
|
||||
manualPracticeAssignments,
|
||||
supervisorScenarioOptions,
|
||||
type SupervisorScenarioOption,
|
||||
type SupervisorScenarioId
|
||||
} from '@/services/supervisor-view';
|
||||
|
||||
@@ -137,6 +138,7 @@ const basePath = '/pages/supervisor/assign/index';
|
||||
const targetExtPartyId = ref('');
|
||||
const targetName = ref('');
|
||||
const assignmentScenarioId = ref<SupervisorScenarioId>('fee-parking');
|
||||
const scenarioOptions = ref<SupervisorScenarioOption[]>([...supervisorScenarioOptions]);
|
||||
const assignmentReason = ref('');
|
||||
const assignments = ref<PracticeAssignment[]>([]);
|
||||
const alerts = ref<PracticeAlert[]>([]);
|
||||
@@ -174,7 +176,7 @@ const queryText = (value: unknown) => {
|
||||
};
|
||||
|
||||
const isScenarioId = (value: string): value is SupervisorScenarioId =>
|
||||
supervisorScenarioOptions.some((item) => item.id === value);
|
||||
scenarioOptions.value.some((item) => item.id === value);
|
||||
|
||||
const refreshAuthState = () => {
|
||||
loggedIn.value = isLoggedIn();
|
||||
@@ -240,6 +242,31 @@ const loadAssignments = async (force = false) => {
|
||||
}
|
||||
};
|
||||
|
||||
const loadScenarioOptions = async () => {
|
||||
try {
|
||||
const rows = await getPracticeScenarios('生活顾问');
|
||||
const nextOptions = rows
|
||||
.filter((item) => item.enabled !== false && item.id && item.name)
|
||||
.map((item) => ({ id: item.id, name: item.name }));
|
||||
if (nextOptions.length) {
|
||||
scenarioOptions.value = nextOptions;
|
||||
if (!isScenarioId(assignmentScenarioId.value)) {
|
||||
assignmentScenarioId.value = nextOptions[0].id;
|
||||
}
|
||||
return;
|
||||
}
|
||||
scenarioOptions.value = [...supervisorScenarioOptions];
|
||||
if (!isScenarioId(assignmentScenarioId.value)) {
|
||||
assignmentScenarioId.value = supervisorScenarioOptions[0].id;
|
||||
}
|
||||
} catch {
|
||||
scenarioOptions.value = [...supervisorScenarioOptions];
|
||||
if (!isScenarioId(assignmentScenarioId.value)) {
|
||||
assignmentScenarioId.value = supervisorScenarioOptions[0].id;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const loadPage = () => {
|
||||
refreshAuthState();
|
||||
message.value = '';
|
||||
@@ -247,7 +274,7 @@ const loadPage = () => {
|
||||
clearPrivateState();
|
||||
return;
|
||||
}
|
||||
void loadAssignments();
|
||||
void Promise.all([loadAssignments(), loadScenarioOptions()]);
|
||||
};
|
||||
|
||||
const assignPractice = async () => {
|
||||
@@ -261,7 +288,7 @@ const assignPractice = async () => {
|
||||
assigning.value = true;
|
||||
message.value = '';
|
||||
try {
|
||||
const scenario = supervisorScenarioOptions.find((item) => item.id === assignmentScenarioId.value);
|
||||
const scenario = scenarioOptions.value.find((item) => item.id === assignmentScenarioId.value);
|
||||
await createPracticeAssignment({
|
||||
extPartyId,
|
||||
traineeName: targetName.value.trim() || `手机用户${extPartyId.slice(-4)}`,
|
||||
@@ -322,9 +349,7 @@ onLoad((query) => {
|
||||
targetName.value = queryText(query?.name);
|
||||
assignmentReason.value = queryText(query?.reason);
|
||||
const requestedScenario = queryText(query?.scenarioId);
|
||||
assignmentScenarioId.value = isScenarioId(requestedScenario)
|
||||
? requestedScenario
|
||||
: inferSupervisorScenarioId(assignmentReason.value);
|
||||
assignmentScenarioId.value = requestedScenario || inferSupervisorScenarioId(assignmentReason.value);
|
||||
});
|
||||
|
||||
onShow(() => {
|
||||
|
||||
Reference in New Issue
Block a user