index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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 #industry>
  8. <el-option v-for="i in sectorList" :key="i.id" :label="i.title" :value="i.title"></el-option>
  9. </template>
  10. </custom-search-bar>
  11. <custom-button-bar :fields="buttonFields" @add="toAdd" @select="toMoreDelect"></custom-button-bar>
  12. <custom-table :data="data" :fields="fields" @query="search" :total="total" :opera="opera" @sign="toSign" @exam="toExam" @edit="toEdit" @delete="toDelete" @toSelect="toSelect" :select="true">
  13. <template #is_use="{ row }">
  14. <el-tag v-if="row.is_use == '0'" type="success" @click="toUse(row, '1')">启用</el-tag>
  15. <el-tag v-else type="info" @click="toUse(row, '0')">禁用</el-tag>
  16. </template>
  17. </custom-table>
  18. <el-dialog v-model="dialog.show" :title="dialog.title" :destroy-on-close="false" @close="toClose">
  19. <el-row>
  20. <el-col :span="24" v-if="dialog.type == '1'">
  21. <custom-form v-model="form" :fields="formFields" :rules="rules" @save="toSave">
  22. <template #file>
  23. <custom-upload model="file" :list="form.file" :limit="1" listType="picture-card" url="/files/web/cxyy_match/upload" @change="onUpload"></custom-upload>
  24. </template>
  25. <template #is_use>
  26. <el-radio v-for="i in isUseList" :key="i.id" :label="i.value">{{ i.label }}</el-radio>
  27. </template>
  28. <template #industry>
  29. <el-option v-for="i in sectorList" :key="i.id" :label="i.title" :value="i.title"></el-option>
  30. </template>
  31. <template #match_status>
  32. <el-option v-for="i in matchList" :key="i.id" :label="i.label" :value="i.value"></el-option>
  33. </template>
  34. <template #match_type>
  35. <el-radio v-for="i in matchTypeList" :key="i.id" :label="i.value">{{ i.label }}</el-radio>
  36. </template>
  37. <template #type>
  38. <el-option v-for="i in typeList" :key="i.id" :label="i.label" :value="i.value"></el-option>
  39. </template>
  40. <template #form>
  41. <el-option v-for="i in formList" :key="i.id" :label="i.label" :value="i.value"></el-option>
  42. </template>
  43. <template #tags>
  44. <el-select v-model="form.tags" multiple filterable allow-create default-first-option :reserve-keyword="false" placeholder="请选择标签" style="width: 100%">
  45. <el-option v-for="item in tagsList" :key="item.id" :label="item.title" :value="item.title" />
  46. </el-select>
  47. </template>
  48. <template #rules>
  49. <div class="rules">
  50. <custom-form v-model="form.rules" :fields="rulesFields" :useSave="false">
  51. <template #rules1>
  52. <WangEditor v-model="form.rules.rules1" />
  53. </template>
  54. <template #rules2>
  55. <WangEditor v-model="form.rules.rules2" />
  56. </template>
  57. <template #rules3>
  58. <WangEditor v-model="form.rules.rules3" />
  59. </template>
  60. <template #rules4>
  61. <WangEditor v-model="form.rules.rules4" />
  62. </template>
  63. <template #rules5>
  64. <WangEditor v-model="form.rules.rules5" />
  65. </template>
  66. <template #rules6>
  67. <WangEditor v-model="form.rules.rules6" />
  68. </template>
  69. <template #rules7>
  70. <WangEditor v-model="form.rules.rules7" />
  71. </template>
  72. <template #rules8>
  73. <WangEditor v-model="form.rules.rules8" />
  74. </template>
  75. <template #rules9>
  76. <WangEditor v-model="form.rules.rules9" />
  77. </template>
  78. <template #rules10>
  79. <WangEditor v-model="form.rules.rules10" />
  80. </template>
  81. <template #rules11>
  82. <WangEditor v-model="form.rules.rules11" />
  83. </template>
  84. <template #rules12>
  85. <WangEditor v-model="form.rules.rules12" />
  86. </template>
  87. </custom-form>
  88. </div>
  89. </template>
  90. <template #brief>
  91. <WangEditor v-model="form.brief" />
  92. </template>
  93. </custom-form>
  94. </el-col>
  95. <el-col :span="24" v-if="dialog.type == '2'">
  96. <custom-form v-model="examForm" :fields="examFormFields" :rules="examRules" @save="toExamSave">
  97. <template #status>
  98. <el-option v-for="i in statusList" :key="i.id" :label="i.label" :value="i.value"></el-option>
  99. </template>
  100. </custom-form>
  101. </el-col>
  102. </el-row>
  103. </el-dialog>
  104. </div>
  105. </template>
  106. <script setup>
  107. // API 引用
  108. import { cloneDeep, get } from 'lodash-es'
  109. const $checkRes = inject('$checkRes')
  110. const { t } = useI18n()
  111. // 路由
  112. const router = useRouter()
  113. // 接口
  114. import { MatchStore } from '@/store/api/platform/match'
  115. import { DictDataStore } from '@/store/api/system/dictData'
  116. import { TagsStore } from '@/store/api/system/tags'
  117. import { SectorStore } from '@/store/api/system/sector'
  118. const store = MatchStore()
  119. const dictDataStore = DictDataStore()
  120. const tagsStore = TagsStore()
  121. const sectorStore = SectorStore()
  122. const data = ref([])
  123. const searchForm = ref({})
  124. const fields = [
  125. { label: t('pages.match.name'), model: 'name', isSearch: true },
  126. { label: t('pages.match.industry'), model: 'industry', type: 'select', isSearch: true },
  127. { label: t('pages.match.tags'), model: 'tags', isSearch: true, format: (i) => getDict(i, 'tags') },
  128. { label: t('pages.match.type'), model: 'type', isSearch: true, type: 'select', format: (i) => getDict(i, 'type') },
  129. // { label: t('pages.match.money'), model: 'money' },
  130. { label: t('pages.match.is_use'), model: 'is_use', custom: true, format: (i) => getDict(i, 'is_use') },
  131. { label: t('pages.match.match_status'), model: 'match_status', format: (i) => getDict(i, 'match') },
  132. { label: t('pages.match.status'), model: 'status', format: (i) => getDict(i, 'status') }
  133. ]
  134. const opera = [
  135. { label: t('common.sign'), method: 'sign', type: 'warning' },
  136. {
  137. label: t('common.update'),
  138. method: 'edit'
  139. },
  140. { label: t('common.exam'), method: 'exam', type: 'warning', display: (i) => i.status === '0' },
  141. {
  142. label: t('common.delete'),
  143. method: 'delete',
  144. confirm: true,
  145. type: 'danger',
  146. display: (i) => i.is_use === '1' && i.match_status === '0'
  147. }
  148. ]
  149. const buttonFields = [
  150. { label: t('common.create'), method: 'add' },
  151. { label: t('common.select'), method: 'select', type: 'danger' }
  152. ]
  153. let skip = 0
  154. let limit = inject('limit')
  155. const total = ref(0)
  156. // 字典表
  157. const isUseList = ref([])
  158. const statusList = ref([])
  159. const typeList = ref([])
  160. const matchList = ref([])
  161. const formList = ref([])
  162. const tagsList = ref([])
  163. const sectorList = ref([])
  164. const matchTypeList = ref([])
  165. // 多选列表
  166. const selectList = ref([])
  167. // 加载中
  168. const loading = ref(false)
  169. const formFields = ref([
  170. { label: t('pages.match.file'), model: 'file', custom: true },
  171. { label: t('pages.match.name'), model: 'name' },
  172. { label: t('pages.match.tags'), model: 'tags', custom: true },
  173. { label: t('pages.match.type'), model: 'type', type: 'select' },
  174. { label: t('pages.match.match_type'), model: 'match_type', type: 'radio' },
  175. { label: t('pages.match.href'), model: 'href' },
  176. { label: t('pages.match.work'), model: 'work' },
  177. { label: t('pages.match.industry'), model: 'industry', type: 'select' },
  178. { label: t('pages.match.form'), model: 'form', type: 'select' },
  179. { label: t('pages.match.money'), model: 'money' },
  180. { label: t('pages.match.time'), model: 'time', type: 'daterange' },
  181. { label: t('pages.match.is_use'), model: 'is_use', type: 'radio' },
  182. { label: t('pages.match.rules'), model: 'rules', custom: true },
  183. { label: t('pages.match.brief'), model: 'brief', custom: true },
  184. { label: t('pages.match.match_status'), model: 'match_status', type: 'select' }
  185. ])
  186. const rules = reactive({
  187. name: [{ required: true, message: t('pages.match.titleMessage'), trigger: 'blur' }]
  188. })
  189. const dialog = ref({ type: '1', show: false, title: t('pages.match.addDialogTitle') })
  190. const form = ref({ rules: {}, file: [] })
  191. // 审核
  192. const examFormFields = [{ label: t('pages.match.status'), model: 'status', type: 'select' }]
  193. const examRules = reactive({
  194. status: [{ required: true, message: t('common.statusMessage'), trigger: 'blur' }]
  195. })
  196. const examForm = ref({})
  197. // 赛事规则
  198. const rulesFields = ref([
  199. { label: t('pages.match.rules1'), model: 'rules1', custom: true },
  200. { label: t('pages.match.rules2'), model: 'rules2', custom: true },
  201. { label: t('pages.match.rules3'), model: 'rules3', custom: true },
  202. { label: t('pages.match.rules4'), model: 'rules4', custom: true },
  203. { label: t('pages.match.rules5'), model: 'rules5', custom: true },
  204. { label: t('pages.match.rules6'), model: 'rules6', custom: true },
  205. { label: t('pages.match.rules7'), model: 'rules7', custom: true },
  206. { label: t('pages.match.rules8'), model: 'rules8', custom: true },
  207. { label: t('pages.match.rules9'), model: 'rules9', custom: true },
  208. { label: t('pages.match.rules10'), model: 'rules10', custom: true },
  209. { label: t('pages.match.rules11'), model: 'rules11', custom: true },
  210. { label: t('pages.match.rules12'), model: 'rules12', custom: true }
  211. ])
  212. // 请求
  213. onMounted(async () => {
  214. loading.value = true
  215. await searchOther()
  216. await search({ skip, limit })
  217. loading.value = false
  218. })
  219. const searchOther = async () => {
  220. let result
  221. // 是否使用
  222. result = await dictDataStore.query({ code: 'isUse', is_use: '0' })
  223. if ($checkRes(result)) isUseList.value = result.data
  224. // 类型
  225. result = await dictDataStore.query({ code: 'matchType', is_use: '0' })
  226. if ($checkRes(result)) typeList.value = result.data
  227. // 赛事类型
  228. result = await dictDataStore.query({ code: 'activeType', is_use: '0' })
  229. if ($checkRes(result)) matchTypeList.value = result.data
  230. // 类别
  231. result = await dictDataStore.query({ code: 'matchForm', is_use: '0' })
  232. if ($checkRes(result)) formList.value = result.data
  233. // 状态
  234. result = await dictDataStore.query({ code: 'examStatus', is_use: '0' })
  235. if ($checkRes(result)) statusList.value = result.data
  236. // 赛事状态
  237. result = await dictDataStore.query({ code: 'matchStatus', is_use: '0' })
  238. if ($checkRes(result)) matchList.value = result.data
  239. // 标签
  240. result = await tagsStore.query({ is_use: '0' })
  241. if ($checkRes(result)) tagsList.value = result.data
  242. // 行业
  243. result = await sectorStore.query({ is_use: '0' })
  244. if ($checkRes(result)) sectorList.value = result.data
  245. }
  246. const search = async (query = { skip, limit }) => {
  247. skip = query.skip
  248. limit = query.limit
  249. const info = { skip: query.skip, limit: query.limit, ...searchForm.value }
  250. const res = await store.query(info)
  251. if (res.errcode == '0') {
  252. data.value = res.data
  253. total.value = res.total
  254. }
  255. }
  256. // 字典数据转换
  257. const getDict = (data, model) => {
  258. if (data) {
  259. let res
  260. if (model == 'is_use') res = isUseList.value.find((f) => f.value == data)
  261. else if (model == 'status') res = statusList.value.find((f) => f.value == data)
  262. else if (model == 'type') res = typeList.value.find((f) => f.value == data)
  263. else if (model == 'match') res = matchList.value.find((f) => f.value == data)
  264. else if (model == 'tags') return data.join(',')
  265. return get(res, 'label')
  266. }
  267. }
  268. // 多选
  269. const toSelect = (val) => {
  270. selectList.value = val
  271. }
  272. // 批量删除
  273. const toMoreDelect = () => {
  274. if (selectList.value.length > 0) {
  275. ElMessageBox.confirm(`确定批量删除数据?`, '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' })
  276. .then(async () => {
  277. console.log(selectList.value)
  278. })
  279. .catch(() => {})
  280. } else {
  281. ElMessage({
  282. message: '未选择要处理的数据!',
  283. type: 'warning'
  284. })
  285. }
  286. }
  287. // 添加
  288. const toAdd = () => {
  289. dialog.value = { type: '1', show: true, title: t('pages.match.addDialogTitle') }
  290. }
  291. // 修改
  292. const toEdit = (data) => {
  293. data.time = [data.start_time, data.end_time]
  294. if (!data.file) data.file = []
  295. form.value = data
  296. dialog.value = { type: '1', show: true, title: t('pages.match.upDialogTitle') }
  297. }
  298. // 报名管理
  299. const toSign = (data) => {
  300. router.push({ path: '/match/sign', query: { id: data.id } })
  301. }
  302. // 删除
  303. const toDelete = async (data) => {
  304. const res = await store.del(data.id)
  305. if ($checkRes(res, true)) {
  306. search({ skip, limit })
  307. }
  308. }
  309. const toSave = async () => {
  310. const data = cloneDeep(form.value)
  311. if (data.time && data.time.length > 1) {
  312. data.start_time = data.time[0]
  313. data.end_time = data.time[1]
  314. }
  315. const other = { status: '0' }
  316. let res
  317. if (get(data, 'id')) res = await store.update({ ...data, ...other })
  318. else res = await store.create({ ...data, ...other })
  319. if ($checkRes(res, true)) {
  320. search({ skip, limit })
  321. toClose()
  322. }
  323. }
  324. // 审核
  325. const toExam = (data) => {
  326. examForm.value = data
  327. dialog.value = { type: '2', show: true, title: t('pages.match.examDialogTitle') }
  328. }
  329. // 审核保存
  330. const toExamSave = async () => {
  331. const data = cloneDeep(examForm.value)
  332. let res = await store.update(data)
  333. if ($checkRes(res, true)) {
  334. search({ skip, limit })
  335. toClose()
  336. }
  337. }
  338. // 开启或禁用
  339. const toUse = async (data, is_use) => {
  340. ElMessageBox.confirm(`确定修改【${data.name}】数据?`, '提示', {
  341. confirmButtonText: '确定',
  342. cancelButtonText: '取消',
  343. type: 'warning'
  344. })
  345. .then(async () => {
  346. let res = await store.update({ id: get(data, 'id'), is_use })
  347. if ($checkRes(res, true)) {
  348. search({ skip, limit })
  349. }
  350. })
  351. .catch(() => {})
  352. }
  353. // 重置
  354. const toReset = async () => {
  355. searchForm.value = {}
  356. await search({ skip, limit })
  357. }
  358. const toClose = () => {
  359. form.value = { rules: {}, file: [] }
  360. dialog.value = { show: false }
  361. }
  362. // 上传图片
  363. const onUpload = (e) => {
  364. const { model, value } = e
  365. form.value[model] = value
  366. }
  367. </script>
  368. <style scoped lang="scss">
  369. .rules {
  370. width: 100%;
  371. border: 1px solid #dcdfe6;
  372. padding: 10px;
  373. border-radius: 5px;
  374. :deep(.el-form-item) {
  375. margin-bottom: 18px !important;
  376. }
  377. :deep(.el-form-item__label-wrap) {
  378. margin-left: 0 !important;
  379. }
  380. }
  381. </style>