detail.vue 19 KB

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