index.vue 17 KB

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