index.vue 17 KB

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