Commit a2877b73 by chenwq

feat: 添加课程多选组件到审批提交页面,优化课程选择逻辑

1 parent 432e2f71
...@@ -13,6 +13,9 @@ export default { ...@@ -13,6 +13,9 @@ export default {
getFlightSupervisorList(data) { getFlightSupervisorList(data) {
return api.post("dj.api.supervisor.mini.list.flightSupervisor", data, "supervisorUrl"); return api.post("dj.api.supervisor.mini.list.flightSupervisor", data, "supervisorUrl");
}, },
getAllCoursePage(data) {
return api.post("dj.supervisor.mini.api.all.course.page", data, "supervisorUrl");
},
submitApproval(data) { submitApproval(data) {
return api.post("dj.api.supervisor.mini.approval.submit", data, "supervisorUrl"); return api.post("dj.api.supervisor.mini.approval.submit", data, "supervisorUrl");
}, },
......
<template>
<div class="course-select" @click="openPicker">
<div class="course-row-header">
<span>{{ label }} <em v-if="required">*</em></span>
<div class="course-row-link">
<span class="placeholder">{{ placeholder }}</span>
<van-icon name="arrow" />
</div>
</div>
<div v-if="selectedCourses.length" class="course-tags">
<span v-for="course in selectedCourses"
:key="course.id"
class="course-tag">
<span class="course-tag-text">{{ course.name }}</span>
<van-icon name="cross" @click.stop="removeCourse(course)" />
</span>
</div>
<van-popup v-model="show"
class="course-popup"
position="bottom"
round>
<div class="course-picker">
<div class="course-picker-title">
课程选择
</div>
<van-search v-model.trim="keyword"
placeholder="搜索"
shape="round" />
<div class="course-list">
<div v-if="loading" class="course-empty">
加载中...
</div>
<div v-else-if="!filteredCourses.length" class="course-empty">
暂无课程
</div>
<template v-else>
<div v-for="course in filteredCourses"
:key="course.id"
class="course-option"
:class="{ selected: isSelected(course) }"
@click.stop="toggleCourse(course)">
<span>{{ course.name }}</span>
<van-icon v-if="isSelected(course)" name="success" />
</div>
</template>
</div>
<div class="course-actions">
<button class="course-cancel"
type="button"
@click.stop="show = false">
取消
</button>
<button class="course-confirm"
type="button"
@click.stop="confirm">
确认
</button>
</div>
</div>
</van-popup>
</div>
</template>
<script>
export default {
name: "CourseMultiSelect",
props: {
value: {
type: Array,
default: () => [],
},
courses: {
type: Array,
default: () => [],
},
label: {
type: String,
default: "推送课程",
},
placeholder: {
type: String,
default: "点击选择(可多选)",
},
required: {
type: Boolean,
default: false,
},
loading: {
type: Boolean,
default: false,
},
},
data() {
return {
show: false,
keyword: "",
tempSelected: [],
};
},
computed: {
selectedCourses() {
return this.courses.filter(course => this.value.includes(course.id));
},
filteredCourses() {
const keyword = this.keyword.trim().toLowerCase();
if (!keyword)
return this.courses;
return this.courses.filter(course => course.name.toLowerCase().includes(keyword));
},
},
methods: {
openPicker() {
this.keyword = "";
this.tempSelected = [...this.value];
this.show = true;
this.$emit("open");
},
isSelected(course) {
return this.tempSelected.includes(course.id);
},
toggleCourse(course) {
const index = this.tempSelected.indexOf(course.id);
if (index > -1) {
this.tempSelected.splice(index, 1);
return;
}
this.tempSelected.push(course.id);
},
confirm() {
this.updateValue(this.tempSelected);
this.show = false;
},
removeCourse(course) {
this.updateValue(this.value.filter(id => id !== course.id));
},
updateValue(ids) {
const selectedSet = new Set(ids);
const selectedCourses = this.courses.filter(course => selectedSet.has(course.id));
this.$emit("input", selectedCourses.map(course => course.id));
this.$emit("change", selectedCourses);
},
},
};
</script>
<style lang="scss" scoped>
.course-select {
width: 100%;
}
.course-row-header {
display: flex;
align-items: center;
justify-content: space-between;
min-height: 22px;
em {
color: #ee0a24;
font-style: normal;
}
}
.course-row-link {
flex: 1;
min-width: 0;
margin-left: 14px;
display: flex;
align-items: center;
justify-content: flex-end;
.placeholder {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: #00000040;
}
.van-icon {
margin-left: 4px;
color: #00000040;
}
}
.course-tags {
display: flex;
flex-wrap: wrap;
gap: 7px;
justify-content: flex-start;
margin-top: 8px;
}
.course-tag {
max-width: 100%;
height: 22px;
line-height: 20px;
padding: 0 8px;
box-sizing: border-box;
border: 1px solid #dfe3eb;
border-radius: 3px;
background: #f7f8fa;
color: #1f2d3d;
font-size: 13px;
display: inline-flex;
align-items: center;
min-width: 0;
.van-icon {
flex: 0 0 auto;
margin-left: 6px;
color: #8a93a3;
font-size: 12px;
}
}
.course-tag-text {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.course-popup {
background: #fff;
}
.course-picker {
height: 712px;
max-height: 84vh;
display: flex;
flex-direction: column;
background: #fff;
}
.course-picker-title {
height: 50px;
line-height: 50px;
text-align: center;
font-size: 17px;
font-weight: 600;
color: #1f2d3d;
border-bottom: 1px solid #edf0f5;
}
.course-list {
flex: 1;
min-height: 0;
overflow-y: auto;
padding: 10px 18px 0;
box-sizing: border-box;
}
.course-option {
min-height: 50px;
display: flex;
align-items: center;
justify-content: space-between;
border-bottom: 1px solid #edf0f5;
color: #1f2d3d;
font-size: 14px;
line-height: 20px;
span {
flex: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.van-icon {
margin-left: 12px;
color: #2f66f6;
font-size: 18px;
}
&.selected {
color: #2f66f6;
}
}
.course-empty {
padding: 50px 0;
text-align: center;
color: #969799;
font-size: 14px;
}
.course-actions {
display: flex;
gap: 14px;
padding: 14px 18px 20px;
box-sizing: border-box;
border-top: 1px solid #f0f0f0;
button {
flex: 1;
height: 40px;
border: 0;
border-radius: 8px;
font-size: 16px;
}
}
.course-cancel {
background: #f5f6f8;
color: #1f2d3d;
}
.course-confirm {
background: #2f66f6;
color: #fff;
}
</style>
...@@ -113,7 +113,8 @@ export default { ...@@ -113,7 +113,8 @@ export default {
<style lang="scss" scoped> <style lang="scss" scoped>
.approval-page { .approval-page {
min-height: 100%; height: 100%;
overflow: auto;
background: #f2f3f7; background: #f2f3f7;
box-sizing: border-box; box-sizing: border-box;
padding: 0 12px 96px; padding: 0 12px 96px;
......
...@@ -4,14 +4,27 @@ ...@@ -4,14 +4,27 @@
<div v-for="item in approveFormItems" <div v-for="item in approveFormItems"
:key="item.key" :key="item.key"
class="form-row" class="form-row"
@click="handleFormItemClick(item)"> :class="{ 'course-form-row': item.type === 'course' }"
<span>{{ item.label }} <em v-if="item.required">*</em></span> @click="item.type !== 'course' && handleFormItemClick(item)">
<div class="row-value"> <template v-if="item.type === 'course'">
<span :class="{ placeholder: !getFormValue(item) }"> <CourseMultiSelect :courses="dicts.course"
{{ getFormValue(item) || item.placeholder }} :label="item.label"
</span> :loading="courseLoading"
<van-icon name="arrow" /> :placeholder="item.placeholder"
</div> :required="item.required"
:value="courseIdList"
@change="setSelectedCourses"
@open="loadCourseList" />
</template>
<template v-else>
<span>{{ item.label }} <em v-if="item.required">*</em></span>
<div class="row-value">
<span :class="{ placeholder: !getFormValue(item) }">
{{ getFormValue(item) || item.placeholder }}
</span>
<van-icon name="arrow" />
</div>
</template>
</div> </div>
</div> </div>
...@@ -68,6 +81,7 @@ import dayjs from "dayjs"; ...@@ -68,6 +81,7 @@ import dayjs from "dayjs";
import { Toast } from "vant"; import { Toast } from "vant";
import api from "@/api/mine"; import api from "@/api/mine";
import util from "@/utils/util"; import util from "@/utils/util";
import CourseMultiSelect from "../components/courseMultiSelect.vue";
const DICT_CONFIG = { const DICT_CONFIG = {
scene: { typeCode: "teaching_scene", title: "选择带教场景" }, scene: { typeCode: "teaching_scene", title: "选择带教场景" },
...@@ -109,6 +123,15 @@ const APPROVE_FORM_CONFIG = [ ...@@ -109,6 +123,15 @@ const APPROVE_FORM_CONFIG = [
placeholder: "点击选择", placeholder: "点击选择",
}, },
{ {
key: "course",
label: "推送课程",
required: true,
requiredKey: "selectedCourseIds",
valueKey: "selectedCourseNames",
type: "course",
placeholder: "点击选择(可多选)",
},
{
key: "topic", key: "topic",
label: "带教主题", label: "带教主题",
valueKey: "teachingTopicName", valueKey: "teachingTopicName",
...@@ -162,12 +185,17 @@ const APPROVE_SUBMIT_KEYS = [ ...@@ -162,12 +185,17 @@ const APPROVE_SUBMIT_KEYS = [
"teachingTime", "teachingTime",
"teachingMethodCode", "teachingMethodCode",
"teachingMethodName", "teachingMethodName",
"selectedCourseIds",
"selectedCourseNames",
"teachingTopicCode", "teachingTopicCode",
"teachingTopicName", "teachingTopicName",
]; ];
export default { export default {
name: "MineApprovalSubmit", name: "MineApprovalSubmit",
components: {
CourseMultiSelect,
},
data() { data() {
return { return {
userInfo: {}, userInfo: {},
...@@ -181,12 +209,14 @@ export default { ...@@ -181,12 +209,14 @@ export default {
methodOnline: [], methodOnline: [],
methodOffline: [], methodOffline: [],
topic: [], topic: [],
course: [],
}, },
picker: { picker: {
show: false, show: false,
key: "", key: "",
title: "", title: "",
}, },
courseLoading: false,
submitting: false, submitting: false,
form: { form: {
assignedSupervisorPhone: "", assignedSupervisorPhone: "",
...@@ -197,6 +227,8 @@ export default { ...@@ -197,6 +227,8 @@ export default {
teachingTime: "", teachingTime: "",
teachingMethodCode: "", teachingMethodCode: "",
teachingMethodName: "", teachingMethodName: "",
selectedCourseIds: "",
selectedCourseNames: "",
teachingTopicCode: "", teachingTopicCode: "",
teachingTopicName: "", teachingTopicName: "",
rejectReason: "", rejectReason: "",
...@@ -211,7 +243,7 @@ export default { ...@@ -211,7 +243,7 @@ export default {
return this.isApprove ? "通过" : "驳回"; return this.isApprove ? "通过" : "驳回";
}, },
approveFormItems() { approveFormItems() {
return APPROVE_FORM_CONFIG; return APPROVE_FORM_CONFIG.filter(item => item.key !== "course" || this.shouldShowCoursePicker);
}, },
rejectFormItems() { rejectFormItems() {
return REJECT_FORM_CONFIG; return REJECT_FORM_CONFIG;
...@@ -226,6 +258,23 @@ export default { ...@@ -226,6 +258,23 @@ export default {
const sceneText = `${this.form.teachingSceneCode}${this.form.teachingSceneName}`; const sceneText = `${this.form.teachingSceneCode}${this.form.teachingSceneName}`;
return sceneText.includes("线下") || sceneText.includes("offline") ? "methodOffline" : "methodOnline"; return sceneText.includes("线下") || sceneText.includes("offline") ? "methodOffline" : "methodOnline";
}, },
isOnlineScene() {
const sceneText = `${this.form.teachingSceneCode}${this.form.teachingSceneName}`.toLowerCase();
return Boolean(sceneText) && !sceneText.includes("线下") && !sceneText.includes("offline");
},
isCoursePushMethod() {
const methodText = `${this.form.teachingMethodCode}${this.form.teachingMethodName}`;
return methodText.includes("课程推送");
},
shouldShowCoursePicker() {
return this.isOnlineScene && this.isCoursePushMethod;
},
courseIdList() {
return this.form.selectedCourseIds ? this.form.selectedCourseIds.split(",").filter(Boolean) : [];
},
selectedCourses() {
return this.dicts.course.filter(course => this.courseIdList.includes(course.id));
},
pickerColumns() { pickerColumns() {
if (this.picker.key === "supervisor") if (this.picker.key === "supervisor")
return this.dicts.supervisor; return this.dicts.supervisor;
...@@ -284,11 +333,24 @@ export default { ...@@ -284,11 +333,24 @@ export default {
uuid: item.uuid || "", uuid: item.uuid || "",
}; };
}, },
normalizeCourseItem(item) {
const id = item.courseId || item.id || item.courseCode || item.code || item.uuid || "";
const name = item.courseName || item.name || item.title || item.label || "";
return {
...item,
id: String(id),
name,
};
},
handleFormItemClick(item) { handleFormItemClick(item) {
if (item.type === "datetime") { if (item.type === "datetime") {
this.showTimePicker = true; this.showTimePicker = true;
return; return;
} }
if (item.key === "method" && !this.form.teachingSceneCode && !this.form.teachingSceneName) {
Toast("请先选带教场景。");
return;
}
this.openPicker(item); this.openPicker(item);
}, },
openPicker(item) { openPicker(item) {
...@@ -306,6 +368,7 @@ export default { ...@@ -306,6 +368,7 @@ export default {
return; return;
} }
this.applyPickerValue(item); this.applyPickerValue(item);
this.afterPickerValueChanged();
this.picker.show = false; this.picker.show = false;
}, },
applyPickerValue(item) { applyPickerValue(item) {
...@@ -318,6 +381,39 @@ export default { ...@@ -318,6 +381,39 @@ export default {
this.form.teachingTime = dayjs(value).format("YYYY-MM-DD HH:mm"); this.form.teachingTime = dayjs(value).format("YYYY-MM-DD HH:mm");
this.showTimePicker = false; this.showTimePicker = false;
}, },
afterPickerValueChanged() {
if (this.picker.key === "scene" || this.picker.key === "method")
this.clearSelectedCourses();
},
clearSelectedCourses() {
this.form.selectedCourseIds = "";
this.form.selectedCourseNames = "";
},
async loadCourseList() {
if (this.dicts.course.length)
return;
this.courseLoading = true;
try {
const res = await api.getAllCoursePage({
pageNum: 1,
pageSize: 9999,
sortType: 0,
sortOrder: "desc",
staffPhone: this.userInfo.phone,
});
const data = res.data || res || {};
const list = data.list || data.records || data.rows || data || [];
this.dicts.course = (Array.isArray(list) ? list : []).map(this.normalizeCourseItem).filter(item => item.id && item.name);
} catch (error) {
Toast("课程加载失败");
} finally {
this.courseLoading = false;
}
},
setSelectedCourses(courses) {
this.form.selectedCourseIds = courses.map(course => course.id).join(",");
this.form.selectedCourseNames = courses.map(course => course.name).join(",");
},
getFormValue(item) { getFormValue(item) {
return this.form[item.valueKey]; return this.form[item.valueKey];
}, },
...@@ -354,6 +450,7 @@ export default { ...@@ -354,6 +450,7 @@ export default {
return { return {
...params, ...params,
...this.pickFormValues(APPROVE_SUBMIT_KEYS), ...this.pickFormValues(APPROVE_SUBMIT_KEYS),
courseList: this.selectedCourses.map(course => ({ bcCourseId: course.id, bcCourseName: course.name })),
}; };
}, },
pickFormValues(keys) { pickFormValues(keys) {
...@@ -423,6 +520,7 @@ export default { ...@@ -423,6 +520,7 @@ export default {
background: #fff; background: #fff;
border-radius: 8px; border-radius: 8px;
overflow: hidden; overflow: hidden;
margin: 4px 0;
} }
.form-row { .form-row {
...@@ -446,6 +544,14 @@ export default { ...@@ -446,6 +544,14 @@ export default {
} }
} }
.course-form-row {
height: auto;
min-height: 52px;
display: block;
padding-top: 12px;
padding-bottom: 8px;
}
.row-value { .row-value {
flex: 1; flex: 1;
min-width: 0; min-width: 0;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!