activityDetail.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. <template>
  2. <!-- 运营活动管理 - 详情页面 -->
  3. <div class="table-box" style="width: 100%; min-height: 100%; background-color: white">
  4. <div class="header">
  5. <el-button @click="goBack"> 返回 </el-button>
  6. <h2 class="title">运营活动详情</h2>
  7. </div>
  8. <div class="content">
  9. <!-- 左侧内容区域 -->
  10. <div class="contentLeft">
  11. <!-- 基础信息模块 -->
  12. <div class="model">
  13. <h3 style="font-weight: bold">基础信息:</h3>
  14. <!-- 活动名称 -->
  15. <div class="detail-item">
  16. <div class="detail-label">活动名称</div>
  17. <div class="detail-value">
  18. {{ activityModel.activityName || "--" }}
  19. </div>
  20. </div>
  21. <!-- 活动类型 -->
  22. <div class="detail-item">
  23. <div class="detail-label">活动类型</div>
  24. <div class="detail-value">
  25. {{ getActivityTypeLabel(activityModel.activityType) }}
  26. </div>
  27. </div>
  28. <!-- 活动时间 -->
  29. <div class="detail-item">
  30. <div class="detail-label">活动时间</div>
  31. <div class="detail-value">
  32. <span v-if="activityModel.startTime && activityModel.endTime">
  33. {{ formatDate(activityModel.startTime) }} - {{ formatDate(activityModel.endTime) }}
  34. </span>
  35. <span v-else>--</span>
  36. </div>
  37. </div>
  38. <!-- 评论有礼相关字段 -->
  39. <template v-if="activityModel.activityType == 2">
  40. <!-- 用户可参与次数 -->
  41. <div class="detail-item">
  42. <div class="detail-label">用户可参与次数</div>
  43. <div class="detail-value">
  44. {{ activityModel.participationLimit || "--" }}
  45. </div>
  46. </div>
  47. <!-- 优惠券/代金券名称 -->
  48. <div class="detail-item">
  49. <div class="detail-label">
  50. {{ activityModel.rewardType === "VOUCHER" ? "代金券" : "优惠券" }}
  51. </div>
  52. <div class="detail-value">
  53. {{
  54. activityModel.rewardType === "VOUCHER" ? activityModel.voucherName || "--" : activityModel.couponName || "--"
  55. }}
  56. </div>
  57. </div>
  58. <!-- 优惠券/代金券发放数量 -->
  59. <div class="detail-item">
  60. <div class="detail-label">
  61. {{ (activityModel.rewardType === "VOUCHER" ? "代金券" : "优惠券") + "发放数量" }}
  62. </div>
  63. <div class="detail-value">
  64. {{
  65. activityModel.rewardType === "VOUCHER"
  66. ? activityModel.voucherQuantity || "--"
  67. : activityModel.couponQuantity || "--"
  68. }}
  69. </div>
  70. </div>
  71. </template>
  72. <!-- 营销活动相关字段 -->
  73. <template v-if="activityModel.activityType == 1">
  74. <!-- 报名时间 -->
  75. <div class="detail-item">
  76. <div class="detail-label">报名时间</div>
  77. <div class="detail-value">
  78. <span v-if="activityModel.signupStartTime && activityModel.signupEndTime">
  79. {{ activityModel.signupStartTime.split(" ")[0] }} - {{ activityModel.signupEndTime.split(" ")[0] }}
  80. </span>
  81. <span v-else>--</span>
  82. </div>
  83. </div>
  84. <!-- 活动限制人数 -->
  85. <div class="detail-item">
  86. <div class="detail-label">活动限制人数</div>
  87. <div class="detail-value">
  88. {{ activityModel.activityLimitPeople + "人" || "无限制" }}
  89. </div>
  90. </div>
  91. <!-- 活动详情 -->
  92. <div class="detail-item">
  93. <div class="detail-label">活动详情</div>
  94. <div class="detail-value" style="word-break: break-word; white-space: pre-wrap">
  95. {{ activityModel.activityDetails || "--" }}
  96. </div>
  97. </div>
  98. </template>
  99. <!-- 审核状态 -->
  100. <div class="detail-item">
  101. <div class="detail-label">审核状态</div>
  102. <div class="detail-value">
  103. {{ activityModel.auditStatus == 1 ? "审核通过" : "审核驳回" }}
  104. </div>
  105. </div>
  106. <!-- 审核时间 -->
  107. <div class="detail-item" v-if="activityModel.auditTime">
  108. <div class="detail-label">审核时间</div>
  109. <div class="detail-value">
  110. {{ formatDateTime(activityModel.auditTime) }}
  111. </div>
  112. </div>
  113. <!-- 审核拒绝原因 -->
  114. <div class="detail-item" v-if="activityModel.approvalComments">
  115. <div class="detail-label">审核拒绝原因</div>
  116. <div class="detail-value" style="word-break: break-word; white-space: pre-wrap">
  117. {{ activityModel.approvalComments }}
  118. </div>
  119. </div>
  120. </div>
  121. </div>
  122. <!-- 右侧内容区域 -->
  123. <div class="contentRight">
  124. <!-- 活动宣传图模块 -->
  125. <div class="model">
  126. <div class="promotion-images-container">
  127. <!-- 活动标题图 -->
  128. <div class="promotion-image-item">
  129. <h3 style="font-weight: bold">活动标题图:</h3>
  130. <div class="image-container">
  131. <div v-if="getImageUrl(activityModel.activityTitleImgUrl)" class="image-item">
  132. <el-image
  133. :src="getImageUrl(activityModel.activityTitleImgUrl)"
  134. fit="contain"
  135. class="promotion-image"
  136. :preview-src-list="getPreviewImageList()"
  137. :initial-index="0"
  138. >
  139. <template #error>
  140. <div class="image-slot">
  141. <el-icon>
  142. <Picture />
  143. </el-icon>
  144. </div>
  145. </template>
  146. </el-image>
  147. </div>
  148. <div v-else class="empty-text">--</div>
  149. </div>
  150. </div>
  151. <!-- 活动详情图 -->
  152. <div class="promotion-image-item">
  153. <h3 style="font-weight: bold">活动详情图:</h3>
  154. <div class="image-container">
  155. <div v-if="detailImageList.length > 0" class="detail-images-grid">
  156. <div
  157. v-for="(imgUrl, index) in detailImageList"
  158. :key="index"
  159. class="detail-image-item"
  160. @click="previewDetailImage(index)"
  161. >
  162. <el-image
  163. :src="imgUrl"
  164. fit="cover"
  165. class="detail-image"
  166. :preview-src-list="getPreviewImageList()"
  167. :initial-index="getImageUrl(activityModel.activityTitleImgUrl) ? index + 1 : index"
  168. >
  169. <template #error>
  170. <div class="image-slot">
  171. <el-icon>
  172. <Picture />
  173. </el-icon>
  174. </div>
  175. </template>
  176. </el-image>
  177. </div>
  178. </div>
  179. <div v-else class="empty-text">--</div>
  180. </div>
  181. </div>
  182. </div>
  183. </div>
  184. </div>
  185. </div>
  186. </div>
  187. </template>
  188. <script setup lang="tsx" name="activityDetail">
  189. /**
  190. * 运营活动管理 - 详情页面
  191. * 功能:显示运营活动的详细信息
  192. */
  193. import { ref, onMounted, computed } from "vue";
  194. import { useRouter, useRoute } from "vue-router";
  195. import { ElMessage } from "element-plus";
  196. import { Picture } from "@element-plus/icons-vue";
  197. import { getActivityDetail } from "@/api/modules/operationManagement";
  198. // ==================== 响应式数据定义 ====================
  199. // 路由相关
  200. const router = useRouter();
  201. const route = useRoute();
  202. // 页面ID参数
  203. const id = ref<string>("");
  204. // ==================== 活动信息数据模型 ====================
  205. const activityModel = ref<any>({
  206. // 活动类型:1-评论有礼,2-营销活动
  207. activityType: 1,
  208. // 活动名称
  209. activityName: "",
  210. // 活动开始时间
  211. startTime: "",
  212. // 活动结束时间
  213. endTime: "",
  214. // 用户可参与次数(评论有礼)
  215. participationLimit: 0,
  216. // 券类型:'COUPON'-优惠券,'VOUCHER'-代金券(评论有礼)
  217. rewardType: "COUPON",
  218. // 优惠券ID(评论有礼)
  219. couponId: "",
  220. // 优惠券名称(评论有礼)
  221. couponName: "",
  222. // 优惠券发放数量(评论有礼)
  223. couponQuantity: 0,
  224. // 代金券ID(评论有礼)
  225. voucherId: "",
  226. // 代金券名称(评论有礼)
  227. voucherName: "",
  228. // 代金券发放数量(评论有礼)
  229. voucherQuantity: 0,
  230. // 报名开始时间(营销活动)
  231. signupStartTime: "",
  232. // 报名结束时间(营销活动)
  233. signupEndTime: "",
  234. // 活动限制人数(营销活动)
  235. activityLimitPeople: "",
  236. // 活动详情(营销活动)
  237. activityDetails: "",
  238. // 活动标题图片
  239. activityTitleImgUrl: null,
  240. // 活动详情图片
  241. activityDetailImgUrl: null,
  242. // 状态
  243. status: 0,
  244. // 审核时间
  245. approvalTime: "",
  246. auditTime: "",
  247. // 审核拒绝原因
  248. approvalComments: ""
  249. });
  250. // ==================== 生命周期钩子 ====================
  251. /**
  252. * 组件挂载时初始化
  253. * 从路由参数中获取ID并加载详情数据
  254. */
  255. onMounted(async () => {
  256. id.value = (route.query.id as string) || "";
  257. if (id.value) {
  258. await loadDetailData();
  259. } else {
  260. ElMessage.warning("缺少活动ID参数");
  261. }
  262. });
  263. // ==================== 事件处理函数 ====================
  264. /**
  265. * 返回上一页
  266. */
  267. const goBack = () => {
  268. router.go(-1);
  269. };
  270. // ==================== 数据加载函数 ====================
  271. /**
  272. * 加载详情数据
  273. */
  274. const loadDetailData = async () => {
  275. try {
  276. const res: any = await getActivityDetail({ id: id.value });
  277. if (res && res.code == 200) {
  278. // 合并主数据
  279. const data = res.data || {};
  280. // 兼容旧数据格式:如果后端返回的是 couponType(数字),转换为 rewardType(字符串)
  281. let rewardType = "COUPON";
  282. if (data.rewardType) {
  283. rewardType = data.rewardType;
  284. } else if (data.couponType !== undefined) {
  285. rewardType = data.couponType === 4 ? "VOUCHER" : "COUPON";
  286. }
  287. // 合并数据,并根据 rewardType 设置对应字段
  288. activityModel.value = { ...activityModel.value, ...data, rewardType };
  289. } else {
  290. ElMessage.error("加载详情数据失败");
  291. }
  292. } catch (error) {
  293. console.error("加载详情数据出错:", error);
  294. ElMessage.error("加载详情数据出错");
  295. }
  296. };
  297. // ==================== 工具函数 ====================
  298. /**
  299. * 格式化日期
  300. * @param date 日期字符串 (YYYY-MM-DD)
  301. * @returns 格式化后的日期字符串 (YYYY/MM/DD)
  302. */
  303. const formatDate = (date: string) => {
  304. if (!date) return "--";
  305. return date.replace(/-/g, "/");
  306. };
  307. /**
  308. * 格式化日期时间
  309. * @param dateTime 日期时间字符串
  310. * @returns 格式化后的日期时间字符串
  311. */
  312. const formatDateTime = (dateTime: string) => {
  313. if (!dateTime) return "--";
  314. // 将 - 替换为 /,并保持时间部分
  315. return dateTime.replace(/-/g, "/");
  316. };
  317. /**
  318. * 获取活动类型标签
  319. */
  320. const getActivityTypeLabel = (activityType: number) => {
  321. const typeMap: Record<number, string> = {
  322. 1: "营销活动",
  323. 2: "评论有礼"
  324. };
  325. return typeMap[activityType] || "--";
  326. };
  327. /**
  328. * 获取状态标签
  329. */
  330. const getStatusLabel = (status: number) => {
  331. const statusMap: Record<number, string> = {
  332. 1: "待审核",
  333. 2: "未开始",
  334. 3: "审核驳回",
  335. 5: "进行中",
  336. 6: "已下架",
  337. 7: "已结束",
  338. 8: "审核通过"
  339. };
  340. return statusMap[status] || "--";
  341. };
  342. /**
  343. * 获取审核状态标签(只显示审核相关的状态)
  344. */
  345. const getAuditStatusLabel = (status: number) => {
  346. const auditStatusMap: Record<number, string> = {
  347. 1: "待审核",
  348. 2: "未开始",
  349. 3: "审核驳回",
  350. 5: "审核通过",
  351. 8: "审核通过"
  352. };
  353. return auditStatusMap[status] || "--";
  354. };
  355. /**
  356. * 获取活动规则显示文本
  357. */
  358. const getRuleDisplayText = (ruleValue: any) => {
  359. if (!ruleValue) return "--";
  360. // 如果是字符串,尝试解析为数组
  361. let ruleArray: any[] = [];
  362. if (typeof ruleValue === "string") {
  363. try {
  364. ruleArray = JSON.parse(ruleValue);
  365. } catch {
  366. return ruleValue.replace(/,/g, " / ");
  367. }
  368. } else if (Array.isArray(ruleValue)) {
  369. ruleArray = ruleValue;
  370. } else {
  371. return ruleValue.replace(/,/g, " / ");
  372. }
  373. // 将数组转换为显示文本,用 " / " 连接
  374. if (ruleArray && ruleArray.length > 0) {
  375. return ruleArray.filter(item => item).join(" / ");
  376. }
  377. return "--";
  378. };
  379. /**
  380. * 获取图片URL(支持对象和字符串格式)
  381. */
  382. const getImageUrl = (img: any): string => {
  383. if (!img) return "";
  384. if (typeof img === "string") return img;
  385. if (img.url) return img.url;
  386. return "";
  387. };
  388. /**
  389. * 处理活动详情图列表(支持字符串、数组、对象数组)
  390. */
  391. const detailImageList = computed(() => {
  392. const imgData = activityModel.value.activityDetailImgUrl || activityModel.value.activityDetailImgUrlList;
  393. if (!imgData) return [];
  394. // 如果是字符串,可能是逗号分隔的多张图片
  395. if (typeof imgData === "string") {
  396. return imgData.split(",").filter((url: string) => url.trim());
  397. }
  398. // 如果是数组
  399. if (Array.isArray(imgData)) {
  400. return imgData
  401. .map((item: any) => {
  402. if (typeof item === "string") return item;
  403. if (item && item.url) return item.url;
  404. return "";
  405. })
  406. .filter((url: string) => url);
  407. }
  408. return [];
  409. });
  410. /**
  411. * 获取预览图片列表
  412. */
  413. const getPreviewImageList = () => {
  414. const list: string[] = [];
  415. const titleUrl = getImageUrl(activityModel.value.activityTitleImgUrl);
  416. if (titleUrl) {
  417. list.push(titleUrl);
  418. }
  419. // 添加所有详情图
  420. list.push(...detailImageList.value);
  421. return list;
  422. };
  423. /**
  424. * 预览详情图
  425. */
  426. const previewDetailImage = (index: number) => {
  427. // 预览功能由 el-image 的 preview-src-list 自动处理
  428. };
  429. </script>
  430. <style scoped lang="scss">
  431. /* 页面容器 */
  432. .table-box {
  433. display: flex;
  434. flex-direction: column;
  435. height: auto !important;
  436. min-height: 100%;
  437. }
  438. /* 头部区域 */
  439. .header {
  440. display: flex;
  441. align-items: center;
  442. padding: 20px 24px;
  443. background-color: #ffffff;
  444. border-bottom: 1px solid #e4e7ed;
  445. box-shadow: 0 2px 4px rgb(0 0 0 / 2%);
  446. }
  447. .title {
  448. flex: 1;
  449. margin: 0;
  450. font-size: 18px;
  451. font-weight: 600;
  452. color: #303133;
  453. text-align: center;
  454. }
  455. /* 内容区域布局 */
  456. .content {
  457. display: flex;
  458. flex: 1;
  459. column-gap: 24px;
  460. width: 100%;
  461. max-width: 800px;
  462. padding: 24px;
  463. margin: 0 auto;
  464. background-color: #ffffff;
  465. .contentLeft {
  466. width: 50%;
  467. padding-right: 12px;
  468. }
  469. .contentRight {
  470. width: 50%;
  471. padding-left: 12px;
  472. }
  473. }
  474. /* 模块容器 */
  475. .model {
  476. margin-bottom: 50px;
  477. h3 {
  478. width: 100%;
  479. padding-bottom: 12px;
  480. margin: 0 0 20px;
  481. font-size: 16px;
  482. color: #303133;
  483. border-bottom: 2px solid #e4e7ed;
  484. }
  485. }
  486. /* 详情项样式 */
  487. .detail-item {
  488. display: flex;
  489. align-items: flex-start;
  490. min-height: 32px;
  491. margin-bottom: 24px;
  492. }
  493. .detail-label {
  494. flex-shrink: 0;
  495. width: 140px;
  496. font-size: 14px;
  497. font-weight: 500;
  498. line-height: 32px;
  499. color: #606266;
  500. }
  501. .detail-value {
  502. flex: 1;
  503. font-size: 14px;
  504. line-height: 32px;
  505. color: #303133;
  506. word-break: break-word;
  507. }
  508. /* 活动宣传图容器 */
  509. .promotion-images-container {
  510. display: flex;
  511. flex-direction: column;
  512. gap: 24px;
  513. align-items: flex-start;
  514. width: 100%;
  515. }
  516. .promotion-image-item {
  517. display: flex;
  518. flex-direction: column;
  519. gap: 12px;
  520. align-items: flex-start;
  521. width: 100%;
  522. .image-label {
  523. font-size: 14px;
  524. font-weight: 500;
  525. color: #409eff;
  526. }
  527. }
  528. /* 图片容器样式 */
  529. .image-container {
  530. width: 100%;
  531. min-height: 100px;
  532. }
  533. .image-item {
  534. width: 100%;
  535. }
  536. .promotion-image {
  537. width: 100%;
  538. border-radius: 6px;
  539. box-shadow: 0 2px 12px rgb(0 0 0 / 10%);
  540. }
  541. .empty-text {
  542. padding: 20px 0;
  543. font-size: 14px;
  544. color: #909399;
  545. }
  546. /* 活动标题图 - 21:9横向样式 */
  547. .promotion-image-item:first-child {
  548. .image-container {
  549. width: 100%;
  550. }
  551. .image-item {
  552. width: 100%;
  553. aspect-ratio: 21 / 9;
  554. }
  555. .promotion-image {
  556. width: 100%;
  557. height: 100%;
  558. object-fit: contain;
  559. }
  560. }
  561. /* 活动详情图 - 网格布局 */
  562. .promotion-image-item:last-child {
  563. .image-container {
  564. width: 100%;
  565. }
  566. .detail-images-grid {
  567. display: grid;
  568. grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  569. gap: 12px;
  570. width: 100%;
  571. }
  572. .detail-image-item {
  573. width: 150px;
  574. height: 150px;
  575. overflow: hidden;
  576. cursor: pointer;
  577. background: #f5f7fa;
  578. border-radius: 8px;
  579. }
  580. .detail-image {
  581. width: 100%;
  582. height: 100%;
  583. object-fit: cover;
  584. }
  585. }
  586. .image-slot {
  587. display: flex;
  588. align-items: center;
  589. justify-content: center;
  590. width: 100%;
  591. height: 100%;
  592. min-height: 200px;
  593. font-size: 30px;
  594. color: var(--el-text-color-placeholder);
  595. background: var(--el-fill-color-light);
  596. }
  597. </style>