friendCouponDetail.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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.storeName || "--" }}
  19. </div>
  20. </div>
  21. <!-- 类型 -->
  22. <div class="detail-item">
  23. <div class="detail-label">类型</div>
  24. <div class="detail-value">
  25. {{ getCouponTypeText(couponModel.couponType) }}
  26. </div>
  27. </div>
  28. <!-- 优惠券名称 -->
  29. <div class="detail-item">
  30. <div class="detail-label">优惠券名称</div>
  31. <div class="detail-value">
  32. {{ couponModel.couponName || couponModel.name || "--" }}
  33. </div>
  34. </div>
  35. <!-- 面值 -->
  36. <div class="detail-item">
  37. <div class="detail-label">面值</div>
  38. <div class="detail-value" v-if="couponId">
  39. {{ formatCurrency(couponModel.nominalValue, 2, "¥") }}
  40. </div>
  41. <div class="detail-value" v-else>
  42. {{ formatCurrency(couponModel.nominalValue ?? couponModel.price, 2, "¥") }}
  43. </div>
  44. </div>
  45. <!-- 数量 -->
  46. <div class="detail-item">
  47. <div class="detail-label">数量</div>
  48. <div class="detail-value">
  49. {{ couponModel.couponNum ?? couponModel.singleQty ?? "--" }}
  50. </div>
  51. </div>
  52. <!-- 结束时间 -->
  53. <div class="detail-item">
  54. <div class="detail-label">结束时间</div>
  55. <div class="detail-value" v-if="couponId">
  56. {{ couponModel.endGetDate || "--" }}
  57. </div>
  58. <div class="detail-value" v-else>
  59. {{ couponModel.endDate || "--" }}
  60. </div>
  61. </div>
  62. <!-- 有效期 -->
  63. <div class="detail-item">
  64. <div class="detail-label">有效期</div>
  65. <div class="detail-value">
  66. {{ couponModel.validityPeriod || couponModel.endDate || "--" }}
  67. </div>
  68. </div>
  69. <!-- 最低消费金额(保留原有) -->
  70. <div class="detail-item">
  71. <div class="detail-label">最低消费金额</div>
  72. <div class="detail-value">
  73. {{ formatCurrency(couponModel.minimumSpendingAmount, 2, "¥") }}
  74. </div>
  75. </div>
  76. </div>
  77. </div>
  78. </div>
  79. </div>
  80. </template>
  81. <script setup lang="tsx" name="friendCouponDetail">
  82. /**
  83. * 好友优惠券 - 详情页面
  84. * 功能:显示好友优惠券的详细信息
  85. */
  86. import { ref, onMounted } from "vue";
  87. import { useRouter, useRoute } from "vue-router";
  88. import { ElMessage } from "element-plus";
  89. import { getFriendCouponDetail, getCouponDetail } from "@/api/modules/newLoginApi";
  90. import { formatCurrency } from "@/utils/formatCurrency";
  91. import { localGet } from "@/utils";
  92. // ==================== 响应式数据定义 ====================
  93. // 路由相关
  94. const router = useRouter();
  95. const route = useRoute();
  96. // 页面ID参数
  97. const couponId = ref<string>("");
  98. const voucherId = ref<string>("");
  99. // 优惠券类型(好友赠我 friendMessage / 我赠好友 myGift)
  100. const type = ref<string>("");
  101. // ==================== 优惠券信息数据模型 ====================
  102. const couponModel = ref<any>({
  103. // 账户名称(赠送人/接收人)
  104. acName: "",
  105. // 优惠券名称
  106. couponName: "",
  107. // 优惠券数量
  108. couponNum: 0,
  109. // 删除标志
  110. deleteFlag: 0,
  111. // 结束日期
  112. endDate: "",
  113. // ID
  114. id: 0,
  115. // 图片URL
  116. imgUrl: "",
  117. // 详细列表
  118. lifeDiscountCouponFriendRuleDetailVos: [],
  119. // 最低消费金额
  120. minimumSpendingAmount: 0,
  121. // 金额上限
  122. moneyHigh: 0,
  123. // 金额下限
  124. moneyLow: 0,
  125. // 面值
  126. nominalValue: 0,
  127. // 状态
  128. status: "",
  129. // 店铺ID
  130. storeId: 0,
  131. // 店铺名称
  132. storeName: ""
  133. });
  134. // ==================== 生命周期钩子 ====================
  135. /**
  136. * 组件挂载时初始化
  137. * 从路由参数中获取couponId并加载详情数据
  138. */
  139. onMounted(async () => {
  140. if (route.query.voucherId) {
  141. voucherId.value = (route.query.voucherId as string) || "";
  142. } else if (route.query.couponId) {
  143. couponId.value = (route.query.couponId as string) || "";
  144. }
  145. type.value = (route.query.type as string) || "";
  146. if (voucherId.value || couponId.value) {
  147. await loadDetailData();
  148. } else {
  149. ElMessage.warning("缺少优惠券ID参数");
  150. }
  151. });
  152. // ==================== 事件处理函数 ====================
  153. /**
  154. * 返回上一页
  155. */
  156. const goBack = () => {
  157. router.go(-1);
  158. };
  159. // ==================== 数据加载函数 ====================
  160. /**
  161. * 加载详情数据
  162. */
  163. const loadDetailData = async () => {
  164. try {
  165. if (voucherId.value) {
  166. const res: any = await getCouponDetail({
  167. id: voucherId.value
  168. });
  169. if (res.code === 200) {
  170. couponModel.value = res.data;
  171. console.log(couponModel.value, "couponModel.value");
  172. } else {
  173. ElMessage.error(res.msg);
  174. }
  175. } else if (couponId.value) {
  176. // 使用 couponId 获取详情数据
  177. const res: any = await getFriendCouponDetail({
  178. counponId: couponId.value
  179. });
  180. if (res.code === 200) {
  181. couponModel.value = res.data;
  182. } else {
  183. ElMessage.error(res.msg);
  184. }
  185. }
  186. } catch (error) {
  187. ElMessage.error("加载详情数据出错");
  188. }
  189. };
  190. /**
  191. * 获取优惠券类型文案
  192. */
  193. const getCouponTypeText = (type: number | string | undefined) => {
  194. const typeMap: Record<string, string> = { "1": "折扣券", "2": "满减券" };
  195. return type != null ? (typeMap[String(type)] ?? String(type)) : "--";
  196. };
  197. /**
  198. * 获取状态文本
  199. */
  200. const getStatusText = () => {
  201. const statusMap: Record<string, string> = {
  202. "0": "未使用",
  203. "1": "已使用",
  204. "2": "已过期"
  205. };
  206. return statusMap[couponModel.value.status] || "--";
  207. };
  208. </script>
  209. <style scoped lang="scss">
  210. /* 页面容器 */
  211. .table-box {
  212. display: flex;
  213. flex-direction: column;
  214. height: auto !important;
  215. min-height: 100%;
  216. }
  217. /* 头部区域 */
  218. .header {
  219. display: flex;
  220. align-items: center;
  221. padding: 20px 24px;
  222. background-color: #ffffff;
  223. border-bottom: 1px solid #e4e7ed;
  224. box-shadow: 0 2px 4px rgb(0 0 0 / 2%);
  225. }
  226. .title {
  227. flex: 1;
  228. margin: 0;
  229. font-size: 18px;
  230. font-weight: 600;
  231. color: #303133;
  232. text-align: center;
  233. }
  234. /* 内容区域布局 */
  235. .content {
  236. display: flex;
  237. flex: 1;
  238. column-gap: 24px;
  239. width: 98%;
  240. padding: 0 12px;
  241. margin: 24px auto;
  242. /* 左侧内容区域 */
  243. .contentLeft {
  244. width: 50%;
  245. padding-right: 12px;
  246. }
  247. /* 右侧内容区域 */
  248. .contentRight {
  249. width: 50%;
  250. padding-left: 12px;
  251. }
  252. }
  253. /* 模块容器 */
  254. .model {
  255. margin-bottom: 50px;
  256. h3 {
  257. padding-bottom: 12px;
  258. margin: 0 0 20px;
  259. font-size: 16px;
  260. color: #303133;
  261. }
  262. }
  263. /* 详情项样式 */
  264. .detail-item {
  265. display: flex;
  266. align-items: flex-start;
  267. min-height: 32px;
  268. margin-bottom: 24px;
  269. }
  270. .detail-label {
  271. flex-shrink: 0;
  272. min-width: 200px;
  273. font-size: 14px;
  274. font-weight: 500;
  275. line-height: 32px;
  276. color: #606266;
  277. }
  278. .detail-value {
  279. flex: 1;
  280. font-size: 14px;
  281. line-height: 32px;
  282. color: #303133;
  283. word-break: break-word;
  284. }
  285. .empty-text {
  286. color: #909399;
  287. }
  288. /* 详情卡片样式 */
  289. .detail-card {
  290. padding: 16px;
  291. margin-bottom: 16px;
  292. background-color: #f5f7fa;
  293. border: 1px solid #e4e7ed;
  294. border-radius: 4px;
  295. }
  296. </style>