logistics-detail.vue 10 KB

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