index.vue 9.1 KB

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