TrackPopup.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <u-popup :show="showPopup" mode="center" round="20" @close="closePopup" :closeable="true"
  3. :safeAreaInsetBottom="false" :closeOnClickOverlay="true">
  4. <view class="express-popup">
  5. <!-- 弹框头部 -->
  6. <view class="popup-header">
  7. <text class="title">物流轨迹</text>
  8. </view>
  9. <!-- 右上角关闭按钮 -->
  10. <view class="close-btn" @tap="closePopup">
  11. <u-icon name="close" size="22" color="#333"></u-icon>
  12. </view>
  13. <!-- 物流轨迹时间线 -->
  14. <scroll-view class="timeline-container" scroll-y="true">
  15. <TimelineItem
  16. v-for="(item, index) in deliverTraceList"
  17. :key="index"
  18. :title="item.title"
  19. :desc="item.context"
  20. :time="item.time"
  21. :is-active="item.isActive"
  22. :show-line="index < deliverTraceList.length - 1"
  23. :show-dot-bg="index === 0"
  24. />
  25. <view v-if="deliverTraceList.length === 0 && !loading" class="empty-trace">
  26. 暂无物流轨迹
  27. </view>
  28. </scroll-view>
  29. </view>
  30. </u-popup>
  31. </template>
  32. <script setup>
  33. import {
  34. ref,
  35. defineProps,
  36. defineEmits,
  37. watch
  38. } from 'vue'
  39. import TimelineItem from '@/components/TimelineItem.vue'
  40. import { queryDeliverTrace } from '@/api/order'
  41. const props = defineProps({
  42. showPopup: {
  43. type: Boolean,
  44. default: false
  45. },
  46. orderNo:{
  47. type: String,
  48. default: ""
  49. },
  50. expressData: {
  51. type: Object,
  52. default: () => ({
  53. company: '顺丰速运',
  54. number: 'SF1234567890123',
  55. status: '已签收'
  56. })
  57. }
  58. })
  59. const emit = defineEmits(['update:showPopup', 'close'])
  60. // 模拟物流轨迹数据,实际应用中应该通过API获取
  61. const trackList = ref([])
  62. watch( showPopup,(olddata,newData) => {
  63. if(showPopup){
  64. getDeliverTrace()
  65. }
  66. })
  67. // 获取真实物流轨迹
  68. const getDeliverTrace = () => {
  69. if (!props.orderNo) return
  70. loading.value = true
  71. const params = {
  72. number: props.orderNo,
  73. company: '' // 可传入快递公司编码
  74. }
  75. queryDeliverTrace(params).then(response => {
  76. if (response.code === 200 && response.data) {
  77. // 按时间倒序排列(最新的在前)
  78. const list = response.data.data.map((item, index) => ({
  79. ...item,
  80. isActive: index === 0
  81. }))
  82. deliverTraceList.value = list
  83. } else {
  84. uni.showToast({ title: '未查询到物流信息', icon: 'none' })
  85. deliverTraceList.value = []
  86. }
  87. }).catch(error => {
  88. console.error('查询物流轨迹失败:', error)
  89. uni.showToast({ title: '查询物流信息失败', icon: 'error' })
  90. deliverTraceList.value = []
  91. }).finally(() => {
  92. loading.value = false
  93. })
  94. }
  95. const closePopup = () => {
  96. emit('update:showPopup', false)
  97. emit('close')
  98. }
  99. </script>
  100. <style scoped lang="less">
  101. .express-popup {
  102. width: 670rpx;
  103. background-color: #ffffff;
  104. border-radius: 32rpx;
  105. padding: 32rpx;
  106. max-height: 88vh;
  107. display: flex;
  108. flex-direction: column;
  109. }
  110. /* 头部样式 */
  111. .popup-header {
  112. display: flex;
  113. justify-content: center;
  114. align-items: center;
  115. padding-bottom: 20rpx;
  116. .title {
  117. font-size: 32rpx;
  118. font-weight: bold;
  119. color: #333333;
  120. }
  121. }
  122. .close-btn {
  123. position: absolute;
  124. right: 32rpx;
  125. top: 40rpx;
  126. }
  127. /* 时间线容器 */
  128. .timeline-container {
  129. overflow-y: auto;
  130. max-height: calc(88vh - 120rpx);
  131. }
  132. /* 弹框样式调整 */
  133. :deep(.u-popup) {
  134. display: flex;
  135. justify-content: center;
  136. align-items: flex-end;
  137. }
  138. :deep(.u-popup__content) {
  139. width: 90% !important;
  140. max-width: 670rpx !important;
  141. /* 限制最大宽度,避免在宽屏上过宽 */
  142. margin: 0 auto;
  143. }
  144. </style>