index.js 21 KB

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