|
|
@@ -103,6 +103,7 @@ export class AppointmentPageComponent implements OnInit {
|
|
|
|
|
|
private applyOrder(order: SourceItem): void {
|
|
|
this.order.set(order);
|
|
|
+ this.syncAppointmentStudent(order);
|
|
|
this.selectedCourse = String(order['kcid'] ?? '');
|
|
|
this.coachComment = String(order['pldp'] ?? '');
|
|
|
this.loadPracticeRecord();
|
|
|
@@ -251,6 +252,7 @@ export class AppointmentPageComponent implements OnInit {
|
|
|
|
|
|
private savePracticeSession(): void {
|
|
|
const student = this.session.student();
|
|
|
+ const studentId = this.appointmentStudentId();
|
|
|
const user = this.session.user();
|
|
|
const existing = this.practiceRecord();
|
|
|
const content: SourceItem = {
|
|
|
@@ -270,7 +272,7 @@ export class AppointmentPageComponent implements OnInit {
|
|
|
const addon = {
|
|
|
jsmz: user?.userId,
|
|
|
kcid: this.selectedCourse,
|
|
|
- xymz: student?.userId ?? this.order()['yhid'],
|
|
|
+ xymz: studentId,
|
|
|
kclx: this.order()['dslx_t'],
|
|
|
yyds: this.orderId,
|
|
|
jffs: this.order()['jffs'],
|
|
|
@@ -329,19 +331,35 @@ export class AppointmentPageComponent implements OnInit {
|
|
|
}
|
|
|
|
|
|
private loadCourses(): void {
|
|
|
- const student = this.session.student();
|
|
|
- if (!student?.userId) return;
|
|
|
- this.api.get<unknown>('content_list', { inputer: '', nid: 28, myfield: `yhid=${student.userId}`, orders: 'id=DESC', psize: 200 }).subscribe({
|
|
|
- next: ({ result }) => this.courses.set(this.findList(result).map((item) => {
|
|
|
- const parts = String(item['Title'] ?? '').split('|');
|
|
|
- return { ...item, Title: parts[parts.length - 1] || '-', kcId: item['kcid'] };
|
|
|
- })),
|
|
|
- error: () => undefined,
|
|
|
+ const studentId = this.appointmentStudentId();
|
|
|
+ const currentCourse = this.currentCourseOption();
|
|
|
+ if (!studentId) {
|
|
|
+ this.courses.set(currentCourse ? [currentCourse] : []);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.api.get<unknown>('content_list', { inputer: '', nid: 28, myfield: `yhid=${studentId}`, orders: 'id=DESC', psize: 200 }).subscribe({
|
|
|
+ next: ({ result }) => {
|
|
|
+ const courses: SourceItem[] = this.findList(result).map((item): SourceItem => {
|
|
|
+ const parts = String(item['Title'] ?? '').split('|');
|
|
|
+ return { ...item, Title: parts[parts.length - 1] || '-', kcId: item['kcid'] };
|
|
|
+ });
|
|
|
+ if (currentCourse && !courses.some((course) => String(course['kcid'] ?? course['kcId'] ?? '') === this.selectedCourse)) {
|
|
|
+ courses.unshift(currentCourse);
|
|
|
+ }
|
|
|
+ this.courses.set(courses);
|
|
|
+ },
|
|
|
+ error: () => this.courses.set(currentCourse ? [currentCourse] : []),
|
|
|
});
|
|
|
}
|
|
|
|
|
|
private loadUnits(): void {
|
|
|
- this.api.get<unknown>('node_list', { pid: this.selectedCourse, ifunit: 1, userId: this.session.user()?.userId }).subscribe({
|
|
|
+ const studentId = this.appointmentStudentId();
|
|
|
+ if (!studentId) {
|
|
|
+ this.units.set([]);
|
|
|
+ this.platform.toast('预约记录缺少学员 ID,暂时无法加载学习单元', 'error');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.api.get<unknown>('node_list', { pid: this.selectedCourse, ifunit: 1, userId: studentId }).subscribe({
|
|
|
next: ({ result }) => {
|
|
|
this.units.set(this.findList(result));
|
|
|
this.loadUnitProgress();
|
|
|
@@ -351,8 +369,9 @@ export class AppointmentPageComponent implements OnInit {
|
|
|
}
|
|
|
|
|
|
private loadUnitProgress(): void {
|
|
|
- const owner = Number(this.session.user()?.groupId) === 3 ? this.session.student() : this.session.user();
|
|
|
- this.api.post<unknown>('content_list', { ModelID: 58, myfield2: `yhid=${owner?.userId}|kcid=${this.selectedCourse}` }).subscribe({
|
|
|
+ const studentId = this.appointmentStudentId();
|
|
|
+ if (!studentId) return;
|
|
|
+ this.api.post<unknown>('content_list', { ModelID: 58, myfield2: `yhid=${studentId}|kcid=${this.selectedCourse}` }).subscribe({
|
|
|
next: ({ result }) => {
|
|
|
const record = this.findList(result)[0] ?? {};
|
|
|
this.bindingRecord.set(record);
|
|
|
@@ -363,9 +382,9 @@ export class AppointmentPageComponent implements OnInit {
|
|
|
}
|
|
|
|
|
|
private loadLearningRecord(): void {
|
|
|
- const student = this.session.student();
|
|
|
- if (!student?.userId) return;
|
|
|
- this.api.get<unknown>('content_list', { ModelID: 56, psize: 1, myfield: `dsid=${this.orderId}`, myfield2: `UserId=${student.userId}` }).subscribe({
|
|
|
+ const studentId = this.appointmentStudentId();
|
|
|
+ if (!studentId) return;
|
|
|
+ this.api.get<unknown>('content_list', { ModelID: 56, psize: 1, myfield: `dsid=${this.orderId}`, myfield2: `UserId=${studentId}` }).subscribe({
|
|
|
next: ({ result }) => this.learningRecord.set(this.findList(result)[0] ?? {}),
|
|
|
error: () => undefined,
|
|
|
});
|
|
|
@@ -387,6 +406,29 @@ export class AppointmentPageComponent implements OnInit {
|
|
|
return value && typeof value === 'object' && !Array.isArray(value) ? value as SourceItem : {};
|
|
|
}
|
|
|
|
|
|
+ private appointmentStudentId(): number {
|
|
|
+ return Number(this.order()['szyh'] ?? this.order()['yhid'] ?? this.session.student()?.userId ?? 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ private syncAppointmentStudent(order: SourceItem): void {
|
|
|
+ const studentId = Number(order['szyh'] ?? order['yhid'] ?? 0);
|
|
|
+ if (!studentId || this.session.student()?.userId === studentId) return;
|
|
|
+ this.session.setStudent({
|
|
|
+ userId: studentId,
|
|
|
+ honeyName: String(order['HoneyName'] ?? order['honeyName'] ?? order['honeyname'] ?? order['xymz_t'] ?? '学员'),
|
|
|
+ groupId: 1,
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private currentCourseOption(): SourceItem | null {
|
|
|
+ if (!this.selectedCourse) return null;
|
|
|
+ return {
|
|
|
+ kcid: this.selectedCourse,
|
|
|
+ kcId: this.selectedCourse,
|
|
|
+ Title: this.field('course') || `课程 ${this.selectedCourse}`,
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
private appointmentSnapshot(): SourceItem {
|
|
|
const state = history.state as { appointmentSnapshot?: unknown } | null;
|
|
|
if (state?.appointmentSnapshot && typeof state.appointmentSnapshot === 'object' && !Array.isArray(state.appointmentSnapshot)) {
|