"use strict"; const common_vendor = require("../../common/vendor.js"); const common_config = require("../../common/config.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, isPhoneValid: false, isNameValid: false, isIdCardValid: false, genderOptions: ["男", "女"], genderIndex: 0 }; }, 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; }, canSubmitSimple() { return this.formData.name.trim() && this.formData.phone.trim() && this.isPhoneValid && this.formData.idCard.trim() && this.isIdCardValid && this.isAgreed; } }, methods: { checkLogin() { const userInfo = common_vendor.index.getStorageSync("userInfo"); if (!userInfo) { common_vendor.index.reLaunch({ url: "/pages/login/login", 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.navigateTo({ url: "/pages/login/login" }); return false; } return true; } catch (e) { console.error("解析用户信息失败:", e); common_vendor.index.removeStorageSync("userInfo"); common_vendor.index.navigateTo({ url: "/pages/login/login" }); 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(); const userData = res; 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; } } } }).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/login/login" }); } }, 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) => { if (res && res.id) { common_vendor.index.setStorageSync("appId", res.id); try { const userInfo = JSON.parse(common_vendor.index.getStorageSync("userInfo") || "{}"); userInfo.appId = res.id; common_vendor.index.setStorageSync("userInfo", JSON.stringify(userInfo)); } catch (e) { console.error("更新用户信息失败:", e); } } 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); common_vendor.index.showToast({ title: "申请职位失败,请重试", icon: "none" }); }); }, 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.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.isAgreed) { common_vendor.index.showToast({ title: "请阅读并同意相关协议", icon: "none" }); return; } common_vendor.index.showLoading({ title: "验证身份信息..." }); common_vendor.index.request({ url: `${common_config.apiBaseUrl}/wechat/identity/verify`, method: "POST", data: { name: this.formData.name, id_number: this.formData.idCard, mobile: this.formData.phone }, header: { "content-type": "application/x-www-form-urlencoded" }, success: (res) => { console.log(res); if (res.statusCode === 200) { if (res.data.code === 200) { this.submitUserInfo(); } else { common_vendor.index.showToast({ title: res.data.data.message, icon: "none" }); } } else { common_vendor.index.hideLoading(); common_vendor.index.showToast({ title: "身份验证失败,请检查信息是否正确", icon: "none" }); } }, fail: (err) => { common_vendor.index.hideLoading(); console.error("身份验证失败:", err); common_vendor.index.showToast({ title: "网络错误,请稍后重试", icon: "none" }); } }); }, submitUserInfo() { 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, gender: this.formData.gender }; api_user.fillUserInfo(submitData).then((res) => { common_vendor.index.hideLoading(); this.updateLocalUserInfo(res.id); common_vendor.index.showToast({ title: "提交成功", icon: "success", duration: 1500, success: () => { this.userInfoFilled = false; } }); }).catch((err) => { common_vendor.index.hideLoading(); console.error("提交表单失败:", err); common_vendor.index.showToast({ title: "网络错误,请稍后重试", icon: "none" }); }); }, updateLocalUserInfo(data) { api_user.getUserInfo(data).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); }); }, validatePhone() { this.isPhoneValid = /^1\d{10}$/.test(this.formData.phone); }, validateName() { this.isNameValid = this.formData.name.trim().length >= 2; }, validateIdCard() { const idCardReg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; this.isIdCardValid = idCardReg.test(this.formData.idCard); }, genderChange(e) { this.genderIndex = e.detail.value; this.formData.gender = this.genderOptions[this.genderIndex]; } } }; 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 ? common_vendor.e({ f: common_vendor.o([($event) => $data.formData.phone = $event.detail.value, (...args) => $options.validatePhone && $options.validatePhone(...args)]), g: $data.formData.phone, h: $data.formData.phone }, $data.formData.phone ? common_vendor.e({ i: $data.isPhoneValid }, $data.isPhoneValid ? {} : {}) : {}, { j: common_vendor.o([($event) => $data.formData.name = $event.detail.value, (...args) => $options.validateName && $options.validateName(...args)]), k: $data.formData.name, l: $data.formData.name }, $data.formData.name ? common_vendor.e({ m: $data.isNameValid }, $data.isNameValid ? {} : {}) : {}, { n: common_vendor.o([($event) => $data.formData.idCard = $event.detail.value, (...args) => $options.validateIdCard && $options.validateIdCard(...args)]), o: $data.formData.idCard, p: $data.formData.idCard }, $data.formData.idCard ? common_vendor.e({ q: $data.isIdCardValid }, $data.isIdCardValid ? {} : {}) : {}, { r: $data.formData.gender, s: common_vendor.o((...args) => $options.genderChange && $options.genderChange(...args)), t: $data.genderIndex, v: $data.genderOptions, w: !$options.canSubmitSimple, x: common_vendor.o((...args) => $options.submitForm && $options.submitForm(...args)), y: $data.isAgreed, z: common_vendor.o((...args) => $options.toggleAgreement && $options.toggleAgreement(...args)) }) : {}); } const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]); wx.createPage(MiniProgramPage);