index.vue 17 KB

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