"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, genderMapping: { "男": "1", "女": "2", "1": "男", "2": "女" } }; }, onLoad(options) { console.log("options:", options); if (options.scene) { const scene = decodeURIComponent(options.scene); console.log("解码后的scene:", scene); const sceneParams = {}; scene.split("&").forEach((pair) => { const [key, value] = pair.split("="); sceneParams[key] = value; }); console.log("解析后的参数:", sceneParams); } 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() { 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, userInfo.openid).then((res) => { common_vendor.index.hideLoading(); const userData = res; if (!userData.name || !userData.phone) { this.userInfoFilled = true; this.formData.name = userData.name || ""; if (userData.gender) { this.formData.gender = this.genderMapping[userData.gender] || userData.gender; const index = this.genderOptions.findIndex((item) => item === this.formData.gender); if (index !== -1) { this.genderIndex = index; } } else { this.formData.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" }); } }, 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) { try { common_vendor.index.removeStorageSync("interviewQuestions"); common_vendor.index.removeStorageSync("currentQuestionIndex"); } catch (e) { console.error("清除问题缓存失败:", e); } this.selectedJobId = job.id; this.selectedJob = job; common_vendor.index.setStorageSync("selectedJob", JSON.stringify(job)); console.log("已选择职位:", job.id, job.title); }, 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/Personal/Personal", 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 genderValue = this.genderMapping[this.formData.gender] || this.formData.gender; 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: genderValue }; api_user.fillUserInfo(submitData).then((res) => { common_vendor.index.hideLoading(); this.updateLocalUserInfo(res.id, JSON.parse(common_vendor.index.getStorageSync("userInfo")).openid); 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; const displayGender = this.genderOptions[this.genderIndex]; this.formData.gender = displayGender; }, viewJobDetail(job) { common_vendor.index.setStorageSync("currentJobDetail", JSON.stringify(job)); common_vendor.index.navigateTo({ url: "/pages/job-detail/job-detail", fail: (err) => { console.error("页面跳转失败:", err); common_vendor.index.showToast({ title: "页面跳转失败", icon: "none" }); } }); } } }; function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { return { a: 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) }; }), b: !$data.selectedJobId, c: common_vendor.o((...args) => $options.applyForJob && $options.applyForJob(...args)) }; } const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]); wx.createPage(MiniProgramPage);