index.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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 = res;
  169. }).catch((err) => {
  170. common_vendor.index.hideLoading();
  171. console.error("获取职位列表失败:", err);
  172. common_vendor.index.showToast({
  173. title: "网络错误,请稍后重试",
  174. icon: "none"
  175. });
  176. });
  177. },
  178. selectJob(job) {
  179. try {
  180. common_vendor.index.removeStorageSync("interviewQuestions");
  181. common_vendor.index.removeStorageSync("currentQuestionIndex");
  182. } catch (e) {
  183. console.error("清除问题缓存失败:", e);
  184. }
  185. this.selectedJobId = job.id;
  186. this.selectedJob = job;
  187. common_vendor.index.setStorageSync("selectedJob", JSON.stringify(job));
  188. console.log("已选择职位:", job.id, job.title);
  189. },
  190. applyForJob() {
  191. if (!this.checkLogin()) {
  192. return;
  193. }
  194. if (!this.selectedJobId) {
  195. common_vendor.index.showToast({
  196. title: "请选择一个职位",
  197. icon: "none"
  198. });
  199. return;
  200. }
  201. common_vendor.index.setStorageSync("selectedJob", JSON.stringify(this.selectedJob));
  202. api_user.applyJob({
  203. job_id: this.selectedJobId,
  204. tenant_id: 1,
  205. openid: JSON.parse(common_vendor.index.getStorageSync("userInfo")).openid
  206. }).then((res) => {
  207. if (res && res.id) {
  208. common_vendor.index.setStorageSync("appId", res.id);
  209. try {
  210. const userInfo = JSON.parse(common_vendor.index.getStorageSync("userInfo") || "{}");
  211. userInfo.appId = res.id;
  212. common_vendor.index.setStorageSync("userInfo", JSON.stringify(userInfo));
  213. } catch (e) {
  214. console.error("更新用户信息失败:", e);
  215. }
  216. }
  217. common_vendor.index.navigateTo({
  218. url: "/pages/Personal/Personal",
  219. fail: (err) => {
  220. console.error("页面跳转失败:", err);
  221. common_vendor.index.showToast({
  222. title: "页面跳转失败",
  223. icon: "none"
  224. });
  225. }
  226. });
  227. }).catch((err) => {
  228. console.error("申请职位失败:", err);
  229. common_vendor.index.showToast({
  230. title: "申请职位失败,请重试",
  231. icon: "none"
  232. });
  233. });
  234. },
  235. submitForm() {
  236. if (!this.checkLogin()) {
  237. return;
  238. }
  239. if (!this.formData.name.trim()) {
  240. common_vendor.index.showToast({
  241. title: "请输入姓名",
  242. icon: "none"
  243. });
  244. return;
  245. }
  246. if (!this.formData.gender) {
  247. common_vendor.index.showToast({
  248. title: "请选择性别",
  249. icon: "none"
  250. });
  251. return;
  252. }
  253. if (!this.formData.phone.trim()) {
  254. common_vendor.index.showToast({
  255. title: "请输入手机号",
  256. icon: "none"
  257. });
  258. return;
  259. }
  260. if (!/^1\d{10}$/.test(this.formData.phone)) {
  261. common_vendor.index.showToast({
  262. title: "请输入正确的手机号",
  263. icon: "none"
  264. });
  265. return;
  266. }
  267. if (!this.formData.idCard.trim()) {
  268. common_vendor.index.showToast({
  269. title: "请输入身份证号",
  270. icon: "none"
  271. });
  272. return;
  273. }
  274. const idCardReg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
  275. if (!idCardReg.test(this.formData.idCard)) {
  276. common_vendor.index.showToast({
  277. title: "请输入正确的身份证号",
  278. icon: "none"
  279. });
  280. return;
  281. }
  282. if (!this.isAgreed) {
  283. common_vendor.index.showToast({
  284. title: "请阅读并同意相关协议",
  285. icon: "none"
  286. });
  287. return;
  288. }
  289. common_vendor.index.showLoading({
  290. title: "验证身份信息..."
  291. });
  292. common_vendor.index.request({
  293. url: `${common_config.apiBaseUrl}/wechat/identity/verify`,
  294. method: "POST",
  295. data: {
  296. name: this.formData.name,
  297. id_number: this.formData.idCard,
  298. mobile: this.formData.phone
  299. },
  300. header: {
  301. "content-type": "application/x-www-form-urlencoded"
  302. },
  303. success: (res) => {
  304. console.log(res);
  305. if (res.statusCode === 200) {
  306. if (res.data.code === 200) {
  307. this.submitUserInfo();
  308. } else {
  309. common_vendor.index.showToast({
  310. title: res.data.data.message,
  311. icon: "none"
  312. });
  313. }
  314. } else {
  315. common_vendor.index.hideLoading();
  316. common_vendor.index.showToast({
  317. title: "身份验证失败,请检查信息是否正确",
  318. icon: "none"
  319. });
  320. }
  321. },
  322. fail: (err) => {
  323. common_vendor.index.hideLoading();
  324. console.error("身份验证失败:", err);
  325. common_vendor.index.showToast({
  326. title: "网络错误,请稍后重试",
  327. icon: "none"
  328. });
  329. }
  330. });
  331. },
  332. submitUserInfo() {
  333. const genderValue = this.genderMapping[this.formData.gender] || this.formData.gender;
  334. const submitData = {
  335. openid: JSON.parse(common_vendor.index.getStorageSync("userInfo") || "{}").openid || "",
  336. name: this.formData.name,
  337. phone: this.formData.phone,
  338. id_card: this.formData.idCard,
  339. status: 1,
  340. source: "mini",
  341. examine: 0,
  342. tenant_id: "1",
  343. /* emergency_contact: this.formData.emergencyContact,
  344. emergency_phone: this.formData.emergencyPhone,
  345. relation: this.formData.relation, */
  346. age: "20",
  347. job_id: this.selectedJobId,
  348. gender: genderValue
  349. };
  350. api_user.fillUserInfo(submitData).then((res) => {
  351. common_vendor.index.hideLoading();
  352. this.updateLocalUserInfo(res.id, JSON.parse(common_vendor.index.getStorageSync("userInfo")).openid);
  353. common_vendor.index.showToast({
  354. title: "提交成功",
  355. icon: "success",
  356. duration: 1500,
  357. success: () => {
  358. this.userInfoFilled = false;
  359. }
  360. });
  361. }).catch((err) => {
  362. common_vendor.index.hideLoading();
  363. console.error("提交表单失败:", err);
  364. common_vendor.index.showToast({
  365. title: "网络错误,请稍后重试",
  366. icon: "none"
  367. });
  368. });
  369. },
  370. updateLocalUserInfo(data) {
  371. api_user.getUserInfo(data).then((res) => {
  372. if (res.code === 200 && res.data) {
  373. let userInfo = {};
  374. try {
  375. userInfo = JSON.parse(common_vendor.index.getStorageSync("userInfo") || "{}");
  376. } catch (e) {
  377. console.error("解析本地存储用户信息失败:", e);
  378. userInfo = {};
  379. }
  380. const updatedUserInfo = {
  381. ...userInfo,
  382. ...res.data
  383. };
  384. common_vendor.index.setStorageSync("userInfo", JSON.stringify(updatedUserInfo));
  385. }
  386. }).catch((err) => {
  387. console.error("更新本地用户信息失败:", err);
  388. });
  389. },
  390. validatePhone() {
  391. this.isPhoneValid = /^1\d{10}$/.test(this.formData.phone);
  392. },
  393. validateName() {
  394. this.isNameValid = this.formData.name.trim().length >= 2;
  395. },
  396. validateIdCard() {
  397. const idCardReg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
  398. this.isIdCardValid = idCardReg.test(this.formData.idCard);
  399. },
  400. genderChange(e) {
  401. this.genderIndex = e.detail.value;
  402. const displayGender = this.genderOptions[this.genderIndex];
  403. this.formData.gender = displayGender;
  404. }
  405. }
  406. };
  407. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  408. return {
  409. a: common_vendor.f($data.jobList, (job, index, i0) => {
  410. return {
  411. a: common_vendor.t(job.title),
  412. b: common_vendor.t(job.publish_date),
  413. c: common_vendor.t(job.location),
  414. d: index,
  415. e: $data.selectedJobId === job.id ? 1 : "",
  416. f: common_vendor.o(($event) => $options.selectJob(job), index)
  417. };
  418. }),
  419. b: !$data.selectedJobId,
  420. c: common_vendor.o((...args) => $options.applyForJob && $options.applyForJob(...args))
  421. };
  422. }
  423. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
  424. wx.createPage(MiniProgramPage);