examApply.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  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="$method.splitImgHost('oss/images/file/20230710/1688974188358.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
  19. label=" "
  20. label-width="74"
  21. prop="userName"
  22. :border-bottom="false"
  23. >
  24. <view class="inputs">
  25. <input
  26. v-model.trim="examform.userName"
  27. class="uni-input"
  28. placeholder="请输入"
  29. />
  30. </view>
  31. </u-form-item>
  32. </view>
  33. <view class="items">
  34. <view class="item_title">
  35. <text class="star_red">*</text>
  36. <text class="number">02</text>
  37. <text class="category">性别</text>
  38. </view>
  39. <u-form-item
  40. label=" "
  41. label-width="74"
  42. prop="userSex"
  43. :border-bottom="false"
  44. >
  45. <u-radio-group
  46. v-model="examform.userSex"
  47. :wrap="true"
  48. @change="radioGroupChange"
  49. >
  50. <u-radio value="1" name="1">男</u-radio>
  51. <u-radio value="2" name="2">女</u-radio>
  52. </u-radio-group>
  53. </u-form-item>
  54. </view>
  55. <view class="items">
  56. <view class="item_title">
  57. <!-- <text class="star_red">*</text> -->
  58. <text class="number">03</text>
  59. <text class="category">企业名称</text>
  60. </view>
  61. <u-form-item
  62. label=" "
  63. label-width="74"
  64. prop="companyName"
  65. :border-bottom="false"
  66. >
  67. <view class="inputs">
  68. <input
  69. v-model.trim="examform.companyName"
  70. class="uni-input"
  71. placeholder="请输入"
  72. />
  73. </view>
  74. </u-form-item>
  75. </view>
  76. <!-- <view class="items">
  77. <view class="item_title">
  78. <text class="star_red">*</text>
  79. <text class="number">04</text>
  80. <text class="category">身份证号</text>
  81. </view>
  82. <u-form-item label=" " label-width="74" prop="userIdCard" :border-bottom='false'>
  83. <view class="inputs">
  84. <input v-model.trim="examform.userIdCard" class="uni-input" placeholder="请输入" />
  85. </view>
  86. </u-form-item>
  87. </view> -->
  88. <!-- <view class="items">
  89. <view class="item_title">
  90. <text class="star_red">*</text>
  91. <text class="number">04</text>
  92. <text class="category">手机号码</text>
  93. </view>
  94. <u-form-item label=" " label-width="74" prop="userPhone" :border-bottom='false'>
  95. <view class="inputs">
  96. <input v-model.trim="examform.userPhone" class="uni-input" placeholder="请输入" />
  97. </view>
  98. </u-form-item>
  99. </view> -->
  100. <view class="items">
  101. <view class="item_title">
  102. <text class="star_red">*</text>
  103. <text class="number">04</text>
  104. <text class="category">报考专业</text>
  105. </view>
  106. <u-form-item
  107. label=" "
  108. label-width="74"
  109. prop="majorId"
  110. :border-bottom="false"
  111. >
  112. <view class="inputs">
  113. <view class="item_box">
  114. <picker
  115. class="picker"
  116. mode="selector"
  117. :range="majorList"
  118. range-key="majorName"
  119. :value="examform.majorId"
  120. @change="majorChange"
  121. >
  122. <view class="pick_con" style="fontsize: 40rpx">{{
  123. majorName
  124. }}</view>
  125. </picker>
  126. <u-icon class="icon" name="arrow-down"></u-icon>
  127. </view>
  128. </view>
  129. </u-form-item>
  130. </view>
  131. <view class="items">
  132. <view class="item_title">
  133. <text class="star_red">*</text>
  134. <text class="number">05</text>
  135. <text class="category">报考科目</text>
  136. </view>
  137. <u-form-item
  138. label=" "
  139. label-width="74"
  140. prop="userMajors"
  141. :border-bottom="false"
  142. >
  143. <template v-if="subjectLists.length">
  144. <u-checkbox-group :wrap="true" @change="checkboxGroupChange">
  145. <u-checkbox
  146. v-model="item.checked"
  147. v-for="(item, index) in subjectLists"
  148. :key="index"
  149. :name="item.subjectId"
  150. >
  151. {{ item.name }}
  152. </u-checkbox>
  153. </u-checkbox-group>
  154. </template>
  155. <template v-else>
  156. <view class="grays">请先选择报考专业</view>
  157. </template>
  158. </u-form-item>
  159. </view>
  160. </u-form>
  161. <!-- 提交按钮 -->
  162. <view class="btns">
  163. <view v-if="endTime <= sysTime" class="submits disable">提交</view>
  164. <view v-else class="submits" @click="submit()"> 提交 </view>
  165. </view>
  166. </view>
  167. </view>
  168. </template>
  169. <script>
  170. import { tenantId, BASE_URL } from "@/common/request.js";
  171. export default {
  172. name: "examApply",
  173. data() {
  174. var validatorMajor = (rule, value, callback) => {
  175. if (value.length) {
  176. callback();
  177. } else {
  178. callback(new Error("请选择报考科目"));
  179. }
  180. };
  181. var validatorMajorId = (rule, value, callback) => {
  182. if (value) {
  183. callback();
  184. } else {
  185. callback(new Error("请选择专业"));
  186. }
  187. };
  188. return {
  189. examform: {
  190. userName: "",
  191. userSex: "",
  192. companyName: "",
  193. // userIdCard: '',
  194. // userPhone: '',
  195. userMajors: [],
  196. majorId: "",
  197. },
  198. rules: {
  199. userName: [
  200. {
  201. required: true,
  202. message: "请输入姓名",
  203. trigger: ["blur", "change"],
  204. },
  205. ],
  206. userSex: [
  207. {
  208. required: true,
  209. message: "请选择性别",
  210. trigger: ["blur", "change"],
  211. },
  212. ],
  213. // companyName: [
  214. // {
  215. // required: true,
  216. // message: "请输入企业名称",
  217. // trigger: ["blur", "change"],
  218. // },
  219. // ],
  220. // userIdCard: [{ required: true, message: '请输入身份证号', trigger: ['blur', 'change']}],
  221. majorId: [{ validator: validatorMajorId, trigger: ["change", "blur"] }],
  222. userMajors: [
  223. { validator: validatorMajor, trigger: ["blur", "change"] },
  224. ],
  225. },
  226. checkboxList: [],
  227. activityId: "", // 活动id
  228. subLoading: true,
  229. majorList: [], // 专业
  230. subjectLists: [], // 科目
  231. majorName: "",
  232. startTime: "",
  233. endTime: "",
  234. sysTime: "", // 当前时间
  235. };
  236. },
  237. onLoad(option) {
  238. this.sysTime = +this.$method.timest();
  239. // console.log('option--: ', option)
  240. if (option.scene) {
  241. let tid = decodeURIComponent(option.scene);
  242. this.activityId = tid.split("=")[1];
  243. // this.getActivity()
  244. } else {
  245. this.activityId = option.tid;
  246. // this.getActivity()
  247. }
  248. },
  249. onShow() {
  250. console.log("activityId: ", this.activityId);
  251. if (!uni.getStorageSync("user_account")) {
  252. // 未登录
  253. console.log("未登录");
  254. uni.navigateTo({
  255. url: "/pages4/login/login?isBack=true",
  256. });
  257. return;
  258. } else {
  259. // 已登录
  260. console.log("已登录");
  261. this.getActivity1();
  262. }
  263. },
  264. // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
  265. onReady() {
  266. this.$refs.uForm.setRules(this.rules);
  267. },
  268. methods: {
  269. // 获取活动信息(专业和科目)
  270. getActivity() {
  271. this.$http({
  272. url: `/apply/activity/detail/${this.activityId}`,
  273. method: "get",
  274. }).then((res) => {
  275. if (res.data.code == 200) {
  276. this.hadCheck();
  277. let data = res.data.data || {};
  278. const { majorList, subjectList, endTime, startTime } = data;
  279. this.majorList = majorList || [];
  280. this.startTime = startTime;
  281. this.endTime = endTime;
  282. if (subjectList) {
  283. this.checkboxList = subjectList.map((item) => {
  284. return {
  285. name: "《" + item.subjectName + "》",
  286. checked: false,
  287. ...item,
  288. };
  289. });
  290. console.log("checkboxList:", this.checkboxList);
  291. }
  292. }
  293. });
  294. },
  295. getActivity1() {
  296. let token = uni.getStorageSync("token");
  297. token &&
  298. uni.request({
  299. url: BASE_URL + `/apply/activity/detail/${this.activityId}`,
  300. method: "get",
  301. data: {},
  302. header: {
  303. AuthorizationToken: "WX " + token,
  304. TenantId: tenantId,
  305. },
  306. success: (res) => {
  307. if (res.data.code == 200) {
  308. this.hadCheck();
  309. let data = res.data.data || {};
  310. const { majorList, subjectList, endTime, startTime } = data;
  311. this.majorList = majorList || [];
  312. this.startTime = startTime;
  313. this.endTime = endTime;
  314. if (subjectList) {
  315. this.checkboxList = subjectList.map((item) => {
  316. return {
  317. name: "《" + item.subjectName + "》",
  318. checked: false,
  319. ...item,
  320. };
  321. });
  322. console.log("checkboxList:", this.checkboxList);
  323. }
  324. } else if (res.data.code == 401) {
  325. uni.navigateTo({
  326. url: "/pages4/login/login?isBack=true",
  327. });
  328. }
  329. },
  330. fail: (err) => {
  331. uni.showToast({
  332. title: "请求接口失败",
  333. icon: "none",
  334. });
  335. },
  336. });
  337. },
  338. // 校验用户是否已报名
  339. hadCheck() {
  340. this.$http({
  341. url: `/apply/activity/check/${this.activityId}`,
  342. method: "get",
  343. }).then((res) => {
  344. if (res.data.data) {
  345. // 已经报名
  346. uni.navigateTo({
  347. url:
  348. "/pages5/mockExam/registrationSuccess?endTime=" +
  349. this.endTime +
  350. "&startTime=" +
  351. this.startTime +
  352. "&activityId=" +
  353. this.activityId,
  354. });
  355. }
  356. });
  357. },
  358. checkboxGroupChange(e) {
  359. this.examform.userMajors = e;
  360. },
  361. radioGroupChange(e) {
  362. console.log(e, this.examform.userSex);
  363. },
  364. majorChange(e) {
  365. let index = e.detail.value;
  366. const { majorName, majorId, mockMajorId } = this.majorList[index];
  367. this.majorName = majorName;
  368. this.examform.majorId = majorId;
  369. // console.log('1111majorId', this.examform.majorId)
  370. this.subjectLists = this.checkboxList.filter(
  371. (e) => e.mockMajorId == mockMajorId
  372. );
  373. this.examform.userMajors = [];
  374. this.subjectLists = this.subjectLists.map((item) => {
  375. return {
  376. name: "《" + item.subjectName + "》",
  377. checked: false,
  378. ...item,
  379. };
  380. });
  381. },
  382. submit() {
  383. this.$refs.uForm.validate((valid) => {
  384. if (valid) {
  385. if (!this.subLoading) {
  386. return;
  387. }
  388. this.subLoading = false;
  389. const { userName, userSex, companyName, majorId, userMajors } =
  390. this.examform;
  391. let arrs = [];
  392. userMajors.forEach((item, index) => {
  393. let findItem = this.subjectLists.find((e) => e.subjectId == item);
  394. if (findItem) {
  395. arrs.push(findItem);
  396. }
  397. });
  398. let mockSubjectIds = arrs.map((e) => e.subjectId).join(",");
  399. let mockMajorSubjectIds = arrs
  400. .map((e) => e.mockMajorSubjectId)
  401. .join(",");
  402. let params = {
  403. activityId: this.activityId,
  404. userName: userName,
  405. userSex: userSex,
  406. companyName: companyName,
  407. mockMajorId: majorId,
  408. mockSubjectIds: mockSubjectIds,
  409. mockMajorSubjectIds: mockMajorSubjectIds,
  410. };
  411. // console.log('eret', params)
  412. this.$http({
  413. url: "/apply/activity/launch",
  414. method: "post",
  415. data: params,
  416. // noToken: true,
  417. })
  418. .then((res) => {
  419. this.subLoading = true;
  420. if (res.data.code == 200) {
  421. let data = res.data.data;
  422. uni.navigateTo({
  423. url:
  424. "/pages5/mockExam/registrationSuccess?endTime=" +
  425. data.endTime +
  426. "&startTime=" +
  427. data.startTime +
  428. "&activityId=" +
  429. this.activityId,
  430. });
  431. }
  432. })
  433. .catch((err) => {
  434. this.subLoading = true;
  435. });
  436. } else {
  437. console.log("验证失败");
  438. }
  439. });
  440. },
  441. },
  442. };
  443. </script>
  444. <style>
  445. page {
  446. background: linear-gradient(90deg, #edf1ff 0%, #d9f0ff 100%);
  447. }
  448. </style>
  449. <style lang="scss" scoped>
  450. .exam_apply {
  451. width: 100%;
  452. height: 100%;
  453. .mock_bg {
  454. width: 100%;
  455. height: 760rpx;
  456. // z-index: -999;
  457. top: 0;
  458. }
  459. .navbar {
  460. background-color: #498afe;
  461. }
  462. .mains {
  463. padding: 16rpx;
  464. position: relative;
  465. top: -270rpx;
  466. }
  467. .items {
  468. padding: 40rpx 0rpx 40rpx 24rpx;
  469. background-color: #fff;
  470. border-radius: 16rpx;
  471. margin-bottom: 16rpx;
  472. .star_red {
  473. color: #f84b39;
  474. }
  475. .number {
  476. font-size: 32rpx;
  477. font-weight: 800;
  478. color: #222222;
  479. margin: 0rpx 20rpx 0rpx 4rpx;
  480. }
  481. .category {
  482. font-size: 32rpx;
  483. font-weight: 400;
  484. color: #222222;
  485. }
  486. .inputs {
  487. width: 580rpx;
  488. height: 88rpx;
  489. background: #ffffff;
  490. border-radius: 8rpx;
  491. border: 2rpx solid #c2c2c2;
  492. display: flex;
  493. align-items: center;
  494. padding-left: 24rpx;
  495. }
  496. .item_box {
  497. height: 86rpx;
  498. display: flex;
  499. align-items: center;
  500. .pick_con {
  501. width: 500rpx;
  502. height: 86rpx;
  503. // font-size: 32rpx;
  504. }
  505. .text {
  506. flex: 1;
  507. display: flex;
  508. align-items: center;
  509. }
  510. }
  511. .grays {
  512. color: #999;
  513. font-size: 28rpx;
  514. }
  515. }
  516. .btns {
  517. width: 100%;
  518. // display: flex;
  519. // align-items: center;
  520. // justify-items: center;
  521. view {
  522. margin: 60rpx auto 0;
  523. }
  524. }
  525. .submits {
  526. width: 686rpx;
  527. height: 96rpx;
  528. line-height: 96rpx;
  529. text-align: center;
  530. background: #3f8dfd;
  531. border-radius: 16rpx;
  532. font-size: 32rpx;
  533. font-weight: 500;
  534. color: #ffffff;
  535. }
  536. .disable {
  537. background: #498afe;
  538. opacity: 0.5;
  539. }
  540. }
  541. </style>