index.vue 16 KB

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