logistics.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <template>
  2. <view class="container" :style="{ '--font-scale': fontScale }">
  3. <view v-if="loading" class="loading-wrap">
  4. <text class="loading-text">加载中...</text>
  5. </view>
  6. <scroll-view v-else scroll-y class="content">
  7. <!-- Header -->
  8. <view class="header-section">
  9. <view class="header-top">
  10. <text class="order-no">订单号: {{ orderNo }}</text>
  11. <text :class="['status-badge', 'status-' + logisticsStatus]">{{ statusLabel }}</text>
  12. </view>
  13. <button class="refresh-btn" @click="loadLogistics">刷新物流信息</button>
  14. </view>
  15. <!-- Logistics Info -->
  16. <view v-if="logisticsData.logisticsNo" class="section">
  17. <text class="section-title">物流信息</text>
  18. <view class="info-row">
  19. <text class="info-label">物流公司</text>
  20. <text class="info-value">{{ logisticsData.logisticsCompany || logisticsData.logisticsName }}</text>
  21. </view>
  22. <view class="info-row">
  23. <text class="info-label">物流单号</text>
  24. <view class="copy-row">
  25. <text class="info-value">{{ logisticsData.logisticsNo }}</text>
  26. <text class="copy-btn" @click="onCopy(logisticsData.logisticsNo)">复制</text>
  27. </view>
  28. </view>
  29. </view>
  30. <!-- Tracking Timeline -->
  31. <view class="section" v-if="trackingData && trackingData.length > 0">
  32. <text class="section-title">物流追踪</text>
  33. <view class="timeline">
  34. <view
  35. v-for="(node, index) in trackingData"
  36. :key="index"
  37. :class="['timeline-node', index === 0 ? 'latest' : '']"
  38. >
  39. <view class="timeline-dot-wrap">
  40. <view :class="['timeline-dot', index === 0 ? 'dot-orange' : 'dot-gray']"></view>
  41. <view v-if="index < trackingData.length - 1" class="timeline-line"></view>
  42. </view>
  43. <view class="timeline-content">
  44. <text class="timeline-text">{{ node.content }}</text>
  45. <text class="timeline-time">{{ node.time }}</text>
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. <!-- Empty tracking -->
  51. <view v-else-if="logisticsData.logisticsNo && (!trackingData || trackingData.length === 0)" class="section">
  52. <view class="empty-tracking">
  53. <text class="empty-icon">🚚</text>
  54. <text class="empty-text">暂无物流信息</text>
  55. </view>
  56. </view>
  57. </scroll-view>
  58. </view>
  59. </template>
  60. <script>
  61. import config from '@/config.js'
  62. import fontScaleMixin from '@/mixins/font-scale.js'
  63. export default {
  64. mixins: [fontScaleMixin],
  65. data() {
  66. return {
  67. orderNo: '',
  68. orderId: null,
  69. loading: false,
  70. logisticsData: {},
  71. trackingData: [],
  72. logisticsStatus: 'pending'
  73. }
  74. },
  75. computed: {
  76. statusLabel() {
  77. var map = {
  78. pending: '待发货',
  79. shipped: '已发货',
  80. pending_receipt: '派送中',
  81. signing: '派送中',
  82. completed: '已签收'
  83. }
  84. return map[this.logisticsStatus] || this.logisticsStatus
  85. }
  86. },
  87. onLoad(options) {
  88. if (options.orderNo) {
  89. this.orderNo = options.orderNo
  90. }
  91. if (options.orderId) {
  92. this.orderId = parseInt(options.orderId)
  93. }
  94. this.loadLogistics()
  95. },
  96. methods: {
  97. loadLogistics() {
  98. if (!this.orderId) {
  99. uni.showToast({ title: '订单ID缺失', icon: 'none' })
  100. return
  101. }
  102. this.loading = true
  103. var that = this
  104. uni.request({
  105. url: config.api('/api/shop/logistics/query'),
  106. method: 'POST',
  107. data: { orderId: this.orderId },
  108. header: {
  109. 'Content-Type': 'application/json',
  110. 'Authorization': 'Bearer ' + uni.getStorageSync('token')
  111. },
  112. success: function(res) {
  113. that.loading = false
  114. if (res.data && res.data.code === 200) {
  115. var data = res.data.data || {}
  116. that.logisticsData = data
  117. that.trackingData = data.trackingData || []
  118. if (data.status) {
  119. that.logisticsStatus = data.status
  120. }
  121. } else {
  122. uni.showToast({ title: res.data.message || '查询失败', icon: 'none' })
  123. }
  124. },
  125. fail: function() {
  126. that.loading = false
  127. uni.showToast({ title: '网络请求失败', icon: 'none' })
  128. }
  129. })
  130. },
  131. onCopy(text) {
  132. uni.setClipboardData({
  133. data: text,
  134. success: function() {
  135. uni.showToast({ title: '已复制', icon: 'success' })
  136. }
  137. })
  138. }
  139. }
  140. }
  141. </script>
  142. <style scoped lang="scss">
  143. .container {
  144. min-height: 100vh;
  145. background: $facade-fill-2;
  146. }
  147. .loading-wrap {
  148. display: flex;
  149. justify-content: center;
  150. padding-top: 200rpx;
  151. }
  152. .loading-text {
  153. font-size: calc(28rpx * var(--font-scale, 1));
  154. color: $facade-text-muted;
  155. }
  156. .content {
  157. height: calc(100vh - 120rpx);
  158. }
  159. .header-section {
  160. background: $app-surface;
  161. padding: $uni-space-page;
  162. border-bottom: 1rpx solid $facade-fill;
  163. display: flex;
  164. flex-direction: column;
  165. }
  166. .header-top {
  167. display: flex;
  168. justify-content: space-between;
  169. align-items: center;
  170. margin-bottom: 20rpx;
  171. }
  172. .order-no {
  173. font-size: calc(26rpx * var(--font-scale, 1));
  174. color: $facade-text-body;
  175. }
  176. .status-badge {
  177. font-size: calc(22rpx * var(--font-scale, 1));
  178. padding: 4rpx 16rpx;
  179. border-radius: 24rpx;
  180. }
  181. .status-pending {
  182. background: $brand-primary-tint-2;
  183. color: $brand-primary-2;
  184. }
  185. .status-shipped {
  186. background: $status-info-tint-3;
  187. color: $status-info-3;
  188. }
  189. .status-pending_receipt,
  190. .status-signing {
  191. background: $brand-primary-tint-2;
  192. color: $brand-primary-2;
  193. }
  194. .status-completed {
  195. background: $status-success-tint-3;
  196. color: $status-success-3;
  197. }
  198. .refresh-btn {
  199. font-size: calc(24rpx * var(--font-scale, 1));
  200. color: $brand-primary;
  201. background: $brand-primary-tint-2;
  202. border: 1rpx solid $brand-primary;
  203. padding: 8rpx $uni-space-page;
  204. border-radius: 24rpx;
  205. width: auto;
  206. align-self: center;
  207. line-height: 1.5;
  208. }
  209. .refresh-btn::after {
  210. border: none;
  211. }
  212. .section {
  213. background: $app-surface;
  214. margin: 20rpx;
  215. border-radius: 16rpx;
  216. padding: 24rpx;
  217. }
  218. .section-title {
  219. font-size: calc(28rpx * var(--font-scale, 1));
  220. font-weight: bold;
  221. color: $facade-text-strong;
  222. margin-bottom: 20rpx;
  223. display: block;
  224. }
  225. .info-row {
  226. display: flex;
  227. justify-content: space-between;
  228. align-items: center;
  229. padding: 16rpx 0;
  230. border-bottom: 1rpx solid $facade-fill-2;
  231. }
  232. .info-row:last-child {
  233. border-bottom: none;
  234. }
  235. .info-label {
  236. font-size: calc(26rpx * var(--font-scale, 1));
  237. color: $facade-text-muted;
  238. }
  239. .info-value {
  240. font-size: calc(26rpx * var(--font-scale, 1));
  241. color: $facade-text-strong;
  242. }
  243. .copy-row {
  244. display: flex;
  245. align-items: center;
  246. }
  247. .copy-btn {
  248. font-size: calc(22rpx * var(--font-scale, 1));
  249. color: $status-info-3;
  250. background: $status-info-tint-3;
  251. padding: 2rpx 16rpx;
  252. border-radius: 24rpx;
  253. margin-left: 12rpx;
  254. }
  255. /* Timeline */
  256. .timeline {
  257. padding: 0;
  258. }
  259. .timeline-node {
  260. display: flex;
  261. min-height: 100rpx;
  262. }
  263. .timeline-dot-wrap {
  264. display: flex;
  265. flex-direction: column;
  266. align-items: center;
  267. width: 40rpx;
  268. margin-right: 20rpx;
  269. position: relative;
  270. }
  271. .timeline-dot {
  272. width: 20rpx;
  273. height: 20rpx;
  274. border-radius: 50%;
  275. margin-top: 8rpx;
  276. z-index: 1;
  277. }
  278. .dot-orange {
  279. background: $brand-primary;
  280. }
  281. .dot-gray {
  282. background: $facade-border-soft;
  283. }
  284. .timeline-line {
  285. width: 2rpx;
  286. flex: 1;
  287. background: $facade-hairline;
  288. margin-top: 4rpx;
  289. }
  290. .timeline-content {
  291. flex: 1;
  292. padding-bottom: $uni-space-lg;
  293. }
  294. .timeline-text {
  295. display: block;
  296. font-size: calc(26rpx * var(--font-scale, 1));
  297. color: $facade-text-strong;
  298. margin-bottom: 6rpx;
  299. line-height: 1.5;
  300. }
  301. .timeline-time {
  302. display: block;
  303. font-size: calc(22rpx * var(--font-scale, 1));
  304. color: $facade-text-muted;
  305. }
  306. .empty-tracking {
  307. display: flex;
  308. flex-direction: column;
  309. align-items: center;
  310. padding: 40rpx 0;
  311. }
  312. .empty-icon {
  313. font-size: calc($uni-font-size-5xl * var(--font-scale, 1));
  314. margin-bottom: 20rpx;
  315. }
  316. .empty-text {
  317. font-size: calc(26rpx * var(--font-scale, 1));
  318. color: $facade-text-muted;
  319. }
  320. </style>