index.vue 8.2 KB

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