index.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 #industry>
  5. <el-option v-for="i in sectorList" :key="i.id" :label="i.title" :value="i.title"></el-option>
  6. </template>
  7. </custom-search-bar>
  8. <custom-button-bar :fields="buttonFields" @add="toAdd" @select="toMoreDelect"></custom-button-bar>
  9. <custom-table :data="data" :fields="fields" @query="search" :total="total" :opera="opera" @exam="toExam" @edit="toEdit" @delete="toDelete" @toSelect="toSelect" :select="true">
  10. <template #is_use="{ row }">
  11. <el-tag v-if="row.is_use == '0'" type="success" @click="toUse(row, '1')">启用</el-tag>
  12. <el-tag v-else type="info" @click="toUse(row, '0')">禁用</el-tag>
  13. </template>
  14. </custom-table>
  15. <el-dialog v-model="dialog.show" :title="dialog.title" :destroy-on-close="false" @close="toClose">
  16. <el-row>
  17. <el-col :span="24" v-if="dialog.type == '1'">
  18. <custom-form v-model="form" :fields="formFields" :rules="rules" @save="toSave">
  19. <template #file>
  20. <custom-upload model="file" :list="form.file" :limit="3" listType="picture-card" url="/files/web/cxyy_support/upload" @change="onUpload"></custom-upload>
  21. </template>
  22. <template #is_use>
  23. <el-radio v-for="i in isUseList" :key="i.id" :label="i.value">{{ i.label }}</el-radio>
  24. </template>
  25. <template #industry>
  26. <el-option v-for="i in sectorList" :key="i.id" :label="i.title" :value="i.title"></el-option>
  27. </template>
  28. <template #area>
  29. <el-cascader v-model="form.area" :props="{ value: 'name', label: 'name' }" :options="cityList" style="width: 100%" />
  30. </template>
  31. <template #tags>
  32. <el-select v-model="form.tags" multiple filterable allow-create default-first-option :reserve-keyword="false" placeholder="请选择标签" style="width: 100%">
  33. <el-option v-for="item in tagsList" :key="item.id" :label="item.title" :value="item.title" />
  34. </el-select>
  35. </template>
  36. </custom-form>
  37. </el-col>
  38. <el-col :span="24" v-if="dialog.type == '2'">
  39. <custom-form v-model="examForm" :fields="examFormFields" :rules="examRules" @save="toExamSave">
  40. <template #status>
  41. <el-option v-for="i in statusList" :key="i.id" :label="i.label" :value="i.value"></el-option>
  42. </template>
  43. </custom-form>
  44. </el-col>
  45. </el-row>
  46. </el-dialog>
  47. </div>
  48. </template>
  49. <script setup>
  50. import { cloneDeep, get } from 'lodash-es'
  51. const $checkRes = inject('$checkRes')
  52. const { t } = useI18n()
  53. // 接口
  54. import { SupportStore } from '@/store/api/platform/support'
  55. import { DictDataStore } from '@/store/api/system/dictData'
  56. import { TagsStore } from '@/store/api/system/tags'
  57. import { SectorStore } from '@/store/api/system/sector'
  58. import { RegionStore } from '@/store/api/system/region'
  59. const regionStore = RegionStore()
  60. const store = SupportStore()
  61. const dictDataStore = DictDataStore()
  62. const tagsStore = TagsStore()
  63. const sectorStore = SectorStore()
  64. const data = ref([])
  65. const searchForm = ref({})
  66. const fields = [
  67. { label: t('pages.support.name'), model: 'name', isSearch: true },
  68. { label: t('pages.support.industry'), model: 'industry', isSearch: true, type: 'select' },
  69. { label: t('pages.support.tags'), model: 'tags', isSearch: true, format: (i) => getDict(i, 'tags') },
  70. { label: t('pages.support.field'), model: 'field', isSearch: true },
  71. { label: t('pages.support.time'), model: 'time', isSearch: true },
  72. { label: t('pages.support.is_use'), model: 'is_use', custom: true, format: (i) => getDict(i, 'is_use') },
  73. { label: t('pages.support.status'), model: 'status', format: (i) => getDict(i, 'status') }
  74. ]
  75. const opera = [
  76. { label: t('common.update'), method: 'edit' },
  77. { label: t('common.exam'), method: 'exam', type: 'warning', display: (i) => i.status === '0' },
  78. { label: t('common.delete'), method: 'delete', confirm: true, type: 'danger', display: (i) => i.is_use === '1' }
  79. ]
  80. const buttonFields = [
  81. { label: t('common.create'), method: 'add' },
  82. { label: t('common.select'), method: 'select', type: 'danger' }
  83. ]
  84. let skip = 0
  85. let limit = inject('limit')
  86. const total = ref(0)
  87. // 字典表
  88. const isUseList = ref([])
  89. const statusList = ref([])
  90. const cityList = ref([])
  91. const tagsList = ref([])
  92. const sectorList = ref([])
  93. // 多选列表
  94. const selectList = ref([])
  95. // 加载中
  96. const loading = ref(false)
  97. const formFields = ref([
  98. { label: t('pages.support.file'), model: 'file', custom: true },
  99. { label: t('pages.support.name'), model: 'name' },
  100. { label: t('pages.support.tags'), model: 'tags', custom: true },
  101. { label: t('pages.support.industry'), model: 'industry', type: 'select' },
  102. { label: t('pages.support.field'), model: 'field' },
  103. { label: t('pages.support.time'), model: 'time', type: 'date' },
  104. { label: t('pages.support.area'), model: 'area', custom: true },
  105. { label: t('pages.support.address'), model: 'address', type: 'textarea' },
  106. { label: t('pages.support.contacts'), model: 'contacts' },
  107. { label: t('pages.support.phone'), model: 'phone' },
  108. { label: t('pages.support.is_use'), model: 'is_use', type: 'radio' },
  109. { label: t('pages.support.brief'), model: 'brief', type: 'textarea' }
  110. ])
  111. const rules = reactive({ name: [{ required: true, message: t('pages.support.titleMessage'), trigger: 'blur' }] })
  112. const dialog = ref({ type: '1', show: false, title: t('pages.support.addDialogTitle') })
  113. const form = ref({ file: [] })
  114. // 审核
  115. const examFormFields = [{ label: t('pages.support.status'), model: 'status', type: 'select' }]
  116. const examRules = reactive({ status: [{ required: true, message: t('common.statusMessage'), trigger: 'blur' }] })
  117. const examForm = ref({})
  118. // 请求
  119. onMounted(async () => {
  120. loading.value = true
  121. await searchOther()
  122. await search({ skip, limit })
  123. loading.value = false
  124. })
  125. const searchOther = async () => {
  126. let result
  127. // 是否使用
  128. result = await dictDataStore.query({ code: 'isUse', is_use: '0' })
  129. if ($checkRes(result)) isUseList.value = result.data
  130. // 状态
  131. result = await dictDataStore.query({ code: 'examStatus', is_use: '0' })
  132. if ($checkRes(result)) statusList.value = result.data
  133. // 标签
  134. result = await tagsStore.query({ is_use: '0' })
  135. if ($checkRes(result)) tagsList.value = result.data
  136. // 行业
  137. result = await sectorStore.query({ is_use: '0' })
  138. if ($checkRes(result)) sectorList.value = result.data
  139. // 城市
  140. result = await regionStore.query({ level: 'city', parent_code: 22 })
  141. if ($checkRes(result)) cityList.value = result.data
  142. }
  143. const search = async (query = { skip, limit }) => {
  144. skip = query.skip
  145. limit = query.limit
  146. const info = { skip: query.skip, limit: query.limit, ...searchForm.value }
  147. const res = await store.query(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. if (data) {
  156. let res
  157. if (model == 'is_use') res = isUseList.value.find((f) => f.value == data)
  158. else if (model == 'status') res = statusList.value.find((f) => f.value == data)
  159. else if (model == 'tags') return data.join(',')
  160. return get(res, 'label')
  161. }
  162. }
  163. // 多选
  164. const toSelect = (val) => {
  165. selectList.value = val
  166. }
  167. // 批量删除
  168. const toMoreDelect = () => {
  169. if (selectList.value.length > 0) {
  170. ElMessageBox.confirm(`确定批量删除数据?`, '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' })
  171. .then(async () => {
  172. console.log(selectList.value)
  173. })
  174. .catch(() => {})
  175. } else {
  176. ElMessage({
  177. message: '未选择要处理的数据!',
  178. type: 'warning'
  179. })
  180. }
  181. }
  182. // 添加
  183. const toAdd = () => {
  184. form.value = {}
  185. dialog.value = { type: '1', show: true, title: t('pages.support.addDialogTitle') }
  186. }
  187. // 修改
  188. const toEdit = (data) => {
  189. if (!data.file) data.file = []
  190. form.value = data
  191. dialog.value = { type: '1', show: true, title: t('pages.support.upDialogTitle') }
  192. }
  193. // 删除
  194. const toDelete = async (data) => {
  195. const res = await store.del(data.id)
  196. if ($checkRes(res, true)) {
  197. search({ skip, limit })
  198. }
  199. }
  200. const toSave = async () => {
  201. const data = cloneDeep(form.value)
  202. const other = { status: '0' }
  203. let res
  204. if (get(data, 'id')) res = await store.update({ ...data, ...other })
  205. else res = await store.create({ ...data, ...other })
  206. if ($checkRes(res, true)) {
  207. search({ skip, limit })
  208. toClose()
  209. }
  210. }
  211. // 上传图片
  212. const onUpload = (e) => {
  213. const { model, value } = e
  214. form.value[model] = value
  215. }
  216. // 审核
  217. const toExam = (data) => {
  218. examForm.value = data
  219. dialog.value = { type: '2', show: true, title: t('pages.support.examDialogTitle') }
  220. }
  221. // 审核保存
  222. const toExamSave = async () => {
  223. const data = cloneDeep(examForm.value)
  224. let res = await store.update({ id: data.id, status: data.status })
  225. if ($checkRes(res, true)) {
  226. search({ skip, limit })
  227. toClose()
  228. }
  229. }
  230. // 开启或禁用
  231. const toUse = async (data, is_use) => {
  232. ElMessageBox.confirm(`确定修改【${data.name}】数据?`, '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' })
  233. .then(async () => {
  234. let res = await store.update({ id: get(data, 'id'), is_use })
  235. if ($checkRes(res, true)) {
  236. search({ skip, limit })
  237. }
  238. })
  239. .catch(() => {})
  240. }
  241. // 重置
  242. const toReset = async () => {
  243. searchForm.value = {}
  244. await search({ skip, limit })
  245. }
  246. const toClose = () => {
  247. form.value = { file: [] }
  248. dialog.value = { show: false }
  249. }
  250. </script>
  251. <style scoped lang="scss"></style>