index.vue 18 KB

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