index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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-select clearable filterable allow-create default-first-option v-model="searchForm.status" placeholder="请选择状态" style="width: 100%; min-width: 200px">
  9. <el-option v-for="i in statusList" :key="i._id" :label="i.label" :value="i.value"></el-option>
  10. </el-select>
  11. </template>
  12. <template #userType>
  13. <el-option v-for="i in userTypeList" :key="i._id" :label="i.label" :value="i.value"></el-option>
  14. </template>
  15. </custom-search-bar>
  16. <custom-table :data="data" :fields="fields" @query="search" :total="total" :opera="opera" @view="toView">
  17. <template #status="{ row }">
  18. <el-tag v-if="row.status == '1'" type="success">已解决</el-tag>
  19. <el-tag v-else type="info">未解决</el-tag>
  20. </template>
  21. </custom-table>
  22. <el-dialog v-model="dialog.show" :title="dialog.title" :destroy-on-close="false" @close="toClose">
  23. <el-row>
  24. <el-col :span="24" v-if="dialog.type == '1'">
  25. <custom-form v-model="form" :fields="formFields" @save="toSave">
  26. <template #file>
  27. <el-image class="images" v-for="i in form.file" :key="i.id" :src="i.url" :preview-src-list="getFlie(form.file)"></el-image>
  28. </template>
  29. <template #status>
  30. <el-option v-for="i in statusList" :key="i._id" :label="i.label" :value="i.value"></el-option>
  31. </template>
  32. <template #type>
  33. <el-option disabled v-for="i in typeList" :key="i._id" :label="i.label" :value="i.value"></el-option>
  34. </template>
  35. <template #userType>
  36. <el-option disabled v-for="i in userTypeList" :key="i._id" :label="i.label" :value="i.value"></el-option>
  37. </template>
  38. </custom-form>
  39. </el-col>
  40. </el-row>
  41. </el-dialog>
  42. </div>
  43. </template>
  44. <script setup>
  45. import { cloneDeep, get } from 'lodash-es'
  46. const { t } = useI18n()
  47. const $checkRes = inject('$checkRes')
  48. // 接口
  49. import { OpinionStore } from '@/store/api/core/opinion'
  50. import { DictDataStore } from '@/store/api/system/dictData'
  51. const dictDataStore = DictDataStore()
  52. const store = OpinionStore()
  53. const data = ref([])
  54. const searchForm = ref({})
  55. const fields = [
  56. { label: t('pages.opinion.user_name'), model: 'user_name' },
  57. { label: t('pages.opinion.userType'), model: 'userType', format: (i) => getDict(i, 'userType'), type: 'select', isSearch: true },
  58. { label: t('pages.opinion.type'), model: 'type', format: (i) => getDict(i, 'type'), type: 'select', isSearch: true },
  59. { label: t('pages.opinion.time'), model: 'time', type: 'date' },
  60. { label: t('pages.opinion.status'), model: 'status', custom: true, isSearch: true }
  61. ]
  62. let skip = 0
  63. let limit = inject('limit')
  64. const total = ref(0)
  65. const opera = [{ label: t('common.view'), method: 'view' }]
  66. const dialog = ref({ type: '1', show: false, title: t('pages.video.addDialogTitle') })
  67. const form = ref({})
  68. const formFields = [
  69. { label: t('pages.opinion.user_name'), model: 'user_name', options: { readonly: true } },
  70. { label: t('pages.opinion.type'), model: 'type', type: 'select' },
  71. { label: t('pages.opinion.time'), model: 'time', type: 'date', options: { readonly: true } },
  72. { label: t('pages.opinion.brief'), model: 'brief', type: 'textarea', options: { readonly: true } },
  73. { label: t('pages.opinion.file'), model: 'file', custom: true },
  74. { label: t('pages.opinion.status'), model: 'status', type: 'select' }
  75. ]
  76. // 加载中
  77. const loading = ref(false)
  78. // 字典表
  79. const statusList = ref([])
  80. const typeList = ref([])
  81. const userTypeList = ref([])
  82. // 请求
  83. onMounted(async () => {
  84. loading.value = true
  85. await searchOther()
  86. await search({ skip, limit })
  87. loading.value = false
  88. })
  89. const searchOther = async () => {
  90. let result
  91. // 类型
  92. result = await dictDataStore.query({ code: 'opinionType', is_use: '0' })
  93. if ($checkRes(result)) typeList.value = result.data
  94. // 状态
  95. result = await dictDataStore.query({ code: 'opinionStatus', is_use: '0' })
  96. if ($checkRes(result)) statusList.value = result.data
  97. // 用户类型
  98. result = await dictDataStore.query({ code: 'role', is_use: '0' })
  99. if ($checkRes(result)) userTypeList.value = result.data
  100. }
  101. const search = async (query = { skip: 0, limit }) => {
  102. const info = { skip: query.skip, limit: query.limit, ...searchForm.value }
  103. const res = await store.query(info)
  104. if (res.errcode == '0') {
  105. data.value = res.data
  106. total.value = res.total
  107. }
  108. }
  109. // 字典数据转换
  110. const getDict = (data, model) => {
  111. let res
  112. if (model == 'status') res = statusList.value.find((f) => f.value == data)
  113. else if (model == 'type') res = typeList.value.find((f) => f.value == data)
  114. else if (model == 'userType') res = userTypeList.value.find((f) => f.value == data)
  115. return get(res, 'label')
  116. }
  117. // 修改
  118. const toView = (data) => {
  119. form.value = data
  120. dialog.value = { type: '1', show: true, title: t('pages.video.upDialogTitle') }
  121. }
  122. // 重置
  123. const toReset = async () => {
  124. searchForm.value = {}
  125. await search({ skip, limit })
  126. }
  127. // 图片处理
  128. const getFlie = (file) => {
  129. if (file && file.length > 0) {
  130. const urls = file.map((i) => {
  131. return i.url
  132. })
  133. return urls
  134. }
  135. }
  136. const toClose = () => {
  137. form.value = {}
  138. dialog.value = { show: false }
  139. }
  140. // 保存
  141. const toSave = async () => {
  142. const data = cloneDeep(form.value)
  143. delete data.user_name
  144. let res = await store.update(data)
  145. if ($checkRes(res, true)) {
  146. search({ skip: 0, limit })
  147. toClose()
  148. }
  149. }
  150. </script>
  151. <style scoped lang="scss">
  152. .images {
  153. width: 100px;
  154. height: 100px;
  155. margin: 0 1vw 0 0;
  156. }
  157. </style>