examApply.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. <template>
  2. <!-- 模考报名页面 -->
  3. <view class="exam_apply">
  4. <nav-bar title="模考报名" class="navbar"></nav-bar>
  5. <!-- background="{ background: '#498AFE' }" -->
  6. <image class="mock_bg" src="../static/mock_bg.png"></image>
  7. <!-- <u-navbar :is-back="false" title="模考报名" :border-bottom="false" title-color="#fff" back-icon-color="#ffffff" background="{ background: '#498AFE' }">
  8. </u-navbar> -->
  9. <!-- <u-line color="#D6D6DB" /> -->
  10. <view class="mains">
  11. <u-form :model="examform" ref="uForm" :rules="rules" label-width='74'>
  12. <view class="items">
  13. <view class="item_title">
  14. <text class="star_red">*</text>
  15. <text class="number">01</text>
  16. <text class="category">姓名</text>
  17. </view>
  18. <u-form-item label=" " label-width="74" prop="userName" :border-bottom='false'>
  19. <view class="inputs">
  20. <input v-model.trim="examform.userName" class="uni-input" placeholder="请输入" />
  21. </view>
  22. </u-form-item>
  23. </view>
  24. <view class="items">
  25. <view class="item_title">
  26. <text class="star_red">*</text>
  27. <text class="number">02</text>
  28. <text class="category">性别</text>
  29. </view>
  30. <u-form-item label=" " label-width="74" prop="userSex" :border-bottom='false'>
  31. <u-radio-group v-model="examform.userSex" :wrap='true' @change="radioGroupChange">
  32. <u-radio value="1" name='1'>男</u-radio>
  33. <u-radio value="2" name='2'>女</u-radio>
  34. </u-radio-group>
  35. </u-form-item>
  36. </view>
  37. <view class="items">
  38. <view class="item_title">
  39. <text class="star_red">*</text>
  40. <text class="number">03</text>
  41. <text class="category">企业名称</text>
  42. </view>
  43. <u-form-item label=" " label-width="74" prop="companyName" :border-bottom='false'>
  44. <view class="inputs">
  45. <input v-model.trim="examform.companyName" class="uni-input" placeholder="请输入" />
  46. </view>
  47. </u-form-item>
  48. </view>
  49. <!-- <view class="items">
  50. <view class="item_title">
  51. <text class="star_red">*</text>
  52. <text class="number">04</text>
  53. <text class="category">身份证号</text>
  54. </view>
  55. <u-form-item label=" " label-width="74" prop="userIdCard" :border-bottom='false'>
  56. <view class="inputs">
  57. <input v-model.trim="examform.userIdCard" class="uni-input" placeholder="请输入" />
  58. </view>
  59. </u-form-item>
  60. </view> -->
  61. <!-- <view class="items">
  62. <view class="item_title">
  63. <text class="star_red">*</text>
  64. <text class="number">04</text>
  65. <text class="category">手机号码</text>
  66. </view>
  67. <u-form-item label=" " label-width="74" prop="userPhone" :border-bottom='false'>
  68. <view class="inputs">
  69. <input v-model.trim="examform.userPhone" class="uni-input" placeholder="请输入" />
  70. </view>
  71. </u-form-item>
  72. </view> -->
  73. <view class="items">
  74. <view class="item_title">
  75. <text class="star_red">*</text>
  76. <text class="number">04</text>
  77. <text class="category">报考专业</text>
  78. </view>
  79. <u-form-item label=" " label-width="74" prop="majorId" :border-bottom='false'>
  80. <view class="inputs">
  81. <view class="item_box">
  82. <picker class="picker" mode="selector" :range="majorList" range-key="majorName" :value="examform.majorId"
  83. @change="majorChange">
  84. <view class="pick_con" style="fontSize: 40rpx">{{ majorName }}</view>
  85. </picker>
  86. <u-icon class="icon" name="arrow-down"></u-icon>
  87. </view>
  88. </view>
  89. </u-form-item>
  90. </view>
  91. <view class="items">
  92. <view class="item_title">
  93. <text class="star_red">*</text>
  94. <text class="number">05</text>
  95. <text class="category">报考科目</text>
  96. </view>
  97. <u-form-item label=" " label-width="74" prop="userMajors" :border-bottom='false'>
  98. <u-checkbox-group :wrap='true' @change="checkboxGroupChange">
  99. <u-checkbox v-model="item.checked" v-for="(item, index) in subjectLists" :key="index" :name="item.subjectId">
  100. {{ item.name }}
  101. </u-checkbox>
  102. </u-checkbox-group>
  103. </u-form-item>
  104. </view>
  105. </u-form>
  106. <!-- 提交按钮 -->
  107. <view class="btns">
  108. <view class="submits" @click="submit()">
  109. 提交
  110. </view>
  111. </view>
  112. </view>
  113. </view>
  114. </template>
  115. <script>
  116. export default {
  117. name: 'examApply',
  118. data() {
  119. var validatorMajor = (rule, value, callback) => {
  120. if (value.length) {
  121. callback()
  122. } else {
  123. callback(new Error("请选择报考科目"))
  124. }
  125. }
  126. var validatorMajorId = (rule, value, callback) => {
  127. if (value) {
  128. callback()
  129. } else {
  130. callback(new Error("请选择专业"))
  131. }
  132. }
  133. return {
  134. examform: {
  135. userName: '',
  136. userSex: '',
  137. companyName: '',
  138. // userIdCard: '',
  139. // userPhone: '',
  140. userMajors: [],
  141. majorId: '',
  142. },
  143. rules: {
  144. userName: [{ required: true, message: '请输入姓名', trigger: ['blur', 'change']}],
  145. userSex: [{ required: true, message: '请选择性别', trigger: ['blur', 'change']}],
  146. companyName: [{ required: true, message: '请输入企业名称', trigger: ['blur', 'change']}],
  147. // userIdCard: [{ required: true, message: '请输入身份证号', trigger: ['blur', 'change']}],
  148. majorId: [{ validator: validatorMajorId, trigger: ['change','blur']}],
  149. userMajors: [{ validator: validatorMajor, trigger: ['blur', 'change']}],
  150. },
  151. checkboxList: [],
  152. activityId: '', // 活动id
  153. subLoading: true,
  154. majorList: [], // 专业
  155. subjectLists: [], // 科目
  156. majorName: '',
  157. startTime: '',
  158. endTime: '',
  159. }
  160. },
  161. onLoad(option) {
  162. console.log('option--: ', option)
  163. if (option.scene) {
  164. let tid = decodeURIComponent(option.scene)
  165. this.activityId = tid.split('=')[1]
  166. // this.getActivity()
  167. } else {
  168. this.activityId = option.tid
  169. // this.getActivity()
  170. }
  171. },
  172. onShow() {
  173. console.log('activityId: ', this.activityId)
  174. if (!uni.getStorageSync('user_account')) { // 未登录
  175. console.log('未登录')
  176. uni.navigateTo({
  177. url: '/pages4/login/login?isBack=true'
  178. })
  179. return
  180. } else {
  181. // 已登录
  182. console.log('已登录')
  183. this.getActivity()
  184. }
  185. },
  186. // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
  187. onReady() {
  188. this.$refs.uForm.setRules(this.rules)
  189. },
  190. methods: {
  191. // 获取活动信息(专业和科目)
  192. getActivity() {
  193. this.$http({
  194. url: `/apply/activity/detail/${this.activityId}`,
  195. method: 'get',
  196. }).then((res) => {
  197. if (res.data.code == 200) {
  198. this.hadCheck()
  199. let data = res.data.data || {}
  200. const { majorList, subjectList, endTime, startTime} = data
  201. this.majorList = majorList || []
  202. this.startTime = startTime
  203. this.endTime = endTime
  204. if (subjectList) {
  205. this.checkboxList = subjectList.map((item) => {
  206. return {
  207. name: '《' + item.subjectName + '》',
  208. checked: false,
  209. ...item
  210. }
  211. })
  212. console.log('checkboxList:', this.checkboxList)
  213. }
  214. }
  215. })
  216. },
  217. // 校验用户是否已报名
  218. hadCheck() {
  219. this.$http({
  220. url: `/apply/activity/check/${this.activityId}`,
  221. method: 'get',
  222. }).then((res) => {
  223. if (res.data.data) {
  224. // 已经报名
  225. uni.navigateTo({
  226. url: '/pages5/mockExam/registrationSuccess?endTime=' + this.endTime + '&startTime=' + this.startTime
  227. + '&activityId=' + this.activityId
  228. })
  229. }
  230. })
  231. },
  232. checkboxGroupChange(e) {
  233. this.examform.userMajors = e
  234. },
  235. radioGroupChange(e) {
  236. console.log(e, this.examform.userSex);
  237. },
  238. majorChange(e) {
  239. this.examform.userMajors = []
  240. let index = e.detail.value
  241. const { majorName, majorId, mockMajorId } = this.majorList[index]
  242. this.majorName = majorName
  243. this.examform.majorId = majorId
  244. // console.log('1111majorId', this.examform.majorId)
  245. this.subjectLists = this.checkboxList.filter(e => e.mockMajorId == mockMajorId)
  246. this.subjectLists = this.subjectLists.map((item) => {
  247. return {
  248. name: '《' + item.subjectName + '》',
  249. checked: false,
  250. ...item
  251. }
  252. })
  253. },
  254. submit() {
  255. this.$refs.uForm.validate(valid => {
  256. if (valid) {
  257. if (!this.subLoading) {
  258. return
  259. }
  260. this.subLoading = false
  261. const { userName, userSex, companyName, majorId, userMajors} = this.examform
  262. let arrs = []
  263. userMajors.forEach((item, index) => {
  264. let findItem = this.subjectLists.find(e => e.subjectId == item)
  265. if (findItem) {
  266. arrs.push(findItem)
  267. }
  268. })
  269. let mockSubjectIds = arrs.map(e => e.subjectId).join(',')
  270. let mockMajorSubjectIds = arrs.map(e => e.mockMajorSubjectId).join(',')
  271. let params = {
  272. activityId: this.activityId,
  273. userName: userName,
  274. userSex: userSex,
  275. companyName: companyName,
  276. mockMajorId: majorId,
  277. mockSubjectIds: mockSubjectIds,
  278. mockMajorSubjectIds: mockMajorSubjectIds,
  279. }
  280. // console.log('eret', params)
  281. this.$http({
  282. url: '/apply/activity/launch',
  283. method: 'post',
  284. data: params,
  285. // noToken: true,
  286. }).then((res) => {
  287. this.subLoading = true
  288. if (res.data.code == 200) {
  289. let data = res.data.data
  290. uni.navigateTo({
  291. url: '/pages5/mockExam/registrationSuccess?endTime=' + data.endTime + '&startTime=' + data.startTime
  292. + '&activityId=' + this.activityId
  293. })
  294. }
  295. }).catch((err) => {
  296. this.subLoading = true
  297. })
  298. } else {
  299. console.log('验证失败');
  300. }
  301. })
  302. }
  303. },
  304. }
  305. </script>
  306. <style>
  307. page {
  308. background: linear-gradient(90deg, #EDF1FF 0%, #D9F0FF 100%);
  309. }
  310. </style>
  311. <style lang="scss" scoped>
  312. .exam_apply {
  313. width: 100%;
  314. height: 100%;
  315. .mock_bg {
  316. width: 100%;
  317. height: 760rpx;
  318. z-index: -999;
  319. top: 0;
  320. }
  321. .navbar {
  322. background-color: #498AFE;
  323. }
  324. .mains {
  325. padding: 16rpx;
  326. position: relative;
  327. top: -270rpx;
  328. }
  329. .items {
  330. padding: 40rpx 0rpx 40rpx 24rpx;
  331. background-color: #fff;
  332. border-radius: 16rpx;
  333. margin-bottom: 16rpx;
  334. .star_red {
  335. color: #F84B39;
  336. }
  337. .number {
  338. font-size: 32rpx;
  339. font-weight: 800;
  340. color: #222222;
  341. margin: 0rpx 20rpx 0rpx 4rpx;
  342. }
  343. .category {
  344. font-size: 32rpx;
  345. font-weight: 400;
  346. color: #222222;
  347. }
  348. .inputs {
  349. width: 580rpx;
  350. height: 88rpx;
  351. background: #FFFFFF;
  352. border-radius: 8rpx;
  353. border: 2rpx solid #C2C2C2;
  354. display: flex;
  355. align-items: center;
  356. padding-left: 24rpx;
  357. }
  358. .item_box {
  359. height: 86rpx;
  360. display: flex;
  361. align-items: center;
  362. .pick_con {
  363. width: 500rpx;
  364. height: 86rpx;
  365. // font-size: 32rpx;
  366. }
  367. .text {
  368. flex:1;
  369. display: flex;
  370. align-items: center;
  371. }
  372. }
  373. }
  374. .btns {
  375. width: 100%;
  376. display: flex;
  377. align-items: center;
  378. justify-items: center;
  379. }
  380. .submits {
  381. width: 686rpx;
  382. height: 96rpx;
  383. line-height: 96rpx;
  384. text-align: center;
  385. background: #3F8DFD;
  386. border-radius: 16rpx;
  387. font-size: 32rpx;
  388. font-weight: 500;
  389. color: #FFFFFF;
  390. }
  391. }
  392. </style>