activityDetail.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  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. <span v-if="activityModel.startTime && activityModel.endTime">
  26. {{ formatDate(activityModel.startTime) }} - {{ formatDate(activityModel.endTime) }}
  27. </span>
  28. <span v-else>--</span>
  29. </div>
  30. </div>
  31. <!-- 用户可参与次数 -->
  32. <div class="detail-item">
  33. <div class="detail-label">用户可参与次数</div>
  34. <div class="detail-value">
  35. {{ activityModel.participationLimit || "--" }}
  36. </div>
  37. </div>
  38. <!-- 活动规则 -->
  39. <div class="detail-item">
  40. <div class="detail-label">活动规则</div>
  41. <div class="detail-value">
  42. {{ getRuleDisplayText(activityModel.activityRule) || "--" }}
  43. </div>
  44. </div>
  45. <!-- 优惠券名称 -->
  46. <div class="detail-item">
  47. <div class="detail-label">优惠券</div>
  48. <div class="detail-value">
  49. {{ activityModel.couponName || "--" }}
  50. </div>
  51. </div>
  52. <!-- 优惠券发放数量 -->
  53. <div class="detail-item">
  54. <div class="detail-label">优惠券发放数量</div>
  55. <div class="detail-value">
  56. {{ activityModel.couponQuantity || "--" }}
  57. </div>
  58. </div>
  59. <!-- 状态 -->
  60. <div class="detail-item">
  61. <div class="detail-label">状态</div>
  62. <div class="detail-value">
  63. {{ getStatusLabel(activityModel.status) }}
  64. </div>
  65. </div>
  66. </div>
  67. </div>
  68. <!-- 右侧内容区域 -->
  69. <div class="contentRight">
  70. <!-- 活动宣传图模块 -->
  71. <div class="model">
  72. <div class="promotion-images-container">
  73. <!-- 活动标题图 -->
  74. <div class="promotion-image-item">
  75. <h3 style="font-weight: bold">活动标题图:</h3>
  76. <div class="image-container">
  77. <div v-if="getImageUrl(activityModel.activityTitleImgUrl)" class="image-item">
  78. <el-image
  79. :src="getImageUrl(activityModel.activityTitleImgUrl)"
  80. fit="contain"
  81. class="promotion-image"
  82. :preview-src-list="getPreviewImageList()"
  83. :initial-index="0"
  84. >
  85. <template #error>
  86. <div class="image-slot">
  87. <el-icon><Picture /></el-icon>
  88. </div>
  89. </template>
  90. </el-image>
  91. </div>
  92. <div v-else class="empty-text">--</div>
  93. </div>
  94. </div>
  95. <!-- 活动详情图 -->
  96. <div class="promotion-image-item">
  97. <h3 style="font-weight: bold">活动详情图:</h3>
  98. <div class="image-container">
  99. <div v-if="getImageUrl(activityModel.activityDetailImgUrl)" class="image-item">
  100. <el-image
  101. :src="getImageUrl(activityModel.activityDetailImgUrl)"
  102. fit=""
  103. class="promotion-image"
  104. :preview-src-list="getPreviewImageList()"
  105. :initial-index="getImageUrl(activityModel.activityTitleImgUrl) ? 1 : 0"
  106. >
  107. <template #error>
  108. <div class="image-slot">
  109. <el-icon><Picture /></el-icon>
  110. </div>
  111. </template>
  112. </el-image>
  113. </div>
  114. <div v-else class="empty-text">--</div>
  115. </div>
  116. </div>
  117. </div>
  118. </div>
  119. </div>
  120. </div>
  121. </div>
  122. </template>
  123. <script setup lang="tsx" name="activityDetail">
  124. /**
  125. * 运营活动管理 - 详情页面
  126. * 功能:显示运营活动的详细信息
  127. */
  128. import { ref, onMounted } from "vue";
  129. import { useRouter, useRoute } from "vue-router";
  130. import { ElMessage } from "element-plus";
  131. import { Picture } from "@element-plus/icons-vue";
  132. import { getActivityDetail } from "@/api/modules/operationManagement";
  133. // ==================== 响应式数据定义 ====================
  134. // 路由相关
  135. const router = useRouter();
  136. const route = useRoute();
  137. // 页面ID参数
  138. const id = ref<string>("");
  139. // ==================== 活动信息数据模型 ====================
  140. const activityModel = ref<any>({
  141. // 活动名称
  142. activityName: "",
  143. // 活动开始时间
  144. startTime: "",
  145. // 活动结束时间
  146. endTime: "",
  147. // 用户可参与次数
  148. participationLimit: 0,
  149. // 活动规则
  150. activityRule: "",
  151. // 优惠券ID
  152. couponId: "",
  153. // 优惠券名称
  154. couponName: "",
  155. // 优惠券发放数量
  156. couponQuantity: 0,
  157. // 活动标题图片
  158. activityTitleImgUrl: null,
  159. // 活动详情图片
  160. activityDetailImgUrl: null,
  161. // 状态
  162. status: 0
  163. });
  164. // ==================== 生命周期钩子 ====================
  165. /**
  166. * 组件挂载时初始化
  167. * 从路由参数中获取ID并加载详情数据
  168. */
  169. onMounted(async () => {
  170. id.value = (route.query.id as string) || "";
  171. if (id.value) {
  172. await loadDetailData();
  173. } else {
  174. ElMessage.warning("缺少活动ID参数");
  175. }
  176. });
  177. // ==================== 事件处理函数 ====================
  178. /**
  179. * 返回上一页
  180. */
  181. const goBack = () => {
  182. router.go(-1);
  183. };
  184. // ==================== 数据加载函数 ====================
  185. /**
  186. * 加载详情数据
  187. */
  188. const loadDetailData = async () => {
  189. try {
  190. const res: any = await getActivityDetail({ id: id.value });
  191. if (res && res.code == 200) {
  192. // 合并主数据
  193. activityModel.value = { ...activityModel.value, ...res.data };
  194. } else {
  195. ElMessage.error("加载详情数据失败");
  196. }
  197. } catch (error) {
  198. console.error("加载详情数据出错:", error);
  199. ElMessage.error("加载详情数据出错");
  200. }
  201. };
  202. // ==================== 工具函数 ====================
  203. /**
  204. * 格式化日期
  205. * @param date 日期字符串 (YYYY-MM-DD)
  206. * @returns 格式化后的日期字符串 (YYYY/MM/DD)
  207. */
  208. const formatDate = (date: string) => {
  209. if (!date) return "--";
  210. return date.replace(/-/g, "/");
  211. };
  212. /**
  213. * 获取状态标签
  214. */
  215. const getStatusLabel = (status: number) => {
  216. const statusMap: Record<number, string> = {
  217. 1: "待审核",
  218. 2: "未开始",
  219. 3: "审核驳回",
  220. 5: "进行中",
  221. 6: "已下架",
  222. 7: "已结束",
  223. 8: "审核通过"
  224. };
  225. return statusMap[status] || "--";
  226. };
  227. /**
  228. * 获取活动规则显示文本
  229. */
  230. const getRuleDisplayText = (ruleValue: any) => {
  231. if (!ruleValue) return "--";
  232. // 如果是字符串,尝试解析为数组
  233. let ruleArray: any[] = [];
  234. if (typeof ruleValue === "string") {
  235. try {
  236. ruleArray = JSON.parse(ruleValue);
  237. } catch {
  238. return ruleValue.replace(/,/g, " / ");
  239. }
  240. } else if (Array.isArray(ruleValue)) {
  241. ruleArray = ruleValue;
  242. } else {
  243. return ruleValue.replace(/,/g, " / ");
  244. }
  245. // 将数组转换为显示文本,用 " / " 连接
  246. if (ruleArray && ruleArray.length > 0) {
  247. return ruleArray.filter(item => item).join(" / ");
  248. }
  249. return "--";
  250. };
  251. /**
  252. * 获取图片URL(支持对象和字符串格式)
  253. */
  254. const getImageUrl = (img: any): string => {
  255. if (!img) return "";
  256. if (typeof img === "string") return img;
  257. if (img.url) return img.url;
  258. return "";
  259. };
  260. /**
  261. * 获取预览图片列表
  262. */
  263. const getPreviewImageList = () => {
  264. const list: string[] = [];
  265. const titleUrl = getImageUrl(activityModel.value.activityTitleImgUrl);
  266. const detailUrl = getImageUrl(activityModel.value.activityDetailImgUrl);
  267. if (titleUrl) {
  268. list.push(titleUrl);
  269. }
  270. if (detailUrl) {
  271. list.push(detailUrl);
  272. }
  273. return list;
  274. };
  275. </script>
  276. <style scoped lang="scss">
  277. /* 页面容器 */
  278. .table-box {
  279. display: flex;
  280. flex-direction: column;
  281. height: auto !important;
  282. min-height: 100%;
  283. }
  284. /* 头部区域 */
  285. .header {
  286. display: flex;
  287. align-items: center;
  288. padding: 20px 24px;
  289. background-color: #ffffff;
  290. border-bottom: 1px solid #e4e7ed;
  291. box-shadow: 0 2px 4px rgb(0 0 0 / 2%);
  292. }
  293. .title {
  294. flex: 1;
  295. margin: 0;
  296. font-size: 18px;
  297. font-weight: 600;
  298. color: #303133;
  299. text-align: center;
  300. }
  301. /* 内容区域布局 */
  302. .content {
  303. display: flex;
  304. flex: 1;
  305. column-gap: 24px;
  306. width: 100%;
  307. max-width: 800px;
  308. padding: 24px;
  309. margin: 0 auto;
  310. background-color: #ffffff;
  311. .contentLeft {
  312. width: 50%;
  313. padding-right: 12px;
  314. }
  315. .contentRight {
  316. width: 50%;
  317. padding-left: 12px;
  318. }
  319. }
  320. /* 模块容器 */
  321. .model {
  322. margin-bottom: 50px;
  323. h3 {
  324. width: 100%;
  325. padding-bottom: 12px;
  326. margin: 0 0 20px;
  327. font-size: 16px;
  328. color: #303133;
  329. border-bottom: 2px solid #e4e7ed;
  330. }
  331. }
  332. /* 详情项样式 */
  333. .detail-item {
  334. display: flex;
  335. align-items: flex-start;
  336. min-height: 32px;
  337. margin-bottom: 24px;
  338. }
  339. .detail-label {
  340. flex-shrink: 0;
  341. width: 140px;
  342. font-size: 14px;
  343. font-weight: 500;
  344. line-height: 32px;
  345. color: #606266;
  346. }
  347. .detail-value {
  348. flex: 1;
  349. font-size: 14px;
  350. line-height: 32px;
  351. color: #303133;
  352. word-break: break-word;
  353. }
  354. /* 活动宣传图容器 */
  355. .promotion-images-container {
  356. display: flex;
  357. flex-direction: column;
  358. gap: 24px;
  359. align-items: flex-start;
  360. width: 100%;
  361. }
  362. .promotion-image-item {
  363. display: flex;
  364. flex-direction: column;
  365. gap: 12px;
  366. align-items: flex-start;
  367. width: 100%;
  368. .image-label {
  369. font-size: 14px;
  370. font-weight: 500;
  371. color: #409eff;
  372. }
  373. }
  374. /* 图片容器样式 */
  375. .image-container {
  376. width: 100%;
  377. min-height: 100px;
  378. }
  379. .image-item {
  380. width: 100%;
  381. }
  382. .promotion-image {
  383. width: 100%;
  384. border-radius: 6px;
  385. box-shadow: 0 2px 12px rgb(0 0 0 / 10%);
  386. }
  387. .empty-text {
  388. padding: 20px 0;
  389. font-size: 14px;
  390. color: #909399;
  391. }
  392. /* 活动标题图 - 21:9横向样式 */
  393. .promotion-image-item:first-child {
  394. .image-container {
  395. width: 100%;
  396. }
  397. .image-item {
  398. width: 100%;
  399. aspect-ratio: 21 / 9;
  400. }
  401. .promotion-image {
  402. width: 100%;
  403. height: 100%;
  404. object-fit: contain;
  405. }
  406. }
  407. /* 活动详情图 - 竖版样式 */
  408. .promotion-image-item:last-child {
  409. .image-container {
  410. width: 100%;
  411. max-width: 300px;
  412. }
  413. .image-item {
  414. width: 100%;
  415. aspect-ratio: 3 / 4;
  416. }
  417. .promotion-image {
  418. width: 100%;
  419. height: 100%;
  420. object-fit: contain;
  421. }
  422. }
  423. .image-slot {
  424. display: flex;
  425. align-items: center;
  426. justify-content: center;
  427. width: 100%;
  428. height: 100%;
  429. min-height: 200px;
  430. font-size: 30px;
  431. color: var(--el-text-color-placeholder);
  432. background: var(--el-fill-color-light);
  433. }
  434. </style>