preliminary.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. <template>
  2. <custom-layout class="main">
  3. <el-col :span="24" class="w_1300 one">
  4. <div v-if="!user.id">
  5. <div class="text">注册信息</div>
  6. <el-form ref="ruleFormRef" :model="form" :rules="rules" label-width="100px" class="form" label-position="left">
  7. <el-form-item label="账号" prop="account">
  8. <el-input size="large" clearable v-model="form.account" placeholder="请输入姓名/单位名称">
  9. <template #prefix>
  10. <el-icon>
  11. <Avatar />
  12. </el-icon>
  13. </template>
  14. </el-input>
  15. </el-form-item>
  16. <el-form-item label="手机号" prop="phone">
  17. <el-input size="large" clearable v-model="form.phone" placeholder="请输入手机号">
  18. <template #prefix>
  19. <el-icon>
  20. <Iphone />
  21. </el-icon>
  22. </template>
  23. </el-input>
  24. </el-form-item>
  25. <el-form-item label="密码" prop="password">
  26. <el-input size="large" v-model="form.password" type="password" show-password placeholder="请输入包含英文字母大小写、数字和特殊符号的 8-16 位组合">
  27. <template #prefix>
  28. <el-icon>
  29. <Unlock />
  30. </el-icon>
  31. </template>
  32. </el-input>
  33. </el-form-item>
  34. <el-form-item label="电子邮箱" prop="email">
  35. <el-input size="large" clearable v-model="form.email" placeholder="请输入电子邮箱">
  36. <template #prefix>
  37. <el-icon>
  38. <Briefcase />
  39. </el-icon>
  40. </template>
  41. </el-input>
  42. </el-form-item>
  43. </el-form>
  44. </div>
  45. <div class="text">填报信息</div>
  46. <div class="list" v-for="(item, index) in investigate" :key="index">
  47. <div class="problem">
  48. <el-icon v-if="item.is_must == '0'" color="red"><StarFilled /></el-icon>
  49. <span style="margin: 0 0 0 10px" v-if="item.is_must == '0'">{{ item.problem }}</span>
  50. <span style="margin: 0 0 0 10px" v-else>{{ item.problem }}</span>
  51. </div>
  52. <div class="type" v-if="item.type == '0'">
  53. <div class="remark" v-if="item.remark">{{ item.remark }}</div>
  54. <el-radio-group v-model="item.reply">
  55. <el-radio v-for="(i, radio) in item.answer" :key="radio" :value="i.text">{{ i.text }}</el-radio>
  56. </el-radio-group>
  57. <div v-if="errors[item.problem]" class="error-message">{{ errors[item.problem] }}</div>
  58. </div>
  59. <div class="type" v-if="item.type == '1'">
  60. <div class="remark" v-if="item.remark">{{ item.remark }}</div>
  61. <el-checkbox-group v-model="checkbox" @change="checkChange($event, item)">
  62. <el-checkbox v-for="(i, checkbox) in item.answer" :key="checkbox" :label="i.text" :value="i.text">
  63. {{ i.text }}
  64. </el-checkbox>
  65. </el-checkbox-group>
  66. <div v-if="errors[item.problem]" class="error-message">{{ errors[item.problem] }}</div>
  67. </div>
  68. <div class="type" v-if="item.type == '2'">
  69. <div class="remark" v-if="item.remark">{{ item.remark }}</div>
  70. <el-select v-model="item.reply" placeholder="请选择" size="large" style="width: 100%">
  71. <el-option v-for="(i, select) in item.answer" :key="select" :label="i.text" :value="i.text" />
  72. </el-select>
  73. <div v-if="errors[item.problem]" class="error-message">{{ errors[item.problem] }}</div>
  74. </div>
  75. <div class="type" v-if="item.type == '3'">
  76. <div class="remark" v-if="item.remark">{{ item.remark }}</div>
  77. <el-input size="large" v-model="item.reply" type="number" :placeholder="getField(item.problem)" />
  78. <div v-if="errors[item.problem]" class="error-message">{{ errors[item.problem] }}</div>
  79. </div>
  80. <div class="type" v-if="item.type == '4'">
  81. <div class="remark" v-if="item.remark">{{ item.remark }}</div>
  82. <el-input size="large" v-model="item.reply" :placeholder="getField(item.problem)" />
  83. <div v-if="errors[item.problem]" class="error-message">{{ errors[item.problem] }}</div>
  84. </div>
  85. <div class="type" v-if="item.type == '5'">
  86. <div class="remark" v-if="item.remark">{{ item.remark }}</div>
  87. <el-input v-model="item.reply" type="textarea" :placeholder="getField(item.problem)" />
  88. <div v-if="errors[item.problem]" class="error-message">{{ errors[item.problem] }}</div>
  89. </div>
  90. <div class="type" v-if="item.type == '6'">
  91. <div class="remark" v-if="item.remark">{{ item.remark }}</div>
  92. <custom-upload model="reply" :list="file" accept="*" :limit="10" url="/files/web/cxyy_match/upload" @change="onUpload($event, item)"></custom-upload>
  93. <div v-if="errors[item.problem]" class="error-message">{{ errors[item.problem] }}</div>
  94. </div>
  95. <div class="type" v-if="item.type == '7'">
  96. <div class="list">
  97. <div v-for="(aa, ina) in item.answer" :key="ina" class="name">{{ aa.text }}</div>
  98. </div>
  99. <div class="list" v-for="(gg, inx) in item.reply" :key="inx">
  100. <div v-for="(aa, ina) in item.answer" :key="ina" class="input">
  101. <el-input size="large" v-model="gg[aa.text]" :placeholder="getField(item.problem)" />
  102. </div>
  103. <el-icon class="icon" size="25" @click="toDel(item, gg.sid)"><Close /></el-icon>
  104. </div>
  105. <div class="add" @click="toAdd(item)">+新增一行</div>
  106. </div>
  107. <div class="type" v-if="item.type == '8'">
  108. <div v-for="(as, img) in item.answer" :key="img">
  109. <el-link :href="getUrl(as)" target="_blank">{{ as.name }}</el-link>
  110. </div>
  111. <div class="remark" v-if="item.remark">{{ item.remark }}</div>
  112. </div>
  113. </div>
  114. <div class="button">
  115. <el-button type="primary" @click="toBack()">返回上一页</el-button>
  116. <el-button type="primary" @click="toSave()">保存</el-button>
  117. </div>
  118. </el-col>
  119. </custom-layout>
  120. </template>
  121. <script setup>
  122. import moment from 'moment'
  123. import { get } from 'lodash-es'
  124. // 接口
  125. import { MatchStore } from '@/store/api/platform/match'
  126. const store = MatchStore()
  127. import { MatchRegStore } from '@/store/api/platform/matchReg'
  128. const matchRegStore = MatchRegStore()
  129. import { UserStore } from '@/store/user'
  130. const userStore = UserStore()
  131. const user = computed(() => userStore.user)
  132. // 加载中
  133. const loading = ref(false)
  134. // 路由
  135. const route = useRoute()
  136. const info = ref({})
  137. const investigate = ref([])
  138. const file = ref([])
  139. const form = ref({ gender: '0', role: ['User'] })
  140. const checkbox = ref([])
  141. // 表单验证
  142. const ruleFormRef = ref()
  143. const validatePhoneNumber = (rule, value, callback) => {
  144. const reg = /^1[3-9]\d{9}$/
  145. if (!value) {
  146. return callback(new Error('手机号不能为空'))
  147. }
  148. if (!reg.test(value)) {
  149. return callback(new Error('请输入正确的手机号'))
  150. }
  151. callback()
  152. }
  153. const passwordValValidate = (rule, value, callback) => {
  154. if (!value) {
  155. return callback(new Error('请输入密码'))
  156. } else if (/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[._~!@#$^&*])[A-Za-z0-9._~!@#$^&*]{8,16}$/g.test(value)) {
  157. return callback()
  158. } else {
  159. return callback(new Error('请输入包含英文字母大小写、数字和特殊符号的 8-16 位组合'))
  160. }
  161. }
  162. const rules = reactive({
  163. nick_name: [{ required: true, message: '请输入昵称', trigger: 'blur' }],
  164. phone: [{ required: true, validator: validatePhoneNumber, trigger: 'blur' }],
  165. account: [{ required: true, message: '请输入账号', trigger: 'blur' }],
  166. password: [{ required: true, validator: passwordValValidate, trigger: 'blur' }],
  167. email: [{ required: true, message: '请输入电子邮箱', trigger: 'blur' }],
  168. checkCode: [{ required: true, message: '请输入验证码', trigger: 'blur' }]
  169. })
  170. // 错误信息
  171. const errors = ref({})
  172. // 请求
  173. onMounted(async () => {
  174. loading.value = true
  175. await search()
  176. loading.value = false
  177. })
  178. const search = async () => {
  179. let id = route.query.id
  180. if (id) {
  181. let res = await store.fetch(id)
  182. if (res.errcode == '0') {
  183. info.value = res.data
  184. if (res.data.ext_info && res.data.ext_info.length > 0) investigate.value = res.data.ext_info
  185. }
  186. }
  187. }
  188. const getField = (data) => {
  189. let res = '请输入内容'
  190. if (data) res = `请输入${data}`
  191. return res
  192. }
  193. // 图片处理
  194. const getUrl = (e) => {
  195. if (e) return `${import.meta.env.VITE_APP_HOST}${get(e, 'uri')}`
  196. }
  197. // 上传图片
  198. const onUpload = (e, item) => {
  199. const { value } = e
  200. for (let val of investigate.value) {
  201. if (val.sid == item.sid) val.reply = value
  202. }
  203. }
  204. // 新增一行
  205. const toAdd = (item) => {
  206. for (let val of investigate.value) {
  207. if (val.sid == item.sid) {
  208. let answer = []
  209. let obj = {
  210. sid: moment().valueOf()
  211. }
  212. for (let s of val.answer) {
  213. obj[s.text] = ''
  214. }
  215. answer.push(obj)
  216. if (val.reply) val.reply = [...val.reply, ...answer]
  217. else val.reply = answer
  218. }
  219. }
  220. }
  221. // 删除一行
  222. const toDel = (item, sid) => {
  223. if (item && item.reply && item.reply.length > 0) {
  224. let answer = item.reply.filter((i) => i.sid != sid)
  225. for (let val of investigate.value) {
  226. if (val.sid == item.sid) {
  227. val.reply = answer
  228. }
  229. }
  230. }
  231. }
  232. const checkChange = (data, item) => {
  233. for (let val of investigate.value) {
  234. if (val.sid == item.sid) {
  235. val.reply = data
  236. }
  237. }
  238. }
  239. // 自定义的验证函数
  240. const validateObject = async (arr) => {
  241. const errors = {}
  242. for (const obj of arr) {
  243. if (obj.is_must == '0') {
  244. if (!obj.reply || obj.reply.length == 0) {
  245. if (obj.type == '0' || obj.type == '1' || obj.type == '1') errors[obj.problem] = `请选择${obj.problem}`
  246. else if (obj.type == '6') errors[obj.problem] = `请上传${obj.problem}`
  247. else errors[obj.problem] = `请填写${obj.problem}`
  248. }
  249. }
  250. }
  251. // 如果有错误,返回错误对象
  252. if (Object.keys(errors).length > 0) {
  253. return errors
  254. }
  255. // 如果没有错误,返回null或undefined
  256. return null
  257. }
  258. const toSave = async () => {
  259. const errorsInfo = await validateObject(investigate.value)
  260. // 检查是否有错误
  261. if (errorsInfo) {
  262. errors.value = errorsInfo
  263. console.log(errorsInfo)
  264. } else {
  265. errors.value = {}
  266. const data = { match_id: info.value.id, info: investigate.value }
  267. if (user.value.id) {
  268. data.user_id = user.value.id
  269. const res = await matchRegStore.create(data)
  270. if (res.errcode == '0') {
  271. ElMessageBox.alert('请在 个人中心-活动管理-大赛报名 中查看报名信息', '报名信息', {
  272. confirmButtonText: '确定',
  273. callback: () => {
  274. toBack()
  275. }
  276. })
  277. } else ElMessage({ message: res.errmsg, type: 'error' })
  278. } else {
  279. if (!ruleFormRef.value) return
  280. await ruleFormRef.value.validate(async (valid) => {
  281. if (valid) {
  282. form.value.nick_name = form.value.account
  283. data.user = form.value
  284. const res = await matchRegStore.create(data)
  285. if (res.errcode == '0') {
  286. ElMessageBox.alert('请在 个人中心-活动管理-大赛报名 中查看报名信息', '报名信息', {
  287. confirmButtonText: '确定',
  288. callback: () => {
  289. toBack()
  290. }
  291. })
  292. } else ElMessage({ message: res.errmsg, type: 'error' })
  293. }
  294. })
  295. }
  296. }
  297. }
  298. // 返回上一页
  299. const toBack = () => {
  300. window.history.go(-1)
  301. }
  302. </script>
  303. <style scoped lang="scss">
  304. .main {
  305. .one {
  306. .text {
  307. margin: 0 0 10px 0;
  308. color: #000;
  309. display: inline-block;
  310. padding-bottom: 20px;
  311. font-size: 30px;
  312. border-bottom: 5px solid #378cff;
  313. cursor: pointer;
  314. }
  315. .list {
  316. .problem {
  317. display: flex;
  318. align-items: center;
  319. font-size: 20px;
  320. margin: 10px 0;
  321. }
  322. .type {
  323. padding: 0 0 10px 15px;
  324. .list {
  325. display: flex;
  326. align-items: center;
  327. justify-content: center;
  328. margin: 10px 0;
  329. .name {
  330. width: 50%;
  331. text-align: center;
  332. }
  333. .input {
  334. width: 50%;
  335. margin: 0 5px 0 0;
  336. .name {
  337. width: 50%;
  338. text-align: center;
  339. margin: 0 0 10px 0;
  340. }
  341. }
  342. .icon {
  343. display: none;
  344. margin: 5px 0 0 0;
  345. }
  346. }
  347. .list:hover {
  348. .icon {
  349. display: block;
  350. }
  351. }
  352. .add {
  353. border: 1px solid #e5e5e5;
  354. border-radius: 5px;
  355. text-align: center;
  356. padding: 10px;
  357. cursor: pointer;
  358. }
  359. .image {
  360. width: 100%;
  361. }
  362. .error-message {
  363. margin: 10px 0 0 10px;
  364. font-size: 14px;
  365. color: red;
  366. }
  367. .remark {
  368. margin: 10px 0 10px 20px;
  369. font-size: 14px;
  370. color: red;
  371. }
  372. }
  373. }
  374. .button {
  375. margin: 10px 0;
  376. padding: 10px;
  377. text-align: center;
  378. button {
  379. padding: 20px 0;
  380. width: 240px;
  381. background-color: #007aff;
  382. }
  383. }
  384. }
  385. }
  386. </style>