sen
1 天以前 5abcde36961125cbf436f91b8c17610a6b5f8308
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
<template>
  <view class="container">
    <Nav title="行程历史" @back="goBack" />
 
    <!-- 加载状态 -->
    <view v-if="loading && !list.length" class="center-state">
      <u-loading-icon size="32" text="加载中..." />
    </view>
 
    <!-- 空状态 -->
    <view v-else-if="!loading && !list.length" class="center-state">
      <u-empty mode="history" text="暂无行程记录" />
    </view>
 
    <!-- 行程历史列表 -->
    <scroll-view v-else class="history-scroll" scroll-y @scrolltolower="loadMore">
      <view class="timeline-list">
        <view
          v-for="(item, index) in list"
          :key="index"
          class="timeline-item"
        >
          <!-- 左侧时间轴 -->
          <view class="timeline-left">
            <view class="timeline-dot" :class="{ first: index === 0 }" />
            <view v-if="index < list.length - 1" class="timeline-line" />
          </view>
 
          <!-- 右侧行程卡片 -->
          <view class="timeline-card">
            <view class="card-top">
              <view class="type-tag" :style="{ backgroundColor: item.tagBg, color: item.tagColor }">
                {{ item.statusStr }}
              </view>
              <text class="card-time">{{ item.tripTime }}</text>
            </view>
 
            <view class="card-address">
              <u-icon name="map-fill" size="14" color="#909399" />
              <text class="address-text">{{ item.address || '暂无地址' }}</text>
            </view>
 
            <view v-if="item.odometer" class="card-odometer">
              <u-icon name="car" size="14" color="#909399" />
              <text class="odometer-text">仪表里程:{{ item.odometer }} km</text>
            </view>
 
            <view v-if="item.images && item.images.length" class="card-images">
              <image
                v-for="(img, i) in item.images"
                :key="i"
                class="img-thumb"
                :src="img"
                mode="aspectFill"
                lazy-load
                @tap="onPreview(index, i)"
              />
            </view>
          </view>
        </view>
      </view>
 
      <view class="load-more">
        <u-loadmore :status="loadStatus" />
      </view>
    </scroll-view>
  </view>
</template>
 
<script>
import { tmsTripListPage, getcarType } from '@/common/examine'
 
const TYPE_COLORS = Object.freeze({
  '1':   { bg: 'rgba(64,158,255,0.1)',  color: '#409eff' },
  '0':   { bg: 'rgba(103,194,58,0.1)',  color: '#67c23a' },
  '2':   { bg: 'rgba(230,162,60,0.1)',  color: '#e6a23c' },
  '3':   { bg: 'rgba(230,162,60,0.1)',  color: '#e6a23c' },
  '4':   { bg: 'rgba(144,147,153,0.1)', color: '#909399' },
  '5':   { bg: 'rgba(144,147,153,0.1)', color: '#909399' },
  '6':   { bg: 'rgba(245,108,108,0.1)', color: '#f56c6c' },
  '7':   { bg: 'rgba(245,108,108,0.1)', color: '#f56c6c' },
  '8':   { bg: 'rgba(103,194,58,0.1)',  color: '#67c23a' },
  '100': { bg: 'rgba(192,196,204,0.1)', color: '#909399' },
})
const DEFAULT_COLOR = { bg: 'rgba(192,196,204,0.1)', color: '#c0c4cc' }
 
