"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 api_order = require("../../api/order.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:140", "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 { if (!jobInfo.value || !jobInfo.value.postName) { const jobRes = await api_position.getPositionDetail(positionId.value); if (jobRes.code === 200 && jobRes.data) { jobInfo.value = jobRes.data; } } const evalRes = await api_assessment.getAssessmentList({ positionId: positionId.value, pageNum: 1, pageSize: 100 }); const fallbackPaidKey = `audit_paid_pos_${positionId.value}`; const isFallbackPaid = !!common_vendor.index.getStorageSync(fallbackPaidKey); let isAnyEvalPaid = evalRes.code === 200 && evalRes.rows ? evalRes.rows.some((e) => common_vendor.index.getStorageSync(`audit_paid_${e.id}`)) || isFallbackPaid : isFallbackPaid || !!common_vendor.index.getStorageSync(`audit_paid_${positionId.value}`); if (!isAnyEvalPaid) { try { const orderRes = await api_order.listOrder({ orderStatus: 1, buyerId: userInfo.studentId }); if (orderRes.code === 200 && orderRes.rows) { isAnyEvalPaid = orderRes.rows.some((order) => { var _a; const remark = order.remark || ""; const matchPost = ((_a = jobInfo.value) == null ? void 0 : _a.postName) && remark.includes(jobInfo.value.postName); const matchEval = evalRes.rows && evalRes.rows.some((e) => e.evaluationName && remark.includes(e.evaluationName)); return matchPost || matchEval; }); } } catch (e) { common_vendor.index.__f__("error", "at pages/jobdetail/index.vue:191", "[JobDetail] 订单校验失败:", e); } } common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:195", "[JobDetail] 支付状态最终综合判定:", isAnyEvalPaid); if (evalRes.code !== 200 || !evalRes.rows || evalRes.rows.length === 0) { jobState.value = isAnyEvalPaid ? "paid" : "initial"; return; } linkedAssessmentId.value = evalRes.rows[0].id; common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:205", "[JobDetail] 关联测评ID:", linkedAssessmentId.value); 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:231", "检查状态失败:", 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:241", "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:245", "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:289", "准备检查收藏状态, id:", id); checkCollectionStatus(id); } } catch (err) { common_vendor.index.__f__("error", "at pages/jobdetail/index.vue:293", "获取岗位详情失败:", err); } finally { common_vendor.index.hideLoading(); } }; const checkCollectionStatus = async (id) => { common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:301", "checkCollectionStatus called with id:", id); const userInfo = common_vendor.index.getStorageSync("userInfo"); common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:303", "checkCollectionStatus userInfo:", userInfo); if (!userInfo || !userInfo.studentId) { common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:305", "checkCollectionStatus: 用户未登录"); return; } try { common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:310", "调用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:312", "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:316", "设置为已收藏, collectionId:", res.data.id); } else { isCollected.value = false; collectionId.value = null; common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:320", "设置为未收藏"); } } catch (err) { common_vendor.index.__f__("error", "at pages/jobdetail/index.vue:323", "检查收藏状态失败", err); } }; const toggleCollect = async () => { common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:329", "toggleCollect clicked"); const userInfo = common_vendor.index.getStorageSync("userInfo"); common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:331", "userInfo:", userInfo); if (!userInfo || !userInfo.studentId) { common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:334", "用户未登录"); 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:343", "jobInfo.value.id 为空:", jobInfo.value); return; } common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:347", "准备发送收藏请求, 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:353", "取消收藏, collectionId:", collectionId.value); if (collectionId.value) { const res = await api_collection.delCollection(collectionId.value); common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:356", "取消收藏响应:", 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:370", "添加收藏请求数据:", requestData); const res = await api_collection.addCollection(requestData); common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:372", "添加收藏响应:", 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:383", "操作收藏失败", 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:397", "收到 payment_done 事件:", data); checkState(); }); common_vendor.index.$on("resume_delivered", (data) => { common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:402", "收到 resume_delivered 事件:", data); if (data && data.postId == positionId.value) { jobState.value = "added"; } }); }); common_vendor.onShow(() => { if (positionId.value) { checkState(); } }); common_vendor.onUnmounted(() => { common_vendor.index.$off("payment_done"); common_vendor.index.$off("resume_delivered"); }); 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 || "")}&workDistrict=${encodeURIComponent(jobInfo.value.workDistrict || "")}` }); } else { common_vendor.index.showToast({ title: "创建会话失败", icon: "none" }); } } catch (err) { common_vendor.index.hideLoading(); common_vendor.index.__f__("error", "at pages/jobdetail/index.vue:451", "创建会话失败:", err); common_vendor.index.showToast({ title: "连接失败,请重试", icon: "none" }); } } else if (jobState.value === "paid") { common_vendor.index.navigateTo({ url: `/pages/assessment/remind?family=audit&id=${linkedAssessmentId.value || ""}` }); } 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; } common_vendor.index.navigateTo({ url: `/pages/my/select-resume?postId=${positionId.value}` }); } }; 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.hrAvatar || 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