detail.js 15 KB

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