couponDetail.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. {{ couponModel.name || "--" }}
  19. </div>
  20. </div>
  21. <!-- 面值 -->
  22. <div class="detail-item">
  23. <div class="detail-label">面值(元)</div>
  24. <div class="detail-value">
  25. {{ formatCurrency(couponModel.nominalValue, 2, "¥") }}
  26. </div>
  27. </div>
  28. <!-- 开始领取时间 -->
  29. <div class="detail-item">
  30. <div class="detail-label">开始领取时间</div>
  31. <div class="detail-value">
  32. {{ couponModel.beginGetDate ? formatDate(couponModel.beginGetDate) : "--" }}
  33. </div>
  34. </div>
  35. <!-- 结束领取时间 -->
  36. <div class="detail-item">
  37. <div class="detail-label">结束领取时间</div>
  38. <div class="detail-value">
  39. {{ couponModel.endGetDate ? formatDate(couponModel.endGetDate) : "--" }}
  40. </div>
  41. </div>
  42. <!-- 有效期 -->
  43. <div class="detail-item">
  44. <div class="detail-label">有效期</div>
  45. <div class="detail-value">
  46. {{ couponModel.specifiedDay ? `${couponModel.specifiedDay}天` : "--" }}
  47. </div>
  48. </div>
  49. <!-- 库存 -->
  50. <div class="detail-item">
  51. <div class="detail-label">库存</div>
  52. <div class="detail-value">
  53. {{ couponModel.singleQty || "--" }}
  54. </div>
  55. </div>
  56. </div>
  57. <!-- 领取规则模块 -->
  58. <div class="model">
  59. <h3 style="font-weight: bold">领取规则:</h3>
  60. <!-- 用户领取规则 -->
  61. <div class="detail-item">
  62. <div class="detail-label">用户领取规则</div>
  63. <div class="detail-value">
  64. {{ getClaimRuleText() }}
  65. </div>
  66. </div>
  67. <!-- 用户是否需要收藏店铺领取 -->
  68. <div class="detail-item">
  69. <div class="detail-label">用户是否需要收藏店铺领取</div>
  70. <div class="detail-value">
  71. {{ couponModel.attentionCanReceived === 1 ? "是" : couponModel.attentionCanReceived === 0 ? "否" : "--" }}
  72. </div>
  73. </div>
  74. </div>
  75. </div>
  76. <!-- 右侧内容区域 -->
  77. <div class="contentRight">
  78. <!-- 使用规则模块 -->
  79. <div class="model">
  80. <h3 style="font-weight: bold">使用规则:</h3>
  81. <!-- 是否有低消 -->
  82. <div class="detail-item">
  83. <div class="detail-label">是否有低消</div>
  84. <div class="detail-value">
  85. {{ couponModel.hasMinimumSpend === 1 ? "是" : couponModel.hasMinimumSpend === 0 ? "否" : "--" }}
  86. </div>
  87. </div>
  88. <!-- 最低消费金额 -->
  89. <div class="detail-item" v-if="couponModel.hasMinimumSpend === 1">
  90. <div class="detail-label">最低消费金额</div>
  91. <div class="detail-value">
  92. {{ formatCurrency(couponModel.minimumSpendingAmount, 2, "¥") }}
  93. </div>
  94. </div>
  95. <!-- 补充说明 -->
  96. <div class="detail-item">
  97. <div class="detail-label">补充说明</div>
  98. <div class="detail-value" v-html="couponModel.supplementaryInstruction || '--'" />
  99. </div>
  100. </div>
  101. </div>
  102. </div>
  103. </div>
  104. </template>
  105. <script setup lang="tsx" name="couponManagementDetail">
  106. /**
  107. * 优惠券管理 - 详情页面
  108. * 功能:显示优惠券的详细信息
  109. */
  110. import { ref, onMounted } from "vue";
  111. import { useRouter, useRoute } from "vue-router";
  112. import { ElMessage } from "element-plus";
  113. import { getCouponDetail } from "@/api/modules/couponManagement";
  114. import { formatCurrency } from "@/utils/formatCurrency";
  115. // ==================== 响应式数据定义 ====================
  116. // 路由相关
  117. const router = useRouter();
  118. const route = useRoute();
  119. // 页面ID参数
  120. const id = ref<string>("");
  121. // ==================== 优惠券信息数据模型 ====================
  122. const couponModel = ref<any>({
  123. // 优惠券名称
  124. name: "",
  125. // 面值(元)
  126. nominalValue: "",
  127. // 开始领取时间
  128. beginGetDate: "",
  129. // 结束领取时间
  130. endGetDate: "",
  131. // 有效期
  132. specifiedDay: "",
  133. // 库存
  134. singleQty: "",
  135. // 用户领取规则:day-每日一领,week-每周一领,month-每月一领
  136. claimRule: "day",
  137. // 用户是否需要收藏店铺领取:1-是,0-否
  138. attentionCanReceived: 0,
  139. // 是否有低消:1-是,0-否
  140. hasMinimumSpend: 0,
  141. // 最低消费金额
  142. minimumSpendingAmount: "",
  143. // 补充说明
  144. supplementaryInstruction: ""
  145. });
  146. // ==================== 生命周期钩子 ====================
  147. /**
  148. * 组件挂载时初始化
  149. * 从路由参数中获取ID并加载详情数据
  150. */
  151. onMounted(async () => {
  152. id.value = (route.query.id as string) || "";
  153. if (id.value) {
  154. await loadDetailData();
  155. } else {
  156. ElMessage.warning("缺少优惠券ID参数");
  157. }
  158. });
  159. // ==================== 事件处理函数 ====================
  160. /**
  161. * 返回上一页
  162. */
  163. const goBack = () => {
  164. router.go(-1);
  165. };
  166. // ==================== 数据加载函数 ====================
  167. /**
  168. * 加载详情数据
  169. */
  170. const loadDetailData = async () => {
  171. try {
  172. const res: any = await getCouponDetail({ counponId: id.value });
  173. if (res && res.code == 200) {
  174. // 合并主数据
  175. couponModel.value = { ...couponModel.value, ...res.data };
  176. // 根据最低消费金额设置是否有低消
  177. const amount = Number(couponModel.value.minimumSpendingAmount);
  178. if (!isNaN(amount) && amount > 0) {
  179. couponModel.value.hasMinimumSpend = 1;
  180. } else {
  181. couponModel.value.hasMinimumSpend = 0;
  182. }
  183. } else {
  184. ElMessage.error("加载详情数据失败");
  185. }
  186. } catch (error) {
  187. console.error("加载详情数据出错:", error);
  188. ElMessage.error("加载详情数据出错");
  189. }
  190. };
  191. // ==================== 工具函数 ====================
  192. /**
  193. * 格式化日期
  194. * @param date 日期字符串 (YYYY-MM-DD)
  195. * @returns 格式化后的日期字符串 (YYYY.MM.DD)
  196. */
  197. const formatDate = (date: string) => {
  198. if (!date) return "--";
  199. return date.replace(/-/g, "/");
  200. };
  201. /**
  202. * 获取用户领取规则文本
  203. */
  204. const getClaimRuleText = () => {
  205. const ruleMap: Record<string, string> = {
  206. day: "每日一领",
  207. week: "每周一领",
  208. month: "每月一领"
  209. };
  210. return ruleMap[couponModel.value.claimRule] || "--";
  211. };
  212. </script>
  213. <style scoped lang="scss">
  214. /* 页面容器 */
  215. .table-box {
  216. display: flex;
  217. flex-direction: column;
  218. height: auto !important;
  219. min-height: 100%;
  220. }
  221. /* 头部区域 */
  222. .header {
  223. display: flex;
  224. align-items: center;
  225. padding: 20px 24px;
  226. background-color: #ffffff;
  227. border-bottom: 1px solid #e4e7ed;
  228. box-shadow: 0 2px 4px rgb(0 0 0 / 2%);
  229. }
  230. .title {
  231. flex: 1;
  232. margin: 0;
  233. font-size: 18px;
  234. font-weight: 600;
  235. color: #303133;
  236. text-align: center;
  237. }
  238. /* 内容区域布局 */
  239. .content {
  240. display: flex;
  241. flex: 1;
  242. column-gap: 24px;
  243. width: 98%;
  244. padding: 0 12px;
  245. margin: 24px auto;
  246. /* 左侧内容区域 */
  247. .contentLeft {
  248. width: 50%;
  249. padding-right: 12px;
  250. }
  251. /* 右侧内容区域 */
  252. .contentRight {
  253. width: 50%;
  254. padding-left: 12px;
  255. }
  256. }
  257. /* 模块容器 */
  258. .model {
  259. margin-bottom: 50px;
  260. h3 {
  261. padding-bottom: 12px;
  262. margin: 0 0 20px;
  263. font-size: 16px;
  264. color: #303133;
  265. border-bottom: 2px solid #e4e7ed;
  266. }
  267. }
  268. /* 详情项样式 */
  269. .detail-item {
  270. display: flex;
  271. align-items: flex-start;
  272. min-height: 32px;
  273. margin-bottom: 24px;
  274. }
  275. .detail-label {
  276. flex-shrink: 0;
  277. min-width: 200px;
  278. font-size: 14px;
  279. font-weight: 500;
  280. line-height: 32px;
  281. color: #606266;
  282. }
  283. .detail-value {
  284. flex: 1;
  285. font-size: 14px;
  286. line-height: 32px;
  287. color: #303133;
  288. word-break: break-word;
  289. }
  290. .empty-text {
  291. color: #909399;
  292. }
  293. </style>