detail.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. <template>
  2. <view class="order-detail-container">
  3. <NavBar title="订单详情" @back="goBack" />
  4. <!-- 订单号和状态卡片 -->
  5. <view class="status-card">
  6. <view class="order-number">
  7. <text class="number-label">订单号</text>
  8. <view class="number-value-row">
  9. <text class="number-value">{{ orderDetail.orderId }}</text>
  10. <AppIcon name="copy" :size="28" color="#C6171E" class="copy-icon" @click.stop="copyText(orderDetail.orderId)" />
  11. </view>
  12. </view>
  13. <view class="status-row">
  14. <text
  15. class="status-tag"
  16. :style="getOrderStatusStyle(orderDetail.orderStatus)"
  17. >
  18. {{ getOrderStatusText(orderDetail.orderStatus) }}
  19. </text>
  20. <text class="create-time">{{ formatTime(orderDetail.createTime) }}</text>
  21. </view>
  22. </view>
  23. <!-- 订单信息卡片 -->
  24. <view class="info-card">
  25. <view class="card-title">订单信息</view>
  26. <view class="info-list">
  27. <view class="info-item">
  28. <text class="item-label">支付状态</text>
  29. <text class="item-value">{{ getPayStatusText(orderDetail.payStatus) }}</text>
  30. </view>
  31. <view class="info-item">
  32. <text class="item-label">用户手机号</text>
  33. <view class="item-value-row">
  34. <text class="item-value">{{ orderDetail.mobilePhone || '匿名用户' }}</text>
  35. <AppIcon v-if="orderDetail.mobilePhone" name="copy" :size="28" color="#C6171E" class="copy-icon" @click.stop="copyText(orderDetail.mobilePhone)" />
  36. </view>
  37. </view>
  38. <view class="info-item">
  39. <text class="item-label">设备编号</text>
  40. <view class="item-value-row">
  41. <text class="item-value">{{ orderDetail.shortId || '未知设备' }}</text>
  42. <AppIcon v-if="orderDetail.shortId" name="copy" :size="28" color="#C6171E" class="copy-icon" @click.stop="copyText(orderDetail.shortId)" />
  43. </view>
  44. </view>
  45. <view class="info-item">
  46. <text class="item-label">消费站点</text>
  47. <text class="item-value">{{ orderDetail.stationName || '未知站点' }}</text>
  48. </view>
  49. <view class="info-item">
  50. <text class="item-label">归属站点</text>
  51. <text class="item-value">{{ orderDetail.userStationName || '未知站点' }}</text>
  52. </view>
  53. <view class="info-item">
  54. <text class="item-label">关机方式</text>
  55. <text class="item-value">{{ getCloseTypeText(orderDetail.closeType) }}</text>
  56. </view>
  57. <view class="info-item">
  58. <text class="item-label">发票状态</text>
  59. <text class="item-value">{{ getInvoiceStatusText(orderDetail.invoiceStatus) }}</text>
  60. </view>
  61. </view>
  62. </view>
  63. <!-- 金额明细卡片 -->
  64. <view class="amount-card">
  65. <view class="card-title">金额明细</view>
  66. <view class="amount-list">
  67. <view class="amount-item">
  68. <text class="amount-label">消费总额</text>
  69. <text class="amount-value">¥{{ formatAmount(orderDetail.amount) }}</text>
  70. </view>
  71. <view class="amount-item">
  72. <text class="amount-label">应收金额</text>
  73. <text class="amount-value">¥{{ formatAmount(orderDetail.amountReceivable) }}</text>
  74. </view>
  75. <view class="amount-item">
  76. <text class="amount-label">实收金额</text>
  77. <text class="amount-value primary">¥{{ formatAmount(orderDetail.amountReceived) }}</text>
  78. </view>
  79. <view class="amount-item" v-if="orderDetail.discountAmount !== undefined && orderDetail.discountAmount > 0">
  80. <text class="amount-label">优惠金额</text>
  81. <text class="amount-value success">-¥{{ formatAmount(orderDetail.discountAmount) }}</text>
  82. </view>
  83. <view class="amount-item" v-if="orderDetail.prepayMoney !== undefined && orderDetail.prepayMoney > 0">
  84. <text class="amount-label">预付金额</text>
  85. <text class="amount-value">¥{{ formatAmount(orderDetail.prepayMoney) }}</text>
  86. </view>
  87. </view>
  88. </view>
  89. <!-- 服务明细 -->
  90. <view class="service-card" v-if="orderDetail.detail && orderDetail.detail.length > 0">
  91. <view class="card-title">服务明细</view>
  92. <view class="service-table">
  93. <view class="table-header">
  94. <text class="col col-name">服务项目</text>
  95. <text class="col col-time">时长</text>
  96. <text class="col col-price">单价</text>
  97. <text class="col col-amount">金额</text>
  98. </view>
  99. <view
  100. v-for="(service, index) in orderDetail.detail"
  101. :key="index"
  102. class="table-row"
  103. >
  104. <text class="col col-name">{{ service.name }}</text>
  105. <text class="col col-time">{{ service.seconds }}</text>
  106. <text class="col col-price">¥{{ service.price }}</text>
  107. <text class="col col-amount">¥{{ service.amount }}</text>
  108. </view>
  109. </view>
  110. </view>
  111. <!-- 操作按钮 -->
  112. <view class="action-section" v-if="canHandleRefund">
  113. <button class="refund-btn" @click="handleRefund">
  114. 处理退款
  115. </button>
  116. </view>
  117. <!-- 加载状态 -->
  118. <view class="loading-state" v-if="loading">
  119. <view class="loading-spinner"></view>
  120. <text class="loading-text">加载中...</text>
  121. </view>
  122. <!-- 空状态 -->
  123. <view class="empty-state" v-if="!loading && !orderDetail.orderId">
  124. <view class="empty-icon-wrapper">
  125. <AppIcon name="inbox" size="48" color="#B0B0B0" />
  126. </view>
  127. <text class="empty-text">未找到该订单</text>
  128. <text class="empty-hint">请检查订单号是否正确,或返回列表重新选择</text>
  129. <button class="empty-back-btn" @click="goBack">返回订单列表</button>
  130. </view>
  131. </view>
  132. </template>
  133. <script setup>
  134. import { ref, onMounted, computed } from 'vue'
  135. import { getOrderDetail, handleRefund as refundApi } from '../../api/order.js'
  136. import { formatTime, showToast, formatAmount, fmtDictName, getDictColor, copyText } from '../../utils/index.js'
  137. import dictUtil, { loadDicts } from '../../utils/dict.js'
  138. const orderId = ref('')
  139. const orderDetail = ref({})
  140. const loading = ref(true)
  141. // 从字典获取订单状态文本
  142. const getOrderStatusText = (status) => {
  143. return fmtDictName('Order.status', status)
  144. }
  145. // 从字典获取支付状态文本
  146. const getPayStatusText = (status) => {
  147. return fmtDictName('Order.pay', status)
  148. }
  149. // 从字典获取关机方式文本
  150. const getCloseTypeText = (type) => {
  151. return fmtDictName('Order.closeType', type)
  152. }
  153. // 从字典获取发票状态文本
  154. const getInvoiceStatusText = (status) => {
  155. return fmtDictName('Invoice.status', status)
  156. }
  157. // 从字典获取订单状态内联样式
  158. const getOrderStatusStyle = (status) => {
  159. const color = getDictColor('Order.status', status)
  160. if (color) {
  161. return {
  162. color: color,
  163. backgroundColor: `${color}1A`
  164. }
  165. }
  166. return {}
  167. }
  168. // 计算是否可以处理退款
  169. const canHandleRefund = computed(() => {
  170. const refundValue = dictUtil.getDictValue('Order.status', '退款中')
  171. return orderDetail.value.orderStatus === refundValue && orderDetail.value.refundLogId
  172. })
  173. // 加载订单详情
  174. const loadOrderDetail = async () => {
  175. if (!orderId.value) {
  176. showToast('订单ID不存在')
  177. loading.value = false
  178. return
  179. }
  180. loading.value = true
  181. try {
  182. const res = await getOrderDetail(orderId.value)
  183. if (res && res.code === 200) {
  184. let data = res.data
  185. // 处理服务明细
  186. if (data.detail) {
  187. // 适配不同的数据结构
  188. if (typeof data.detail === 'string') {
  189. try {
  190. data.detail = JSON.parse(data.detail)
  191. } catch (e) {
  192. console.error('解析服务明细失败:', e)
  193. data.detail = []
  194. }
  195. }
  196. // 格式化服务明细
  197. data.detail = data.detail
  198. .filter(item => item.amount > 0 || item.seconds > 0)
  199. .map(item => {
  200. const serviceName = dictUtil.getDictLabel('Order.feeType', item.name)
  201. return {
  202. name: serviceName,
  203. seconds: formatDuration(item.seconds),
  204. price: formatAmount(item.price),
  205. amount: formatAmount(item.amount)
  206. }
  207. })
  208. } else {
  209. data.detail = []
  210. }
  211. orderDetail.value = data
  212. } else {
  213. showToast(res.msg || '获取订单详情失败')
  214. }
  215. } catch (error) {
  216. console.error('获取订单详情失败:', error)
  217. showToast('获取订单详情失败')
  218. } finally {
  219. loading.value = false
  220. }
  221. }
  222. // 格式化时长
  223. const formatDuration = (seconds) => {
  224. if (!seconds || isNaN(seconds)) return '0秒'
  225. const totalSeconds = parseInt(seconds)
  226. const minutes = Math.floor(totalSeconds / 60)
  227. const remainingSeconds = totalSeconds % 60
  228. if (minutes > 0) {
  229. return `${minutes}分${remainingSeconds}秒`
  230. } else {
  231. return `${remainingSeconds}秒`
  232. }
  233. }
  234. // 处理退款
  235. const handleRefund = async () => {
  236. if (!orderDetail.value.refundLogId) {
  237. showToast('没有退款记录ID')
  238. return
  239. }
  240. try {
  241. await refundApi(orderDetail.value.refundLogId)
  242. showToast('退款处理成功', 'success')
  243. // 刷新订单详情
  244. loadOrderDetail()
  245. } catch (error) {
  246. console.error('处理退款失败:', error)
  247. showToast('处理退款失败')
  248. }
  249. }
  250. // 返回上一页
  251. const goBack = () => {
  252. uni.navigateBack()
  253. }
  254. // 页面加载时获取订单ID并加载详情
  255. onMounted(async () => {
  256. await loadDicts()
  257. // 获取页面参数
  258. const pages = getCurrentPages()
  259. const currentPage = pages[pages.length - 1]
  260. const receivedOrderId = currentPage.options.orderId || ''
  261. if (!receivedOrderId) {
  262. showToast('订单ID不存在,无法加载详情')
  263. loading.value = false
  264. return
  265. }
  266. orderId.value = receivedOrderId
  267. loadOrderDetail()
  268. })
  269. </script>
  270. <style scoped>
  271. /* 容器 */
  272. .order-detail-container {
  273. min-height: 100vh;
  274. background-color: #F5F7FA;
  275. padding-bottom: 120rpx;
  276. }
  277. /* 订单号和状态卡片 */
  278. .status-card {
  279. margin: 20rpx 30rpx;
  280. padding: 24rpx 30rpx;
  281. background: #FFFFFF;
  282. border-radius: 48rpx;
  283. }
  284. .order-number {
  285. display: flex;
  286. align-items: center;
  287. justify-content: space-between;
  288. margin-bottom: 20rpx;
  289. padding-bottom: 20rpx;
  290. border-bottom: 1rpx solid #F0F0F0;
  291. }
  292. .number-label {
  293. font-size: 24rpx;
  294. color: #999999;
  295. }
  296. .number-value {
  297. font-size: 24rpx;
  298. color: #1A1A1A;
  299. font-weight: 600;
  300. flex: 1;
  301. text-align: right;
  302. }
  303. .status-row {
  304. display: flex;
  305. align-items: center;
  306. justify-content: space-between;
  307. }
  308. .status-tag {
  309. font-size: 24rpx;
  310. font-weight: 500;
  311. padding: 6rpx 24rpx;
  312. border-radius: 200rpx;
  313. }
  314. .create-time {
  315. font-size: 24rpx;
  316. color: #999999;
  317. }
  318. /* 信息卡片 */
  319. .info-card,
  320. .amount-card,
  321. .service-card {
  322. margin: 20rpx 30rpx;
  323. background: #FFFFFF;
  324. border-radius: 48rpx;
  325. overflow: hidden;
  326. }
  327. .card-title {
  328. padding: 24rpx 30rpx 20rpx;
  329. font-size: 32rpx;
  330. font-weight: 600;
  331. color: #1A1A1A;
  332. border-bottom: 1rpx solid #F0F0F0;
  333. }
  334. /* 信息列表 */
  335. .info-list {
  336. padding: 20rpx 30rpx 24rpx;
  337. }
  338. .info-item {
  339. display: flex;
  340. align-items: center;
  341. justify-content: space-between;
  342. padding: 16rpx 0;
  343. border-bottom: 1rpx solid #F5F7FA;
  344. }
  345. .info-item:last-child {
  346. border-bottom: none;
  347. }
  348. .item-label {
  349. font-size: 28rpx;
  350. color: #666666;
  351. }
  352. .item-value {
  353. font-size: 28rpx;
  354. color: #1A1A1A;
  355. font-weight: 500;
  356. text-align: right;
  357. }
  358. .item-value-row {
  359. display: flex;
  360. align-items: center;
  361. gap: 8rpx;
  362. }
  363. .number-value-row {
  364. display: flex;
  365. align-items: center;
  366. gap: 8rpx;
  367. flex: 1;
  368. justify-content: flex-end;
  369. }
  370. .copy-icon {
  371. flex-shrink: 0;
  372. }
  373. /* 金额列表 */
  374. .amount-list {
  375. padding: 20rpx 30rpx 24rpx;
  376. }
  377. .amount-item {
  378. display: flex;
  379. align-items: center;
  380. justify-content: space-between;
  381. padding: 16rpx 0;
  382. border-bottom: 1rpx solid #F5F7FA;
  383. }
  384. .amount-item:last-child {
  385. border-bottom: none;
  386. }
  387. .amount-label {
  388. font-size: 28rpx;
  389. color: #666666;
  390. }
  391. .amount-value {
  392. font-size: 28rpx;
  393. color: #1A1A1A;
  394. font-weight: 600;
  395. }
  396. .amount-value.primary {
  397. font-size: 32rpx;
  398. color: #C6171E;
  399. font-weight: 700;
  400. }
  401. .amount-value.success {
  402. color: #52C41A;
  403. }
  404. /* 服务明细表格 */
  405. .service-table {
  406. padding: 0 30rpx 24rpx;
  407. }
  408. .table-header,
  409. .table-row {
  410. display: flex;
  411. align-items: center;
  412. padding: 16rpx 0;
  413. }
  414. .table-header {
  415. border-bottom: 1rpx solid #F0F0F0;
  416. }
  417. .table-header .col {
  418. font-size: 24rpx;
  419. color: #999999;
  420. font-weight: 500;
  421. }
  422. .table-row {
  423. border-bottom: 1rpx solid #F5F7FA;
  424. }
  425. .table-row:last-child {
  426. border-bottom: none;
  427. }
  428. .table-row .col {
  429. font-size: 28rpx;
  430. color: #1A1A1A;
  431. }
  432. .col-name,
  433. .col-time,
  434. .col-price,
  435. .col-amount {
  436. flex: 1;
  437. text-align: center;
  438. min-width: 0;
  439. word-break: break-all;
  440. }
  441. .col-amount {
  442. font-weight: 600;
  443. color: #52C41A;
  444. }
  445. /* 操作按钮 */
  446. .action-section {
  447. position: fixed;
  448. bottom: 0;
  449. left: 0;
  450. right: 0;
  451. padding: 24rpx 30rpx;
  452. padding-bottom: calc(24rpx + env(safe-area-inset-bottom));
  453. background: #FFFFFF;
  454. border-top: 1rpx solid #F0F0F0;
  455. box-shadow: 0 -4rpx 16rpx rgba(0, 0, 0, 0.06);
  456. z-index: 100;
  457. }
  458. .refund-btn {
  459. width: 100%;
  460. padding: 22rpx 0;
  461. background: #C6171E;
  462. color: #FFFFFF;
  463. border: none;
  464. border-radius: 16rpx;
  465. font-size: 30rpx;
  466. font-weight: 600;
  467. box-shadow: 0 4rpx 16rpx rgba(198, 23, 30, 0.25);
  468. }
  469. .refund-btn:active {
  470. background: #A81212;
  471. transform: scale(0.97);
  472. }
  473. /* 加载状态 */
  474. .loading-state {
  475. display: flex;
  476. flex-direction: column;
  477. align-items: center;
  478. justify-content: center;
  479. padding: 200rpx 0;
  480. color: #999999;
  481. }
  482. .loading-spinner {
  483. font-size: 64rpx;
  484. animation: spin 1s linear infinite;
  485. margin-bottom: 32rpx;
  486. color: #B0B0B0;
  487. }
  488. .loading-text {
  489. font-size: 28rpx;
  490. color: #999999;
  491. }
  492. /* 空状态 */
  493. .empty-state {
  494. display: flex;
  495. flex-direction: column;
  496. align-items: center;
  497. justify-content: center;
  498. padding: 160rpx 60rpx;
  499. color: #999999;
  500. text-align: center;
  501. }
  502. .empty-icon-wrapper {
  503. margin-bottom: 24rpx;
  504. }
  505. .empty-text {
  506. font-size: 32rpx;
  507. font-weight: 600;
  508. color: #1A1A1A;
  509. margin-top: 24rpx;
  510. margin-bottom: 16rpx;
  511. }
  512. .empty-hint {
  513. font-size: 28rpx;
  514. color: #999999;
  515. margin-bottom: 40rpx;
  516. line-height: 1.5;
  517. }
  518. .empty-back-btn {
  519. padding: 20rpx 60rpx;
  520. background: #C6171E;
  521. color: #FFFFFF;
  522. border: none;
  523. border-radius: 32rpx;
  524. font-size: 28rpx;
  525. font-weight: 500;
  526. }
  527. .empty-back-btn:active {
  528. background: #A81212;
  529. transform: scale(0.97);
  530. }
  531. @keyframes spin {
  532. from { transform: rotate(0deg); }
  533. to { transform: rotate(360deg); }
  534. }
  535. </style>