1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
| import { listCourse, getCourse, delCourse, addCourse, updateCourse } from "@/api/course/course";
const { proxy } = getCurrentInstance();
const { course_subject } = proxy.useDict('course_subject');
const courseList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const data = reactive({ // 新增或修改表单数据 form: {}, // 搜索条件参数 queryParams: { pageNum: 1, pageSize: 10, code: null, subject: null, name: null, applicablePerson: null, }, // 表单校验规则 rules: { code: [ { required: true, message: "课程编码不能为空", trigger: "blur" } ], subject: [ { required: true, message: "课程学科不能为空", trigger: "change" } ], name: [ { required: true, message: "课程名称不能为空", trigger: "blur" } ], price: [ { required: true, message: "价格不能为空", trigger: "blur" } ], applicablePerson: [ { required: true, message: "适用人群不能为空", trigger: "blur" } ], info: [ { required: true, message: "课程介绍不能为空", trigger: "blur" } ], } });
const { queryParams, form, rules } = toRefs(data);
function getList() { loading.value = true; listCourse(queryParams.value).then(response => { courseList.value = response.rows; total.value = response.total; loading.value = false; }); }
function cancel() { open.value = false; reset(); }
function reset() { form.value = { id: null, code: null, subject: null, name: null, price: null, applicablePerson: null, info: null, createTime: null, updateTime: null }; proxy.resetForm("courseRef"); }
function handleQuery() { queryParams.value.pageNum = 1; getList(); }
function resetQuery() { proxy.resetForm("queryRef"); handleQuery(); }
function handleSelectionChange(selection) { ids.value = selection.map(item => item.id); single.value = selection.length != 1; multiple.value = !selection.length; }
function handleAdd() { reset(); open.value = true; title.value = "添加课程管理"; }
function handleUpdate(row) { reset(); const _id = row.id || ids.value getCourse(_id).then(response => { form.value = response.data; open.value = true; title.value = "修改课程管理"; }); }
function submitForm() { proxy.$refs["courseRef"].validate(valid => { if (valid) { if (form.value.id != null) { updateCourse(form.value).then(response => { proxy.$modal.msgSuccess("修改成功"); open.value = false; getList(); }); } else { addCourse(form.value).then(response => { proxy.$modal.msgSuccess("新增成功"); open.value = false; getList(); }); } } }); }
function handleDelete(row) { const _ids = row.id || ids.value; proxy.$modal.confirm('是否确认删除课程管理编号为"' + _ids + '"的数据项?').then(function() { return delCourse(_ids); }).then(() => { getList(); proxy.$modal.msgSuccess("删除成功"); }).catch(() => {}); }
function handleExport() { proxy.download('course/course/export', { ...queryParams.value }, `course_${new Date().getTime()}.xlsx`) }
getList(); </script>
|