index.js 21 KB

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