detail.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. <template>
  2. <view class="order-detail-container">
  3. <!-- 顶部紫色导航栏 -->
  4. <view class="header-nav" @click="goBack">
  5. <text class="back-icon">←</text>
  6. <text class="nav-title">订单详情</text>
  7. </view>
  8. <!-- 订单号和状态卡片 -->
  9. <view class="status-card">
  10. <view class="order-number">
  11. <text class="number-label">订单号</text>
  12. <text class="number-value">{{ orderDetail.orderId }}</text>
  13. </view>
  14. <view class="status-row">
  15. <text
  16. class="status-tag"
  17. :class="getOrderStatusClass(orderDetail.orderStatus)"
  18. :style="getOrderStatusStyle(orderDetail.orderStatus)"
  19. >
  20. {{ getOrderStatusText(orderDetail.orderStatus) }}
  21. </text>
  22. <text class="create-time">{{ formatTime(orderDetail.createTime) }}</text>
  23. </view>
  24. </view>
  25. <!-- 订单信息卡片 -->
  26. <view class="info-card">
  27. <view class="card-title">订单信息</view>
  28. <view class="info-list">
  29. <view class="info-item">
  30. <text class="item-label">支付状态</text>
  31. <text class="item-value">{{ getPayStatusText(orderDetail.payStatus) }}</text>
  32. </view>
  33. <view class="info-item">
  34. <text class="item-label">用户手机号</text>
  35. <text class="item-value">{{ orderDetail.mobilePhone || '匿名用户' }}</text>
  36. </view>
  37. <view class="info-item">
  38. <text class="item-label">设备编号</text>
  39. <text class="item-value">{{ orderDetail.shortId || '未知设备' }}</text>
  40. </view>
  41. <view class="info-item">
  42. <text class="item-label">消费站点</text>
  43. <text class="item-value">{{ orderDetail.stationName || '未知站点' }}</text>
  44. </view>
  45. <view class="info-item">
  46. <text class="item-label">归属站点</text>
  47. <text class="item-value">{{ orderDetail.userStationName || '未知站点' }}</text>
  48. </view>
  49. <view class="info-item">
  50. <text class="item-label">关机方式</text>
  51. <text class="item-value">{{ getCloseTypeText(orderDetail.closeType) }}</text>
  52. </view>
  53. <view class="info-item">
  54. <text class="item-label">发票状态</text>
  55. <text class="item-value">{{ getInvoiceStatusText(orderDetail.invoiceStatus) }}</text>
  56. </view>
  57. </view>
  58. </view>
  59. <!-- 金额明细卡片 -->
  60. <view class="amount-card">
  61. <view class="card-title">金额明细</view>
  62. <view class="amount-list">
  63. <view class="amount-item">
  64. <text class="amount-label">消费总额</text>
  65. <text class="amount-value">¥{{ formatAmount(orderDetail.amount) }}</text>
  66. </view>
  67. <view class="amount-item">
  68. <text class="amount-label">应收金额</text>
  69. <text class="amount-value">¥{{ formatAmount(orderDetail.amountReceivable) }}</text>
  70. </view>
  71. <view class="amount-item">
  72. <text class="amount-label">实收金额</text>
  73. <text class="amount-value primary">¥{{ formatAmount(orderDetail.amountReceived) }}</text>
  74. </view>
  75. <view class="amount-item" v-if="orderDetail.discountAmount !== undefined && orderDetail.discountAmount > 0">
  76. <text class="amount-label">优惠金额</text>
  77. <text class="amount-value success">-¥{{ formatAmount(orderDetail.discountAmount) }}</text>
  78. </view>
  79. <view class="amount-item" v-if="orderDetail.prepayMoney !== undefined && orderDetail.prepayMoney > 0">
  80. <text class="amount-label">预付金额</text>
  81. <text class="amount-value">¥{{ formatAmount(orderDetail.prepayMoney) }}</text>
  82. </view>
  83. </view>
  84. </view>
  85. <!-- 服务明细 -->
  86. <view class="service-card" v-if="orderDetail.detail && orderDetail.detail.length > 0">
  87. <view class="card-title">服务明细</view>
  88. <view class="service-table">
  89. <view class="table-header">
  90. <text class="col col-name">服务项目</text>
  91. <text class="col col-time">时长</text>
  92. <text class="col col-price">单价</text>
  93. <text class="col col-amount">金额</text>
  94. </view>
  95. <view
  96. v-for="(service, index) in orderDetail.detail"
  97. :key="index"
  98. class="table-row"
  99. >
  100. <text class="col col-name">{{ service.name }}</text>
  101. <text class="col col-time">{{ service.seconds }}</text>
  102. <text class="col col-price">¥{{ service.price }}</text>
  103. <text class="col col-amount">¥{{ service.amount }}</text>
  104. </view>
  105. </view>
  106. </view>
  107. <!-- 操作按钮 -->
  108. <view class="action-section" v-if="canHandleRefund">
  109. <button class="refund-btn" @click="handleRefund">
  110. 处理退款
  111. </button>
  112. </view>
  113. <!-- 加载状态 -->
  114. <view class="loading-overlay" v-if="loading">
  115. <text class="loading-spinner">🔄</text>
  116. <text class="loading-text">加载中...</text>
  117. </view>
  118. <!-- 空状态 -->
  119. <view class="empty-state" v-if="!loading && !orderDetail.id">
  120. <text class="empty-icon">📭</text>
  121. <text class="empty-text">订单不存在</text>
  122. <button class="refresh-btn" @click="loadOrderDetail">刷新</button>
  123. </view>
  124. </view>
  125. </template>
  126. <script setup>
  127. import { ref, onMounted, computed } from 'vue'
  128. import { getOrderDetail, handleRefund as refundApi } from '../../api/order.js'
  129. import { formatTime, showToast, formatAmount, storage } from '../../utils/index.js'
  130. const orderId = ref('')
  131. const orderDetail = ref({})
  132. const loading = ref(true)
  133. // 获取订单状态文本
  134. const getOrderStatusText = (status) => {
  135. if (!status) return '未知状态'
  136. try {
  137. const dicts = storage.get('dicts')
  138. if (!dicts || !dicts['Order.status']) {
  139. console.warn('字典数据未加载或不存在 Order.status')
  140. return status
  141. }
  142. const orderStatusDict = dicts['Order.status']
  143. const dictItem = orderStatusDict.find(item => item.value == status)
  144. return dictItem ? dictItem.name : status
  145. } catch (error) {
  146. console.error('获取订单状态文本失败:', error)
  147. return status
  148. }
  149. }
  150. // 获取支付状态文本
  151. const getPayStatusText = (status) => {
  152. if (!status) return '未知状态'
  153. try {
  154. const dicts = storage.get('dicts')
  155. if (!dicts || !dicts['Order.pay']) {
  156. console.warn('字典数据未加载或不存在 Order.pay')
  157. return status
  158. }
  159. const payStatusDict = dicts['Order.pay']
  160. const dictItem = payStatusDict.find(item => item.value == status)
  161. return dictItem ? dictItem.name : status
  162. } catch (error) {
  163. console.error('获取支付状态文本失败:', error)
  164. return status
  165. }
  166. }
  167. // 获取关机方式文本
  168. const getCloseTypeText = (type) => {
  169. if (!type) return '未知方式'
  170. try {
  171. const dicts = storage.get('dicts')
  172. if (!dicts || !dicts['Order.closeType']) {
  173. console.warn('字典数据未加载或不存在 Order.closeType')
  174. return type
  175. }
  176. const closeTypeDict = dicts['Order.closeType']
  177. const dictItem = closeTypeDict.find(item => item.value == type)
  178. return dictItem ? dictItem.name : type
  179. } catch (error) {
  180. console.error('获取关机方式文本失败:', error)
  181. return type
  182. }
  183. }
  184. // 获取发票状态文本
  185. const getInvoiceStatusText = (status) => {
  186. if (!status) return '未开票'
  187. try {
  188. const dicts = storage.get('dicts')
  189. if (!dicts || !dicts['Invoice.status']) {
  190. console.warn('字典数据未加载或不存在 Invoice.status')
  191. return status
  192. }
  193. const invoiceStatusDict = dicts['Invoice.status']
  194. const dictItem = invoiceStatusDict.find(item => item.value == status)
  195. return dictItem ? dictItem.name : status
  196. } catch (error) {
  197. console.error('获取发票状态文本失败:', error)
  198. return status
  199. }
  200. }
  201. // 获取订单状态样式类
  202. const getOrderStatusClass = (status) => {
  203. if (!status) return ''
  204. const statusClassMap = {
  205. '0': 'status-wait', // 待支付
  206. '1': 'status-processing', // 进行中
  207. '2': 'status-completed', // 已完成
  208. '3': 'status-refunded', // 已退款
  209. '4': 'status-refunding', // 退款中
  210. '5': 'status-canceled' // 已取消
  211. }
  212. return statusClassMap[status] || ''
  213. }
  214. // 获取订单状态样式
  215. const getOrderStatusStyle = (status) => {
  216. if (!status) return {}
  217. try {
  218. const dicts = storage.get('dicts')
  219. if (!dicts || !dicts['Order.status']) {
  220. return {}
  221. }
  222. const orderStatusDict = dicts['Order.status']
  223. const dictItem = orderStatusDict.find(item => item.value == status)
  224. // 如果字典项有颜色,使用字典颜色
  225. if (dictItem && dictItem.color) {
  226. return {
  227. color: dictItem.color,
  228. backgroundColor: `${dictItem.color}1A` // 添加10%透明度
  229. }
  230. }
  231. return {}
  232. } catch (error) {
  233. console.error('获取订单状态样式失败:', error)
  234. return {}
  235. }
  236. }
  237. // 计算是否可以处理退款
  238. const canHandleRefund = computed(() => {
  239. return orderDetail.value.orderStatus === '4' && orderDetail.value.refundLogId
  240. })
  241. // 加载订单详情
  242. const loadOrderDetail = async () => {
  243. if (!orderId.value) {
  244. console.error('订单ID为空')
  245. showToast('订单ID不存在')
  246. loading.value = false
  247. return
  248. }
  249. console.log('正在加载订单详情,订单ID:', orderId.value)
  250. loading.value = true
  251. try {
  252. const res = await getOrderDetail(orderId.value)
  253. console.log('订单详情响应:', res)
  254. if (res && res.code === 200) {
  255. let data = res.data
  256. // 处理服务明细
  257. if (data.detail) {
  258. // 适配不同的数据结构
  259. if (typeof data.detail === 'string') {
  260. try {
  261. data.detail = JSON.parse(data.detail)
  262. } catch (e) {
  263. console.error('解析服务明细失败:', e)
  264. data.detail = []
  265. }
  266. }
  267. // 格式化服务明细
  268. data.detail = data.detail
  269. .filter(item => item.amount > 0 || item.seconds > 0)
  270. .map(item => {
  271. // 从字典中获取服务项目名称
  272. let serviceName = item.name
  273. try {
  274. const dicts = storage.get('dicts')
  275. if (dicts && dicts['Order.feeType']) {
  276. const feeTypeDict = dicts['Order.feeType']
  277. const dictItem = feeTypeDict.find(d => d.value == item.name)
  278. if (dictItem) {
  279. serviceName = dictItem.name
  280. }
  281. }
  282. } catch (e) {
  283. console.error('解析服务项目字典失败:', e)
  284. }
  285. return {
  286. name: serviceName,
  287. seconds: formatDuration(item.seconds),
  288. price: formatAmount(item.price),
  289. amount: formatAmount(item.amount)
  290. }
  291. })
  292. } else {
  293. data.detail = []
  294. }
  295. orderDetail.value = data
  296. } else {
  297. showToast(res.msg || '获取订单详情失败')
  298. }
  299. } catch (error) {
  300. console.error('获取订单详情失败:', error)
  301. showToast('获取订单详情失败')
  302. } finally {
  303. loading.value = false
  304. }
  305. }
  306. // 格式化时长
  307. const formatDuration = (seconds) => {
  308. if (!seconds || isNaN(seconds)) return '0秒'
  309. const totalSeconds = parseInt(seconds)
  310. const minutes = Math.floor(totalSeconds / 60)
  311. const remainingSeconds = totalSeconds % 60
  312. if (minutes > 0) {
  313. return `${minutes}分${remainingSeconds}秒`
  314. } else {
  315. return `${remainingSeconds}秒`
  316. }
  317. }
  318. // 处理退款
  319. const handleRefund = async () => {
  320. if (!orderDetail.value.refundLogId) {
  321. showToast('没有退款记录ID')
  322. return
  323. }
  324. try {
  325. await refundApi(orderDetail.value.refundLogId)
  326. showToast('退款处理成功', 'success')
  327. // 刷新订单详情
  328. loadOrderDetail()
  329. } catch (error) {
  330. console.error('处理退款失败:', error)
  331. showToast('处理退款失败')
  332. }
  333. }
  334. // 返回上一页
  335. const goBack = () => {
  336. uni.navigateBack()
  337. }
  338. // 页面加载时获取订单ID并加载详情
  339. onMounted(() => {
  340. // 获取页面参数
  341. const pages = getCurrentPages()
  342. const currentPage = pages[pages.length - 1]
  343. const receivedOrderId = currentPage.options.orderId || ''
  344. console.log('订单详情页接收到的参数:', currentPage.options)
  345. console.log('订单ID:', receivedOrderId)
  346. if (!receivedOrderId) {
  347. console.error('未接收到订单ID')
  348. showToast('订单ID不存在,无法加载详情')
  349. loading.value = false
  350. return
  351. }
  352. orderId.value = receivedOrderId
  353. loadOrderDetail()
  354. })
  355. </script>
  356. <style scoped>
  357. /* 容器 */
  358. .order-detail-container {
  359. min-height: 100vh;
  360. background-color: #F8F9FA;
  361. padding-bottom: 120rpx;
  362. }
  363. /* 顶部紫色导航栏 */
  364. .header-nav {
  365. display: flex;
  366. align-items: center;
  367. padding-top: calc(24rpx + var(--status-bar-height));
  368. padding-right: 30rpx;
  369. padding-bottom: 24rpx;
  370. padding-left: 30rpx;
  371. background: linear-gradient(135deg, #667EEA 0%, #764BA2 100%);
  372. box-shadow: 0 4rpx 16rpx rgba(102, 126, 234, 0.2);
  373. position: relative;
  374. z-index: 10;
  375. }
  376. /* 确保内容不被导航栏遮挡 */
  377. .status-card {
  378. margin-top: 40rpx;
  379. }
  380. .back-icon {
  381. font-size: 40rpx;
  382. color: #FFFFFF;
  383. font-weight: 600;
  384. margin-right: 16rpx;
  385. }
  386. .nav-title {
  387. font-size: 34rpx;
  388. color: #FFFFFF;
  389. font-weight: 600;
  390. }
  391. /* 订单号和状态卡片 */
  392. .status-card {
  393. margin: 20rpx 30rpx;
  394. padding: 24rpx 30rpx;
  395. background: #FFFFFF;
  396. border-radius: 20rpx;
  397. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
  398. }
  399. .order-number {
  400. display: flex;
  401. align-items: center;
  402. justify-content: space-between;
  403. margin-bottom: 20rpx;
  404. padding-bottom: 20rpx;
  405. border-bottom: 1rpx solid #F0F0F0;
  406. }
  407. .number-label {
  408. font-size: 24rpx;
  409. color: #999999;
  410. }
  411. .number-value {
  412. font-size: 24rpx;
  413. color: #1A1A1A;
  414. font-weight: 600;
  415. flex: 1;
  416. text-align: right;
  417. }
  418. .status-row {
  419. display: flex;
  420. align-items: center;
  421. justify-content: space-between;
  422. }
  423. .status-tag {
  424. font-size: 22rpx;
  425. font-weight: 600;
  426. padding: 6rpx 20rpx;
  427. border-radius: 30rpx;
  428. }
  429. .create-time {
  430. font-size: 22rpx;
  431. color: #999999;
  432. }
  433. /* 信息卡片 */
  434. .info-card,
  435. .amount-card,
  436. .service-card {
  437. margin: 20rpx 30rpx;
  438. background: #FFFFFF;
  439. border-radius: 20rpx;
  440. overflow: hidden;
  441. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
  442. }
  443. .card-title {
  444. padding: 24rpx 30rpx 20rpx;
  445. font-size: 28rpx;
  446. font-weight: 600;
  447. color: #1A1A1A;
  448. border-bottom: 1rpx solid #F0F0F0;
  449. }
  450. /* 信息列表 */
  451. .info-list {
  452. padding: 20rpx 30rpx 24rpx;
  453. }
  454. .info-item {
  455. display: flex;
  456. align-items: center;
  457. justify-content: space-between;
  458. padding: 16rpx 0;
  459. border-bottom: 1rpx solid #F8F9FA;
  460. }
  461. .info-item:last-child {
  462. border-bottom: none;
  463. }
  464. .item-label {
  465. font-size: 26rpx;
  466. color: #666666;
  467. }
  468. .item-value {
  469. font-size: 26rpx;
  470. color: #1A1A1A;
  471. font-weight: 500;
  472. text-align: right;
  473. }
  474. /* 金额列表 */
  475. .amount-list {
  476. padding: 20rpx 30rpx 24rpx;
  477. }
  478. .amount-item {
  479. display: flex;
  480. align-items: center;
  481. justify-content: space-between;
  482. padding: 16rpx 0;
  483. border-bottom: 1rpx solid #F8F9FA;
  484. }
  485. .amount-item:last-child {
  486. border-bottom: none;
  487. }
  488. .amount-label {
  489. font-size: 26rpx;
  490. color: #666666;
  491. }
  492. .amount-value {
  493. font-size: 28rpx;
  494. color: #1A1A1A;
  495. font-weight: 600;
  496. }
  497. .amount-value.primary {
  498. font-size: 32rpx;
  499. color: #667EEA;
  500. font-weight: 700;
  501. }
  502. .amount-value.success {
  503. color: #52C41A;
  504. }
  505. /* 服务明细表格 */
  506. .service-table {
  507. padding: 0 30rpx 24rpx;
  508. }
  509. .table-header,
  510. .table-row {
  511. display: flex;
  512. align-items: center;
  513. padding: 16rpx 0;
  514. }
  515. .table-header {
  516. border-bottom: 1rpx solid #F0F0F0;
  517. }
  518. .table-header .col {
  519. font-size: 22rpx;
  520. color: #999999;
  521. font-weight: 600;
  522. }
  523. .table-row {
  524. border-bottom: 1rpx solid #F8F9FA;
  525. }
  526. .table-row:last-child {
  527. border-bottom: none;
  528. }
  529. .table-row .col {
  530. font-size: 24rpx;
  531. color: #1A1A1A;
  532. }
  533. .col-name {
  534. flex: 1;
  535. }
  536. .col-time {
  537. width: 120rpx;
  538. text-align: center;
  539. }
  540. .col-price {
  541. width: 100rpx;
  542. text-align: center;
  543. }
  544. .col-amount {
  545. width: 100rpx;
  546. text-align: right;
  547. font-weight: 600;
  548. color: #52C41A;
  549. }
  550. /* 操作按钮 */
  551. .action-section {
  552. position: fixed;
  553. bottom: 0;
  554. left: 0;
  555. right: 0;
  556. padding: 24rpx 30rpx;
  557. background: #FFFFFF;
  558. border-top: 1rpx solid #F0F0F0;
  559. box-shadow: 0 -4rpx 16rpx rgba(0, 0, 0, 0.06);
  560. z-index: 100;
  561. }
  562. .refund-btn {
  563. width: 100%;
  564. padding: 22rpx 0;
  565. background: linear-gradient(90deg, #F5222D 0%, #FF4D4F 100%);
  566. color: #FFFFFF;
  567. border: none;
  568. border-radius: 16rpx;
  569. font-size: 30rpx;
  570. font-weight: 600;
  571. box-shadow: 0 6rpx 20rpx rgba(245, 34, 45, 0.35);
  572. }
  573. .refund-btn:active {
  574. transform: translateY(2rpx);
  575. opacity: 0.9;
  576. }
  577. /* 加载状态 */
  578. .loading-overlay {
  579. position: fixed;
  580. top: 0;
  581. left: 0;
  582. right: 0;
  583. bottom: 0;
  584. background-color: rgba(0, 0, 0, 0.4);
  585. backdrop-filter: blur(2px);
  586. display: flex;
  587. flex-direction: column;
  588. align-items: center;
  589. justify-content: center;
  590. z-index: 999;
  591. }
  592. .loading-spinner {
  593. font-size: 64rpx;
  594. animation: spin 1s linear infinite;
  595. margin-bottom: 32rpx;
  596. color: #fff;
  597. }
  598. .loading-text {
  599. font-size: 28rpx;
  600. color: #fff;
  601. }
  602. @keyframes spin {
  603. from { transform: rotate(0deg); }
  604. to { transform: rotate(360deg); }
  605. }
  606. /* 空状态 */
  607. .empty-state {
  608. display: flex;
  609. flex-direction: column;
  610. align-items: center;
  611. justify-content: center;
  612. padding: 120rpx 0;
  613. color: #999999;
  614. }
  615. .empty-icon {
  616. font-size: 120rpx;
  617. margin-bottom: 32rpx;
  618. opacity: 0.5;
  619. }
  620. .empty-text {
  621. font-size: 28rpx;
  622. margin-bottom: 40rpx;
  623. }
  624. .refresh-btn {
  625. padding: 20rpx 60rpx;
  626. background: linear-gradient(90deg, #667EEA 0%, #764BA2 100%);
  627. color: #FFFFFF;
  628. border: none;
  629. border-radius: 16rpx;
  630. font-size: 28rpx;
  631. font-weight: 500;
  632. }
  633. .refresh-btn:active {
  634. transform: scale(0.95);
  635. opacity: 0.9;
  636. }
  637. /* 状态颜色 */
  638. .status-wait {
  639. color: #FAAD14;
  640. background: linear-gradient(135deg, #FFF7E6 0%, #FFE7BA 100%);
  641. }
  642. .status-processing {
  643. color: #1890FF;
  644. background: linear-gradient(135deg, #E6F7FF 0%, #BAE7FF 100%);
  645. }
  646. .status-completed {
  647. color: #52C41A;
  648. background: linear-gradient(135deg, #F6FFED 0%, #D9F7BE 100%);
  649. }
  650. .status-refunded,
  651. .status-canceled {
  652. color: #999999;
  653. background: linear-gradient(135deg, #F5F5F5 0%, #E0E0E0 100%);
  654. }
  655. .status-refunding {
  656. color: #F5222D;
  657. background: linear-gradient(135deg, #FFF1F0 0%, #FFCCC7 100%);
  658. }
  659. </style>