detail.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const common_assets = require("../../common/assets.js");
  4. const api_collection = require("../../api/collection.js");
  5. const api_message = require("../../api/message.js");
  6. const api_assessment = require("../../api/assessment.js");
  7. const _sfc_main = {
  8. __name: "detail",
  9. setup(__props) {
  10. const statusBarHeight = common_vendor.ref(20);
  11. const isFavorited = common_vendor.ref(false);
  12. const collectionId = common_vendor.ref(null);
  13. const assessmentId = common_vendor.ref(null);
  14. const loading = common_vendor.ref(true);
  15. const assessmentData = common_vendor.ref({});
  16. const bannerImages = common_vendor.ref([
  17. "/static/images/assess_cover.svg",
  18. "/static/images/assess_cover.svg"
  19. ]);
  20. const tags = common_vendor.ref([]);
  21. const hasRecord = common_vendor.ref(false);
  22. const isAllCompleted = common_vendor.ref(false);
  23. const hasPaid = common_vendor.ref(false);
  24. const isPassed = common_vendor.ref(false);
  25. const isApplied = common_vendor.ref(false);
  26. const decodeBase64Utf8 = (value) => {
  27. if (!value || typeof value !== "string")
  28. return "";
  29. try {
  30. const binary = atob(value);
  31. const bytes = Array.from(binary, (char) => char.charCodeAt(0));
  32. return decodeURIComponent(bytes.map((byte) => `%${byte.toString(16).padStart(2, "0")}`).join(""));
  33. } catch (e) {
  34. return value;
  35. }
  36. };
  37. const displayDescription = common_vendor.computed(() => {
  38. const data = assessmentData.value || {};
  39. if (data.remark || data.description) {
  40. return data.remark || data.description;
  41. }
  42. if (data.detail) {
  43. return /^[A-Za-z0-9+/=]+$/.test(data.detail) ? decodeBase64Utf8(data.detail) : data.detail;
  44. }
  45. return "暂无描述";
  46. });
  47. common_vendor.onMounted(() => {
  48. const sysInfo = common_vendor.index.getSystemInfoSync();
  49. statusBarHeight.value = sysInfo.statusBarHeight || 20;
  50. });
  51. common_vendor.onLoad((options) => {
  52. if (options.id) {
  53. assessmentId.value = options.id;
  54. loadAssessmentDetail(options.id);
  55. checkCollectionStatus(options.id);
  56. checkExamRecord(options.id);
  57. }
  58. });
  59. const loadAssessmentDetail = async (id) => {
  60. try {
  61. loading.value = true;
  62. const res = await api_assessment.getAssessmentDetail(id);
  63. if (res.code === 200 && res.data) {
  64. assessmentData.value = res.data;
  65. if (res.data.tags) {
  66. tags.value = res.data.tags.split(",").filter((tag) => tag.trim());
  67. }
  68. if (res.data.imageAlbumUrls) {
  69. const urls = res.data.imageAlbumUrls.split(",");
  70. bannerImages.value = urls.length > 0 ? urls : ["/static/images/assess_cover.svg"];
  71. } else if (res.data.mainImageUrl) {
  72. bannerImages.value = [res.data.mainImageUrl];
  73. } else {
  74. bannerImages.value = ["/static/images/assess_cover.svg"];
  75. }
  76. if (res.data.positionId) {
  77. isApplied.value = common_vendor.index.getStorageSync(`candidate_applied_${res.data.positionId}`) === true;
  78. }
  79. } else {
  80. common_vendor.index.showToast({ title: "获取测评详情失败", icon: "none" });
  81. }
  82. } catch (err) {
  83. common_vendor.index.__f__("error", "at pages/assessment/detail.vue:200", "获取测评详情失败:", err);
  84. common_vendor.index.showToast({ title: "网络错误,请重试", icon: "none" });
  85. } finally {
  86. loading.value = false;
  87. }
  88. };
  89. const checkCollectionStatus = async (id) => {
  90. const userInfo = common_vendor.index.getStorageSync("userInfo");
  91. if (!userInfo || !userInfo.studentId)
  92. return;
  93. try {
  94. const res = await api_collection.checkCollection(userInfo.studentId, id, "assessment");
  95. if (res.code === 200 && res.data) {
  96. isFavorited.value = true;
  97. collectionId.value = res.data.id;
  98. } else {
  99. isFavorited.value = false;
  100. collectionId.value = null;
  101. }
  102. } catch (err) {
  103. common_vendor.index.__f__("error", "at pages/assessment/detail.vue:222", "检查收藏状态失败", err);
  104. }
  105. };
  106. const formatDateRange = (startTime, endTime) => {
  107. if (!startTime || !endTime)
  108. return "";
  109. const formatDate = (dateStr) => {
  110. const date = new Date(dateStr);
  111. const year = date.getFullYear();
  112. const month = String(date.getMonth() + 1).padStart(2, "0");
  113. const day = String(date.getDate()).padStart(2, "0");
  114. const hours = String(date.getHours()).padStart(2, "0");
  115. const minutes = String(date.getMinutes()).padStart(2, "0");
  116. return `${year}.${month}.${day} ${hours}:${minutes}`;
  117. };
  118. return `${formatDate(startTime)}—${formatDate(endTime)}`;
  119. };
  120. const goBack = () => common_vendor.index.navigateBack();
  121. const goToRemind = () => {
  122. if (!assessmentId.value) {
  123. common_vendor.index.showToast({ title: "测评信息加载中", icon: "none" });
  124. return;
  125. }
  126. common_vendor.index.navigateTo({
  127. url: `/pages/assessment/remind?id=${assessmentId.value}`
  128. });
  129. };
  130. const viewReport = () => {
  131. if (!assessmentId.value || !isAllCompleted.value)
  132. return;
  133. common_vendor.index.navigateTo({
  134. url: `/pages/assessment/report?id=${assessmentId.value}`
  135. });
  136. };
  137. const checkExamRecord = async (id) => {
  138. const userInfo = common_vendor.index.getStorageSync("userInfo") || {};
  139. const studentId = userInfo.studentId;
  140. if (!studentId)
  141. return;
  142. hasPaid.value = common_vendor.index.getStorageSync(`audit_paid_${id}`) === true;
  143. try {
  144. const res = await api_assessment.getAssessmentRecordList(studentId);
  145. if (res.code === 200 && res.data) {
  146. const records = res.data.filter((r) => String(r.evaluationId) === String(id));
  147. if (records.length > 0) {
  148. hasRecord.value = true;
  149. const completedRecords = records.filter((r) => r.finalResult === "1" || r.finalResult === "2");
  150. isAllCompleted.value = completedRecords.length > 0;
  151. const passedRecords = records.filter((r) => r.finalResult === "1");
  152. isPassed.value = passedRecords.length > 0;
  153. }
  154. }
  155. if (assessmentData.value.positionId) {
  156. isApplied.value = common_vendor.index.getStorageSync(`candidate_applied_${assessmentData.value.positionId}`) === true;
  157. }
  158. } catch (err) {
  159. common_vendor.index.__f__("error", "at pages/assessment/detail.vue:294", "检查测评记录失败", err);
  160. }
  161. };
  162. const handleConsult = async () => {
  163. var _a, _b;
  164. try {
  165. common_vendor.index.showLoading({ title: "正在连接客服..." });
  166. const userInfo = common_vendor.index.getStorageSync("userInfo") || {};
  167. const userId = userInfo.studentId || null;
  168. const userName = userInfo.name || "用户";
  169. const userAvatar = userInfo.avatarUrl || "/static/images/user_avatar.svg";
  170. common_vendor.index.__f__("log", "at pages/assessment/detail.vue:305", "创建会话参数:", {
  171. sessionType: 1,
  172. fromUserId: userId,
  173. fromUserName: userName,
  174. fromUserAvatar: userAvatar,
  175. sourceId: "assessment_" + (((_a = assessmentData.value) == null ? void 0 : _a.id) || assessmentId.value)
  176. });
  177. const res = await api_message.createOrGetSession({
  178. sessionType: 1,
  179. fromUserId: userId,
  180. fromUserName: userName,
  181. fromUserAvatar: userAvatar,
  182. sourceId: "assessment_" + (((_b = assessmentData.value) == null ? void 0 : _b.id) || assessmentId.value)
  183. });
  184. common_vendor.index.hideLoading();
  185. if (res.data) {
  186. const session = res.data;
  187. const title = encodeURIComponent(assessmentData.value.evaluationName || "测评详情");
  188. const cover = encodeURIComponent(bannerImages.value[0] || "");
  189. const price = assessmentData.value.price || "0.00";
  190. common_vendor.index.navigateTo({
  191. 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}`
  192. });
  193. } else {
  194. common_vendor.index.showToast({ title: "创建会话失败", icon: "none" });
  195. }
  196. } catch (err) {
  197. common_vendor.index.hideLoading();
  198. common_vendor.index.__f__("error", "at pages/assessment/detail.vue:333", "创建会话失败:", err);
  199. common_vendor.index.showToast({ title: "连接失败,请重试", icon: "none" });
  200. }
  201. };
  202. const handleApply = () => {
  203. const postId = assessmentData.value.positionId;
  204. if (!postId) {
  205. common_vendor.index.showToast({ title: "该测评未关联岗位,无法投递", icon: "none" });
  206. return;
  207. }
  208. const userInfo = common_vendor.index.getStorageSync("userInfo") || {};
  209. if (!userInfo.studentId) {
  210. common_vendor.index.showToast({ title: "请先登录", icon: "none" });
  211. return;
  212. }
  213. common_vendor.index.navigateTo({
  214. url: `/pages/my/select-resume?postId=${postId}`
  215. });
  216. };
  217. const toggleFavorite = async () => {
  218. const userInfo = common_vendor.index.getStorageSync("userInfo");
  219. if (!userInfo || !userInfo.studentId) {
  220. common_vendor.index.showToast({ title: "请先登录", icon: "none" });
  221. setTimeout(() => {
  222. common_vendor.index.navigateTo({ url: "/pages/login/login" });
  223. }, 1e3);
  224. return;
  225. }
  226. if (!assessmentId.value)
  227. return;
  228. common_vendor.index.showLoading({ title: isFavorited.value ? "取消收藏中..." : "收藏中..." });
  229. try {
  230. if (isFavorited.value) {
  231. if (collectionId.value) {
  232. const res = await api_collection.delCollection(collectionId.value);
  233. if (res.code === 200) {
  234. isFavorited.value = false;
  235. collectionId.value = null;
  236. common_vendor.index.showToast({ title: "已取消收藏", icon: "none" });
  237. }
  238. }
  239. } else {
  240. const res = await api_collection.addCollection({
  241. studentId: userInfo.studentId,
  242. targetId: assessmentId.value,
  243. type: "assessment"
  244. });
  245. if (res.code === 200) {
  246. isFavorited.value = true;
  247. checkCollectionStatus(assessmentId.value);
  248. common_vendor.index.showToast({ title: "收藏成功", icon: "success" });
  249. }
  250. }
  251. } catch (err) {
  252. common_vendor.index.__f__("error", "at pages/assessment/detail.vue:394", "操作收藏失败", err);
  253. common_vendor.index.showToast({ title: "操作失败", icon: "none" });
  254. } finally {
  255. common_vendor.index.hideLoading();
  256. }
  257. };
  258. return (_ctx, _cache) => {
  259. return common_vendor.e({
  260. a: common_assets._imports_0$7,
  261. b: common_vendor.o(goBack),
  262. c: statusBarHeight.value + "px",
  263. d: common_vendor.f(bannerImages.value, (img, index, i0) => {
  264. return {
  265. a: img,
  266. b: index
  267. };
  268. }),
  269. e: !loading.value
  270. }, !loading.value ? common_vendor.e({
  271. f: common_vendor.t(assessmentData.value.evaluationName || "测评详情"),
  272. g: assessmentData.value.startTime && assessmentData.value.endTime
  273. }, assessmentData.value.startTime && assessmentData.value.endTime ? {
  274. h: common_vendor.t(formatDateRange(assessmentData.value.startTime, assessmentData.value.endTime))
  275. } : {}, {
  276. i: assessmentData.value.questionTypes
  277. }, assessmentData.value.questionTypes ? {
  278. j: common_vendor.t(assessmentData.value.questionTypes)
  279. } : {}, {
  280. k: assessmentData.value.questionCount
  281. }, assessmentData.value.questionCount ? {
  282. l: common_vendor.t(assessmentData.value.questionCount)
  283. } : {}, {
  284. m: assessmentData.value.duration
  285. }, assessmentData.value.duration ? {
  286. n: common_vendor.t(assessmentData.value.duration)
  287. } : {}) : {}, {
  288. o: loading.value
  289. }, loading.value ? {} : {}, {
  290. p: !loading.value
  291. }, !loading.value ? common_vendor.e({
  292. q: tags.value.length > 0
  293. }, tags.value.length > 0 ? {
  294. r: common_vendor.f(tags.value, (tag, k0, i0) => {
  295. return {
  296. a: common_vendor.t(tag),
  297. b: tag
  298. };
  299. })
  300. } : {}, {
  301. s: displayDescription.value
  302. }, displayDescription.value ? {
  303. t: common_vendor.t(displayDescription.value)
  304. } : {}) : {}, {
  305. v: assessmentData.value.detail && assessmentData.value.detail.includes("<")
  306. }, assessmentData.value.detail && assessmentData.value.detail.includes("<") ? {
  307. w: assessmentData.value.detail
  308. } : {}, {
  309. x: isFavorited.value ? "/static/icons/star_filled.svg" : "/static/icons/star_hollow.svg",
  310. y: common_vendor.t(isFavorited.value ? "已收藏" : "收藏"),
  311. z: common_vendor.n(isFavorited.value ? "active" : ""),
  312. A: common_vendor.o(toggleFavorite),
  313. B: !hasPaid.value && !hasRecord.value
  314. }, !hasPaid.value && !hasRecord.value ? {
  315. C: common_vendor.o(handleConsult)
  316. } : {}, {
  317. D: hasPaid.value && !hasRecord.value
  318. }, hasPaid.value && !hasRecord.value ? {
  319. E: common_vendor.o(goToRemind)
  320. } : {}, {
  321. F: hasRecord.value
  322. }, hasRecord.value ? {
  323. G: !isAllCompleted.value ? 1 : "",
  324. H: common_vendor.o(viewReport)
  325. } : {}, {
  326. I: hasRecord.value && !isPassed.value
  327. }, hasRecord.value && !isPassed.value ? {
  328. J: common_vendor.o(goToRemind)
  329. } : {}, {
  330. K: isPassed.value && !isApplied.value
  331. }, isPassed.value && !isApplied.value ? {
  332. L: common_vendor.o(handleApply)
  333. } : {}, {
  334. M: isPassed.value && isApplied.value
  335. }, isPassed.value && isApplied.value ? {} : {});
  336. };
  337. }
  338. };
  339. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-db914789"]]);
  340. wx.createPage(MiniProgramPage);
  341. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/assessment/detail.js.map