couponDetail.vue 8.0 KB

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