road-detail-list.vue
8.83 KB
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
354
355
<template>
<view class="page-container">
<!-- 顶部吸顶区域 -->
<up-sticky>
<view class="sticky-header">
<!-- 状态Tabs -->
<up-tabs
v-model="activeStatus"
:list="statusTabs"
line-width="40rpx"
active-color="#1989fa"
inactive-color="#666"
:scrollable="true"
class="status-tabs"
@click="handleStatusChange"
></up-tabs>
<!-- 搜索框 -->
<up-search
v-model="searchValue"
:placeholder="searchPlaceholder"
bg-color="#f5f5f5"
shape="round"
:show-action="true"
actionText="搜索"
:animation="true"
@search="handleSearch"
@custom="handleSearch"
:clearabled="false"
maxlength="50"
class="search-input"
></up-search>
</view>
</up-sticky>
<!-- 分页列表区域 -->
<z-paging
ref="pagingRef"
v-model="planList"
@query="queryList"
:top="140"
>
<!-- 空数据插槽 -->
<template #empty>
<view class="empty-container">
<up-empty mode="list" text="暂无相关计划数据"></up-empty>
</view>
</template>
<!-- 列表内容 -->
<view class="card-list">
<view
class="plan-card"
v-for="(item, index) in planList"
:key="index"
>
<view class="card-header">
<text class="plan-name">{{ item.planName || '未命名计划' }}</text>
<!-- <text class="plan-status" :class="getStatusClass(item.status)">{{ getStatusText(item.status) }}</text>-->
</view>
<view class="card-body">
<view class="info-item">
<text class="label">计划编码:</text>
<text class="value">{{ item.planNo || '-' }}</text>
</view>
<view class="info-item">
<text class="label">养护周期:</text>
<text class="value">{{ item.rate || '-' }} {{ uni.$dict.getDictLabel('cycle_id_type', item.cycleId) }}</text>
</view>
<view class="info-item">
<text class="label">计划完成次数:</text>
<text class="value">{{ item.planNum || 0 }}</text>
</view>
<view class="info-item">
<text class="label">已完成比例:</text>
<text class="value">{{ item.finishPercent || 0 }}%</text>
</view>
<view class="info-item">
<text class="label">计划有效期:</text>
<text class="value">{{ timeFormat(item.beginTime,'yyyy-mm-dd') || '-'}} 至 {{ timeFormat(item.endTime,'yyyy-mm-dd') || '-'}}</text>
</view>
</view>
<view class="card-footer">
<up-button
type="primary"
size="mini"
@click="handleDetail(item)"
>
查看详情
</up-button>
</view>
</view>
</view>
</z-paging>
</view>
</template>
<script setup>
import { ref, computed, onMounted } from 'vue'
import { onLoad, onShow } from '@dcloudio/uni-app'
import { timeFormat } from '@/uni_modules/uview-plus'
import { getRoadDetails } from "@/api/maintain-manage/maintain-manage";
// ========== 基础数据定义 ==========
// 状态Tabs数据
const statusTabs = ref([
{ name: '待完成', id: '1' },
{ name: '已失效', id: '3' },
{ name: '已完成', id: '2' }
])
// 响应式数据
const activeStatus = ref('1') // 当前选中的状态
const searchValue = ref('') // 搜索框值
const planList = ref([]) // 计划列表(绑定z-paging)
const pagingRef = ref(null) // z-paging实例
const loading = ref(false) // 加载状态
// URL参数存储
const roadId = ref('') // 从URL获取的roadId
const finishState = ref('') // 从URL获取的finish_state
// 搜索占位符
const searchPlaceholder = computed(() => {
return '请输入计划名称'
})
// ========== 方法定义 ==========
// 从URL获取参数
const getUrlParams = (options) => {
// 1. 修复:URL中是roadId(驼峰),不是road_id
if (options?.roadId) {
roadId.value = options.roadId
console.log('从URL获取的roadId:', roadId.value) // 打印验证
}
if (options?.finish_state) {
finishState.value = options.finish_state
// 同步更新Tabs选中状态
activeStatus.value = options.finish_state
console.log('从URL获取的finish_state:', finishState.value)
}
}
// 状态切换
const handleStatusChange = (item) => {
console.log('切换状态:', item)
activeStatus.value = item.id
// 更新finishState值
finishState.value = item.id
// 重置分页并刷新
pagingRef.value?.reload()
}
// 搜索处理
const handleSearch = () => {
console.log('搜索关键词:', searchValue.value)
// 重置分页并刷新
pagingRef.value?.reload()
}
// 获取状态文本
const getStatusText = (status) => {
const statusMap = {
'1': '待完成',
'2': '已完成',
'3': '已失效'
}
return statusMap[status] || '未知状态'
}
// 获取状态样式类
const getStatusClass = (status) => {
const classMap = {
'1': 'status-pending',
'2': 'status-completed',
'3': 'status-invalid'
}
return classMap[status] || ''
}
// 查看详情
const handleDetail = (item) => {
uni.navigateTo({
url: `/pages/planDetail/planDetail?planId=${item.id || ''}`
})
}
// 分页请求数据(z-paging回调)
const queryList = async (pageNo, pageSize) => {
try {
loading.value = true
// 构造请求参数:优先使用URL参数
const paramsData = {
pageNo: pageNo,
pageSize: pageSize,
road_id: roadId.value, // 现在能拿到正确的roadId了
finish_state: finishState.value || activeStatus.value,
planName: searchValue.value.trim()
}
console.log('请求参数:', paramsData) // 验证road_id是否有值
const res = await getRoadDetails(paramsData)
console.log(res)
// 兼容不同的接口返回格式
const listData = res?.list || res || []
// 告知z-paging数据加载完成
pagingRef.value?.complete(listData)
loading.value = false
} catch (error) {
console.error('请求失败:', error)
uni.showToast({ title: '加载失败,请重试', icon: 'none' })
pagingRef.value?.complete(false)
loading.value = false
}
}
// ========== 生命周期修复 ==========
// 2. 修复:只有onLoad才会接收页面跳转的options参数
onLoad((options) => {
// 页面首次加载时获取URL参数
getUrlParams(options)
// 初始化数据
pagingRef.value?.reload()
})
onShow(() => {
// 可选:页面再次显示时刷新(比如从详情页返回)
// if (roadId.value) { // 有roadId才刷新
// pagingRef.value?.reload()
// }
})
onMounted(() => {
// 可选:初始化其他逻辑
})
</script>
<style scoped lang="scss">
.page-container {
min-height: 100vh;
background-color: #f8f8f8;
}
// 顶部吸顶区域样式
.sticky-header {
background-color: #ffffff;
padding-bottom: 10rpx;
border-bottom: 1px solid #eee;
// 状态Tabs样式
.status-tabs {
margin: 10rpx 0 0 0;
}
// 搜索框样式
.search-input {
margin: 20rpx 20rpx 10rpx !important;
}
}
// 卡片列表样式
.card-list {
padding: 0 20rpx;
display: flex;
flex-direction: column;
gap: 20rpx;
}
// 计划卡片样式
.plan-card {
background-color: #ffffff;
border-radius: 12rpx;
padding: 24rpx;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
// 卡片头部
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20rpx;
padding-bottom: 12rpx;
border-bottom: 1px solid #f5f5f5;
.plan-name {
font-size: 30rpx;
font-weight: 600;
color: #333;
}
.plan-status {
font-size: 24rpx;
padding: 4rpx 12rpx;
border-radius: 20rpx;
// 状态样式
&.status-pending {
background-color: #fff7e6;
color: #ff9f1c;
}
&.status-completed {
background-color: #e8f8f5;
color: #00b42a;
}
&.status-invalid {
background-color: #f5f5f5;
color: #999;
}
}
}
// 卡片内容
.card-body {
display: flex;
flex-direction: column;
gap: 16rpx;
margin-bottom: 20rpx;
.info-item {
display: flex;
align-items: center;
font-size: 28rpx;
.label {
color: #999;
flex-shrink: 0;
}
.value {
color: #333;
flex: 1;
}
}
}
// 卡片底部
.card-footer {
display: flex;
justify-content: flex-end;
}
}
// 空数据样式
.empty-container {
display: flex;
justify-content: center;
align-items: center;
height: 400rpx;
}
</style>