index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <template>
  2. <div class="main animate__animated animate__backInRight" v-loading="loading">
  3. <custom-search-bar :fields="fields.filter((f) => f.isSearch)" v-model="searchForm" @search="search" @reset="toReset">
  4. <template #type>
  5. <el-option v-for="i in typeList" :key="i._id" :label="i.label" :value="i.value"></el-option>
  6. </template>
  7. <template #status>
  8. <el-option v-for="i in statusList" :key="i._id" :label="i.label" :value="i.value"></el-option>
  9. </template>
  10. <template #subject>
  11. <el-option v-for="i in subjectList" :key="i._id" :label="i.label" :value="i.value"></el-option>
  12. </template>
  13. <template #grade>
  14. <el-option v-for="i in gradeList" :key="i._id" :label="i.label" :value="i.value"></el-option>
  15. </template>
  16. </custom-search-bar>
  17. <custom-table :data="data" :fields="fields" @query="search" :total="total" :opera="opera" @view="toView" @exam="toExam" @delete="toDelete">
  18. <template #status="{ row }">
  19. <el-tag v-if="row.status == '1'" type="success">已解决</el-tag>
  20. <el-tag v-else type="info">未解决</el-tag>
  21. </template>
  22. </custom-table>
  23. <el-dialog v-model="dialog.show" :title="dialog.title" :destroy-on-close="false" @close="toClose">
  24. <el-row>
  25. <el-col :span="24" v-if="dialog.type == '1'">
  26. <custom-form v-model="form" :fields="formFields" @save="toSave">
  27. <template #status>
  28. <el-option v-for="i in statusList" :key="i._id" :label="i.label" :value="i.value"></el-option>
  29. </template>
  30. <template #type>
  31. <el-option disabled v-for="i in typeList" :key="i._id" :label="i.label" :value="i.value"></el-option>
  32. </template>
  33. <template #subject>
  34. <el-option disabled v-for="i in subjectList" :key="i._id" :label="i.label" :value="i.value"></el-option>
  35. </template>
  36. <template #grade>
  37. <el-option disabled v-for="i in gradeList" :key="i._id" :label="i.label" :value="i.value"></el-option>
  38. </template>
  39. <template #is_show>
  40. <el-option v-for="i in showList" :key="i._id" :label="i.label" :value="i.value"></el-option>
  41. </template>
  42. </custom-form>
  43. </el-col>
  44. <el-col :span="24" v-if="dialog.type == '2'">
  45. <custom-form v-model="examForm" :fields="examFormFields" :rules="examRules" @save="toExamSave">
  46. <template #status>
  47. <el-option v-for="i in statusList" :key="i._id" :label="i.label" :value="i.value"></el-option>
  48. </template>
  49. </custom-form>
  50. </el-col>
  51. </el-row>
  52. </el-dialog>
  53. </div>
  54. </template>
  55. <script setup>
  56. import { cloneDeep, get } from 'lodash-es'
  57. const { t } = useI18n()
  58. const $checkRes = inject('$checkRes')
  59. // 接口
  60. import { CourseStore } from '@/store/api/core/course'
  61. import { DictDataStore } from '@/store/api/system/dictData'
  62. const dictDataStore = DictDataStore()
  63. const store = CourseStore()
  64. const data = ref([])
  65. const searchForm = ref({})
  66. const fields = [
  67. { label: t('pages.course.teacher_name'), model: 'teacher_name' },
  68. { label: t('pages.course.teacher_phone'), model: 'teacher_phone' },
  69. { label: t('pages.course.name'), model: 'name', isSearch: true },
  70. { label: t('pages.course.money'), model: 'money' },
  71. { label: t('pages.course.subject'), model: 'subject', format: (i) => getDict(i, 'subject'), type: 'select', isSearch: true },
  72. { label: t('pages.course.grade'), model: 'grade', format: (i) => getDict(i, 'grade'), type: 'select', isSearch: true },
  73. { label: t('pages.course.type'), model: 'type', format: (i) => getDict(i, 'type'), type: 'select', isSearch: true },
  74. { label: t('pages.course.start_time'), model: 'start_time', type: 'datetime' },
  75. { label: t('pages.course.end_time'), model: 'end_time', type: 'datetime' },
  76. { label: t('pages.course.status'), model: 'status', format: (i) => getDict(i, 'status'), type: 'select', isSearch: true }
  77. ]
  78. let skip = 0
  79. let limit = inject('limit')
  80. const total = ref(0)
  81. const opera = [
  82. { label: t('common.view'), method: 'view' },
  83. { label: t('common.exam'), method: 'exam', type: 'warning', display: (i) => i.status === '0' },
  84. {
  85. label: t('common.delete'),
  86. method: 'delete',
  87. confirm: true,
  88. type: 'danger'
  89. }
  90. ]
  91. const dialog = ref({ type: '1', show: false, title: t('pages.course.addDialogTitle') })
  92. const form = ref({})
  93. const formFields = [
  94. { label: t('pages.course.teacher_name'), model: 'teacher_name', options: { readonly: true } },
  95. { label: t('pages.course.teacher_phone'), model: 'teacher_phone', options: { readonly: true } },
  96. { label: t('pages.course.name'), model: 'name', options: { readonly: true } },
  97. { label: t('pages.course.subject'), model: 'subject', type: 'select' },
  98. { label: t('pages.course.grade'), model: 'grade', type: 'select' },
  99. { label: t('pages.course.type'), model: 'type', type: 'select' },
  100. { label: t('pages.course.money'), model: 'money', options: { readonly: true } },
  101. { label: t('pages.course.start_time'), model: 'start_time', options: { readonly: true } },
  102. { label: t('pages.course.end_time'), model: 'end_time', options: { readonly: true } },
  103. { label: t('pages.course.brief'), model: 'brief', type: 'textarea', options: { readonly: true } },
  104. { label: t('pages.course.is_show'), model: 'is_show', type: 'select' }
  105. ]
  106. // 审核
  107. const examFormFields = [{ label: t('pages.teacher.status'), model: 'status', type: 'select' }]
  108. const examRules = reactive({
  109. status: [{ required: true, message: t('common.statusMessage'), trigger: 'blur' }]
  110. })
  111. const examForm = ref({})
  112. // 加载中
  113. const loading = ref(false)
  114. // 字典表
  115. const statusList = ref([])
  116. const typeList = ref([])
  117. const gradeList = ref([])
  118. const showList = ref([])
  119. const subjectList = ref([])
  120. // 请求
  121. onMounted(async () => {
  122. loading.value = true
  123. await searchOther()
  124. await search({ skip, limit })
  125. loading.value = false
  126. })
  127. const searchOther = async () => {
  128. let result
  129. // 类型
  130. result = await dictDataStore.query({ code: 'courseType', is_use: '0' })
  131. if ($checkRes(result)) typeList.value = result.data
  132. // 状态
  133. result = await dictDataStore.query({ code: 'courseStatus', is_use: '0' })
  134. if ($checkRes(result)) statusList.value = result.data
  135. // 学科
  136. result = await dictDataStore.query({ code: 'subject', is_use: '0' })
  137. if ($checkRes(result)) subjectList.value = result.data
  138. // 年级
  139. result = await dictDataStore.query({ code: 'grade', is_use: '0' })
  140. if ($checkRes(result)) gradeList.value = result.data
  141. // 是否公开
  142. result = await dictDataStore.query({ code: 'show', is_use: '0' })
  143. if ($checkRes(result)) showList.value = result.data
  144. }
  145. const search = async (query = { skip: 0, limit }) => {
  146. const info = { skip: query.skip, limit: query.limit, ...searchForm.value }
  147. const res = await store.list(info)
  148. if (res.errcode == '0') {
  149. data.value = res.data
  150. total.value = res.total
  151. }
  152. }
  153. // 字典数据转换
  154. const getDict = (data, model) => {
  155. let res
  156. if (model == 'subject') res = subjectList.value.find((f) => f.value == data)
  157. else if (model == 'type') res = typeList.value.find((f) => f.value == data)
  158. else if (model == 'status') res = statusList.value.find((f) => f.value == data)
  159. else if (model == 'grade') res = gradeList.value.find((f) => f.value == data)
  160. else if (model == 'is_show') res = showList.value.find((f) => f.value == data)
  161. return get(res, 'label')
  162. }
  163. // 查看
  164. const toView = (data) => {
  165. form.value = data
  166. dialog.value = { type: '1', show: true, title: t('pages.course.dialogTitle') }
  167. }
  168. // 审核
  169. const toExam = (data) => {
  170. examForm.value = data
  171. dialog.value = { type: '2', show: true, title: t('pages.course.examDialogTitle') }
  172. }
  173. // 审核保存
  174. const toExamSave = async () => {
  175. const data = cloneDeep(examForm.value)
  176. delete data.teacher_name
  177. delete data.teacher_phone
  178. let res = await store.update(data)
  179. if ($checkRes(res, true)) {
  180. search({ skip: 0, limit })
  181. toClose()
  182. }
  183. }
  184. // 删除
  185. const toDelete = async (data) => {
  186. const res = await store.del(data._id)
  187. if ($checkRes(res, true)) {
  188. search({ skip: 0, limit })
  189. }
  190. }
  191. // 重置
  192. const toReset = async () => {
  193. searchForm.value = {}
  194. await search({ skip, limit })
  195. }
  196. const toClose = () => {
  197. form.value = {}
  198. dialog.value = { show: false }
  199. }
  200. // 保存
  201. const toSave = async () => {
  202. const data = cloneDeep(form.value)
  203. delete data.teacher_name
  204. delete data.teacher_phone
  205. let res = await store.update(data)
  206. if ($checkRes(res, true)) {
  207. search({ skip: 0, limit })
  208. toClose()
  209. }
  210. }
  211. </script>
  212. <style scoped lang="scss">
  213. .images {
  214. width: 100px;
  215. height: 100px;
  216. margin: 0 1vw 0 0;
  217. }
  218. </style>