logistics-detail.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <template>
  2. <view class="logistics-page">
  3. <!-- 顶部包裹切换 -->
  4. <scroll-view scroll-x class="package-tabs" :scroll-into-view="'tab-' + currentPackageIndex">
  5. <view class="tab-list">
  6. <view class="tab-item" v-for="(item, index) in packages" :key="index" :id="'tab-' + index"
  7. :class="{ active: currentPackageIndex === index }" @click="switchPackage(index)">
  8. {{ item.name }}
  9. </view>
  10. </view>
  11. </scroll-view>
  12. <!-- 物流基本信息 -->
  13. <view class="card info-card">
  14. <view class="info-row">
  15. <text class="label">承运商:</text>
  16. <text class="value">{{ currentPackage.expressName }}</text>
  17. </view>
  18. <view class="info-row">
  19. <text class="label">物流单号:</text>
  20. <text class="value">{{ currentPackage.waybillCode }}</text>
  21. <view class="copy-btn" @click="copyTrackingNo">复制</view>
  22. </view>
  23. </view>
  24. <!-- 物流轨迹 -->
  25. <view class="card timeline-card">
  26. <!-- 收货地址 -->
  27. <view class="timeline-item address-item">
  28. <view class="left-col">
  29. <view class="icon-box address-icon">收</view>
  30. <view class="line"></view>
  31. </view>
  32. <view class="right-col">
  33. <view class="status-title">收货地址:{{ currentPackage.receiveAddress }}</view>
  34. </view>
  35. </view>
  36. <!-- 轨迹列表 -->
  37. <view class="timeline-item" v-for="(trace, index) in currentPackage.trackingVoList" :key="index">
  38. <view class="left-col">
  39. <!-- 不同状态显示不同图标 -->
  40. <view v-if="index === 0 && ['已签收', '签收'].includes(trace.status)" class="icon-box check-icon">
  41. <u-icon name="checkmark" color="#fff" size="20"></u-icon>
  42. </view>
  43. <view v-else-if="['派送中', '派件'].includes(trace.status)" class="icon-box delivery-icon">
  44. <u-icon name="man" color="#fff" size="24"></u-icon>
  45. </view>
  46. <view v-else-if="['运输中', '在途'].includes(trace.status)" class="icon-box transport-icon">
  47. <u-icon name="car" color="#fff" size="24"></u-icon>
  48. </view>
  49. <view v-else-if="['已下单', '揽收'].includes(trace.status)" class="icon-box order-icon">
  50. <u-icon name="order" color="#fff" size="24"></u-icon>
  51. </view>
  52. <view v-else class="dot"></view>
  53. <view class="line" v-if="index !== currentPackage.trackingVoList.length - 1"></view>
  54. </view>
  55. <view class="right-col" :class="{ 'is-first': index === 0 }">
  56. <view class="status-title">{{ trace.status }}</view>
  57. <view class="status-desc">{{ trace.context }}</view>
  58. <view class="status-time">{{ trace.ftime }}</view>
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. </template>
  64. <script>
  65. export default {
  66. data() {
  67. return {
  68. currentPackageIndex: 0,
  69. packages: [], // Changed to empty array, will be populated by API
  70. orderId: '',
  71. refundOrderId: ''
  72. };
  73. },
  74. onLoad(options) {
  75. if (options.orderId) {
  76. this.orderId = options.orderId;
  77. this.getLogisticsData();
  78. } else if (options.refundOrderId) {
  79. this.refundOrderId = options.refundOrderId;
  80. this.getLogisticsData();
  81. }
  82. },
  83. computed: {
  84. currentPackage() {
  85. return this.packages[this.currentPackageIndex] || {};
  86. }
  87. },
  88. methods: {
  89. getLogisticsData() {
  90. uni.showLoading({
  91. title: '加载中'
  92. });
  93. const params = {};
  94. if (this.orderId) params.orderId = this.orderId;
  95. if (this.refundOrderId) params.refundOrderId = this.refundOrderId;
  96. this.$u.api.getOrderTrackingAjax(params).then(res => {
  97. uni.hideLoading();
  98. if (res.code == 200) {
  99. const data = res.data || [];
  100. // 直接使用后端返回的字段
  101. this.packages = data.map((item, index) => ({
  102. name: `包裹${index + 1}`,
  103. ...item
  104. }));
  105. } else {
  106. this.$u.toast(res.msg || '获取物流信息失败');
  107. }
  108. }).catch(() => {
  109. uni.hideLoading();
  110. this.$u.toast('网络请求失败');
  111. });
  112. },
  113. switchPackage(index) {
  114. this.currentPackageIndex = index;
  115. },
  116. copyTrackingNo() {
  117. if (!this.currentPackage.waybillCode) return;
  118. uni.setClipboardData({
  119. data: this.currentPackage.waybillCode,
  120. success: () => {
  121. uni.showToast({
  122. title: '复制成功',
  123. icon: 'none'
  124. });
  125. }
  126. });
  127. }
  128. }
  129. }
  130. </script>
  131. <style lang="scss" scoped>
  132. .logistics-page {
  133. min-height: 100vh;
  134. background-color: #f5f5f5;
  135. padding: 20rpx;
  136. padding-bottom: 40rpx;
  137. }
  138. .package-tabs {
  139. white-space: nowrap;
  140. margin-bottom: 20rpx;
  141. .tab-list {
  142. display: flex;
  143. padding: 10rpx 0;
  144. }
  145. .tab-item {
  146. display: inline-block;
  147. padding: 12rpx 36rpx;
  148. background-color: #ccc; // Default gray
  149. color: #fff;
  150. font-size: 28rpx;
  151. border-radius: 8rpx;
  152. margin-right: 20rpx;
  153. transition: all 0.3s;
  154. &.active {
  155. background-color: #38C148; // Theme green
  156. font-weight: bold;
  157. }
  158. &:last-child {
  159. margin-right: 0;
  160. }
  161. }
  162. }
  163. .card {
  164. background-color: #fff;
  165. border-radius: 16rpx;
  166. padding: 30rpx;
  167. margin-bottom: 20rpx;
  168. }
  169. .info-card {
  170. .info-row {
  171. display: flex;
  172. align-items: center;
  173. margin-bottom: 20rpx;
  174. font-size: 30rpx;
  175. &:last-child {
  176. margin-bottom: 0;
  177. }
  178. .label {
  179. color: #333;
  180. width: 160rpx;
  181. font-weight: 500;
  182. }
  183. .value {
  184. color: #333;
  185. font-weight: 500;
  186. }
  187. .copy-btn {
  188. font-size: 24rpx;
  189. color: $app-theme-color;
  190. background-color: #edf7e8;
  191. padding: 4rpx 12rpx;
  192. border-radius: 4rpx;
  193. margin-left: 20rpx;
  194. }
  195. }
  196. }
  197. .timeline-card {
  198. padding: 30rpx 20rpx;
  199. }
  200. .timeline-item {
  201. display: flex;
  202. position: relative;
  203. .left-col {
  204. width: 80rpx;
  205. display: flex;
  206. flex-direction: column;
  207. align-items: center;
  208. margin-right: 10rpx;
  209. position: relative;
  210. .line {
  211. width: 2rpx;
  212. background-color: #eee;
  213. flex: 1;
  214. min-height: 40rpx;
  215. margin-top: 10rpx;
  216. margin-bottom: -10rpx; // Connect to next
  217. }
  218. .icon-box {
  219. width: 40rpx;
  220. height: 40rpx;
  221. border-radius: 50%;
  222. display: flex;
  223. justify-content: center;
  224. align-items: center;
  225. font-size: 20rpx;
  226. z-index: 1;
  227. &.address-icon {
  228. background-color: #ff5b5b;
  229. color: #fff;
  230. }
  231. &.check-icon {
  232. background-color: #ff5b5b;
  233. }
  234. &.delivery-icon,
  235. &.transport-icon,
  236. &.order-icon {
  237. background-color: #ccc;
  238. }
  239. }
  240. .dot {
  241. width: 16rpx;
  242. height: 16rpx;
  243. background-color: #eee;
  244. border-radius: 50%;
  245. margin-top: 12rpx;
  246. z-index: 1;
  247. }
  248. }
  249. .right-col {
  250. flex: 1;
  251. padding-bottom: 40rpx;
  252. &.is-first {
  253. .status-title {
  254. font-size: 32rpx;
  255. font-weight: bold;
  256. color: #333;
  257. }
  258. .status-desc {
  259. color: #333;
  260. }
  261. }
  262. .status-title {
  263. font-size: 30rpx;
  264. font-weight: 500;
  265. color: #333;
  266. margin-bottom: 10rpx;
  267. line-height: 1.4;
  268. }
  269. .status-desc {
  270. font-size: 26rpx;
  271. color: #999;
  272. line-height: 1.5;
  273. margin-bottom: 10rpx;
  274. }
  275. .status-time {
  276. font-size: 24rpx;
  277. color: #999;
  278. }
  279. }
  280. &.address-item {
  281. .right-col {
  282. padding-bottom: 30rpx;
  283. .status-title {
  284. font-weight: bold;
  285. margin-bottom: 0;
  286. }
  287. }
  288. }
  289. }
  290. </style>