activityDetail.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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=""
  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. };
  224. return statusMap[status] || "--";
  225. };
  226. /**
  227. * 获取活动规则显示文本
  228. */
  229. const getRuleDisplayText = (ruleValue: any) => {
  230. if (!ruleValue) return "--";
  231. // 如果是字符串,尝试解析为数组
  232. let ruleArray: any[] = [];
  233. if (typeof ruleValue === "string") {
  234. try {
  235. ruleArray = JSON.parse(ruleValue);
  236. } catch {
  237. return ruleValue.replace(/,/g, " / ");
  238. }
  239. } else if (Array.isArray(ruleValue)) {
  240. ruleArray = ruleValue;
  241. } else {
  242. return ruleValue.replace(/,/g, " / ");
  243. }
  244. // 将数组转换为显示文本,用 " / " 连接
  245. if (ruleArray && ruleArray.length > 0) {
  246. return ruleArray.filter(item => item).join(" / ");
  247. }
  248. return "--";
  249. };
  250. /**
  251. * 获取图片URL(支持对象和字符串格式)
  252. */
  253. const getImageUrl = (img: any): string => {
  254. if (!img) return "";
  255. if (typeof img === "string") return img;
  256. if (img.url) return img.url;
  257. return "";
  258. };
  259. /**
  260. * 获取预览图片列表
  261. */
  262. const getPreviewImageList = () => {
  263. const list: string[] = [];
  264. const titleUrl = getImageUrl(activityModel.value.activityTitleImgUrl);
  265. const detailUrl = getImageUrl(activityModel.value.activityDetailImgUrl);
  266. if (titleUrl) {
  267. list.push(titleUrl);
  268. }
  269. if (detailUrl) {
  270. list.push(detailUrl);
  271. }
  272. return list;
  273. };
  274. </script>
  275. <style scoped lang="scss">
  276. /* 页面容器 */
  277. .table-box {
  278. display: flex;
  279. flex-direction: column;
  280. height: auto !important;
  281. min-height: 100%;
  282. }
  283. /* 头部区域 */
  284. .header {
  285. display: flex;
  286. align-items: center;
  287. padding: 20px 24px;
  288. background-color: #ffffff;
  289. border-bottom: 1px solid #e4e7ed;
  290. box-shadow: 0 2px 4px rgb(0 0 0 / 2%);
  291. }
  292. .title {
  293. flex: 1;
  294. margin: 0;
  295. font-size: 18px;
  296. font-weight: 600;
  297. color: #303133;
  298. text-align: center;
  299. }
  300. /* 内容区域布局 */
  301. .content {
  302. display: flex;
  303. flex: 1;
  304. column-gap: 24px;
  305. width: 100%;
  306. max-width: 800px;
  307. padding: 24px;
  308. margin: 0 auto;
  309. background-color: #ffffff;
  310. .contentLeft {
  311. width: 50%;
  312. padding-right: 12px;
  313. }
  314. .contentRight {
  315. width: 50%;
  316. padding-left: 12px;
  317. }
  318. }
  319. /* 模块容器 */
  320. .model {
  321. margin-bottom: 50px;
  322. h3 {
  323. width: 100%;
  324. padding-bottom: 12px;
  325. margin: 0 0 20px;
  326. font-size: 16px;
  327. color: #303133;
  328. border-bottom: 2px solid #e4e7ed;
  329. }
  330. }
  331. /* 详情项样式 */
  332. .detail-item {
  333. display: flex;
  334. align-items: flex-start;
  335. min-height: 32px;
  336. margin-bottom: 24px;
  337. }
  338. .detail-label {
  339. flex-shrink: 0;
  340. width: 140px;
  341. font-size: 14px;
  342. font-weight: 500;
  343. line-height: 32px;
  344. color: #606266;
  345. }
  346. .detail-value {
  347. flex: 1;
  348. font-size: 14px;
  349. line-height: 32px;
  350. color: #303133;
  351. word-break: break-word;
  352. }
  353. /* 活动宣传图容器 */
  354. .promotion-images-container {
  355. display: flex;
  356. flex-direction: column;
  357. gap: 24px;
  358. align-items: flex-start;
  359. width: 100%;
  360. }
  361. .promotion-image-item {
  362. display: flex;
  363. flex-direction: column;
  364. gap: 12px;
  365. align-items: flex-start;
  366. width: 100%;
  367. .image-label {
  368. font-size: 14px;
  369. font-weight: 500;
  370. color: #409eff;
  371. }
  372. }
  373. /* 图片容器样式 */
  374. .image-container {
  375. width: 100%;
  376. min-height: 100px;
  377. }
  378. .image-item {
  379. width: 100%;
  380. }
  381. .promotion-image {
  382. width: 100%;
  383. border-radius: 6px;
  384. box-shadow: 0 2px 12px rgb(0 0 0 / 10%);
  385. }
  386. .empty-text {
  387. padding: 20px 0;
  388. font-size: 14px;
  389. color: #909399;
  390. }
  391. /* 活动标题图 - 21:9横向样式 */
  392. .promotion-image-item:first-child {
  393. .image-container {
  394. width: 100%;
  395. }
  396. .image-item {
  397. width: 100%;
  398. aspect-ratio: 21 / 9;
  399. }
  400. .promotion-image {
  401. width: 100%;
  402. height: 100%;
  403. object-fit: contain;
  404. }
  405. }
  406. /* 活动详情图 - 竖版样式 */
  407. .promotion-image-item:last-child {
  408. .image-container {
  409. width: 100%;
  410. max-width: 300px;
  411. }
  412. .image-item {
  413. width: 100%;
  414. aspect-ratio: 3 / 4;
  415. }
  416. .promotion-image {
  417. width: 100%;
  418. height: 100%;
  419. object-fit: contain;
  420. }
  421. }
  422. .image-slot {
  423. display: flex;
  424. align-items: center;
  425. justify-content: center;
  426. width: 100%;
  427. height: 100%;
  428. min-height: 200px;
  429. font-size: 30px;
  430. color: var(--el-text-color-placeholder);
  431. background: var(--el-fill-color-light);
  432. }
  433. </style>