sign.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <template>
  2. <div class="index">
  3. <el-row>
  4. <el-col :span="24" class="main" v-loading="loading">
  5. <el-col :span="24" class="one">
  6. <el-radio-group size="large" v-model="type">
  7. <el-radio-button label="活动报名" value="1" />
  8. <el-radio-button label="大赛报名" value="2" />
  9. </el-radio-group>
  10. </el-col>
  11. <div v-if="type == '1'">
  12. <el-col :span="24" class="two">
  13. <el-table :data="list" style="width: 100%" size="large" :header-cell-style="{ backgroundColor: '#edf3ff' }">
  14. <template #empty>
  15. <el-empty description="暂无数据" />
  16. </template>
  17. <el-table-column prop="matchInfo.name" align="center" label="活动名称" />
  18. <el-table-column prop="time" align="center" label="报名时间" width="180" />
  19. <el-table-column prop="status" align="center" label="状态" width="180">
  20. <template #default="scope">
  21. <div>{{ getDict(scope.row.status, 'status') }}</div>
  22. </template>
  23. </el-table-column>
  24. <el-table-column align="center" label="操作" width="180">
  25. <template #default="{ row }">
  26. <el-link :underline="false" type="primary" size="mini" @click="toView(row)" style="margin-right: 10px">查看活动</el-link>
  27. <el-link :underline="false" v-if="row.status != '1'" type="warning" size="mini" @click="toEdit(row)" style="margin-right: 10px">修改报名信息</el-link>
  28. </template>
  29. </el-table-column>
  30. </el-table>
  31. </el-col>
  32. <el-col :span="24" class="thr">
  33. <el-pagination background layout="prev, pager, next" :total="total" :page-size="limit" v-model:current-page="currentPage" @current-change="changePage" @size-change="sizeChange" />
  34. </el-col>
  35. </div>
  36. <div v-else>
  37. <preliminary :userInfo="user"></preliminary>
  38. </div>
  39. </el-col>
  40. </el-row>
  41. <el-dialog v-model="dialog.show" :title="dialog.title" :destroy-on-close="false" @close="toClose">
  42. <el-row>
  43. <el-col :span="24" v-if="dialog.type == '1'">
  44. <form2 v-if="form.matchInfo && form.matchInfo.form == '3'"></form2>
  45. <form1 v-else></form1>
  46. </el-col>
  47. </el-row>
  48. </el-dialog>
  49. </div>
  50. </template>
  51. <script setup>
  52. // 组件
  53. import form1 from './parts/form-1.vue'
  54. import form2 from './parts/form-2.vue'
  55. import preliminary from './parts/preliminaryUser.vue'
  56. import moment from 'moment'
  57. import { cloneDeep, get } from 'lodash-es'
  58. const $checkRes = inject('$checkRes')
  59. import { UserStore } from '@/store/user'
  60. const userStore = UserStore()
  61. const user = computed(() => userStore.user)
  62. // 接口
  63. import { SignStore } from '@/store/api/platform/sign'
  64. import { DictDataStore } from '@/store/api/system/dictData'
  65. const store = SignStore()
  66. const dictDataStore = DictDataStore()
  67. // 加载中
  68. const loading = ref(false)
  69. // 路由
  70. const router = useRouter()
  71. // 列表
  72. const list = ref([])
  73. let skip = 0
  74. let limit = inject('limit')
  75. const total = ref(0)
  76. const currentPage = ref(1)
  77. const dialog = ref({ type: '1', show: false, title: '修改报名信息' })
  78. const ruleFormRef = ref()
  79. const form = ref({ project_file: [] })
  80. const type = ref('1')
  81. const validatePhoneNumber = (rule, value, callback) => {
  82. const reg = /^1[3-9]\d{9}$/
  83. if (!value) {
  84. return callback(new Error('手机号不能为空'))
  85. }
  86. if (!reg.test(value)) {
  87. return callback(new Error('请输入正确的手机号'))
  88. }
  89. callback()
  90. }
  91. const validateCardNumber = (rule, value, callback) => {
  92. var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/
  93. if (!value) {
  94. return callback(new Error('证件号码不能为空'))
  95. }
  96. if (!reg.test(value)) {
  97. return callback(new Error('请输入正确的证件号码'))
  98. }
  99. callback()
  100. }
  101. const rules = reactive({
  102. name: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
  103. phone: [{ required: true, validator: validatePhoneNumber, trigger: 'blur' }],
  104. cardType: [{ required: true, message: '请选择证件类型', trigger: 'change' }],
  105. card: [{ required: true, validator: validateCardNumber, trigger: 'change' }],
  106. remark: [{ required: true, message: '请输入备注', trigger: 'blur' }]
  107. })
  108. // 字典表
  109. const statusList = ref([])
  110. const cardTypeList = ref([])
  111. const signTypeList = ref([])
  112. // 请求
  113. onMounted(async () => {
  114. loading.value = true
  115. await searchOther()
  116. await search()
  117. loading.value = false
  118. })
  119. const search = async (query = { skip, limit }) => {
  120. skip = query.skip
  121. limit = query.limit
  122. const info = {
  123. skip: query.skip,
  124. limit: query.limit,
  125. user: user.value.id
  126. // ...searchForm.value
  127. }
  128. const res = await store.sign(info)
  129. if (res.errcode == '0') {
  130. list.value = res.data
  131. total.value = res.total
  132. }
  133. }
  134. const searchOther = async () => {
  135. let result
  136. // 状态
  137. result = await dictDataStore.query({ code: 'examStatus', is_use: '0' })
  138. if ($checkRes(result)) statusList.value = result.data
  139. // 证件类型
  140. result = await dictDataStore.query({ code: 'cardType', is_use: '0' })
  141. if ($checkRes(result)) cardTypeList.value = result.data
  142. // 报名类型
  143. result = await dictDataStore.query({ code: 'signType', is_use: '0' })
  144. if ($checkRes(result)) signTypeList.value = result.data
  145. }
  146. // 字典数据转换
  147. const getDict = (data, model) => {
  148. if (data) {
  149. let res
  150. if (model == 'status') res = statusList.value.find((f) => f.value == data)
  151. return get(res, 'label')
  152. }
  153. }
  154. // 修改
  155. const toEdit = (data) => {
  156. form.value = data
  157. dialog.value = { type: '1', show: true, title: '修改报名信息' }
  158. }
  159. // 查看赛事
  160. const toView = (item) => {
  161. router.push({ path: '/match/detail', query: { id: item.match } })
  162. }
  163. // 报名
  164. const submitForm = async (formEl) => {
  165. if (!formEl) return
  166. await formEl.validate(async (valid, fields) => {
  167. if (valid) {
  168. ElMessageBox.confirm(`您确定修改该数据将会重新审核?`, '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' })
  169. .then(async () => {
  170. const data = cloneDeep(form.value)
  171. const other = { time: moment().format('YYYY-MM-DD'), status: '0' }
  172. let res = await store.update({ ...data, ...other })
  173. if ($checkRes(res, true)) {
  174. await toClose()
  175. await search()
  176. } else {
  177. ElMessage({ message: `${res.errmsg}`, type: 'error' })
  178. }
  179. })
  180. .catch(() => {})
  181. } else {
  182. console.log('error submit!', fields)
  183. }
  184. })
  185. }
  186. const toClose = () => {
  187. form.value = { project_file: [] }
  188. dialog.value = { show: false }
  189. }
  190. // 分页
  191. const changePage = (page = currentPage.value) => {
  192. search({ skip: (page - 1) * limit, limit: limit })
  193. }
  194. const sizeChange = (limits) => {
  195. limit = limits
  196. currentPage.value = 1
  197. search({ skip: 0, limit: limit })
  198. }
  199. // provide
  200. provide('form', form)
  201. provide('rules', rules)
  202. provide('ruleFormRef', ruleFormRef)
  203. provide('cardTypeList', cardTypeList)
  204. provide('signTypeList', signTypeList)
  205. provide('submitForm', submitForm)
  206. </script>
  207. <style scoped lang="scss">
  208. .main {
  209. .one {
  210. margin: 0 0 10px 0;
  211. }
  212. .thr {
  213. display: flex;
  214. justify-content: center;
  215. margin: 20px 0 0 0;
  216. }
  217. .button {
  218. text-align: center;
  219. }
  220. }
  221. </style>