logistics.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <template>
  2. <view class="container">
  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. export default {
  63. data() {
  64. return {
  65. orderNo: '',
  66. orderId: null,
  67. loading: false,
  68. logisticsData: {},
  69. trackingData: [],
  70. logisticsStatus: 'pending'
  71. }
  72. },
  73. computed: {
  74. statusLabel() {
  75. var map = {
  76. pending: '待发货',
  77. shipped: '已发货',
  78. signing: '派送中',
  79. completed: '已签收'
  80. }
  81. return map[this.logisticsStatus] || this.logisticsStatus
  82. }
  83. },
  84. onLoad(options) {
  85. if (options.orderNo) {
  86. this.orderNo = options.orderNo
  87. }
  88. if (options.orderId) {
  89. this.orderId = parseInt(options.orderId)
  90. }
  91. this.loadLogistics()
  92. },
  93. methods: {
  94. loadLogistics() {
  95. if (!this.orderId) {
  96. uni.showToast({ title: '订单ID缺失', icon: 'none' })
  97. return
  98. }
  99. this.loading = true
  100. var that = this
  101. uni.request({
  102. url: config.api('/api/shop/logistics/query'),
  103. method: 'POST',
  104. data: { orderId: this.orderId },
  105. header: {
  106. 'Content-Type': 'application/json',
  107. 'Authorization': 'Bearer ' + uni.getStorageSync('token')
  108. },
  109. success: function(res) {
  110. that.loading = false
  111. if (res.data && res.data.code === 200) {
  112. var data = res.data.data || {}
  113. that.logisticsData = data
  114. that.trackingData = data.trackingData || []
  115. if (data.status) {
  116. that.logisticsStatus = data.status
  117. }
  118. } else {
  119. uni.showToast({ title: res.data.message || '查询失败', icon: 'none' })
  120. }
  121. },
  122. fail: function() {
  123. that.loading = false
  124. uni.showToast({ title: '网络请求失败', icon: 'none' })
  125. }
  126. })
  127. },
  128. onCopy(text) {
  129. uni.setClipboardData({
  130. data: text,
  131. success: function() {
  132. uni.showToast({ title: '已复制', icon: 'success' })
  133. }
  134. })
  135. }
  136. }
  137. }
  138. </script>
  139. <style scoped>
  140. .container {
  141. min-height: 100vh;
  142. background: #f5f5f5;
  143. }
  144. .loading-wrap {
  145. display: flex;
  146. justify-content: center;
  147. padding-top: 200rpx;
  148. }
  149. .loading-text {
  150. font-size: 28rpx;
  151. color: #999;
  152. }
  153. .content {
  154. height: calc(100vh - 120rpx);
  155. }
  156. .header-section {
  157. background: #fff;
  158. padding: 30rpx;
  159. border-bottom: 1rpx solid #f0f0f0;
  160. display: flex;
  161. flex-direction: column;
  162. }
  163. .header-top {
  164. display: flex;
  165. justify-content: space-between;
  166. align-items: center;
  167. margin-bottom: 20rpx;
  168. }
  169. .order-no {
  170. font-size: 26rpx;
  171. color: #666;
  172. }
  173. .status-badge {
  174. font-size: 22rpx;
  175. padding: 4rpx 16rpx;
  176. border-radius: 20rpx;
  177. }
  178. .status-pending {
  179. background: #fff7e6;
  180. color: #fa8c16;
  181. }
  182. .status-shipped {
  183. background: #e6f7ff;
  184. color: #1890ff;
  185. }
  186. .status-signing {
  187. background: #fff7e6;
  188. color: #fa8c16;
  189. }
  190. .status-completed {
  191. background: #f6ffed;
  192. color: #52c41a;
  193. }
  194. .refresh-btn {
  195. font-size: 24rpx;
  196. color: #F97316;
  197. background: #fff7e6;
  198. border: 1rpx solid #F97316;
  199. padding: 8rpx 30rpx;
  200. border-radius: 30rpx;
  201. width: auto;
  202. align-self: center;
  203. line-height: 1.5;
  204. }
  205. .refresh-btn::after {
  206. border: none;
  207. }
  208. .section {
  209. background: #fff;
  210. margin: 20rpx;
  211. border-radius: 16rpx;
  212. padding: 24rpx;
  213. }
  214. .section-title {
  215. font-size: 28rpx;
  216. font-weight: bold;
  217. color: #333;
  218. margin-bottom: 20rpx;
  219. display: block;
  220. }
  221. .info-row {
  222. display: flex;
  223. justify-content: space-between;
  224. align-items: center;
  225. padding: 16rpx 0;
  226. border-bottom: 1rpx solid #f5f5f5;
  227. }
  228. .info-row:last-child {
  229. border-bottom: none;
  230. }
  231. .info-label {
  232. font-size: 26rpx;
  233. color: #999;
  234. }
  235. .info-value {
  236. font-size: 26rpx;
  237. color: #333;
  238. }
  239. .copy-row {
  240. display: flex;
  241. align-items: center;
  242. }
  243. .copy-btn {
  244. font-size: 22rpx;
  245. color: #1890ff;
  246. background: #e6f7ff;
  247. padding: 2rpx 16rpx;
  248. border-radius: 20rpx;
  249. margin-left: 12rpx;
  250. }
  251. /* Timeline */
  252. .timeline {
  253. padding: 0;
  254. }
  255. .timeline-node {
  256. display: flex;
  257. min-height: 100rpx;
  258. }
  259. .timeline-dot-wrap {
  260. display: flex;
  261. flex-direction: column;
  262. align-items: center;
  263. width: 40rpx;
  264. margin-right: 20rpx;
  265. position: relative;
  266. }
  267. .timeline-dot {
  268. width: 20rpx;
  269. height: 20rpx;
  270. border-radius: 50%;
  271. margin-top: 8rpx;
  272. z-index: 1;
  273. }
  274. .dot-orange {
  275. background: #F97316;
  276. }
  277. .dot-gray {
  278. background: #ddd;
  279. }
  280. .timeline-line {
  281. width: 2rpx;
  282. flex: 1;
  283. background: #e0e0e0;
  284. margin-top: 4rpx;
  285. }
  286. .timeline-content {
  287. flex: 1;
  288. padding-bottom: 30rpx;
  289. }
  290. .timeline-text {
  291. display: block;
  292. font-size: 26rpx;
  293. color: #333;
  294. margin-bottom: 6rpx;
  295. line-height: 1.5;
  296. }
  297. .timeline-time {
  298. display: block;
  299. font-size: 22rpx;
  300. color: #999;
  301. }
  302. .empty-tracking {
  303. display: flex;
  304. flex-direction: column;
  305. align-items: center;
  306. padding: 40rpx 0;
  307. }
  308. .empty-icon {
  309. font-size: 80rpx;
  310. margin-bottom: 20rpx;
  311. }
  312. .empty-text {
  313. font-size: 26rpx;
  314. color: #999;
  315. }
  316. </style>