score.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <div class="index">
  3. <el-row>
  4. <el-col :span="24" class="main animate__animated animate__backInRight" v-loading="loading">
  5. <el-col :span="24" class="one">
  6. <div class="one_left" @click="toAdd">添加分数</div>
  7. <div class="one_right">
  8. <el-input v-model="searchForm.matchPath_name" style="width: 250px" size="large" placeholder="搜索" @change="search" :suffix-icon="Search" />
  9. </div>
  10. </el-col>
  11. <el-col :span="24" class="two">
  12. <el-table :data="list" style="width: 100%" size="large" :header-cell-style="{ backgroundColor: '#edf3ff' }">
  13. <template #empty>
  14. <el-empty description="暂无数据" />
  15. </template>
  16. <el-table-column prop="matchPath_name" align="center" label="流程名称" />
  17. <el-table-column prop="sign_name" align="center" label="选手" />
  18. <el-table-column prop="score" align="center" label="分数" width="180" />
  19. <el-table-column prop="time" align="center" label="时间" width="180" />
  20. <el-table-column align="center" label="操作" width="180">
  21. <template #default="{ row }">
  22. <el-link :underline="false" type="primary" size="mini" @click="toEdit(row)" style="margin-right: 10px">修改</el-link>
  23. <el-link :underline="false" type="danger" size="mini" @click="toDelete(row)"> 删除 </el-link>
  24. </template>
  25. </el-table-column>
  26. </el-table>
  27. </el-col>
  28. <el-col :span="24" class="thr">
  29. <el-pagination background layout="prev, pager, next" :total="total" :page-size="limit" v-model:current-page="currentPage" @current-change="changePage" @size-change="sizeChange" />
  30. </el-col>
  31. </el-col>
  32. </el-row>
  33. <el-dialog v-model="dialog.show" :title="dialog.title" :destroy-on-close="false" @close="toClose">
  34. <el-row>
  35. <el-col :span="24" v-if="dialog.type == '1'">
  36. <custom-form v-model="form" :fields="formFields" :rules="rules" @save="toSave" :DraftSave="false" submitText="保存">
  37. <template #matchPath>
  38. <el-option v-for="i in matchPathList" :key="i.id" :label="i.name" :value="i.id"></el-option>
  39. </template>
  40. <template #sign>
  41. <el-option v-for="i in signList" :key="i.id" :label="i.name" :value="i.id"></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 moment from 'moment'
  51. import { cloneDeep, get } from 'lodash-es'
  52. const $checkRes = inject('$checkRes')
  53. // 接口
  54. import { ScoreStore } from '@/store/api/platform/score'
  55. import { SignStore } from '@/store/api/platform/sign'
  56. import { ProcessStore } from '@/store/api/platform/process'
  57. const store = ScoreStore()
  58. const processStore = ProcessStore()
  59. const signStore = SignStore()
  60. // 路由
  61. const searchForm = ref({})
  62. // 列表
  63. const list = ref([])
  64. let skip = 0
  65. let limit = inject('limit')
  66. const total = ref(0)
  67. const currentPage = ref(1)
  68. const props = defineProps({
  69. matchForm: { type: Object, default: () => {} }
  70. })
  71. const { matchForm } = toRefs(props)
  72. const formFields = ref([
  73. { label: '流程', model: 'matchPath', type: 'select' },
  74. { label: '选手', model: 'sign', type: 'select' },
  75. { label: '分数', model: 'score', type: 'number' }
  76. ])
  77. const rules = reactive({
  78. sign: [{ required: true, message: '请选择选手', trigger: 'blur' }],
  79. score: [{ required: true, message: '请填写分数', trigger: 'blur' }]
  80. })
  81. const dialog = ref({ type: '1', show: false, title: '维护分数' })
  82. const form = ref({})
  83. // 字典表
  84. const matchPathList = ref([])
  85. const signList = ref([])
  86. // 加载中
  87. const loading = ref(false)
  88. // 请求
  89. onMounted(async () => {
  90. loading.value = true
  91. await searchOther()
  92. await search({ skip, limit })
  93. loading.value = false
  94. })
  95. const searchOther = async () => {
  96. let result
  97. // 流程
  98. result = await processStore.query({ match: matchForm.value.id, is_use: '0' })
  99. if ($checkRes(result)) matchPathList.value = result.data
  100. // 选手
  101. result = await signStore.query({ match: matchForm.value.id, status: '1' })
  102. if ($checkRes(result)) signList.value = result.data
  103. }
  104. const search = async (query = { skip, limit }) => {
  105. skip = query.skip
  106. limit = query.limit
  107. const info = { skip: query.skip, limit: query.limit, ...searchForm.value, match: matchForm.value.id }
  108. const res = await store.list(info)
  109. if (res.errcode == '0') {
  110. list.value = res.data
  111. total.value = res.total
  112. }
  113. }
  114. // 添加
  115. const toAdd = () => {
  116. dialog.value = { type: '1', show: true, title: '添加分数' }
  117. }
  118. // 修改
  119. const toEdit = (data) => {
  120. form.value = data
  121. dialog.value = { type: '1', show: true, title: '修改分数' }
  122. }
  123. // 删除
  124. const toDelete = async (data) => {
  125. const res = await store.del(data.id)
  126. if ($checkRes(res, true)) {
  127. search({ skip, limit })
  128. }
  129. }
  130. const toSave = async () => {
  131. const data = cloneDeep(form.value)
  132. const other = { time: moment().format('YYYY-MM-DD'), match: matchForm.value.id }
  133. let res
  134. if (get(data, 'id')) res = await store.update({ ...data, ...other })
  135. else res = await store.create({ ...data, ...other })
  136. if ($checkRes(res, true)) {
  137. search({ skip, limit })
  138. toClose()
  139. }
  140. }
  141. const toClose = () => {
  142. form.value = {}
  143. dialog.value = { show: false }
  144. }
  145. // 分页
  146. const changePage = (page = currentPage.value) => {
  147. search({ skip: (page - 1) * limit, limit: limit })
  148. }
  149. const sizeChange = (limits) => {
  150. limit = limits
  151. currentPage.value = 1
  152. search({ skip: 0, limit: limit })
  153. }
  154. </script>
  155. <style scoped lang="scss">
  156. .main {
  157. .one {
  158. height: 50px;
  159. display: flex;
  160. justify-content: space-between;
  161. align-items: center;
  162. margin: 0 0 10px 0;
  163. .one_left {
  164. background: #1875df;
  165. padding: 0 10px;
  166. height: 30px;
  167. color: #fff;
  168. line-height: 30px;
  169. text-align: center;
  170. font-size: 16px;
  171. cursor: default;
  172. }
  173. }
  174. .thr {
  175. display: flex;
  176. justify-content: center;
  177. margin: 20px 0 0 0;
  178. }
  179. }
  180. </style>