detail.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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. {{ formData.couponName || "--" }}
  19. </div>
  20. </div>
  21. <!-- 订单编号 -->
  22. <div class="detail-item">
  23. <div class="detail-label">订单编号</div>
  24. <div class="detail-value">
  25. {{ formData.orderNo || "--" }}
  26. </div>
  27. </div>
  28. <!-- 下单时间 -->
  29. <div class="detail-item">
  30. <div class="detail-label">下单时间</div>
  31. <div class="detail-value">
  32. {{ formData.createdTime?.replace(/-/g, "/") || "--" }}
  33. </div>
  34. </div>
  35. <!-- 原价 -->
  36. <div class="detail-item">
  37. <div class="detail-label">原价</div>
  38. <div class="detail-value">
  39. {{ formatCurrency(formData.originalPrice, 2, "¥") }}
  40. </div>
  41. </div>
  42. <!-- 优惠价 -->
  43. <div class="detail-item">
  44. <div class="detail-label">优惠价</div>
  45. <div class="detail-value">
  46. {{ formatCurrency(formData.price, 2, "¥") }}
  47. </div>
  48. </div>
  49. <!-- 数量 -->
  50. <div class="detail-item">
  51. <div class="detail-label">数量</div>
  52. <div class="detail-value">x{{ formData.orderCouponMiddleList ? formData.orderCouponMiddleList.length : 0 }}</div>
  53. </div>
  54. <!-- 优惠券减免 -->
  55. <div class="detail-item">
  56. <div class="detail-label">优惠券减免</div>
  57. <div class="detail-value">
  58. {{ formatCurrency(formData.nominalValue, 2, "¥") }}
  59. </div>
  60. </div>
  61. <!-- 优惠券类型 -->
  62. <div class="detail-item">
  63. <div class="detail-label">优惠券类型</div>
  64. <div class="detail-value">
  65. {{ getCouponType(formData.type) }}
  66. </div>
  67. </div>
  68. <!-- 预留手机号 -->
  69. <div class="detail-item">
  70. <div class="detail-label">预留手机号</div>
  71. <div class="detail-value">
  72. {{ formData.userPhone || "--" }}
  73. </div>
  74. </div>
  75. <!-- 预计收入 -->
  76. <div class="detail-item">
  77. <div class="detail-label">预计收入</div>
  78. <div class="detail-value">
  79. {{ formatCurrency(formData.expectIncome, 2, "¥") }}
  80. </div>
  81. </div>
  82. </div>
  83. </div>
  84. <!-- 右侧内容区域 -->
  85. <div class="contentRight">
  86. <!-- 券码信息模块 -->
  87. <div class="model">
  88. <h3 style="font-weight: bold">券码信息:</h3>
  89. <div v-if="couponList && couponList.length > 0" class="coupon-list">
  90. <div v-for="(coupon, index) in couponList" :key="index" class="coupon-item">
  91. <!-- 状态 -->
  92. <div class="detail-item">
  93. <div class="detail-label">状态</div>
  94. <div class="detail-value">
  95. {{ getCouponStatusName(coupon.status) }}
  96. </div>
  97. </div>
  98. <template v-for="(item, index) in coupon.list" :key="index">
  99. <!-- 券码 -->
  100. <div class="detail-item">
  101. <div class="detail-label">券码</div>
  102. <div class="detail-value">
  103. {{ item.couponCode || "--" }}
  104. </div>
  105. </div>
  106. <!-- 核销时间 -->
  107. <div v-if="item.usedTime && coupon.status == 2" class="detail-item">
  108. <div class="detail-label">核销时间</div>
  109. <div class="detail-value">
  110. {{ item.usedTime || "--" }}
  111. </div>
  112. </div>
  113. <!-- 退款时间 -->
  114. <div v-if="item.refundTime && coupon.status == 5" class="detail-item">
  115. <div class="detail-label">退款时间</div>
  116. <div class="detail-value">
  117. {{ item.refundTime || "--" }}
  118. </div>
  119. </div>
  120. <!-- 分隔线 -->
  121. <el-divider v-if="index < couponList.length - 1" style="margin: 20px 0" />
  122. </template>
  123. </div>
  124. </div>
  125. <div v-else class="empty-text">--</div>
  126. </div>
  127. </div>
  128. </div>
  129. </div>
  130. </template>
  131. <script setup lang="tsx" name="orderManagementDetail">
  132. /**
  133. * 订单管理 - 详情页面
  134. * 功能:显示订单的详细信息
  135. */
  136. import { ref, onMounted, computed } from "vue";
  137. import { useRoute, useRouter } from "vue-router";
  138. import { ElMessage } from "element-plus";
  139. import { getStaffConfigDeatail } from "@/api/modules/staffConfig";
  140. import { queryUserOrderDetail } from "@/api/modules/orderManagement";
  141. import { formatCurrency } from "@/utils/formatCurrency";
  142. // ==================== 响应式数据定义 ====================
  143. // 路由相关
  144. const route = useRoute();
  145. const router = useRouter();
  146. // 页面ID参数
  147. const id = ref((route.query.id as string) || "");
  148. // 订单数据
  149. const formData = ref<any>({});
  150. const couponList = ref<any[]>([]);
  151. // ==================== 工具函数 ====================
  152. /**
  153. * 获取券码状态名称
  154. */
  155. const getCouponStatusName = computed(() => {
  156. return status => {
  157. switch (status) {
  158. case 0:
  159. return "待支付";
  160. case 1:
  161. return "未核销";
  162. case 2:
  163. return "已核销";
  164. case 3:
  165. return "已过期";
  166. case 4:
  167. return "已取消";
  168. case 5:
  169. return "已退款";
  170. default:
  171. return "--";
  172. }
  173. };
  174. });
  175. const getCouponType = computed(() => {
  176. return status => {
  177. switch (status) {
  178. case 1:
  179. return "优惠券";
  180. case 2:
  181. return "红包";
  182. case 3:
  183. return "平台优惠券";
  184. default:
  185. return "--";
  186. }
  187. };
  188. });
  189. // ==================== 生命周期钩子 ====================
  190. /**
  191. * 组件挂载时初始化
  192. * 从路由参数中获取ID并加载详情数据
  193. */
  194. onMounted(async () => {
  195. await initData();
  196. });
  197. // ==================== 事件处理函数 ====================
  198. /**
  199. * 返回上一页
  200. */
  201. const goBack = () => {
  202. router.go(-1);
  203. };
  204. // ==================== 数据加载函数 ====================
  205. /**
  206. * 初始化数据
  207. */
  208. const initData = async () => {
  209. if (id.value) {
  210. try {
  211. const res: any = await queryUserOrderDetail({ orderId: id.value });
  212. if (res.code === 200) {
  213. formData.value = res.data;
  214. couponList.value = groupByA(formData.value.orderCouponMiddleList) || [];
  215. }
  216. } catch (error) {
  217. ElMessage.error("获取详情失败");
  218. }
  219. }
  220. };
  221. const groupByA = arr => {
  222. // 创建一个映射表存储每个status值对应的条目
  223. const map = {};
  224. // 遍历原始数组
  225. arr.forEach(item => {
  226. // 从当前项中提取status字段
  227. const { status, ...rest } = item;
  228. // 如果当前status值在映射表中不存在,则创建一个新条目
  229. if (!map[status]) {
  230. map[status] = {
  231. status: status,
  232. list: []
  233. };
  234. }
  235. // 将剩余的所有字段添加到对应status的list中
  236. map[status].list.push(rest);
  237. });
  238. // 将映射表的值转换为数组并返回
  239. return Object.values(map);
  240. };
  241. </script>
  242. <style scoped lang="scss">
  243. /* 页面容器 */
  244. .table-box {
  245. display: flex;
  246. flex-direction: column;
  247. height: auto !important;
  248. min-height: 100%;
  249. }
  250. /* 头部区域 */
  251. .header {
  252. display: flex;
  253. align-items: center;
  254. padding: 20px 24px;
  255. background-color: #ffffff;
  256. border-bottom: 1px solid #e4e7ed;
  257. box-shadow: 0 2px 4px rgb(0 0 0 / 2%);
  258. }
  259. .title {
  260. flex: 1;
  261. margin: 0;
  262. font-size: 18px;
  263. font-weight: 600;
  264. color: #303133;
  265. text-align: center;
  266. }
  267. /* 内容区域布局 */
  268. .content {
  269. display: flex;
  270. flex: 1;
  271. column-gap: 24px;
  272. width: 98%;
  273. padding: 0 12px;
  274. margin: 24px auto;
  275. /* 左侧内容区域 */
  276. .contentLeft {
  277. width: 50%;
  278. padding-right: 12px;
  279. }
  280. /* 右侧内容区域 */
  281. .contentRight {
  282. width: 50%;
  283. padding-left: 12px;
  284. }
  285. }
  286. /* 模块容器 */
  287. .model {
  288. margin-bottom: 50px;
  289. h3 {
  290. padding-bottom: 12px;
  291. margin: 0 0 20px;
  292. font-size: 16px;
  293. color: #303133;
  294. border-bottom: 2px solid #e4e7ed;
  295. }
  296. }
  297. /* 详情项样式 */
  298. .detail-item {
  299. display: flex;
  300. align-items: flex-start;
  301. min-height: 32px;
  302. margin-bottom: 24px;
  303. }
  304. .detail-label {
  305. flex-shrink: 0;
  306. min-width: 120px;
  307. font-size: 14px;
  308. font-weight: 500;
  309. line-height: 32px;
  310. color: #606266;
  311. }
  312. .detail-value {
  313. flex: 1;
  314. font-size: 14px;
  315. line-height: 32px;
  316. color: #303133;
  317. word-break: break-word;
  318. }
  319. .empty-text {
  320. color: #909399;
  321. }
  322. /* 券码列表样式 */
  323. .coupon-list {
  324. .coupon-item {
  325. margin-bottom: 0;
  326. &:last-child {
  327. margin-bottom: 0;
  328. }
  329. }
  330. }
  331. </style>