index.vue 12 KB

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