| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const common_assets = require("../../common/assets.js");
- const api_collection = require("../../api/collection.js");
- const api_message = require("../../api/message.js");
- const api_assessment = require("../../api/assessment.js");
- const api_order = require("../../api/order.js");
- const _sfc_main = {
- __name: "detail",
- setup(__props) {
- const statusBarHeight = common_vendor.ref(20);
- const isFavorited = common_vendor.ref(false);
- const collectionId = common_vendor.ref(null);
- const assessmentId = common_vendor.ref(null);
- const loading = common_vendor.ref(true);
- const assessmentData = common_vendor.ref({});
- const bannerImages = common_vendor.ref([
- "/static/images/assess_cover.svg",
- "/static/images/assess_cover.svg"
- ]);
- const tags = common_vendor.ref([]);
- const hasRecord = common_vendor.ref(false);
- const isAllCompleted = common_vendor.ref(false);
- const hasPaid = common_vendor.ref(false);
- const isPassed = common_vendor.ref(false);
- const isApplied = common_vendor.ref(false);
- const decodeBase64Utf8 = (value) => {
- if (!value || typeof value !== "string")
- return "";
- try {
- const binary = atob(value);
- const bytes = Array.from(binary, (char) => char.charCodeAt(0));
- return decodeURIComponent(bytes.map((byte) => `%${byte.toString(16).padStart(2, "0")}`).join(""));
- } catch (e) {
- return value;
- }
- };
- const displayDescription = common_vendor.computed(() => {
- const data = assessmentData.value || {};
- if (data.remark || data.description) {
- return data.remark || data.description;
- }
- if (data.detail) {
- return /^[A-Za-z0-9+/=]+$/.test(data.detail) ? decodeBase64Utf8(data.detail) : data.detail;
- }
- return "暂无描述";
- });
- common_vendor.onMounted(() => {
- const sysInfo = common_vendor.index.getSystemInfoSync();
- statusBarHeight.value = sysInfo.statusBarHeight || 20;
- });
- common_vendor.onLoad((options) => {
- if (options.id) {
- assessmentId.value = options.id;
- loadAssessmentDetail(options.id);
- checkCollectionStatus(options.id);
- checkExamRecord(options.id);
- }
- });
- common_vendor.onShow(() => {
- if (assessmentId.value) {
- checkExamRecord(assessmentId.value);
- }
- });
- const loadAssessmentDetail = async (id) => {
- try {
- loading.value = true;
- const res = await api_assessment.getAssessmentDetail(id);
- if (res.code === 200 && res.data) {
- assessmentData.value = res.data;
- if (res.data.tags) {
- tags.value = res.data.tags.split(",").filter((tag) => tag.trim());
- }
- if (res.data.imageAlbumUrls) {
- const urls = res.data.imageAlbumUrls.split(",");
- bannerImages.value = urls.length > 0 ? urls : ["/static/images/assess_cover.svg"];
- } else if (res.data.mainImageUrl) {
- bannerImages.value = [res.data.mainImageUrl];
- } else {
- bannerImages.value = ["/static/images/assess_cover.svg"];
- }
- if (res.data.positionId) {
- isApplied.value = common_vendor.index.getStorageSync(`candidate_applied_${res.data.positionId}`) === true;
- }
- } else {
- common_vendor.index.showToast({ title: "获取测评详情失败", icon: "none" });
- }
- } catch (err) {
- common_vendor.index.__f__("error", "at pages/assessment/detail.vue:207", "获取测评详情失败:", err);
- common_vendor.index.showToast({ title: "网络错误,请重试", icon: "none" });
- } finally {
- loading.value = false;
- }
- };
- const checkCollectionStatus = async (id) => {
- const userInfo = common_vendor.index.getStorageSync("userInfo");
- if (!userInfo || !userInfo.studentId)
- return;
- try {
- const res = await api_collection.checkCollection(userInfo.studentId, id, "assessment");
- if (res.code === 200 && res.data) {
- isFavorited.value = true;
- collectionId.value = res.data.id;
- } else {
- isFavorited.value = false;
- collectionId.value = null;
- }
- } catch (err) {
- common_vendor.index.__f__("error", "at pages/assessment/detail.vue:229", "检查收藏状态失败", err);
- }
- };
- const formatDateRange = (startTime, endTime) => {
- if (!startTime || !endTime)
- return "";
- const formatDate = (dateStr) => {
- const date = new Date(dateStr);
- const year = date.getFullYear();
- const month = String(date.getMonth() + 1).padStart(2, "0");
- const day = String(date.getDate()).padStart(2, "0");
- const hours = String(date.getHours()).padStart(2, "0");
- const minutes = String(date.getMinutes()).padStart(2, "0");
- return `${year}.${month}.${day} ${hours}:${minutes}`;
- };
- return `${formatDate(startTime)}—${formatDate(endTime)}`;
- };
- const goBack = () => common_vendor.index.navigateBack();
- const goToRemind = () => {
- if (!assessmentId.value) {
- common_vendor.index.showToast({ title: "测评信息加载中", icon: "none" });
- return;
- }
- common_vendor.index.navigateTo({
- url: `/pages/assessment/remind?id=${assessmentId.value}`
- });
- };
- const viewReport = () => {
- if (!assessmentId.value || !isAllCompleted.value)
- return;
- common_vendor.index.navigateTo({
- url: `/pages/assessment/report?id=${assessmentId.value}`
- });
- };
- const checkExamRecord = async (id) => {
- var _a;
- const userInfo = common_vendor.index.getStorageSync("userInfo") || {};
- const studentId = userInfo.studentId;
- if (!studentId)
- return;
- hasPaid.value = common_vendor.index.getStorageSync(`audit_paid_${id}`) === true;
- if (!hasPaid.value) {
- try {
- const orderRes = await api_order.listOrder({
- orderStatus: 1,
- buyerId: studentId
- });
- if (orderRes.code === 200 && orderRes.rows) {
- const evalName = ((_a = assessmentData.value) == null ? void 0 : _a.evaluationName) || "";
- hasPaid.value = orderRes.rows.some((order) => {
- const remark = order.remark || "";
- return evalName && remark.includes(evalName);
- });
- }
- } catch (e) {
- common_vendor.index.__f__("error", "at pages/assessment/detail.vue:295", "[AssessmentDetail] 订单校验失败:", e);
- }
- }
- try {
- const res = await api_assessment.getAssessmentRecordList(studentId);
- if (res.code === 200 && res.data) {
- const records = res.data.filter((r) => String(r.evaluationId) === String(id));
- if (records.length > 0) {
- hasRecord.value = true;
- const completedRecords = records.filter((r) => r.finalResult === "1" || r.finalResult === "2");
- isAllCompleted.value = completedRecords.length > 0;
- const passedRecords = records.filter((r) => r.finalResult === "1");
- isPassed.value = passedRecords.length > 0;
- }
- }
- if (assessmentData.value.positionId) {
- isApplied.value = common_vendor.index.getStorageSync(`candidate_applied_${assessmentData.value.positionId}`) === true;
- }
- } catch (err) {
- common_vendor.index.__f__("error", "at pages/assessment/detail.vue:320", "检查测评记录失败", err);
- }
- };
- const handleConsult = async () => {
- var _a, _b;
- 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";
- common_vendor.index.__f__("log", "at pages/assessment/detail.vue:331", "创建会话参数:", {
- sessionType: 1,
- fromUserId: userId,
- fromUserName: userName,
- fromUserAvatar: userAvatar,
- sourceId: "assessment_" + (((_a = assessmentData.value) == null ? void 0 : _a.id) || assessmentId.value)
- });
- const res = await api_message.createOrGetSession({
- sessionType: 1,
- fromUserId: userId,
- fromUserName: userName,
- fromUserAvatar: userAvatar,
- sourceId: "assessment_" + (((_b = assessmentData.value) == null ? void 0 : _b.id) || assessmentId.value)
- });
- common_vendor.index.hideLoading();
- if (res.data) {
- const session = res.data;
- const title = encodeURIComponent(assessmentData.value.evaluationName || "测评详情");
- const cover = encodeURIComponent(bannerImages.value[0] || "");
- const price = assessmentData.value.price || "0.00";
- common_vendor.index.navigateTo({
- url: `/pages/chat/chat?sessionId=${session.sessionId}&sessionNo=${session.sessionNo || ""}&fromUserId=${userId || ""}&userName=${encodeURIComponent(userName)}&type=assessment&title=${title}&cover=${cover}&assessmentId=${assessmentId.value || ""}&price=${price}`
- });
- } else {
- common_vendor.index.showToast({ title: "创建会话失败", icon: "none" });
- }
- } catch (err) {
- common_vendor.index.hideLoading();
- common_vendor.index.__f__("error", "at pages/assessment/detail.vue:359", "创建会话失败:", err);
- common_vendor.index.showToast({ title: "连接失败,请重试", icon: "none" });
- }
- };
- const handleApply = () => {
- const postId = assessmentData.value.positionId;
- if (!postId) {
- common_vendor.index.showToast({ title: "该测评未关联岗位,无法投递", icon: "none" });
- return;
- }
- const userInfo = common_vendor.index.getStorageSync("userInfo") || {};
- if (!userInfo.studentId) {
- common_vendor.index.showToast({ title: "请先登录", icon: "none" });
- return;
- }
- common_vendor.index.navigateTo({
- url: `/pages/my/select-resume?postId=${postId}`
- });
- };
- const toggleFavorite = async () => {
- const userInfo = common_vendor.index.getStorageSync("userInfo");
- if (!userInfo || !userInfo.studentId) {
- common_vendor.index.showToast({ title: "请先登录", icon: "none" });
- setTimeout(() => {
- common_vendor.index.navigateTo({ url: "/pages/login/login" });
- }, 1e3);
- return;
- }
- if (!assessmentId.value)
- return;
- common_vendor.index.showLoading({ title: isFavorited.value ? "取消收藏中..." : "收藏中..." });
- try {
- if (isFavorited.value) {
- if (collectionId.value) {
- const res = await api_collection.delCollection(collectionId.value);
- if (res.code === 200) {
- isFavorited.value = false;
- collectionId.value = null;
- common_vendor.index.showToast({ title: "已取消收藏", icon: "none" });
- }
- }
- } else {
- const res = await api_collection.addCollection({
- studentId: userInfo.studentId,
- targetId: assessmentId.value,
- type: "assessment"
- });
- if (res.code === 200) {
- isFavorited.value = true;
- checkCollectionStatus(assessmentId.value);
- common_vendor.index.showToast({ title: "收藏成功", icon: "success" });
- }
- }
- } catch (err) {
- common_vendor.index.__f__("error", "at pages/assessment/detail.vue:420", "操作收藏失败", err);
- common_vendor.index.showToast({ title: "操作失败", icon: "none" });
- } finally {
- common_vendor.index.hideLoading();
- }
- };
- return (_ctx, _cache) => {
- return common_vendor.e({
- a: common_assets._imports_0$7,
- b: common_vendor.o(goBack),
- c: statusBarHeight.value + "px",
- d: common_vendor.f(bannerImages.value, (img, index, i0) => {
- return {
- a: img,
- b: index
- };
- }),
- e: !loading.value
- }, !loading.value ? common_vendor.e({
- f: common_vendor.t(assessmentData.value.evaluationName || "测评详情"),
- g: assessmentData.value.startTime && assessmentData.value.endTime
- }, assessmentData.value.startTime && assessmentData.value.endTime ? {
- h: common_vendor.t(formatDateRange(assessmentData.value.startTime, assessmentData.value.endTime))
- } : {}, {
- i: assessmentData.value.questionTypes
- }, assessmentData.value.questionTypes ? {
- j: common_vendor.t(assessmentData.value.questionTypes)
- } : {}, {
- k: assessmentData.value.questionCount
- }, assessmentData.value.questionCount ? {
- l: common_vendor.t(assessmentData.value.questionCount)
- } : {}, {
- m: assessmentData.value.duration
- }, assessmentData.value.duration ? {
- n: common_vendor.t(assessmentData.value.duration)
- } : {}) : {}, {
- o: loading.value
- }, loading.value ? {} : {}, {
- p: !loading.value
- }, !loading.value ? common_vendor.e({
- q: tags.value.length > 0
- }, tags.value.length > 0 ? {
- r: common_vendor.f(tags.value, (tag, k0, i0) => {
- return {
- a: common_vendor.t(tag),
- b: tag
- };
- })
- } : {}, {
- s: displayDescription.value
- }, displayDescription.value ? {
- t: common_vendor.t(displayDescription.value)
- } : {}) : {}, {
- v: assessmentData.value.detail && assessmentData.value.detail.includes("<")
- }, assessmentData.value.detail && assessmentData.value.detail.includes("<") ? {
- w: assessmentData.value.detail
- } : {}, {
- x: isFavorited.value ? "/static/icons/star_filled.svg" : "/static/icons/star_hollow.svg",
- y: common_vendor.t(isFavorited.value ? "已收藏" : "收藏"),
- z: common_vendor.n(isFavorited.value ? "active" : ""),
- A: common_vendor.o(toggleFavorite),
- B: !hasPaid.value && !hasRecord.value
- }, !hasPaid.value && !hasRecord.value ? {
- C: common_vendor.o(handleConsult)
- } : {}, {
- D: hasPaid.value && !hasRecord.value
- }, hasPaid.value && !hasRecord.value ? {
- E: common_vendor.o(goToRemind)
- } : {}, {
- F: hasRecord.value
- }, hasRecord.value ? {
- G: !isAllCompleted.value ? 1 : "",
- H: common_vendor.o(viewReport)
- } : {}, {
- I: hasRecord.value && !isPassed.value
- }, hasRecord.value && !isPassed.value ? {
- J: common_vendor.o(goToRemind)
- } : {}, {
- K: isPassed.value && !isApplied.value
- }, isPassed.value && !isApplied.value ? {
- L: common_vendor.o(handleApply)
- } : {}, {
- M: isPassed.value && isApplied.value
- }, isPassed.value && isApplied.value ? {} : {});
- };
- }
- };
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-db914789"]]);
- wx.createPage(MiniProgramPage);
- //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/assessment/detail.js.map
|