"use strict"; const common_vendor = require("../../common/vendor.js"); const api_user = require("../../api/user.js"); const _sfc_main = { data() { return { formData: { name: "", gender: "", phone: "", email: "", idCard: "", emergencyContact: "", emergencyPhone: "", relation: "" }, relationOptions: ["父母", "配偶", "子女", "兄弟姐妹", "朋友", "其他"], relationIndex: 0, isAgreed: false, userInfoFilled: false, jobList: [], selectedJobId: null, selectedJob: null }; }, onLoad() { this.checkLogin(); this.checkUserInfo(); this.fetchJobList(); }, computed: { canSubmit() { 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; } }, methods: { checkLogin() { const userInfo = common_vendor.index.getStorageSync("userInfo"); if (!userInfo) { common_vendor.index.switchTab({ url: "/pages/my/my", success: () => { console.log("跳转到登录页面成功"); }, fail: (err) => { console.error("跳转到登录页面失败:", err); common_vendor.index.showToast({ title: "跳转失败,请重试", icon: "none" }); } }); return false; } try { const parsedUserInfo = JSON.parse(userInfo); if (!parsedUserInfo.openid) { common_vendor.index.switchTab({ url: "/pages/my/my" }); return false; } return true; } catch (e) { console.error("解析用户信息失败:", e); common_vendor.index.removeStorageSync("userInfo"); common_vendor.index.switchTab({ url: "/pages/my/my" }); return false; } }, goHome() { common_vendor.index.navigateBack({ delta: 1 }); }, toggleAgreement() { this.isAgreed = !this.isAgreed; }, relationChange(e) { this.relationIndex = e.detail.value; this.formData.relation = this.relationOptions[this.relationIndex]; }, checkUserInfo() { if (!this.checkLogin()) { return; } common_vendor.index.showLoading({ title: "加载中..." }); try { const userInfo = JSON.parse(common_vendor.index.getStorageSync("userInfo")); console.log("id:", userInfo.id); api_user.getUserInfo(userInfo.id).then((res) => { common_vendor.index.hideLoading(); if (res.code === 200 && res.data) { const userData = res.data; if (userData.name && userData.phone) { this.userInfoFilled = true; this.formData.name = userData.name || ""; this.formData.gender = userData.gender || ""; this.formData.phone = userData.phone || ""; this.formData.idCard = userData.id_card || ""; this.formData.emergencyContact = userData.emergency_contact || ""; this.formData.emergencyPhone = userData.emergency_phone || ""; this.formData.relation = userData.relation || ""; if (userData.relation) { const index = this.relationOptions.findIndex((item) => item === userData.relation); if (index !== -1) { this.relationIndex = index; } } common_vendor.index.navigateTo({ url: "/pages/success/success" }); } } }).catch((err) => { common_vendor.index.hideLoading(); console.error("获取用户信息失败:", err); common_vendor.index.showToast({ title: "获取用户信息失败", icon: "none" }); }); } catch (e) { common_vendor.index.hideLoading(); console.error("获取用户信息失败:", e); common_vendor.index.showToast({ title: "获取用户信息失败", icon: "none" }); common_vendor.index.navigateTo({ url: "/pages/my/my" }); } }, fetchJobList() { common_vendor.index.showLoading({ title: "加载职位列表..." }); api_user.getJobList().then((res) => { common_vendor.index.hideLoading(); console.log(res); this.jobList = res; }).catch((err) => { common_vendor.index.hideLoading(); console.error("获取职位列表失败:", err); common_vendor.index.showToast({ title: "网络错误,请稍后重试", icon: "none" }); }); }, selectJob(job) { this.selectedJobId = job.id; this.selectedJob = job; }, applyForJob() { if (!this.checkLogin()) { return; } if (!this.selectedJobId) { common_vendor.index.showToast({ title: "请选择一个职位", icon: "none" }); return; } common_vendor.index.setStorageSync("selectedJob", JSON.stringify(this.selectedJob)); api_user.applyJob({ job_id: this.selectedJobId, tenant_id: 1, openid: JSON.parse(common_vendor.index.getStorageSync("userInfo")).openid }).then((res) => { common_vendor.index.navigateTo({ url: "/pages/interview-notice/interview-notice", fail: (err) => { console.error("页面跳转失败:", err); common_vendor.index.showToast({ title: "页面跳转失败", icon: "none" }); } }); }).catch((err) => { console.error("申请职位失败:", err); }); }, submitForm() { if (!this.checkLogin()) { return; } if (!this.formData.name.trim()) { common_vendor.index.showToast({ title: "请输入姓名", icon: "none" }); return; } if (!this.formData.gender) { common_vendor.index.showToast({ title: "请选择性别", icon: "none" }); return; } if (!this.formData.phone.trim()) { common_vendor.index.showToast({ title: "请输入手机号", icon: "none" }); return; } if (!/^1\d{10}$/.test(this.formData.phone)) { common_vendor.index.showToast({ title: "请输入正确的手机号", icon: "none" }); return; } if (this.formData.email && !/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/.test(this.formData.email)) { common_vendor.index.showToast({ title: "请输入正确的邮箱", icon: "none" }); return; } if (!this.formData.idCard.trim()) { common_vendor.index.showToast({ title: "请输入身份证号", icon: "none" }); return; } const idCardReg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; if (!idCardReg.test(this.formData.idCard)) { common_vendor.index.showToast({ title: "请输入正确的身份证号", icon: "none" }); return; } if (!this.formData.emergencyContact.trim()) { common_vendor.index.showToast({ title: "请输入紧急联系人", icon: "none" }); return; } if (!this.formData.emergencyPhone.trim()) { common_vendor.index.showToast({ title: "请输入紧急联系人电话", icon: "none" }); return; } if (!/^1\d{10}$/.test(this.formData.emergencyPhone)) { common_vendor.index.showToast({ title: "请输入正确的紧急联系人电话", icon: "none" }); return; } if (!this.formData.relation) { common_vendor.index.showToast({ title: "请选择与紧急联系人关系", icon: "none" }); return; } if (!this.isAgreed) { common_vendor.index.showToast({ title: "请阅读并同意相关协议", icon: "none" }); return; } const submitData = { openid: JSON.parse(common_vendor.index.getStorageSync("userInfo") || "{}").openid || "", name: this.formData.name, phone: this.formData.phone, id_card: this.formData.idCard, status: 1, source: "mini", examine: 0, tenant_id: "1", emergency_contact: this.formData.emergencyContact, emergency_phone: this.formData.emergencyPhone, relation: this.formData.relation, age: "20", job_id: this.selectedJobId }; common_vendor.index.showLoading({ title: "提交中..." }); api_user.fillUserInfo(submitData).then((res) => { common_vendor.index.hideLoading(); this.updateLocalUserInfo(); common_vendor.index.showToast({ title: "提交成功", icon: "success", duration: 1500, success: () => { setTimeout(() => { common_vendor.index.navigateTo({ url: "/pages/success/success", fail: (err) => { console.error("页面跳转失败:", err); common_vendor.index.showToast({ title: "页面跳转失败", icon: "none" }); } }); }, 1500); } }); }).catch((err) => { common_vendor.index.hideLoading(); console.error("提交表单失败:", err); common_vendor.index.showToast({ title: "网络错误,请稍后重试", icon: "none" }); }); }, updateLocalUserInfo() { api_user.getUserInfo().then((res) => { if (res.code === 200 && res.data) { let userInfo = {}; try { userInfo = JSON.parse(common_vendor.index.getStorageSync("userInfo") || "{}"); } catch (e) { console.error("解析本地存储用户信息失败:", e); userInfo = {}; } const updatedUserInfo = { ...userInfo, ...res.data }; common_vendor.index.setStorageSync("userInfo", JSON.stringify(updatedUserInfo)); } }).catch((err) => { console.error("更新本地用户信息失败:", err); }); } } }; function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { return common_vendor.e({ a: !$data.userInfoFilled }, !$data.userInfoFilled ? { b: common_vendor.f($data.jobList, (job, index, i0) => { return { a: common_vendor.t(job.title), b: common_vendor.t(job.publish_date), c: common_vendor.t(job.location), d: index, e: $data.selectedJobId === job.id ? 1 : "", f: common_vendor.o(($event) => $options.selectJob(job), index) }; }), c: !$data.selectedJobId, d: common_vendor.o((...args) => $options.applyForJob && $options.applyForJob(...args)) } : {}, { e: $data.userInfoFilled }, $data.userInfoFilled ? { f: $data.formData.name, g: common_vendor.o(($event) => $data.formData.name = $event.detail.value), h: $data.formData.gender === "男" ? 1 : "", i: common_vendor.o(($event) => $data.formData.gender = "男"), j: $data.formData.gender === "女" ? 1 : "", k: common_vendor.o(($event) => $data.formData.gender = "女"), l: $data.formData.idCard, m: common_vendor.o(($event) => $data.formData.idCard = $event.detail.value), n: $data.formData.phone, o: common_vendor.o(($event) => $data.formData.phone = $event.detail.value), p: $data.formData.emergencyContact, q: common_vendor.o(($event) => $data.formData.emergencyContact = $event.detail.value), r: $data.formData.emergencyPhone, s: common_vendor.o(($event) => $data.formData.emergencyPhone = $event.detail.value), t: common_vendor.t($data.formData.relation || "请选择关系"), v: common_vendor.o((...args) => $options.relationChange && $options.relationChange(...args)), w: $data.relationIndex, x: $data.relationOptions, y: $data.isAgreed, z: common_vendor.o((...args) => $options.toggleAgreement && $options.toggleAgreement(...args)), A: !$options.canSubmit, B: common_vendor.o((...args) => $options.submitForm && $options.submitForm(...args)) } : {}); } const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]); wx.createPage(MiniProgramPage);