index.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const common_config = require("../../common/config.js");
  4. const api_user = require("../../api/user.js");
  5. const _sfc_main = {
  6. data() {
  7. return {
  8. formData: {
  9. name: "",
  10. gender: "",
  11. phone: "",
  12. email: "",
  13. idCard: "",
  14. emergencyContact: "",
  15. emergencyPhone: "",
  16. relation: ""
  17. },
  18. relationOptions: ["父母", "配偶", "子女", "兄弟姐妹", "朋友", "其他"],
  19. relationIndex: 0,
  20. isAgreed: false,
  21. userInfoFilled: false,
  22. jobList: [],
  23. selectedJobId: null,
  24. selectedJob: null,
  25. isPhoneValid: false,
  26. isNameValid: false,
  27. isIdCardValid: false,
  28. genderOptions: ["男", "女"],
  29. genderIndex: 0,
  30. genderMapping: {
  31. "男": "1",
  32. "女": "2",
  33. "1": "男",
  34. "2": "女"
  35. }
  36. };
  37. },
  38. onLoad(options) {
  39. console.log("options:", options);
  40. if (options.scene) {
  41. const scene = decodeURIComponent(options.scene);
  42. console.log("解码后的scene:", scene);
  43. const sceneParams = {};
  44. scene.split("&").forEach((pair) => {
  45. const [key, value] = pair.split("=");
  46. sceneParams[key] = value;
  47. });
  48. console.log("解析后的参数:", sceneParams);
  49. }
  50. this.checkUserInfo();
  51. this.fetchJobList();
  52. },
  53. computed: {
  54. canSubmit() {
  55. return this.formData.name.trim() && this.formData.gender && this.formData.phone.trim() && /^1\d{10}$/.test(this.formData.phone) && (!this.formData.email || /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/.test(this.formData.email)) && this.formData.idCard.trim() && this.formData.emergencyContact.trim() && this.formData.emergencyPhone.trim() && /^1\d{10}$/.test(this.formData.emergencyPhone) && this.formData.relation && this.isAgreed;
  56. },
  57. canSubmitSimple() {
  58. return this.formData.name.trim() && this.formData.phone.trim() && this.isPhoneValid && this.formData.idCard.trim() && this.isIdCardValid && this.isAgreed;
  59. }
  60. },
  61. methods: {
  62. checkLogin() {
  63. const userInfo = common_vendor.index.getStorageSync("userInfo");
  64. if (!userInfo) {
  65. common_vendor.index.reLaunch({
  66. url: "/pages/login/login",
  67. success: () => {
  68. console.log("跳转到身份验证登录页面成功");
  69. },
  70. fail: (err) => {
  71. console.error("跳转到身份验证登录页面失败:", err);
  72. common_vendor.index.showToast({
  73. title: "跳转失败,请重试",
  74. icon: "none"
  75. });
  76. }
  77. });
  78. return false;
  79. }
  80. try {
  81. const parsedUserInfo = JSON.parse(userInfo);
  82. if (!parsedUserInfo.openid) {
  83. common_vendor.index.navigateTo({
  84. url: "/pages/login/login"
  85. });
  86. return false;
  87. }
  88. return true;
  89. } catch (e) {
  90. console.error("解析用户信息失败:", e);
  91. common_vendor.index.removeStorageSync("userInfo");
  92. common_vendor.index.navigateTo({
  93. url: "/pages/login/login"
  94. });
  95. return false;
  96. }
  97. },
  98. goHome() {
  99. common_vendor.index.navigateBack({
  100. delta: 1
  101. });
  102. },
  103. toggleAgreement() {
  104. this.isAgreed = !this.isAgreed;
  105. },
  106. relationChange(e) {
  107. this.relationIndex = e.detail.value;
  108. this.formData.relation = this.relationOptions[this.relationIndex];
  109. },
  110. checkUserInfo() {
  111. common_vendor.index.showLoading({
  112. title: "加载中..."
  113. });
  114. try {
  115. const userInfo = JSON.parse(common_vendor.index.getStorageSync("userInfo"));
  116. console.log("id:", userInfo.id);
  117. api_user.getUserInfo(userInfo.id, userInfo.openid).then((res) => {
  118. common_vendor.index.hideLoading();
  119. const userData = res;
  120. if (!userData.name || !userData.phone) {
  121. this.userInfoFilled = true;
  122. this.formData.name = userData.name || "";
  123. if (userData.gender) {
  124. this.formData.gender = this.genderMapping[userData.gender] || userData.gender;
  125. const index = this.genderOptions.findIndex((item) => item === this.formData.gender);
  126. if (index !== -1) {
  127. this.genderIndex = index;
  128. }
  129. } else {
  130. this.formData.gender = "";
  131. }
  132. this.formData.phone = userData.phone || "";
  133. this.formData.idCard = userData.id_card || "";
  134. this.formData.emergencyContact = userData.emergency_contact || "";
  135. this.formData.emergencyPhone = userData.emergency_phone || "";
  136. this.formData.relation = userData.relation || "";
  137. if (userData.relation) {
  138. const index = this.relationOptions.findIndex((item) => item === userData.relation);
  139. if (index !== -1) {
  140. this.relationIndex = index;
  141. }
  142. }
  143. }
  144. }).catch((err) => {
  145. common_vendor.index.hideLoading();
  146. console.error("获取用户信息失败:", err);
  147. common_vendor.index.showToast({
  148. title: "获取用户信息失败",
  149. icon: "none"
  150. });
  151. });
  152. } catch (e) {
  153. common_vendor.index.hideLoading();
  154. console.error("获取用户信息失败:", e);
  155. common_vendor.index.showToast({
  156. title: "获取用户信息失败",
  157. icon: "none"
  158. });
  159. }
  160. },
  161. fetchJobList() {
  162. common_vendor.index.showLoading({
  163. title: "加载职位列表..."
  164. });
  165. api_user.getJobList().then((res) => {
  166. common_vendor.index.hideLoading();
  167. console.log("职位列表数据:", res);
  168. this.jobList = Array.isArray(res) ? res.filter((job) => job !== null && job !== void 0) : [];
  169. if (this.jobList.length === 0) {
  170. common_vendor.index.showToast({
  171. title: "暂无可用职位",
  172. icon: "none"
  173. });
  174. }
  175. }).catch((err) => {
  176. common_vendor.index.hideLoading();
  177. console.error("获取职位列表失败:", err);
  178. this.jobList = [];
  179. common_vendor.index.showToast({
  180. title: "网络错误,请稍后重试",
  181. icon: "none"
  182. });
  183. });
  184. },
  185. selectJob(job) {
  186. try {
  187. common_vendor.index.removeStorageSync("interviewQuestions");
  188. common_vendor.index.removeStorageSync("currentQuestionIndex");
  189. } catch (e) {
  190. console.error("清除问题缓存失败:", e);
  191. }
  192. this.selectedJobId = job.id;
  193. this.selectedJob = job;
  194. common_vendor.index.setStorageSync("selectedJob", JSON.stringify(job));
  195. console.log("已选择职位:", job.id, job.title);
  196. },
  197. // 获取当前职位配置
  198. getConfig() {
  199. common_vendor.index.request({
  200. url: `${common_config.apiBaseUrl}/api/job/config/position/${this.selectedJobId}`,
  201. method: "GET",
  202. data: {
  203. openid: JSON.parse(common_vendor.index.getStorageSync("userInfo")).openid
  204. },
  205. header: {
  206. "content-type": "application/x-www-form-urlencoded"
  207. },
  208. success: (res) => {
  209. console.log(res);
  210. if (res.statusCode === 200) {
  211. if (res.data.code === 2e3) {
  212. common_vendor.index.setStorageSync("configData", JSON.stringify(res.data.data));
  213. const openid = JSON.parse(common_vendor.index.getStorageSync("userInfo")).openid;
  214. common_vendor.index.request({
  215. url: `${common_config.apiBaseUrl}/api/wechat/user/get_full_info?tenant_id=1&openid=${openid}`,
  216. method: "GET",
  217. success: (infoRes) => {
  218. if (infoRes.statusCode === 200 && infoRes.data && infoRes.data.data && infoRes.data.data.profile) {
  219. const resumeUrl = infoRes.data.data.profile.resume_url || "";
  220. if (!resumeUrl) {
  221. common_vendor.index.navigateTo({
  222. url: "/pages/uploadResume/uploadResume",
  223. // 假设跳转到上传简历页面
  224. fail: (err) => {
  225. console.error("页面跳转失败:", err);
  226. common_vendor.index.showToast({
  227. title: "页面跳转失败",
  228. icon: "none"
  229. });
  230. }
  231. });
  232. } else {
  233. common_vendor.index.navigateTo({
  234. url: "/pages/Personal/Personal",
  235. fail: (err) => {
  236. console.error("页面跳转失败:", err);
  237. common_vendor.index.showToast({
  238. title: "页面跳转失败",
  239. icon: "none"
  240. });
  241. }
  242. });
  243. }
  244. } else {
  245. common_vendor.index.navigateTo({
  246. url: "/pages/Personal/Personal",
  247. fail: (err) => {
  248. console.error("页面跳转失败:", err);
  249. common_vendor.index.showToast({
  250. title: "页面跳转失败",
  251. icon: "none"
  252. });
  253. }
  254. });
  255. }
  256. },
  257. fail: (err) => {
  258. console.error("获取用户信息失败:", err);
  259. common_vendor.index.navigateTo({
  260. url: "/pages/Personal/Personal",
  261. fail: (err2) => {
  262. console.error("页面跳转失败:", err2);
  263. common_vendor.index.showToast({
  264. title: "页面跳转失败",
  265. icon: "none"
  266. });
  267. }
  268. });
  269. }
  270. });
  271. }
  272. } else {
  273. common_vendor.index.hideLoading();
  274. }
  275. },
  276. fail: (err) => {
  277. common_vendor.index.hideLoading();
  278. common_vendor.index.showToast({
  279. title: "网络错误,请稍后重试",
  280. icon: "none"
  281. });
  282. }
  283. });
  284. },
  285. applyForJob() {
  286. if (!this.checkLogin()) {
  287. return;
  288. }
  289. if (!this.selectedJobId) {
  290. common_vendor.index.showToast({
  291. title: "请选择一个职位",
  292. icon: "none"
  293. });
  294. return;
  295. }
  296. common_vendor.index.setStorageSync("selectedJob", JSON.stringify(this.selectedJob));
  297. api_user.applyJob({
  298. job_id: this.selectedJobId,
  299. tenant_id: 1,
  300. openid: JSON.parse(common_vendor.index.getStorageSync("userInfo")).openid
  301. }).then((res) => {
  302. if (res && res.id) {
  303. common_vendor.index.setStorageSync("appId", res.id);
  304. try {
  305. const userInfo = JSON.parse(common_vendor.index.getStorageSync("userInfo") || "{}");
  306. userInfo.appId = res.id;
  307. common_vendor.index.setStorageSync("userInfo", JSON.stringify(userInfo));
  308. } catch (e) {
  309. console.error("更新用户信息失败:", e);
  310. }
  311. }
  312. this.getConfig();
  313. }).catch((err) => {
  314. console.error("申请职位失败:", err);
  315. common_vendor.index.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. common_vendor.index.showToast({
  327. title: "请输入姓名",
  328. icon: "none"
  329. });
  330. return;
  331. }
  332. if (!this.formData.gender) {
  333. common_vendor.index.showToast({
  334. title: "请选择性别",
  335. icon: "none"
  336. });
  337. return;
  338. }
  339. if (!this.formData.phone.trim()) {
  340. common_vendor.index.showToast({
  341. title: "请输入手机号",
  342. icon: "none"
  343. });
  344. return;
  345. }
  346. if (!/^1\d{10}$/.test(this.formData.phone)) {
  347. common_vendor.index.showToast({
  348. title: "请输入正确的手机号",
  349. icon: "none"
  350. });
  351. return;
  352. }
  353. if (!this.formData.idCard.trim()) {
  354. common_vendor.index.showToast({
  355. title: "请输入身份证号",
  356. icon: "none"
  357. });
  358. return;
  359. }
  360. const idCardReg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
  361. if (!idCardReg.test(this.formData.idCard)) {
  362. common_vendor.index.showToast({
  363. title: "请输入正确的身份证号",
  364. icon: "none"
  365. });
  366. return;
  367. }
  368. if (!this.isAgreed) {
  369. common_vendor.index.showToast({
  370. title: "请阅读并同意相关协议",
  371. icon: "none"
  372. });
  373. return;
  374. }
  375. common_vendor.index.showLoading({
  376. title: "验证身份信息..."
  377. });
  378. common_vendor.index.request({
  379. url: `${common_config.apiBaseUrl}/wechat/identity/verify`,
  380. method: "POST",
  381. data: {
  382. name: this.formData.name,
  383. id_number: this.formData.idCard,
  384. mobile: this.formData.phone
  385. },
  386. header: {
  387. "content-type": "application/x-www-form-urlencoded"
  388. },
  389. success: (res) => {
  390. console.log(res);
  391. if (res.statusCode === 200) {
  392. if (res.data.code === 200) {
  393. this.submitUserInfo();
  394. } else {
  395. common_vendor.index.showToast({
  396. title: res.data.data.message,
  397. icon: "none"
  398. });
  399. }
  400. } else {
  401. common_vendor.index.hideLoading();
  402. common_vendor.index.showToast({
  403. title: "身份验证失败,请检查信息是否正确",
  404. icon: "none"
  405. });
  406. }
  407. },
  408. fail: (err) => {
  409. common_vendor.index.hideLoading();
  410. console.error("身份验证失败:", err);
  411. common_vendor.index.showToast({
  412. title: "网络错误,请稍后重试",
  413. icon: "none"
  414. });
  415. }
  416. });
  417. },
  418. submitUserInfo() {
  419. const genderValue = this.genderMapping[this.formData.gender] || this.formData.gender;
  420. const submitData = {
  421. openid: JSON.parse(common_vendor.index.getStorageSync("userInfo") || "{}").openid || "",
  422. name: this.formData.name,
  423. phone: this.formData.phone,
  424. id_card: this.formData.idCard,
  425. status: 1,
  426. source: "mini",
  427. examine: 0,
  428. tenant_id: "1",
  429. /* emergency_contact: this.formData.emergencyContact,
  430. emergency_phone: this.formData.emergencyPhone,
  431. relation: this.formData.relation, */
  432. age: "20",
  433. job_id: this.selectedJobId,
  434. gender: genderValue
  435. };
  436. api_user.fillUserInfo(submitData).then((res) => {
  437. common_vendor.index.hideLoading();
  438. this.updateLocalUserInfo(res.id, JSON.parse(common_vendor.index.getStorageSync("userInfo")).openid);
  439. common_vendor.index.showToast({
  440. title: "提交成功",
  441. icon: "success",
  442. duration: 1500,
  443. success: () => {
  444. this.userInfoFilled = false;
  445. }
  446. });
  447. }).catch((err) => {
  448. common_vendor.index.hideLoading();
  449. console.error("提交表单失败:", err);
  450. common_vendor.index.showToast({
  451. title: "网络错误,请稍后重试",
  452. icon: "none"
  453. });
  454. });
  455. },
  456. updateLocalUserInfo(data) {
  457. api_user.getUserInfo(data).then((res) => {
  458. if (res.code === 200 && res.data) {
  459. let userInfo = {};
  460. try {
  461. userInfo = JSON.parse(common_vendor.index.getStorageSync("userInfo") || "{}");
  462. } catch (e) {
  463. console.error("解析本地存储用户信息失败:", e);
  464. userInfo = {};
  465. }
  466. const updatedUserInfo = {
  467. ...userInfo,
  468. ...res.data
  469. };
  470. common_vendor.index.setStorageSync("userInfo", JSON.stringify(updatedUserInfo));
  471. }
  472. }).catch((err) => {
  473. console.error("更新本地用户信息失败:", err);
  474. });
  475. },
  476. validatePhone() {
  477. this.isPhoneValid = /^1\d{10}$/.test(this.formData.phone);
  478. },
  479. validateName() {
  480. this.isNameValid = this.formData.name.trim().length >= 2;
  481. },
  482. validateIdCard() {
  483. const idCardReg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
  484. this.isIdCardValid = idCardReg.test(this.formData.idCard);
  485. },
  486. genderChange(e) {
  487. this.genderIndex = e.detail.value;
  488. const displayGender = this.genderOptions[this.genderIndex];
  489. this.formData.gender = displayGender;
  490. },
  491. viewJobDetail(job) {
  492. common_vendor.index.setStorageSync("currentJobDetail", JSON.stringify(job));
  493. console.log(job);
  494. common_vendor.index.navigateTo({
  495. url: "/pages/job-detail/job-detail?id=" + job.id,
  496. fail: (err) => {
  497. console.error("页面跳转失败:", err);
  498. common_vendor.index.showToast({
  499. title: "页面跳转失败",
  500. icon: "none"
  501. });
  502. }
  503. });
  504. },
  505. formatLocation(location) {
  506. if (!location)
  507. return "";
  508. if (typeof location === "string" && location.startsWith("[")) {
  509. try {
  510. const locationArray = JSON.parse(location.replace(/'/g, '"'));
  511. return locationArray.join(" ");
  512. } catch (e) {
  513. console.error("解析location失败:", e);
  514. return location;
  515. }
  516. }
  517. if (Array.isArray(location)) {
  518. return location.join(" ");
  519. }
  520. if (typeof location === "object" && location !== null) {
  521. const { province, city, district } = location;
  522. if (province && city) {
  523. return province + " " + city + (district ? " " + district : "");
  524. }
  525. }
  526. return location;
  527. }
  528. }
  529. };
  530. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  531. return {
  532. a: common_vendor.f($data.jobList, (job, index, i0) => {
  533. return {
  534. a: common_vendor.t(job.title),
  535. b: common_vendor.o(($event) => $options.viewJobDetail(job), index),
  536. c: common_vendor.t($options.formatLocation(job.location)),
  537. d: index,
  538. e: $data.selectedJobId === job.id ? 1 : "",
  539. f: job.status == 1,
  540. g: common_vendor.o(($event) => $options.selectJob(job), index)
  541. };
  542. }),
  543. b: !$data.selectedJobId,
  544. c: common_vendor.o((...args) => $options.applyForJob && $options.applyForJob(...args))
  545. };
  546. }
  547. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
  548. wx.createPage(MiniProgramPage);