index.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. <template>
  2. <view class="logistics-container">
  3. <!-- 头部快递信息 -->
  4. <view class="logistics-header">
  5. <!-- <image class="logo" src="/static/img/icon-logo-jd.png"></image> -->
  6. <view class="company-info">
  7. <text class="company-name">{{compamyName}}</text>
  8. <view class="tracking-number">
  9. <text class="number">{{ orderNo }}</text>
  10. <text class="copy-btn" @click="copyTrackingNumber(orderNo)">复制</text>
  11. </view>
  12. </view>
  13. </view>
  14. <!-- 当前最新物流状态 -->
  15. <!-- <view v-if="currentTrace" class="current-status"> -->
  16. <!-- <view class="status-icon">
  17. <text class="icon">{{ getStatusIcon(currentTrace.title) }}</text>
  18. </view>
  19. <view class="status-info">
  20. <text class="status-text">{{ currentTrace.title }}</text>
  21. <text class="status-desc">{{ currentTrace.desc }}</text>
  22. <view class="courier-info" v-if="currentTrace.courier">
  23. <text class="courier-text">快递员:{{ currentTrace.courier.name }}</text>
  24. <text class="contact-text" @click="contactCourier(currentTrace.courier.phone)">联系</text>
  25. </view>
  26. <text class="status-time">{{ currentTrace.time }}</text>
  27. </view>
  28. </view> -->
  29. <!-- 物流轨迹时间轴(滚动区域) -->
  30. <scroll-view class="timeline-scroll" :style="{ height: scrollHeight + 'px' }" scroll-y>
  31. <view class="timeline-container">
  32. <TimelineItem
  33. v-for="(item, index) in deliverTraceList"
  34. :key="index"
  35. :title="item.title"
  36. :desc="item.context"
  37. :time="item.time"
  38. :is-active="item.isActive"
  39. :show-line="index < deliverTraceList.length - 1"
  40. :show-dot-bg="index === 0"
  41. />
  42. <view v-if="deliverTraceList.length === 0 && !loading" class="empty-trace">
  43. 暂无物流轨迹
  44. </view>
  45. </view>
  46. </scroll-view>
  47. <!-- 底部操作栏 -->
  48. <!-- <view class="bottom-actions">
  49. <button class="action-btn" @click="viewDetails">查看详情</button>
  50. <button class="action-btn" @click="copyAllInfo">复制全部信息</button>
  51. </view> -->
  52. </view>
  53. </template>
  54. <script setup>
  55. import { ref, onMounted, computed } from 'vue'
  56. import { onLoad } from '@dcloudio/uni-app'
  57. import TimelineItem from '@/components/TimelineItem.vue'
  58. import { queryDeliverTrace } from '@/api/order'
  59. // 响应式数据
  60. const orderNo = ref('')
  61. const compamyName = ref('')
  62. const scrollHeight = ref(600)
  63. const deliverTraceList = ref([])
  64. const loading = ref(false)
  65. // 当前最新一条物流(用于头部状态展示)
  66. const currentTrace = computed(() => {
  67. return deliverTraceList.value.length > 0 ? deliverTraceList.value[0] : null
  68. })
  69. // 从路由参数获取运单号
  70. onLoad((options) => {
  71. if (options.orderNo) {
  72. orderNo.value = options.orderNo
  73. getDeliverTrace()
  74. }
  75. })
  76. // 计算滚动区域高度(减去头部、当前状态、底部等固定高度)
  77. onMounted(() => {
  78. uni.getSystemInfo({
  79. success: (res) => {
  80. // 64px 约等于 128rpx,根据实际布局调整
  81. const headerHeight = 140 // 头部高度(rpx)
  82. const statusHeight = 200 // 当前状态高度(rpx)
  83. const bottomHeight = 120 // 底部按钮高度(rpx)
  84. const pxRatio = res.windowWidth / 750
  85. scrollHeight.value = res.windowHeight - (headerHeight + statusHeight + bottomHeight) * pxRatio - 40
  86. }
  87. })
  88. })
  89. // 获取真实物流轨迹
  90. const getDeliverTrace = () => {
  91. if (!orderNo.value) return
  92. loading.value = true
  93. const params = {
  94. number: orderNo.value,
  95. company: '' // 可传入快递公司编码
  96. }
  97. queryDeliverTrace(params).then(response => {
  98. if (response.code === 200 && response.data) {
  99. compamyName.value = response.data.compamyName
  100. // 按时间倒序排列(最新的在前)
  101. const list = response.data.data.map((item, index) => ({
  102. ...item,
  103. isActive: index === 0
  104. }))
  105. deliverTraceList.value = list
  106. } else {
  107. uni.showToast({ title: '未查询到物流信息', icon: 'none' })
  108. deliverTraceList.value = []
  109. }
  110. }).catch(error => {
  111. console.error('查询物流轨迹失败:', error)
  112. uni.showToast({ title: '查询物流信息失败', icon: 'error' })
  113. deliverTraceList.value = []
  114. }).finally(() => {
  115. loading.value = false
  116. })
  117. }
  118. // 复制运单号
  119. const copyTrackingNumber = (text) => {
  120. uni.setClipboardData({
  121. data: text,
  122. success: () => uni.showToast({ title: '已复制', icon: 'success' })
  123. })
  124. }
  125. // 联系快递员
  126. const contactCourier = (phone) => {
  127. uni.showModal({
  128. title: '联系快递员',
  129. content: `拨打 ${phone} ?`,
  130. success: (res) => {
  131. if (res.confirm) uni.makePhoneCall({ phoneNumber: phone })
  132. }
  133. })
  134. }
  135. // 查看详情(示例)
  136. const viewDetails = () => {
  137. uni.showToast({ title: '功能开发中', icon: 'none' })
  138. }
  139. // 复制全部物流信息
  140. const copyAllInfo = () => {
  141. let info = `京东物流\n运单号:${orderNo.value}\n`
  142. if (currentTrace.value) {
  143. info += `状态:${currentTrace.value.title}\n`
  144. if (currentTrace.value.courier) info += `快递员:${currentTrace.value.courier.name}\n`
  145. info += `\n物流轨迹:\n`
  146. }
  147. deliverTraceList.value.forEach(item => {
  148. info += `${item.time} ${item.title} ${item.desc}\n`
  149. })
  150. uni.setClipboardData({
  151. data: info,
  152. success: () => uni.showToast({ title: '已复制全部信息', icon: 'success' })
  153. })
  154. }
  155. // 根据状态显示图标(可根据实际需求扩展)
  156. const getStatusIcon = (title) => {
  157. const map = {
  158. '已代收': '📦',
  159. '派送中': '🚚',
  160. '运输中': '🚛',
  161. '已揽件': '📦',
  162. '已签收': '✅'
  163. }
  164. return map[title] || '●'
  165. }
  166. </script>
  167. <style lang="scss" scoped>
  168. .logistics-container {
  169. display: flex;
  170. flex-direction: column;
  171. padding: 20rpx;
  172. background-color: #f5f5f5;
  173. min-height: 100vh;
  174. box-sizing: border-box;
  175. }
  176. /* 头部快递信息 */
  177. .logistics-header {
  178. height: 140rpx;
  179. background: #fff;
  180. border-radius: 32rpx;
  181. padding: 20rpx;
  182. display: flex;
  183. align-items: center;
  184. margin-bottom: 20rpx;
  185. .logo {
  186. width: 100rpx;
  187. height: 100rpx;
  188. flex-shrink: 0;
  189. }
  190. .company-info {
  191. margin-left: 20rpx;
  192. flex: 1;
  193. .company-name {
  194. font-size: 32rpx;
  195. font-weight: bold;
  196. display: block;
  197. margin-bottom: 8rpx;
  198. }
  199. .tracking-number {
  200. display: flex;
  201. align-items: center;
  202. .number {
  203. font-size: 28rpx;
  204. color: #666;
  205. }
  206. .copy-btn {
  207. font-size: 28rpx;
  208. color: #1B64F0;
  209. margin-left: 16rpx;
  210. padding: 0 8rpx;
  211. background: #f0f6ff;
  212. border-radius: 8rpx;
  213. }
  214. }
  215. }
  216. }
  217. /* 当前状态卡片 */
  218. .current-status {
  219. background: #fff;
  220. border-radius: 24rpx;
  221. padding: 30rpx;
  222. margin-bottom: 20rpx;
  223. display: flex;
  224. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.05);
  225. .status-icon {
  226. width: 80rpx;
  227. height: 80rpx;
  228. background: #1aad19;
  229. border-radius: 50%;
  230. display: flex;
  231. align-items: center;
  232. justify-content: center;
  233. margin-right: 20rpx;
  234. flex-shrink: 0;
  235. .icon {
  236. color: #fff;
  237. font-size: 44rpx;
  238. }
  239. }
  240. .status-info {
  241. flex: 1;
  242. .status-text {
  243. font-size: 32rpx;
  244. font-weight: bold;
  245. color: #333;
  246. display: block;
  247. margin-bottom: 8rpx;
  248. }
  249. .status-desc {
  250. font-size: 26rpx;
  251. color: #666;
  252. line-height: 1.4;
  253. margin-bottom: 12rpx;
  254. }
  255. .courier-info {
  256. background: #f8f8f8;
  257. border-radius: 12rpx;
  258. padding: 16rpx;
  259. margin-bottom: 12rpx;
  260. display: flex;
  261. justify-content: space-between;
  262. align-items: center;
  263. .courier-text {
  264. font-size: 26rpx;
  265. color: #333;
  266. }
  267. .contact-text {
  268. font-size: 26rpx;
  269. color: #1aad19;
  270. padding: 0 12rpx;
  271. }
  272. }
  273. .status-time {
  274. font-size: 24rpx;
  275. color: #999;
  276. }
  277. }
  278. }
  279. /* 时间轴滚动区域 */
  280. .timeline-scroll {
  281. background: #fff;
  282. border-radius: 32rpx;
  283. margin-bottom: 20rpx;
  284. overflow: hidden;
  285. }
  286. .timeline-container {
  287. padding: 20rpx 30rpx;
  288. box-sizing: border-box;
  289. }
  290. .empty-trace {
  291. text-align: center;
  292. padding: 60rpx 0;
  293. color: #999;
  294. font-size: 28rpx;
  295. }
  296. /* 底部操作栏 */
  297. .bottom-actions {
  298. display: flex;
  299. justify-content: space-around;
  300. padding: 20rpx 0;
  301. background: #fff;
  302. border-radius: 32rpx;
  303. margin-top: auto;
  304. .action-btn {
  305. width: 300rpx;
  306. height: 80rpx;
  307. line-height: 80rpx;
  308. background: #f0f6ff;
  309. color: #1B64F0;
  310. border-radius: 40rpx;
  311. font-size: 28rpx;
  312. border: none;
  313. padding: 0;
  314. margin: 0;
  315. &::after {
  316. border: none;
  317. }
  318. }
  319. }
  320. </style>