"use strict"; const common_vendor = require("../../common/vendor.js"); const common_assets = require("../../common/assets.js"); const api_position = require("../../api/position.js"); const api_message = require("../../api/message.js"); const api_collection = require("../../api/collection.js"); const api_assessment = require("../../api/assessment.js"); const _sfc_main = { __name: "index", setup(__props) { const isCollected = common_vendor.ref(false); const collectionId = common_vendor.ref(null); const jobInfo = common_vendor.ref({}); const tags = common_vendor.ref([]); const jobState = common_vendor.ref("initial"); const btnText = common_vendor.computed(() => { switch (jobState.value) { case "initial": return "咨询"; case "paid": return "开始测评"; case "assessed": return "投递简历"; case "added": return "已投递"; default: return "咨询"; } }); const positionId = common_vendor.ref(null); const checkState = async () => { common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:139", "Checking job state for position:", positionId.value); const userInfo = common_vendor.index.getStorageSync("userInfo"); if (!userInfo || !userInfo.studentId || !positionId.value) { jobState.value = "initial"; return; } const appliedKey = `candidate_applied_${positionId.value}`; if (common_vendor.index.getStorageSync(appliedKey)) { jobState.value = "added"; return; } try { const evalRes = await api_assessment.getAssessmentList({ positionId: positionId.value, pageNum: 1, pageSize: 100 }); const isAnyEvalPaid = evalRes.code === 200 && evalRes.rows ? evalRes.rows.some((e) => common_vendor.index.getStorageSync(`audit_paid_${e.id}`)) : common_vendor.index.getStorageSync(`audit_paid_${positionId.value}`); if (evalRes.code !== 200 || !evalRes.rows || evalRes.rows.length === 0) { jobState.value = isAnyEvalPaid ? "paid" : "initial"; return; } const recordRes = await api_assessment.getAssessmentRecordList(userInfo.studentId); if (recordRes.code !== 200 || !recordRes.data) { jobState.value = isAnyEvalPaid ? "paid" : "initial"; return; } const evaluationIds = evalRes.rows.map((e) => e.id); const passedRecord = recordRes.data.find( (r) => r.finalResult === "1" && evaluationIds.includes(r.evaluationId) ); if (passedRecord) { jobState.value = "assessed"; } else if (isAnyEvalPaid) { jobState.value = "paid"; } else { jobState.value = "initial"; } } catch (err) { common_vendor.index.__f__("error", "at pages/jobdetail/index.vue:191", "检查状态失败:", err); jobState.value = "initial"; } }; const latitude = common_vendor.ref(31.22863); const longitude = common_vendor.ref(121.45039); const markers = common_vendor.ref([]); const fetchDetail = async (id) => { common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:201", "fetchDetail called with id:", id); common_vendor.index.showLoading({ title: "加载中..." }); try { const res = await api_position.getPositionDetail(id); common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:205", "getPositionDetail响应:", res); if (res.code === 200 && res.data) { jobInfo.value = res.data; positionId.value = res.data.id; const data = res.data; if (data.latitude && data.longitude) { latitude.value = parseFloat(data.latitude); longitude.value = parseFloat(data.longitude); markers.value = [{ id: 1, latitude: latitude.value, longitude: longitude.value, title: data.postName || "办公地点", iconPath: "/static/icons/location.svg", width: 32, height: 32, callout: { content: data.workAddress || data.workProvince + data.workCity + data.workDistrict, color: "#333333", fontSize: 12, borderRadius: 8, padding: 8, bgColor: "#ffffff", display: "ALWAYS", boxShadow: "0 4rpx 12rpx rgba(0,0,0,0.1)" } }]; } else { markers.value = []; } let t = []; if (data.postTypeLabel) t.push(data.postTypeLabel); if (data.schoolRequirementLabel) t.push(data.schoolRequirementLabel); if (data.gradeRequirementLabel) t.push(data.gradeRequirementLabel); if (data.welfareTags) { t.push(...data.welfareTags.split(",").filter(Boolean)); } tags.value = t; common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:249", "准备检查收藏状态, id:", id); checkCollectionStatus(id); } } catch (err) { common_vendor.index.__f__("error", "at pages/jobdetail/index.vue:253", "获取岗位详情失败:", err); } finally { common_vendor.index.hideLoading(); } }; const checkCollectionStatus = async (id) => { common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:261", "checkCollectionStatus called with id:", id); const userInfo = common_vendor.index.getStorageSync("userInfo"); common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:263", "checkCollectionStatus userInfo:", userInfo); if (!userInfo || !userInfo.studentId) { common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:265", "checkCollectionStatus: 用户未登录"); return; } try { common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:270", "调用checkCollection API, studentId:", userInfo.studentId, "targetId:", id, "type: job"); const res = await api_collection.checkCollection(userInfo.studentId, id, "job"); common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:272", "checkCollection API响应:", res); if (res.code === 200 && res.data) { isCollected.value = true; collectionId.value = res.data.id; common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:276", "设置为已收藏, collectionId:", res.data.id); } else { isCollected.value = false; collectionId.value = null; common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:280", "设置为未收藏"); } } catch (err) { common_vendor.index.__f__("error", "at pages/jobdetail/index.vue:283", "检查收藏状态失败", err); } }; const toggleCollect = async () => { common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:289", "toggleCollect clicked"); const userInfo = common_vendor.index.getStorageSync("userInfo"); common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:291", "userInfo:", userInfo); if (!userInfo || !userInfo.studentId) { common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:294", "用户未登录"); common_vendor.index.showToast({ title: "请先登录", icon: "none" }); setTimeout(() => { common_vendor.index.navigateTo({ url: "/pages/login/login" }); }, 1e3); return; } if (!jobInfo.value.id) { common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:303", "jobInfo.value.id 为空:", jobInfo.value); return; } common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:307", "准备发送收藏请求, jobInfo.value.id:", jobInfo.value.id); common_vendor.index.showLoading({ title: isCollected.value ? "取消收藏中..." : "收藏中..." }); try { if (isCollected.value) { common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:313", "取消收藏, collectionId:", collectionId.value); if (collectionId.value) { const res = await api_collection.delCollection(collectionId.value); common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:316", "取消收藏响应:", res); if (res.code === 200) { isCollected.value = false; collectionId.value = null; common_vendor.index.showToast({ title: "已取消收藏", icon: "none" }); } } } else { const requestData = { studentId: userInfo.studentId, targetId: jobInfo.value.id, type: "job" }; common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:330", "添加收藏请求数据:", requestData); const res = await api_collection.addCollection(requestData); common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:332", "添加收藏响应:", res); if (res.code === 200) { isCollected.value = true; checkCollectionStatus(jobInfo.value.id); common_vendor.index.showToast({ title: "收藏成功", icon: "success" }); } else { common_vendor.index.showToast({ title: res.msg || "收藏失败", icon: "none" }); } } } catch (err) { common_vendor.index.__f__("error", "at pages/jobdetail/index.vue:343", "操作收藏失败", err); common_vendor.index.showToast({ title: "操作失败", icon: "none" }); } finally { common_vendor.index.hideLoading(); } }; common_vendor.onLoad((options) => { if (options.id) { positionId.value = options.id; fetchDetail(options.id); } common_vendor.index.$on("payment_done", (data) => { common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:357", "收到 payment_done 事件:", data); checkState(); }); }); common_vendor.onShow(() => { if (positionId.value) { checkState(); } }); common_vendor.onUnmounted(() => { common_vendor.index.$off("payment_done"); }); const handleMainAction = async () => { if (jobState.value === "initial") { try { common_vendor.index.showLoading({ title: "正在连接客服..." }); const userInfo = common_vendor.index.getStorageSync("userInfo") || {}; const userId = userInfo.studentId || null; const userName = userInfo.name || "用户"; const userAvatar = userInfo.avatarUrl || "/static/images/user_avatar.svg"; const res = await api_message.createOrGetSession({ sessionType: 1, fromUserId: userId, fromUserName: userName, fromUserAvatar: userAvatar, sourceId: "job_" + positionId.value }); common_vendor.index.hideLoading(); if (res.data) { const session = res.data; common_vendor.index.navigateTo({ url: `/pages/chat/chat?sessionId=${session.sessionId}&sessionNo=${session.sessionNo || ""}&fromUserId=${userId}&userName=${encodeURIComponent(userName)}&jobName=${encodeURIComponent(jobInfo.value.postName || "")}&type=job&positionId=${positionId.value}&salaryRange=${encodeURIComponent(jobInfo.value.salaryRange || "")}&companyName=${encodeURIComponent(jobInfo.value.companyName || "")}&workCity=${encodeURIComponent(jobInfo.value.workCity || "")}` }); } else { common_vendor.index.showToast({ title: "创建会话失败", icon: "none" }); } } catch (err) { common_vendor.index.hideLoading(); common_vendor.index.__f__("error", "at pages/jobdetail/index.vue:403", "创建会话失败:", err); common_vendor.index.showToast({ title: "连接失败,请重试", icon: "none" }); } } else if (jobState.value === "paid") { common_vendor.index.navigateTo({ url: "/pages/assessment/remind?family=audit" }); } else if (jobState.value === "assessed") { const userInfo = common_vendor.index.getStorageSync("userInfo") || {}; if (!userInfo.studentId) { common_vendor.index.showToast({ title: "请先登录", icon: "none" }); setTimeout(() => { common_vendor.index.navigateTo({ url: "/pages/login/login" }); }, 1e3); return; } try { common_vendor.index.showLoading({ title: "投递中..." }); const res = await api_assessment.applyPosition({ postId: positionId.value }); common_vendor.index.hideLoading(); if (res.code === 200) { common_vendor.index.showToast({ title: "投递成功", icon: "success" }); } else if (res.msg && res.msg.includes("已投递")) { } else { common_vendor.index.showToast({ title: res.msg || "投递失败", icon: "none" }); } jobState.value = "added"; common_vendor.index.setStorageSync(`candidate_applied_${positionId.value}`, true); } catch (err) { common_vendor.index.hideLoading(); common_vendor.index.__f__("error", "at pages/jobdetail/index.vue:437", "投递失败:", err); const errMsg = String((err == null ? void 0 : err.msg) || (err == null ? void 0 : err.message) || ""); if (errMsg.includes("已投递")) { jobState.value = "added"; common_vendor.index.setStorageSync(`candidate_applied_${positionId.value}`, true); common_vendor.index.showToast({ title: "您已投递过该岗位", icon: "none" }); } else { common_vendor.index.showToast({ title: "网络错误,投递失败", icon: "none" }); } } } }; return (_ctx, _cache) => { return common_vendor.e({ a: common_vendor.t(jobInfo.value.postName || ""), b: jobInfo.value.isUrgent === 1 }, jobInfo.value.isUrgent === 1 ? {} : {}, { c: common_vendor.t(jobInfo.value.salaryRange || "面议"), d: common_assets._imports_2$2, e: common_vendor.t(jobInfo.value.workProvince || ""), f: common_vendor.t(jobInfo.value.workCity ? "·" + jobInfo.value.workCity : ""), g: common_vendor.t(jobInfo.value.workDistrict ? "·" + jobInfo.value.workDistrict : ""), h: common_assets._imports_0$2, i: common_vendor.t(jobInfo.value.recruitNum || 1), j: common_assets._imports_1$1, k: common_vendor.t(jobInfo.value.registrationEndDate ? jobInfo.value.registrationEndDate.split(" ")[0] : "长期有效"), l: jobInfo.value.companyAvatar || "/static/images/hr_avatar.svg", m: common_vendor.t(jobInfo.value.companyName || "平台推荐"), n: common_vendor.f(tags.value, (tag, k0, i0) => { return { a: common_vendor.t(tag), b: tag }; }), o: jobInfo.value.postDescription }, jobInfo.value.postDescription ? { p: jobInfo.value.postDescription } : {}, { q: latitude.value, r: longitude.value, s: markers.value, t: jobInfo.value.companyAvatar || "/static/images/logo1.png", v: common_vendor.t(jobInfo.value.companyName || "未知企业"), w: isCollected.value ? "/static/icons/star_filled.svg" : "/static/icons/star_hollow.svg", x: common_vendor.t(isCollected.value ? "已收藏" : "收藏"), y: common_vendor.o(toggleCollect), z: common_vendor.t(btnText.value), A: common_vendor.n(jobState.value), B: common_vendor.o(handleMainAction) }); }; } }; const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-dc9d1727"]]); wx.createPage(MiniProgramPage); //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/jobdetail/index.js.map