index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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. common_vendor.index.navigateTo({
  117. url: "/pages/interview-notice/interview-notice",
  118. fail: (err) => {
  119. console.error("页面跳转失败:", err);
  120. common_vendor.index.showToast({
  121. title: "页面跳转失败",
  122. icon: "none"
  123. });
  124. }
  125. });
  126. },
  127. submitForm() {
  128. if (!this.formData.name.trim()) {
  129. common_vendor.index.showToast({
  130. title: "请输入姓名",
  131. icon: "none"
  132. });
  133. return;
  134. }
  135. if (!this.formData.gender) {
  136. common_vendor.index.showToast({
  137. title: "请选择性别",
  138. icon: "none"
  139. });
  140. return;
  141. }
  142. if (!this.formData.phone.trim()) {
  143. common_vendor.index.showToast({
  144. title: "请输入手机号",
  145. icon: "none"
  146. });
  147. return;
  148. }
  149. if (!/^1\d{10}$/.test(this.formData.phone)) {
  150. common_vendor.index.showToast({
  151. title: "请输入正确的手机号",
  152. icon: "none"
  153. });
  154. return;
  155. }
  156. if (this.formData.email && !/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/.test(this.formData.email)) {
  157. common_vendor.index.showToast({
  158. title: "请输入正确的邮箱",
  159. icon: "none"
  160. });
  161. return;
  162. }
  163. if (!this.formData.idCard.trim()) {
  164. common_vendor.index.showToast({
  165. title: "请输入身份证号",
  166. icon: "none"
  167. });
  168. return;
  169. }
  170. const idCardReg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
  171. if (!idCardReg.test(this.formData.idCard)) {
  172. common_vendor.index.showToast({
  173. title: "请输入正确的身份证号",
  174. icon: "none"
  175. });
  176. return;
  177. }
  178. if (!this.formData.emergencyContact.trim()) {
  179. common_vendor.index.showToast({
  180. title: "请输入紧急联系人",
  181. icon: "none"
  182. });
  183. return;
  184. }
  185. if (!this.formData.emergencyPhone.trim()) {
  186. common_vendor.index.showToast({
  187. title: "请输入紧急联系人电话",
  188. icon: "none"
  189. });
  190. return;
  191. }
  192. if (!/^1\d{10}$/.test(this.formData.emergencyPhone)) {
  193. common_vendor.index.showToast({
  194. title: "请输入正确的紧急联系人电话",
  195. icon: "none"
  196. });
  197. return;
  198. }
  199. if (!this.formData.relation) {
  200. common_vendor.index.showToast({
  201. title: "请选择与紧急联系人关系",
  202. icon: "none"
  203. });
  204. return;
  205. }
  206. if (!this.isAgreed) {
  207. common_vendor.index.showToast({
  208. title: "请阅读并同意相关协议",
  209. icon: "none"
  210. });
  211. return;
  212. }
  213. const submitData = {
  214. openid: JSON.parse(common_vendor.index.getStorageSync("userInfo")).openid || "",
  215. name: this.formData.name,
  216. phone: this.formData.phone,
  217. id_card: this.formData.idCard,
  218. status: 1,
  219. source: "mini",
  220. examine: 0,
  221. tenant_id: "1",
  222. emergency_contact: this.formData.emergencyContact,
  223. emergency_phone: this.formData.emergencyPhone,
  224. relation: this.formData.relation,
  225. age: "20",
  226. job_id: this.selectedJobId
  227. };
  228. common_vendor.index.showLoading({
  229. title: "提交中..."
  230. });
  231. api_user.fillUserInfo(submitData).then((res) => {
  232. common_vendor.index.hideLoading();
  233. this.updateLocalUserInfo();
  234. common_vendor.index.showToast({
  235. title: "提交成功",
  236. icon: "success",
  237. duration: 1500,
  238. success: () => {
  239. setTimeout(() => {
  240. common_vendor.index.navigateTo({
  241. url: "/pages/success/success",
  242. fail: (err) => {
  243. console.error("页面跳转失败:", err);
  244. common_vendor.index.showToast({
  245. title: "页面跳转失败",
  246. icon: "none"
  247. });
  248. }
  249. });
  250. }, 1500);
  251. }
  252. });
  253. }).catch((err) => {
  254. common_vendor.index.hideLoading();
  255. console.error("提交表单失败:", err);
  256. common_vendor.index.showToast({
  257. title: "网络错误,请稍后重试",
  258. icon: "none"
  259. });
  260. });
  261. },
  262. updateLocalUserInfo() {
  263. api_user.getUserInfo().then((res) => {
  264. if (res.code === 200 && res.data) {
  265. let userInfo = {};
  266. try {
  267. userInfo = JSON.parse(common_vendor.index.getStorageSync("userInfo") || "{}");
  268. } catch (e) {
  269. console.error("解析本地存储用户信息失败:", e);
  270. userInfo = {};
  271. }
  272. const updatedUserInfo = {
  273. ...userInfo,
  274. ...res.data
  275. };
  276. common_vendor.index.setStorageSync("userInfo", JSON.stringify(updatedUserInfo));
  277. }
  278. }).catch((err) => {
  279. console.error("更新本地用户信息失败:", err);
  280. });
  281. }
  282. }
  283. };
  284. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  285. return common_vendor.e({
  286. a: !$data.userInfoFilled
  287. }, !$data.userInfoFilled ? {
  288. b: common_vendor.f($data.jobList, (job, index, i0) => {
  289. return {
  290. a: common_vendor.t(job.title),
  291. b: common_vendor.t(job.publish_date),
  292. c: common_vendor.t(job.location),
  293. d: index,
  294. e: $data.selectedJobId === job.id ? 1 : "",
  295. f: common_vendor.o(($event) => $options.selectJob(job), index)
  296. };
  297. }),
  298. c: !$data.selectedJobId,
  299. d: common_vendor.o((...args) => $options.applyForJob && $options.applyForJob(...args))
  300. } : {}, {
  301. e: $data.userInfoFilled
  302. }, $data.userInfoFilled ? {
  303. f: $data.formData.name,
  304. g: common_vendor.o(($event) => $data.formData.name = $event.detail.value),
  305. h: $data.formData.gender === "男" ? 1 : "",
  306. i: common_vendor.o(($event) => $data.formData.gender = "男"),
  307. j: $data.formData.gender === "女" ? 1 : "",
  308. k: common_vendor.o(($event) => $data.formData.gender = "女"),
  309. l: $data.formData.idCard,
  310. m: common_vendor.o(($event) => $data.formData.idCard = $event.detail.value),
  311. n: $data.formData.phone,
  312. o: common_vendor.o(($event) => $data.formData.phone = $event.detail.value),
  313. p: $data.formData.emergencyContact,
  314. q: common_vendor.o(($event) => $data.formData.emergencyContact = $event.detail.value),
  315. r: $data.formData.emergencyPhone,
  316. s: common_vendor.o(($event) => $data.formData.emergencyPhone = $event.detail.value),
  317. t: common_vendor.t($data.formData.relation || "请选择关系"),
  318. v: common_vendor.o((...args) => $options.relationChange && $options.relationChange(...args)),
  319. w: $data.relationIndex,
  320. x: $data.relationOptions,
  321. y: $data.isAgreed,
  322. z: common_vendor.o((...args) => $options.toggleAgreement && $options.toggleAgreement(...args)),
  323. A: !$options.canSubmit,
  324. B: common_vendor.o((...args) => $options.submitForm && $options.submitForm(...args))
  325. } : {});
  326. }
  327. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
  328. wx.createPage(MiniProgramPage);