index.js 20 KB

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