TrackPopup.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. }
  54. })
  55. const emit = defineEmits(['update:showPopup', 'close'])
  56. const loading = ref(false)
  57. const deliverTraceList = ref([])
  58. watch(() => props.showPopup, (newVal) => {
  59. if (newVal) {
  60. getDeliverTrace()
  61. }
  62. })
  63. const getDeliverTrace = async () => {
  64. if (!props.orderNo) {
  65. deliverTraceList.value = []
  66. return
  67. }
  68. loading.value = true
  69. try {
  70. const response = await queryDeliverTrace({
  71. number: props.orderNo,
  72. company: ''
  73. })
  74. if (response.code === 200 && response.data) {
  75. const list = response.data.data.map((item, index) => ({
  76. ...item,
  77. isActive: index === 0
  78. }))
  79. deliverTraceList.value = list
  80. } else {
  81. deliverTraceList.value = []
  82. uni.showToast({ title: '未查询到物流信息', icon: 'none' })
  83. }
  84. } catch (error) {
  85. console.error('查询物流轨迹失败:', error)
  86. uni.showToast({ title: '查询物流信息失败', icon: 'error' })
  87. deliverTraceList.value = []
  88. } finally {
  89. loading.value = false
  90. }
  91. }
  92. const closePopup = () => {
  93. emit('update:showPopup', false)
  94. emit('close')
  95. }
  96. </script>
  97. <style scoped lang="less">
  98. .express-popup {
  99. width: 670rpx;
  100. background-color: #ffffff;
  101. border-radius: 32rpx;
  102. padding: 32rpx;
  103. max-height: 88vh;
  104. min-height: 50vh;
  105. display: flex;
  106. flex-direction: column;
  107. }
  108. /* 头部样式 */
  109. .popup-header {
  110. display: flex;
  111. justify-content: center;
  112. align-items: center;
  113. padding-bottom: 20rpx;
  114. .title {
  115. font-size: 32rpx;
  116. font-weight: bold;
  117. color: #333333;
  118. }
  119. }
  120. .close-btn {
  121. position: absolute;
  122. right: 32rpx;
  123. top: 40rpx;
  124. }
  125. /* 时间线容器 */
  126. .timeline-container {
  127. overflow-y: auto;
  128. max-height: calc(88vh - 120rpx);
  129. .empty-trace {
  130. text-align: center;
  131. padding: 90rpx 0;
  132. color: #999;
  133. font-size: 28rpx;
  134. }
  135. }
  136. /* 弹框样式调整 */
  137. :deep(.u-popup) {
  138. display: flex;
  139. justify-content: center;
  140. align-items: flex-end;
  141. }
  142. :deep(.u-popup__content) {
  143. width: 90% !important;
  144. max-width: 670rpx !important;
  145. /* 限制最大宽度,避免在宽屏上过宽 */
  146. margin: 0 auto;
  147. }
  148. </style>