detail.js 14 KB

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