index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. <template>
  2. <view class="interview-container">
  3. <!-- 顶部导航栏 -->
  4. <!-- 面试信息 -->
  5. <!-- <view class="interview-info">
  6. <view class="info-item">
  7. <text class="label">面试岗位:</text>
  8. <text class="value">前端岗位</text>
  9. </view>
  10. <view class="info-item">
  11. <text class="label">面试岗位:</text>
  12. <text class="value">2024年06月28日 14:48</text>
  13. </view>
  14. <view class="info-item">
  15. <text class="value">2024年06月28日 16:47</text>
  16. </view>
  17. <view class="info-item">
  18. <text class="label">公司全称:</text>
  19. <text class="value">敏龙科技集团有限公司</text>
  20. </view>
  21. </view> -->
  22. <!-- 职位列表 -->
  23. <view class="job-list-container" v-if="!userInfoFilled">
  24. <view class="job-list-title">可选职位列表</view>
  25. <view class="job-list">
  26. <view v-for="(job, index) in jobList" :key="index" class="job-item"
  27. :class="{'job-selected': selectedJobId === job.id}" @click="selectJob(job)">
  28. <view class="job-name">{{job.title}}</view>
  29. <view class="job-details">
  30. <text class="job-salary">{{job.publish_date}}</text>
  31. <text class="job-location">{{job.location}}</text>
  32. </view>
  33. </view>
  34. </view>
  35. <button class="apply-btn" :disabled="!selectedJobId" @click="applyForJob">申请面试</button>
  36. </view>
  37. <!-- 表单信息 -->
  38. <view class="form-container" v-if="userInfoFilled">
  39. <view class="form-title">填写报名信息</view>
  40. <view class="form-subtitle">如确认报名(此次面试),请填写以下信息</view>
  41. <view class="form-item">
  42. <text class="form-label">姓名 <text class="required">*</text></text>
  43. <input type="text" v-model="formData.name" placeholder="请输入姓名" />
  44. </view>
  45. <view class="form-item">
  46. <text class="form-label">性别 <text class="required">*</text></text>
  47. <view class="radio-group">
  48. <view class="radio-item" @click="formData.gender = '男'">
  49. <view class="radio-circle" :class="{'radio-selected': formData.gender === '男'}"></view>
  50. <text class="radio-text">男</text>
  51. </view>
  52. <view class="radio-item" @click="formData.gender = '女'">
  53. <view class="radio-circle" :class="{'radio-selected': formData.gender === '女'}"></view>
  54. <text class="radio-text">女</text>
  55. </view>
  56. </view>
  57. </view>
  58. <view class="form-item">
  59. <text class="form-label">身份证号 <text class="required">*</text></text>
  60. <input type="text" v-model="formData.idCard" placeholder="请输入有效身份证号" maxlength="18" />
  61. </view>
  62. <view class="form-item">
  63. <text class="form-label">手机号 <text class="required">*</text></text>
  64. <input type="number" v-model="formData.phone" placeholder="请输入手机号" maxlength="11" />
  65. </view>
  66. <view class="form-item">
  67. <text class="form-label">紧急联系人 <text class="required">*</text></text>
  68. <input type="text" v-model="formData.emergencyContact" placeholder="请输入紧急联系人姓名" />
  69. </view>
  70. <view class="form-item">
  71. <text class="form-label">紧急联系人电话 <text class="required">*</text></text>
  72. <input type="number" v-model="formData.emergencyPhone" placeholder="请输入紧急联系人电话" maxlength="11" />
  73. </view>
  74. <view class="form-item">
  75. <text class="form-label">与紧急联系人关系 <text class="required">*</text></text>
  76. <picker @change="relationChange" :value="relationIndex" :range="relationOptions">
  77. <view class="picker-view">
  78. <text>{{formData.relation || '请选择关系'}}</text>
  79. <text class="picker-arrow">▼</text>
  80. </view>
  81. </picker>
  82. </view>
  83. <view class="agreement">
  84. <checkbox :checked="isAgreed" @tap="toggleAgreement" color="#6c5ce7" />
  85. <text class="agreement-text">
  86. 我已阅读并同意
  87. <text class="agreement-link">《身份验证服务协议》</text>
  88. <text class="agreement-link">《隐私保护政策》</text>
  89. <text class="agreement-link">《网络安全协议》</text>
  90. </text>
  91. </view>
  92. <button class="submit-btn" :disabled="!canSubmit" @click="submitForm">提交</button>
  93. </view>
  94. </view>
  95. </template>
  96. <script>
  97. import {
  98. fillUserInfo,
  99. getUserInfo,
  100. getJobList,
  101. applyJob
  102. } from '@/api/user';
  103. export default {
  104. data() {
  105. return {
  106. formData: {
  107. name: '',
  108. gender: '',
  109. phone: '',
  110. email: '',
  111. idCard: '',
  112. emergencyContact: '',
  113. emergencyPhone: '',
  114. relation: ''
  115. },
  116. relationOptions: ['父母', '配偶', '子女', '兄弟姐妹', '朋友', '其他'],
  117. relationIndex: 0,
  118. isAgreed: false,
  119. userInfoFilled: false,
  120. jobList: [],
  121. selectedJobId: null,
  122. selectedJob: null
  123. }
  124. },
  125. onLoad() {
  126. this.checkUserInfo();
  127. this.fetchJobList();
  128. },
  129. computed: {
  130. canSubmit() {
  131. return this.formData.name.trim() &&
  132. this.formData.gender &&
  133. this.formData.phone.trim() &&
  134. (/^1\d{10}$/.test(this.formData.phone)) &&
  135. (!this.formData.email || /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/.test(this.formData.email)) &&
  136. this.formData.idCard.trim() &&
  137. this.formData.emergencyContact.trim() &&
  138. this.formData.emergencyPhone.trim() &&
  139. (/^1\d{10}$/.test(this.formData.emergencyPhone)) &&
  140. this.formData.relation &&
  141. this.isAgreed;
  142. }
  143. },
  144. methods: {
  145. goHome() {
  146. uni.navigateBack({
  147. delta: 1
  148. });
  149. },
  150. toggleAgreement() {
  151. this.isAgreed = !this.isAgreed;
  152. },
  153. relationChange(e) {
  154. this.relationIndex = e.detail.value;
  155. this.formData.relation = this.relationOptions[this.relationIndex];
  156. },
  157. checkUserInfo() {
  158. uni.showLoading({
  159. title: '加载中...'
  160. });
  161. console.log('id:', JSON.parse(uni.getStorageSync('userInfo')).id);
  162. getUserInfo(JSON.parse(uni.getStorageSync('userInfo')).id)
  163. .then(res => {
  164. uni.hideLoading();
  165. if (res.code === 200 && res.data) {
  166. const userData = res.data;
  167. if (userData.name && userData.phone) {
  168. this.userInfoFilled = true;
  169. this.formData.name = userData.name || '';
  170. this.formData.gender = userData.gender || '';
  171. this.formData.phone = userData.phone || '';
  172. this.formData.idCard = userData.id_card || '';
  173. this.formData.emergencyContact = userData.emergency_contact || '';
  174. this.formData.emergencyPhone = userData.emergency_phone || '';
  175. this.formData.relation = userData.relation || '';
  176. if (userData.relation) {
  177. const index = this.relationOptions.findIndex(item => item === userData.relation);
  178. if (index !== -1) {
  179. this.relationIndex = index;
  180. }
  181. }
  182. uni.navigateTo({
  183. url: '/pages/success/success'
  184. });
  185. }
  186. }
  187. })
  188. .catch(err => {
  189. uni.hideLoading();
  190. console.error('获取用户信息失败:', err);
  191. uni.showToast({
  192. title: '获取用户信息失败',
  193. icon: 'none'
  194. });
  195. });
  196. },
  197. fetchJobList() {
  198. uni.showLoading({
  199. title: '加载职位列表...'
  200. });
  201. getJobList()
  202. .then(res => {
  203. uni.hideLoading();
  204. console.log(res);
  205. this.jobList = res;
  206. })
  207. .catch(err => {
  208. uni.hideLoading();
  209. console.error('获取职位列表失败:', err);
  210. uni.showToast({
  211. title: '网络错误,请稍后重试',
  212. icon: 'none'
  213. });
  214. });
  215. },
  216. selectJob(job) {
  217. this.selectedJobId = job.id;
  218. this.selectedJob = job;
  219. },
  220. applyForJob() {
  221. if (!this.selectedJobId) {
  222. uni.showToast({
  223. title: '请选择一个职位',
  224. icon: 'none'
  225. });
  226. return;
  227. }
  228. // 保存所选职位信息
  229. uni.setStorageSync('selectedJob', JSON.stringify(this.selectedJob));
  230. applyJob({
  231. job_id: this.selectedJobId,
  232. tenant_id: 1,
  233. openid: JSON.parse(uni.getStorageSync('userInfo')).openid
  234. }).then(res => {
  235. uni.navigateTo({
  236. url: '/pages/interview-notice/interview-notice',
  237. fail: (err) => {
  238. console.error('页面跳转失败:', err);
  239. uni.showToast({
  240. title: '页面跳转失败',
  241. icon: 'none'
  242. });
  243. }
  244. });
  245. }).catch(err => {
  246. console.error('申请职位失败:', err);
  247. });
  248. // 显示填写个人信息表单
  249. // this.userInfoFilled = true;
  250. },
  251. submitForm() {
  252. if (!this.formData.name.trim()) {
  253. uni.showToast({
  254. title: '请输入姓名',
  255. icon: 'none'
  256. });
  257. return;
  258. }
  259. if (!this.formData.gender) {
  260. uni.showToast({
  261. title: '请选择性别',
  262. icon: 'none'
  263. });
  264. return;
  265. }
  266. if (!this.formData.phone.trim()) {
  267. uni.showToast({
  268. title: '请输入手机号',
  269. icon: 'none'
  270. });
  271. return;
  272. }
  273. if (!/^1\d{10}$/.test(this.formData.phone)) {
  274. uni.showToast({
  275. title: '请输入正确的手机号',
  276. icon: 'none'
  277. });
  278. return;
  279. }
  280. if (this.formData.email && !/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/.test(this.formData.email)) {
  281. uni.showToast({
  282. title: '请输入正确的邮箱',
  283. icon: 'none'
  284. });
  285. return;
  286. }
  287. if (!this.formData.idCard.trim()) {
  288. uni.showToast({
  289. title: '请输入身份证号',
  290. icon: 'none'
  291. });
  292. return;
  293. }
  294. const idCardReg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
  295. if (!idCardReg.test(this.formData.idCard)) {
  296. uni.showToast({
  297. title: '请输入正确的身份证号',
  298. icon: 'none'
  299. });
  300. return;
  301. }
  302. if (!this.formData.emergencyContact.trim()) {
  303. uni.showToast({
  304. title: '请输入紧急联系人',
  305. icon: 'none'
  306. });
  307. return;
  308. }
  309. if (!this.formData.emergencyPhone.trim()) {
  310. uni.showToast({
  311. title: '请输入紧急联系人电话',
  312. icon: 'none'
  313. });
  314. return;
  315. }
  316. if (!/^1\d{10}$/.test(this.formData.emergencyPhone)) {
  317. uni.showToast({
  318. title: '请输入正确的紧急联系人电话',
  319. icon: 'none'
  320. });
  321. return;
  322. }
  323. if (!this.formData.relation) {
  324. uni.showToast({
  325. title: '请选择与紧急联系人关系',
  326. icon: 'none'
  327. });
  328. return;
  329. }
  330. if (!this.isAgreed) {
  331. uni.showToast({
  332. title: '请阅读并同意相关协议',
  333. icon: 'none'
  334. });
  335. return;
  336. }
  337. const submitData = {
  338. openid: JSON.parse(uni.getStorageSync('userInfo')).openid || '',
  339. name: this.formData.name,
  340. phone: this.formData.phone,
  341. id_card: this.formData.idCard,
  342. status: 1,
  343. source: 'mini',
  344. examine: 0,
  345. tenant_id: '1',
  346. emergency_contact: this.formData.emergencyContact,
  347. emergency_phone: this.formData.emergencyPhone,
  348. relation: this.formData.relation,
  349. age: '20',
  350. job_id: this.selectedJobId
  351. };
  352. uni.showLoading({
  353. title: '提交中...'
  354. });
  355. fillUserInfo(submitData)
  356. .then(res => {
  357. uni.hideLoading();
  358. this.updateLocalUserInfo();
  359. uni.showToast({
  360. title: '提交成功',
  361. icon: 'success',
  362. duration: 1500,
  363. success: () => {
  364. setTimeout(() => {
  365. uni.navigateTo({
  366. url: '/pages/success/success',
  367. fail: (err) => {
  368. console.error('页面跳转失败:', err);
  369. uni.showToast({
  370. title: '页面跳转失败',
  371. icon: 'none'
  372. });
  373. }
  374. });
  375. }, 1500);
  376. }
  377. });
  378. // } else {
  379. // uni.showToast({
  380. // title: res.msg || '提交失败,请重试',
  381. // icon: 'none'
  382. // });
  383. // }
  384. })
  385. .catch(err => {
  386. uni.hideLoading();
  387. console.error('提交表单失败:', err);
  388. uni.showToast({
  389. title: '网络错误,请稍后重试',
  390. icon: 'none'
  391. });
  392. });
  393. },
  394. updateLocalUserInfo() {
  395. getUserInfo()
  396. .then(res => {
  397. if (res.code === 200 && res.data) {
  398. let userInfo = {};
  399. try {
  400. userInfo = JSON.parse(uni.getStorageSync('userInfo') || '{}');
  401. } catch (e) {
  402. console.error('解析本地存储用户信息失败:', e);
  403. userInfo = {};
  404. }
  405. const updatedUserInfo = {
  406. ...userInfo,
  407. ...res.data
  408. };
  409. uni.setStorageSync('userInfo', JSON.stringify(updatedUserInfo));
  410. }
  411. })
  412. .catch(err => {
  413. console.error('更新本地用户信息失败:', err);
  414. });
  415. }
  416. }
  417. }
  418. </script>
  419. <style>
  420. .interview-container {
  421. display: flex;
  422. flex-direction: column;
  423. min-height: 100vh;
  424. background-color: #f5f7fa;
  425. }
  426. .nav-bar {
  427. display: flex;
  428. justify-content: space-between;
  429. align-items: center;
  430. padding: 20rpx 30rpx;
  431. background-color: #6c5ce7;
  432. color: #fff;
  433. }
  434. .scan-btn {
  435. display: flex;
  436. flex-direction: column;
  437. align-items: center;
  438. background-color: #ff9f43;
  439. padding: 10rpx 30rpx;
  440. border-radius: 30rpx;
  441. font-size: 24rpx;
  442. }
  443. .interview-info {
  444. background-color: #6c5ce7;
  445. color: #fff;
  446. padding: 20rpx 30rpx 40rpx;
  447. }
  448. .info-item {
  449. margin: 10rpx 0;
  450. font-size: 28rpx;
  451. }
  452. .label {
  453. margin-right: 10rpx;
  454. }
  455. .form-container {
  456. flex: 1;
  457. background-color: #fff;
  458. border-radius: 20rpx 20rpx 0 0;
  459. margin-top: -20rpx;
  460. padding: 40rpx 30rpx;
  461. }
  462. .form-title {
  463. font-size: 32rpx;
  464. font-weight: bold;
  465. margin-bottom: 10rpx;
  466. }
  467. .form-subtitle {
  468. font-size: 24rpx;
  469. color: #999;
  470. margin-bottom: 40rpx;
  471. }
  472. .form-item {
  473. margin-bottom: 30rpx;
  474. }
  475. .form-label {
  476. display: block;
  477. font-size: 28rpx;
  478. margin-bottom: 10rpx;
  479. }
  480. .required {
  481. color: #ff4757;
  482. }
  483. input {
  484. width: 100%;
  485. height: 80rpx;
  486. border: 1px solid #eee;
  487. border-radius: 8rpx;
  488. padding: 0 20rpx;
  489. font-size: 28rpx;
  490. box-sizing: border-box;
  491. }
  492. .submit-btn {
  493. width: 100%;
  494. height: 90rpx;
  495. line-height: 90rpx;
  496. background-color: #6c5ce7;
  497. color: #fff;
  498. border-radius: 45rpx;
  499. font-size: 32rpx;
  500. margin-top: 60rpx;
  501. }
  502. .agreement {
  503. display: flex;
  504. align-items: flex-start;
  505. margin-top: 20rpx;
  506. }
  507. .agreement-text {
  508. font-size: 24rpx;
  509. color: #666;
  510. line-height: 1.5;
  511. margin-left: 10rpx;
  512. }
  513. .agreement-link {
  514. color: #6c5ce7;
  515. }
  516. .submit-btn[disabled] {
  517. background-color: #b2b2b2;
  518. color: #fff;
  519. }
  520. .radio-group {
  521. display: flex;
  522. flex-direction: row;
  523. margin-top: 10rpx;
  524. }
  525. .radio-item {
  526. display: flex;
  527. align-items: center;
  528. margin-right: 60rpx;
  529. }
  530. .radio-circle {
  531. width: 36rpx;
  532. height: 36rpx;
  533. border-radius: 50%;
  534. border: 2rpx solid #999;
  535. margin-right: 10rpx;
  536. position: relative;
  537. }
  538. .radio-selected {
  539. border-color: #6c5ce7;
  540. }
  541. .radio-selected:after {
  542. content: '';
  543. position: absolute;
  544. width: 24rpx;
  545. height: 24rpx;
  546. background-color: #6c5ce7;
  547. border-radius: 50%;
  548. top: 50%;
  549. left: 50%;
  550. transform: translate(-50%, -50%);
  551. }
  552. .radio-text {
  553. font-size: 28rpx;
  554. }
  555. .picker-view {
  556. width: 100%;
  557. height: 80rpx;
  558. border: 1px solid #eee;
  559. border-radius: 8rpx;
  560. padding: 0 20rpx;
  561. font-size: 28rpx;
  562. box-sizing: border-box;
  563. display: flex;
  564. align-items: center;
  565. justify-content: space-between;
  566. }
  567. .picker-arrow {
  568. font-size: 24rpx;
  569. color: #999;
  570. }
  571. /* 职位列表样式 */
  572. .job-list-container {
  573. flex: 1;
  574. background-color: #fff;
  575. border-radius: 20rpx 20rpx 0 0;
  576. margin-top: -20rpx;
  577. padding: 40rpx 30rpx;
  578. }
  579. .job-list-title {
  580. font-size: 32rpx;
  581. font-weight: bold;
  582. margin-bottom: 30rpx;
  583. }
  584. .job-list {
  585. max-height: 800rpx;
  586. overflow-y: auto;
  587. }
  588. .job-item {
  589. padding: 30rpx;
  590. border-radius: 12rpx;
  591. background-color: #f8f9fa;
  592. margin-bottom: 20rpx;
  593. border: 2rpx solid transparent;
  594. }
  595. .job-selected {
  596. border-color: #6c5ce7;
  597. background-color: rgba(108, 92, 231, 0.1);
  598. }
  599. .job-name {
  600. font-size: 30rpx;
  601. font-weight: bold;
  602. margin-bottom: 10rpx;
  603. }
  604. .job-details {
  605. display: flex;
  606. justify-content: space-between;
  607. font-size: 24rpx;
  608. color: #666;
  609. }
  610. .job-salary {
  611. color: #ff6b6b;
  612. }
  613. .apply-btn {
  614. width: 100%;
  615. height: 90rpx;
  616. line-height: 90rpx;
  617. background-color: #6c5ce7;
  618. color: #fff;
  619. border-radius: 45rpx;
  620. font-size: 32rpx;
  621. margin-top: 40rpx;
  622. }
  623. .apply-btn[disabled] {
  624. background-color: #b2b2b2;
  625. color: #fff;
  626. }
  627. </style>