logistics.vue 7.2 KB

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