detail.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. <template>
  2. <view class="container">
  3. <!-- ① 固定返回按钮:适配状态栏,带阴影层确保白图标可见 -->
  4. <view class="custom-nav" :style="{ paddingTop: statusBarHeight + 'px' }">
  5. <view class="nav-back-wrap" @click="goBack">
  6. <image src="/static/icons/back_white.svg" class="back-icon" mode="aspectFit"></image>
  7. </view>
  8. </view>
  9. <!-- ② 核心滑动容器:显式关闭滚动条,设定 flex: 1 确保可滑动 -->
  10. <scroll-view
  11. class="scroll-body"
  12. scroll-y
  13. :show-scrollbar="false"
  14. :enhanced="true"
  15. >
  16. <!-- 轮播图区域 -->
  17. <view class="banner-section">
  18. <swiper class="banner-swiper" circular autoplay interval="3000" indicator-dots indicator-active-color="#FFFFFF">
  19. <swiper-item v-for="(img, index) in bannerImages" :key="index">
  20. <image :src="img" class="banner-img" mode="aspectFill"></image>
  21. </swiper-item>
  22. </swiper>
  23. </view>
  24. <!-- 内容主体:还原单一白底背板 -->
  25. <view class="content-panel">
  26. <view class="header-info" v-if="!loading">
  27. <text class="title">{{ assessmentData.evaluationName || '测评详情' }}</text>
  28. <view class="meta-list">
  29. <view class="meta-item" v-if="assessmentData.startTime && assessmentData.endTime">
  30. <text class="label">参与时间:</text>
  31. <text class="value">{{ formatDateRange(assessmentData.startTime, assessmentData.endTime) }}</text>
  32. </view>
  33. <view class="meta-item" v-if="assessmentData.questionTypes">
  34. <text class="label">考题题型:</text>
  35. <text class="value">{{ assessmentData.questionTypes }}</text>
  36. </view>
  37. <view class="meta-item" v-if="assessmentData.questionCount">
  38. <text class="label">考题数量:</text>
  39. <text class="value">{{ assessmentData.questionCount }}题</text>
  40. </view>
  41. <view class="meta-item" v-if="assessmentData.duration">
  42. <text class="label">考试时间:</text>
  43. <text class="value">{{ assessmentData.duration }}分钟</text>
  44. </view>
  45. </view>
  46. </view>
  47. <!-- 加载状态 -->
  48. <view class="loading-state" v-if="loading">
  49. <text class="loading-text">加载中...</text>
  50. </view>
  51. <view class="divider-line"></view>
  52. <view class="detail-section" v-if="!loading">
  53. <text class="section-title">测评详情</text>
  54. <view class="tag-cloud" v-if="tags.length > 0">
  55. <text class="detail-tag" v-for="tag in tags" :key="tag">{{ tag }}</text>
  56. </view>
  57. <view class="description" v-if="displayDescription">
  58. <text class="desc-label">测评描述:</text>
  59. <text class="desc-content">
  60. {{ displayDescription }}
  61. </text>
  62. </view>
  63. </view>
  64. <!-- 富文本内容 (严格控制侧边距) -->
  65. <view class="diagram-section" v-if="assessmentData.detail && assessmentData.detail.includes('<')">
  66. <rich-text :nodes="assessmentData.detail"></rich-text>
  67. </view>
  68. <!-- ③ 到底啦提示 -->
  69. <view class="end-of-page">
  70. <view class="line"></view>
  71. <text class="end-text">已到底啦~</text>
  72. <view class="line"></view>
  73. </view>
  74. <!-- 底部撑开,预留按钮位置 -->
  75. <view class="bottom-placeholder"></view>
  76. </view>
  77. </scroll-view>
  78. <!-- ④ 底部固定操作栏 -->
  79. <view class="bottom-bar">
  80. <view class="action-item" @click="toggleFavorite">
  81. <image :src="isFavorited ? '/static/icons/star_filled.svg' : '/static/icons/star_hollow.svg'" class="action-icon"></image>
  82. <text :class="['action-text', isFavorited ? 'active' : '']">{{ isFavorited ? '已收藏' : '收藏' }}</text>
  83. </view>
  84. <button v-if="!hasPaid && !hasRecord" class="small-consult-btn" @click="handleConsult">咨询</button>
  85. <button v-if="hasPaid && !hasRecord" class="start-exam-btn" @click="goToRemind">开始测评</button>
  86. <button
  87. v-if="hasRecord"
  88. class="report-btn"
  89. :class="{ disabled: !isAllCompleted }"
  90. @click="viewReport"
  91. >查看报告</button>
  92. <button v-if="hasRecord && !isPassed" class="start-exam-btn" @click="goToRemind">重新测评</button>
  93. <button v-if="isPassed && !isApplied" class="apply-btn" @click="handleApply">投递简历</button>
  94. <button v-if="isPassed && isApplied" class="applied-btn">已投递</button>
  95. </view>
  96. </view>
  97. </template>
  98. <script setup>
  99. import { ref, onMounted, computed } from 'vue';
  100. import { onLoad } from '@dcloudio/uni-app';
  101. import { addCollection, delCollection, checkCollection } from '../../api/collection.js';
  102. import { createOrGetSession } from '../../api/message.js';
  103. import { getAssessmentDetail, getAssessmentRecordList } from '../../api/assessment.js';
  104. const statusBarHeight = ref(20);
  105. const isFavorited = ref(false);
  106. const collectionId = ref(null);
  107. const assessmentId = ref(null);
  108. const loading = ref(true);
  109. const assessmentData = ref({});
  110. const bannerImages = ref([
  111. '/static/images/assess_cover.svg',
  112. '/static/images/assess_cover.svg'
  113. ]);
  114. const tags = ref([]);
  115. // 测评记录相关
  116. const hasRecord = ref(false); // 是否有测评记录
  117. const isAllCompleted = ref(false); // 是否全部考完(finalResult 有值)
  118. const hasPaid = ref(false); // 是否已付款
  119. const isPassed = ref(false); // 是否测评通过
  120. const isApplied = ref(false); // 是否已投递简历
  121. const decodeBase64Utf8 = (value) => {
  122. if (!value || typeof value !== 'string') return '';
  123. try {
  124. const binary = atob(value);
  125. const bytes = Array.from(binary, char => char.charCodeAt(0));
  126. return decodeURIComponent(bytes.map(byte => `%${byte.toString(16).padStart(2, '0')}`).join(''));
  127. } catch (e) {
  128. return value;
  129. }
  130. };
  131. const displayDescription = computed(() => {
  132. const data = assessmentData.value || {};
  133. if (data.remark || data.description) {
  134. return data.remark || data.description;
  135. }
  136. if (data.detail) {
  137. return /^[A-Za-z0-9+/=]+$/.test(data.detail) ? decodeBase64Utf8(data.detail) : data.detail;
  138. }
  139. return '暂无描述';
  140. });
  141. onMounted(() => {
  142. // #ifdef MP-WEIXIN
  143. const sysInfo = uni.getSystemInfoSync();
  144. statusBarHeight.value = (sysInfo.statusBarHeight || 20);
  145. // #endif
  146. });
  147. onLoad((options) => {
  148. if (options.id) {
  149. assessmentId.value = options.id;
  150. loadAssessmentDetail(options.id);
  151. checkCollectionStatus(options.id);
  152. checkExamRecord(options.id);
  153. }
  154. });
  155. // 加载测评详情数据
  156. const loadAssessmentDetail = async (id) => {
  157. try {
  158. loading.value = true;
  159. const res = await getAssessmentDetail(id);
  160. if (res.code === 200 && res.data) {
  161. assessmentData.value = res.data;
  162. // 处理标签数据
  163. if (res.data.tags) {
  164. tags.value = res.data.tags.split(',').filter(tag => tag.trim());
  165. }
  166. // 处理轮播图
  167. if (res.data.imageAlbumUrls) {
  168. const urls = res.data.imageAlbumUrls.split(',');
  169. bannerImages.value = urls.length > 0 ? urls : ['/static/images/assess_cover.svg'];
  170. } else if (res.data.mainImageUrl) {
  171. bannerImages.value = [res.data.mainImageUrl];
  172. } else {
  173. bannerImages.value = ['/static/images/assess_cover.svg'];
  174. }
  175. // 检查是否已投递简历(基于关联的岗位ID)
  176. if (res.data.positionId) {
  177. isApplied.value = uni.getStorageSync(`candidate_applied_${res.data.positionId}`) === true;
  178. }
  179. } else {
  180. uni.showToast({ title: '获取测评详情失败', icon: 'none' });
  181. }
  182. } catch (err) {
  183. console.error('获取测评详情失败:', err);
  184. uni.showToast({ title: '网络错误,请重试', icon: 'none' });
  185. } finally {
  186. loading.value = false;
  187. }
  188. };
  189. // 检查收藏状态
  190. const checkCollectionStatus = async (id) => {
  191. const userInfo = uni.getStorageSync('userInfo');
  192. if (!userInfo || !userInfo.studentId) return;
  193. try {
  194. const res = await checkCollection(userInfo.studentId, id, 'assessment');
  195. if (res.code === 200 && res.data) {
  196. isFavorited.value = true;
  197. collectionId.value = res.data.id;
  198. } else {
  199. isFavorited.value = false;
  200. collectionId.value = null;
  201. }
  202. } catch (err) {
  203. console.error('检查收藏状态失败', err);
  204. }
  205. };
  206. // 格式化日期范围
  207. const formatDateRange = (startTime, endTime) => {
  208. if (!startTime || !endTime) return '';
  209. const formatDate = (dateStr) => {
  210. const date = new Date(dateStr);
  211. const year = date.getFullYear();
  212. const month = String(date.getMonth() + 1).padStart(2, '0');
  213. const day = String(date.getDate()).padStart(2, '0');
  214. const hours = String(date.getHours()).padStart(2, '0');
  215. const minutes = String(date.getMinutes()).padStart(2, '0');
  216. return `${year}.${month}.${day} ${hours}:${minutes}`;
  217. };
  218. return `${formatDate(startTime)}—${formatDate(endTime)}`;
  219. };
  220. const goBack = () => uni.navigateBack();
  221. // 跳转到测评提醒页面
  222. const goToRemind = () => {
  223. if (!assessmentId.value) {
  224. uni.showToast({ title: '测评信息加载中', icon: 'none' });
  225. return;
  226. }
  227. uni.navigateTo({
  228. url: `/pages/assessment/remind?id=${assessmentId.value}`
  229. });
  230. };
  231. // 查看考试报告
  232. const viewReport = () => {
  233. if (!assessmentId.value || !isAllCompleted.value) return;
  234. uni.navigateTo({
  235. url: `/pages/assessment/report?id=${assessmentId.value}`
  236. });
  237. };
  238. // 检查是否有测评记录
  239. const checkExamRecord = async (id) => {
  240. const userInfo = uni.getStorageSync('userInfo') || {};
  241. const studentId = userInfo.studentId;
  242. if (!studentId) return;
  243. // 检查是否已付款
  244. hasPaid.value = uni.getStorageSync(`audit_paid_${id}`) === true;
  245. try {
  246. const res = await getAssessmentRecordList(studentId);
  247. if (res.code === 200 && res.data) {
  248. // 找到当前测评的记录
  249. const records = res.data.filter(r => String(r.evaluationId) === String(id));
  250. if (records.length > 0) {
  251. hasRecord.value = true;
  252. // 检查是否全部考完(finalResult 有值表示已完成评分)
  253. const completedRecords = records.filter(r => r.finalResult === '1' || r.finalResult === '2');
  254. isAllCompleted.value = completedRecords.length > 0;
  255. // 检查是否通过
  256. const passedRecords = records.filter(r => r.finalResult === '1');
  257. isPassed.value = passedRecords.length > 0;
  258. }
  259. }
  260. // 检查是否已投递(需要等 assessmentData 加载完成后才有 positionId)
  261. if (assessmentData.value.positionId) {
  262. isApplied.value = uni.getStorageSync(`candidate_applied_${assessmentData.value.positionId}`) === true;
  263. }
  264. } catch (err) {
  265. console.error('检查测评记录失败', err);
  266. }
  267. };
  268. const handleConsult = async () => {
  269. try {
  270. uni.showLoading({ title: '正在连接客服...' });
  271. const userInfo = uni.getStorageSync('userInfo') || {};
  272. const userId = userInfo.studentId || null;
  273. const userName = userInfo.name || '用户';
  274. const userAvatar = userInfo.avatarUrl || '/static/images/user_avatar.svg';
  275. console.log('创建会话参数:', {
  276. sessionType: 1,
  277. fromUserId: userId,
  278. fromUserName: userName,
  279. fromUserAvatar: userAvatar,
  280. sourceId: 'assessment_' + (assessmentData.value?.id || assessmentId.value)
  281. });
  282. const res = await createOrGetSession({
  283. sessionType: 1,
  284. fromUserId: userId,
  285. fromUserName: userName,
  286. fromUserAvatar: userAvatar,
  287. sourceId: 'assessment_' + (assessmentData.value?.id || assessmentId.value)
  288. });
  289. uni.hideLoading();
  290. if (res.data) {
  291. const session = res.data;
  292. const title = encodeURIComponent(assessmentData.value.evaluationName || '测评详情');
  293. const cover = encodeURIComponent(bannerImages.value[0] || '');
  294. const price = assessmentData.value.price || '0.00';
  295. uni.navigateTo({
  296. 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}`
  297. });
  298. } else {
  299. uni.showToast({ title: '创建会话失败', icon: 'none' });
  300. }
  301. } catch (err) {
  302. uni.hideLoading();
  303. console.error('创建会话失败:', err);
  304. uni.showToast({ title: '连接失败,请重试', icon: 'none' });
  305. }
  306. };
  307. // 投递简历:跳转到选择简历页面
  308. const handleApply = () => {
  309. const postId = assessmentData.value.positionId;
  310. if (!postId) {
  311. uni.showToast({ title: '该测评未关联岗位,无法投递', icon: 'none' });
  312. return;
  313. }
  314. const userInfo = uni.getStorageSync('userInfo') || {};
  315. if (!userInfo.studentId) {
  316. uni.showToast({ title: '请先登录', icon: 'none' });
  317. return;
  318. }
  319. uni.navigateTo({
  320. url: `/pages/my/select-resume?postId=${postId}`
  321. });
  322. };
  323. const toggleFavorite = async () => {
  324. const userInfo = uni.getStorageSync('userInfo');
  325. if (!userInfo || !userInfo.studentId) {
  326. uni.showToast({ title: '请先登录', icon: 'none' });
  327. setTimeout(() => {
  328. uni.navigateTo({ url: '/pages/login/login' });
  329. }, 1000);
  330. return;
  331. }
  332. if (!assessmentId.value) return;
  333. uni.showLoading({ title: isFavorited.value ? '取消收藏中...' : '收藏中...' });
  334. try {
  335. if (isFavorited.value) {
  336. // 取消收藏
  337. if (collectionId.value) {
  338. const res = await delCollection(collectionId.value);
  339. if (res.code === 200) {
  340. isFavorited.value = false;
  341. collectionId.value = null;
  342. uni.showToast({ title: '已取消收藏', icon: 'none' });
  343. }
  344. }
  345. } else {
  346. // 添加收藏
  347. const res = await addCollection({
  348. studentId: userInfo.studentId,
  349. targetId: assessmentId.value,
  350. type: 'assessment'
  351. });
  352. if (res.code === 200) {
  353. isFavorited.value = true;
  354. checkCollectionStatus(assessmentId.value);
  355. uni.showToast({ title: '收藏成功', icon: 'success' });
  356. }
  357. }
  358. } catch (err) {
  359. console.error('操作收藏失败', err);
  360. uni.showToast({ title: '操作失败', icon: 'none' });
  361. } finally {
  362. uni.hideLoading();
  363. }
  364. };
  365. </script>
  366. <style lang="scss" scoped>
  367. .container {
  368. width: 100%;
  369. height: 100vh;
  370. background-color: #FFFFFF;
  371. display: flex;
  372. flex-direction: column;
  373. overflow: hidden; /* 防止页面整体滚动,交给 scroll-view */
  374. }
  375. /* 返回按钮 */
  376. .custom-nav {
  377. position: fixed; top: 0; left: 0; width: 100%; z-index: 999;
  378. padding-left: 30rpx;
  379. .nav-back-wrap {
  380. width: 64rpx; height: 64rpx; background: rgba(0,0,0,0.35); border-radius: 50%;
  381. display: flex; align-items: center; justify-content: center;
  382. margin-top: 10px;
  383. .back-icon { width: 44rpx; height: 44rpx; }
  384. }
  385. }
  386. /* 滑动主体 */
  387. .scroll-body {
  388. flex: 1; /* 撑满剩余空间 */
  389. height: 0; /* 触发 flex 计算 */
  390. }
  391. /* 轮播图 */
  392. .banner-section {
  393. width: 100%; height: 500rpx;
  394. .banner-swiper { width: 100%; height: 100%; }
  395. .banner-img { width: 100%; height: 100%; }
  396. }
  397. /* 内容板块 */
  398. .content-panel {
  399. background: #FFF;
  400. border-radius: 40rpx 40rpx 0 0;
  401. margin-top: -40rpx;
  402. position: relative;
  403. z-index: 10;
  404. padding: 50rpx 40rpx 0;
  405. .header-info {
  406. margin-bottom: 40rpx;
  407. .title { font-size: 44rpx; font-weight: bold; color: #1A1A1A; display: block; margin-bottom: 30rpx; }
  408. .meta-list {
  409. display: flex; flex-direction: column; gap: 16rpx;
  410. .meta-item {
  411. display: flex; font-size: 28rpx;
  412. .label { color: #666; width: 160rpx; flex-shrink: 0; }
  413. .value { color: #333; font-weight: 500; }
  414. }
  415. }
  416. }
  417. .divider-line {
  418. height: 1rpx; background: #F0F0F0; margin: 40rpx 0;
  419. }
  420. .detail-section {
  421. margin-bottom: 40rpx;
  422. .section-title { font-size: 34rpx; font-weight: bold; color: #1A1A1A; display: block; margin-bottom: 30rpx; }
  423. .tag-cloud {
  424. display: flex; flex-wrap: wrap; gap: 16rpx; margin-bottom: 32rpx;
  425. .detail-tag { font-size: 24rpx; color: #666; background: #F5F7FA; padding: 10rpx 24rpx; border-radius: 10rpx; }
  426. }
  427. .description {
  428. margin-bottom: 40rpx;
  429. .desc-label { font-size: 28rpx; color: #1A1A1A; font-weight: bold; display: block; margin-bottom: 12rpx; }
  430. .desc-content { font-size: 28rpx; color: #666; line-height: 1.6; }
  431. }
  432. }
  433. .diagram-section {
  434. width: 100%; margin-top: 20rpx;
  435. .diagram-img { width: 100%; border-radius: 12rpx; }
  436. }
  437. .loading-state {
  438. display: flex; justify-content: center; align-items: center;
  439. padding: 80rpx 0;
  440. .loading-text { font-size: 28rpx; color: #999; }
  441. }
  442. }
  443. .end-of-page {
  444. display: flex; align-items: center; justify-content: center; padding: 60rpx 0 40rpx;
  445. .line { width: 60rpx; height: 1rpx; background: #EEE; margin: 0 20rpx; }
  446. .end-text { font-size: 24rpx; color: #BBB; }
  447. }
  448. .bottom-placeholder {
  449. height: calc(140rpx + env(safe-area-inset-bottom));
  450. }
  451. .bottom-bar {
  452. position: fixed; bottom: 0; left: 0; right: 0; background: #FFF;
  453. padding: 20rpx 40rpx; padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
  454. box-shadow: 0 -4rpx 20rpx rgba(0,0,0,0.05); z-index: 1000;
  455. display: flex; align-items: center; gap: 40rpx;
  456. .action-item {
  457. display: flex; flex-direction: column; align-items: center; min-width: 100rpx;
  458. .action-icon { width: 44rpx; height: 44rpx; margin-bottom: 4rpx; }
  459. .action-text { font-size: 22rpx; color: #666; &.active { color: #FFB700; } }
  460. }
  461. .small-consult-btn {
  462. flex: 1; height: 84rpx; line-height: 84rpx;
  463. background: #FFB700; color: #FFF; border-radius: 42rpx;
  464. font-size: 30rpx; font-weight: bold;
  465. box-shadow: 0 6rpx 12rpx rgba(255, 183, 0, 0.2);
  466. &::after { border: none; }
  467. &:active { opacity: 0.9; }
  468. }
  469. .report-btn {
  470. flex: 1; height: 84rpx; line-height: 84rpx;
  471. background: #E8F0FF; color: #2B5CFF; border-radius: 42rpx;
  472. font-size: 30rpx; font-weight: bold;
  473. &::after { border: none; }
  474. &:active { opacity: 0.9; }
  475. &.disabled {
  476. background: #F0F2F5; color: #C0C4CC; pointer-events: none;
  477. }
  478. }
  479. .start-exam-btn {
  480. flex: 1.5; height: 84rpx; line-height: 84rpx;
  481. background: linear-gradient(135deg, #1F6CFF 0%, #0056FF 100%); color: #FFF; border-radius: 42rpx;
  482. font-size: 30rpx; font-weight: bold;
  483. box-shadow: 0 6rpx 16rpx rgba(31, 108, 255, 0.3);
  484. &::after { border: none; }
  485. &:active { opacity: 0.9; transform: scale(0.98); }
  486. }
  487. .apply-btn {
  488. flex: 1.5; height: 84rpx; line-height: 84rpx;
  489. background: #1F6CFF; color: #FFF; border-radius: 42rpx;
  490. font-size: 30rpx; font-weight: bold;
  491. box-shadow: 0 6rpx 16rpx rgba(31, 108, 255, 0.3);
  492. &::after { border: none; }
  493. &:active { opacity: 0.9; transform: scale(0.98); }
  494. }
  495. .applied-btn {
  496. flex: 1.5; height: 84rpx; line-height: 84rpx;
  497. background: #E0E0E0; color: #999; border-radius: 42rpx;
  498. font-size: 30rpx; font-weight: bold;
  499. &::after { border: none; }
  500. }
  501. }
  502. </style>
  503. <style>
  504. /* 针对所有 scroll-view 隐藏滚动条 */
  505. ::-webkit-scrollbar {
  506. display: none !important;
  507. width: 0 !important;
  508. height: 0 !important;
  509. background: transparent;
  510. }
  511. </style>