index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const api_user = require("../../api/user.js");
  4. const _sfc_main = {
  5. data() {
  6. return {
  7. formData: {
  8. name: "",
  9. gender: "",
  10. phone: "",
  11. email: "",
  12. idCard: "",
  13. emergencyContact: "",
  14. emergencyPhone: "",
  15. relation: ""
  16. },
  17. relationOptions: ["父母", "配偶", "子女", "兄弟姐妹", "朋友", "其他"],
  18. relationIndex: 0,
  19. isAgreed: false,
  20. userInfoFilled: false,
  21. jobList: [],
  22. selectedJobId: null,
  23. selectedJob: null
  24. };
  25. },
  26. onLoad() {
  27. this.checkUserInfo();
  28. this.fetchJobList();
  29. },
  30. computed: {
  31. canSubmit() {
  32. 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;
  33. }
  34. },
  35. methods: {
  36. goHome() {
  37. common_vendor.index.navigateBack({
  38. delta: 1
  39. });
  40. },
  41. toggleAgreement() {
  42. this.isAgreed = !this.isAgreed;
  43. },
  44. relationChange(e) {
  45. this.relationIndex = e.detail.value;
  46. this.formData.relation = this.relationOptions[this.relationIndex];
  47. },
  48. checkUserInfo() {
  49. common_vendor.index.showLoading({
  50. title: "加载中..."
  51. });
  52. console.log("id:", JSON.parse(common_vendor.index.getStorageSync("userInfo")).id);
  53. api_user.getUserInfo(JSON.parse(common_vendor.index.getStorageSync("userInfo")).id).then((res) => {
  54. common_vendor.index.hideLoading();
  55. if (res.code === 200 && res.data) {
  56. const userData = res.data;
  57. if (userData.name && userData.phone) {
  58. this.userInfoFilled = true;
  59. this.formData.name = userData.name || "";
  60. this.formData.gender = userData.gender || "";
  61. this.formData.phone = userData.phone || "";
  62. this.formData.idCard = userData.id_card || "";
  63. this.formData.emergencyContact = userData.emergency_contact || "";
  64. this.formData.emergencyPhone = userData.emergency_phone || "";
  65. this.formData.relation = userData.relation || "";
  66. if (userData.relation) {
  67. const index = this.relationOptions.findIndex((item) => item === userData.relation);
  68. if (index !== -1) {
  69. this.relationIndex = index;
  70. }
  71. }
  72. common_vendor.index.navigateTo({
  73. url: "/pages/success/success"
  74. });
  75. }
  76. }
  77. }).catch((err) => {
  78. common_vendor.index.hideLoading();
  79. console.error("获取用户信息失败:", err);
  80. common_vendor.index.showToast({
  81. title: "获取用户信息失败",
  82. icon: "none"
  83. });
  84. });
  85. },
  86. fetchJobList() {
  87. common_vendor.index.showLoading({
  88. title: "加载职位列表..."
  89. });
  90. api_user.getJobList().then((res) => {
  91. common_vendor.index.hideLoading();
  92. console.log(res);
  93. this.jobList = res;
  94. }).catch((err) => {
  95. common_vendor.index.hideLoading();
  96. console.error("获取职位列表失败:", err);
  97. common_vendor.index.showToast({
  98. title: "网络错误,请稍后重试",
  99. icon: "none"
  100. });
  101. });
  102. },
  103. selectJob(job) {
  104. this.selectedJobId = job.id;
  105. this.selectedJob = job;
  106. },
  107. applyForJob() {
  108. if (!this.selectedJobId) {
  109. common_vendor.index.showToast({
  110. title: "请选择一个职位",
  111. icon: "none"
  112. });
  113. return;
  114. }
  115. common_vendor.index.setStorageSync("selectedJob", JSON.stringify(this.selectedJob));
  116. api_user.applyJob({
  117. job_id: this.selectedJobId,
  118. tenant_id: 1,
  119. openid: JSON.parse(common_vendor.index.getStorageSync("userInfo")).openid
  120. }).then((res) => {
  121. common_vendor.index.navigateTo({
  122. url: "/pages/interview-notice/interview-notice",
  123. fail: (err) => {
  124. console.error("页面跳转失败:", err);
  125. common_vendor.index.showToast({
  126. title: "页面跳转失败",
  127. icon: "none"
  128. });
  129. }
  130. });
  131. }).catch((err) => {
  132. console.error("申请职位失败:", err);
  133. });
  134. },
  135. submitForm() {
  136. if (!this.formData.name.trim()) {
  137. common_vendor.index.showToast({
  138. title: "请输入姓名",
  139. icon: "none"
  140. });
  141. return;
  142. }
  143. if (!this.formData.gender) {
  144. common_vendor.index.showToast({
  145. title: "请选择性别",
  146. icon: "none"
  147. });
  148. return;
  149. }
  150. if (!this.formData.phone.trim()) {
  151. common_vendor.index.showToast({
  152. title: "请输入手机号",
  153. icon: "none"
  154. });
  155. return;
  156. }
  157. if (!/^1\d{10}$/.test(this.formData.phone)) {
  158. common_vendor.index.showToast({
  159. title: "请输入正确的手机号",
  160. icon: "none"
  161. });
  162. return;
  163. }
  164. if (this.formData.email && !/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/.test(this.formData.email)) {
  165. common_vendor.index.showToast({
  166. title: "请输入正确的邮箱",
  167. icon: "none"
  168. });
  169. return;
  170. }
  171. if (!this.formData.idCard.trim()) {
  172. common_vendor.index.showToast({
  173. title: "请输入身份证号",
  174. icon: "none"
  175. });
  176. return;
  177. }
  178. const idCardReg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
  179. if (!idCardReg.test(this.formData.idCard)) {
  180. common_vendor.index.showToast({
  181. title: "请输入正确的身份证号",
  182. icon: "none"
  183. });
  184. return;
  185. }
  186. if (!this.formData.emergencyContact.trim()) {
  187. common_vendor.index.showToast({
  188. title: "请输入紧急联系人",
  189. icon: "none"
  190. });
  191. return;
  192. }
  193. if (!this.formData.emergencyPhone.trim()) {
  194. common_vendor.index.showToast({
  195. title: "请输入紧急联系人电话",
  196. icon: "none"
  197. });
  198. return;
  199. }
  200. if (!/^1\d{10}$/.test(this.formData.emergencyPhone)) {
  201. common_vendor.index.showToast({
  202. title: "请输入正确的紧急联系人电话",
  203. icon: "none"
  204. });
  205. return;
  206. }
  207. if (!this.formData.relation) {
  208. common_vendor.index.showToast({
  209. title: "请选择与紧急联系人关系",
  210. icon: "none"
  211. });
  212. return;
  213. }
  214. if (!this.isAgreed) {
  215. common_vendor.index.showToast({
  216. title: "请阅读并同意相关协议",
  217. icon: "none"
  218. });
  219. return;
  220. }
  221. const submitData = {
  222. openid: JSON.parse(common_vendor.index.getStorageSync("userInfo")).openid || "",
  223. name: this.formData.name,
  224. phone: this.formData.phone,
  225. id_card: this.formData.idCard,
  226. status: 1,
  227. source: "mini",
  228. examine: 0,
  229. tenant_id: "1",
  230. emergency_contact: this.formData.emergencyContact,
  231. emergency_phone: this.formData.emergencyPhone,
  232. relation: this.formData.relation,
  233. age: "20",
  234. job_id: this.selectedJobId
  235. };
  236. common_vendor.index.showLoading({
  237. title: "提交中..."
  238. });
  239. api_user.fillUserInfo(submitData).then((res) => {
  240. common_vendor.index.hideLoading();
  241. this.updateLocalUserInfo();
  242. common_vendor.index.showToast({
  243. title: "提交成功",
  244. icon: "success",
  245. duration: 1500,
  246. success: () => {
  247. setTimeout(() => {
  248. common_vendor.index.navigateTo({
  249. url: "/pages/success/success",
  250. fail: (err) => {
  251. console.error("页面跳转失败:", err);
  252. common_vendor.index.showToast({
  253. title: "页面跳转失败",
  254. icon: "none"
  255. });
  256. }
  257. });
  258. }, 1500);
  259. }
  260. });
  261. }).catch((err) => {
  262. common_vendor.index.hideLoading();
  263. console.error("提交表单失败:", err);
  264. common_vendor.index.showToast({
  265. title: "网络错误,请稍后重试",
  266. icon: "none"
  267. });
  268. });
  269. },
  270. updateLocalUserInfo() {
  271. api_user.getUserInfo().then((res) => {
  272. if (res.code === 200 && res.data) {
  273. let userInfo = {};
  274. try {
  275. userInfo = JSON.parse(common_vendor.index.getStorageSync("userInfo") || "{}");
  276. } catch (e) {
  277. console.error("解析本地存储用户信息失败:", e);
  278. userInfo = {};
  279. }
  280. const updatedUserInfo = {
  281. ...userInfo,
  282. ...res.data
  283. };
  284. common_vendor.index.setStorageSync("userInfo", JSON.stringify(updatedUserInfo));
  285. }
  286. }).catch((err) => {
  287. console.error("更新本地用户信息失败:", err);
  288. });
  289. }
  290. }
  291. };
  292. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  293. return common_vendor.e({
  294. a: !$data.userInfoFilled
  295. }, !$data.userInfoFilled ? {
  296. b: common_vendor.f($data.jobList, (job, index, i0) => {
  297. return {
  298. a: common_vendor.t(job.title),
  299. b: common_vendor.t(job.publish_date),
  300. c: common_vendor.t(job.location),
  301. d: index,
  302. e: $data.selectedJobId === job.id ? 1 : "",
  303. f: common_vendor.o(($event) => $options.selectJob(job), index)
  304. };
  305. }),
  306. c: !$data.selectedJobId,
  307. d: common_vendor.o((...args) => $options.applyForJob && $options.applyForJob(...args))
  308. } : {}, {
  309. e: $data.userInfoFilled
  310. }, $data.userInfoFilled ? {
  311. f: $data.formData.name,
  312. g: common_vendor.o(($event) => $data.formData.name = $event.detail.value),
  313. h: $data.formData.gender === "男" ? 1 : "",
  314. i: common_vendor.o(($event) => $data.formData.gender = "男"),
  315. j: $data.formData.gender === "女" ? 1 : "",
  316. k: common_vendor.o(($event) => $data.formData.gender = "女"),
  317. l: $data.formData.idCard,
  318. m: common_vendor.o(($event) => $data.formData.idCard = $event.detail.value),
  319. n: $data.formData.phone,
  320. o: common_vendor.o(($event) => $data.formData.phone = $event.detail.value),
  321. p: $data.formData.emergencyContact,
  322. q: common_vendor.o(($event) => $data.formData.emergencyContact = $event.detail.value),
  323. r: $data.formData.emergencyPhone,
  324. s: common_vendor.o(($event) => $data.formData.emergencyPhone = $event.detail.value),
  325. t: common_vendor.t($data.formData.relation || "请选择关系"),
  326. v: common_vendor.o((...args) => $options.relationChange && $options.relationChange(...args)),
  327. w: $data.relationIndex,
  328. x: $data.relationOptions,
  329. y: $data.isAgreed,
  330. z: common_vendor.o((...args) => $options.toggleAgreement && $options.toggleAgreement(...args)),
  331. A: !$options.canSubmit,
  332. B: common_vendor.o((...args) => $options.submitForm && $options.submitForm(...args))
  333. } : {});
  334. }
  335. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
  336. wx.createPage(MiniProgramPage);