preliminary.vue 11 KB

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