export default {
  data() {
    return {
      formData: {},
      list: [],
      tripTypeDict: [],
      loading: false,
      pageNum: 1,
      pageSize: 10,
      total: 0,
      finished: false
    }
  },
 
  computed: {
    loadStatus() {
      if (this.loading) return 'loading'
      if (this.finished) return 'nomore'
      return 'loadmore'
    }
  },
 
  onLoad(options) {
    this.formData = options || {}
    this.initData()
  },
 
  methods: {
    goBack() {
      const pages = getCurrentPages()
      for (let i = pages.length - 2; i >= 0; i--) {
        if (pages[i].route && pages[i].route.includes('pages/examine')) {
          uni.navigateBack({ delta: pages.length - 1 - i })
          return
        }
      }
      uni.navigateBack({ delta: 1 })
    },
 
    async initData() {
      this.loading = true
      try {
        const tripTypes = await getcarType('trip_type')
        this.tripTypeDict = tripTypes || []
        await this.loadPage()
      } catch {
        uni.$u.toast('加载失败')
      } finally {
        this.loading = false
      }
    },
 
    async loadPage() {
      this.loading = true
      try {
        const params = { pageNum: this.pageNum, pageSize: this.pageSize }
        // dispatchId 可选,不传查全部行程
        if (this.formData.id) {
          params.dispatchId = this.formData.id
        }
 
        const res = await tmsTripListPage(params)
 
        let rows, total
        if (res && res.rows) {
          rows = res.rows || []
          total = res.total || 0
        } else {
          // 兼容非分页返回
          rows = Array.isArray(res) ? res : []
          total = rows.length
          this.finished = true
        }
 
        const processed = rows.map(item => {
          const dict = this.tripTypeDict.find(d => d.dictValue == item.tripType)
          const typeKey = String(item.tripType)
          const colors = TYPE_COLORS[typeKey] || DEFAULT_COLOR
          return {
            ...item,
            statusStr: dict?.dictLabel || '未知',
            tagBg: colors.bg,
            tagColor: colors.color,
            images: item.voucherUrl
              ? item.voucherUrl.split(',').filter(u => u.trim())
              : []
          }
        })
 
        if (this.pageNum === 1) {
          this.list = processed
        } else {
          this.list = this.list.concat(processed)
        }
 
        this.total = total
        if (this.list.length >= total || rows.length < this.pageSize) {
          this.finished = true
        }
      } catch {
        uni.$u.toast('加载失败')
      } finally {
        this.loading = false
      }
    },
 
    loadMore() {
      if (this.loading || this.finished) return
      this.pageNum++
      this.loadPage()
    },
 
    onPreview(itemIndex, imgIndex) {
      const item = this.list[itemIndex]
      if (item && item.images && item.images.length) {
        uni.previewImage({
          urls: item.images,
          current: item.images[imgIndex]
        })
      }
    }
  }
}
</script>
 
<style lang="scss" scoped>
.container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background-color: #f5f7fa;
}
 
.center-state {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 60vh;
}
 
.history-scroll {
  flex: 1;
  height: calc(100vh - 88rpx);
  box-sizing: border-box;
}
 
.timeline-list {
  padding: 30rpx 24rpx 0;
}
 
.timeline-item {
  display: flex;
 
  &:last-child .timeline-line {
    display: none;
  }
}
 
.timeline-left {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 50rpx;
  flex-shrink: 0;
  padding-top: 30rpx;
}
 
.timeline-dot {
  width: 20rpx;
  height: 20rpx;
  border-radius: 50%;
  background-color: #dcdfe6;
  border: 4rpx solid #fff;
  box-shadow: 0 0 0 4rpx rgba(0, 0, 0, 0.06);
  flex-shrink: 0;
 
  &.first {
    background-color: #4285f4;
    box-shadow: 0 0 0 4rpx rgba(66, 133, 244, 0.25);
  }
}
 
.timeline-line {
  width: 3rpx;
  flex: 1;
  background-color: #e4e7ed;
  min-height: 40rpx;
}
 
.timeline-card {
  flex: 1;
  background: #fff;
  border-radius: 16rpx;
  padding: 28rpx;
  margin-left: 16rpx;
  margin-bottom: 20rpx;
  box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
}
 
.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20rpx;
}
 
.type-tag {
  padding: 6rpx 20rpx;
  border-radius: 8rpx;
  font-size: 24rpx;
  font-weight: 500;
  line-height: 1.6;
}
 
.card-time {
  font-size: 24rpx;
  color: #909399;
}
 
.card-address {
  display: flex;
  align-items: flex-start;
  gap: 10rpx;
  margin-bottom: 12rpx;
}
 
.address-text {
  flex: 1;
  font-size: 28rpx;
  color: #303133;
  line-height: 1.5;
  word-break: break-all;
}
 
.card-odometer {
  display: flex;
  align-items: center;
  gap: 10rpx;
  margin-bottom: 12rpx;
}
 
.odometer-text {
  font-size: 26rpx;
  color: #606266;
}
 
.card-images {
  display: flex;
  flex-wrap: wrap;
  gap: 12rpx;
  margin-top: 20rpx;
  padding-top: 20rpx;
  border-top: 1rpx solid #f2f3f5;
}
 
.img-thumb {
  width: 140rpx;
  height: 140rpx;
  border-radius: 10rpx;
  border: 1rpx solid #ebeef5;
  background-color: #f5f7fa;
}
 
.load-more {
  padding: 30rpx 0 50rpx;
}
</style>