index.vue
7.26 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
<template>
<view class="container">
<!-- 归属单位选择 -->
<up-form :model="formData" ref="formRef" label-width="140rpx" border-bottom style="padding: 0 15px">
<up-form-item
label="归属单位"
prop="companyId"
@click="showActionSheet = true"
class="form-item-custom"
>
<up-input
v-model="formData.companyId"
placeholder="请选择归属单位"
disabled
disabled-color="#ffffff"
border="none"
bg-color="transparent"
/>
<template #right>
<up-icon name="arrow-right" size="16"></up-icon>
</template>
</up-form-item>
</up-form>
<!-- 弹窗式 Search 搜索组件 -->
<view class="search-wrap">
<up-search
v-model="searchValue"
placeholder="请输入道路名称搜索"
@search="handleSearch"
bg-color="#f5f5f5"
:clearabled="false"
:show-action="true"
actionText="搜索"
:animation="true"
@custom="handleSearch"
/>
</view>
<!-- ✅ 核心:uview-plus up-row+up-col 实现左右布局【无u-scroll-list,无任何多余组件】 -->
<up-row type="flex" class="cate-layout" align="flex-start">
<!-- 左侧:班组列表 (uview栅格列 + 原生滚动) -->
<up-col span="3" class="cate-left">
<view
class="left-item"
:class="{ active: currentIndex === index }"
v-for="(item, index) in cateTabList"
:key="item.deptId"
@click="cateTabChange(index)"
>
{{ item.deptName }}
</view>
</up-col>
<!-- 右侧:道路列表 (uview栅格列 + 原生滚动) -->
<up-col span="9" class="cate-right">
<scroll-view scroll-y class="right-scroll">
<!-- 暂无数据 -->
<empty-view v-if="!hasValidRoadId"></empty-view>
<!-- 道路数据列表 -->
<view v-else class="road-list-wrap">
<view
v-for="item in roads"
class="card-wrap cad-box-shadow"
:key="item.roadId"
@click="toNewPage(item.roadId, item.treeCount)"
>
<p class="fs-flex__between">
<span class="up-line-1">{{ item.roadName }}</span>
<span class="treeCount">{{ item.treeCount }}棵</span>
</p>
<p class="up-line-1 fs-my8">已录入行道树:{{ item.recordedCount }}棵</p>
<p class="up-line-1 fs-my8" style="color: #999;font-size: 12px">起点:{{ item.startRemark }}</p>
<p class="up-line-1" style="color: #999;font-size: 12px">终点:{{ item.endRemark }}</p>
</view>
</view>
</scroll-view>
</up-col>
</up-row>
<!-- ActionSheet 底部弹出选择菜单 -->
<up-action-sheet
:show="showActionSheet"
:actions="belongCompanyData"
title="请选择归属单位"
@select="actionSheetSelect"
@close="showActionSheet = false"
></up-action-sheet>
</view>
</template>
<script setup>
import { ref, reactive, watch } from 'vue'
import { onShow } from '@dcloudio/uni-app';
import { getCompanyList } from "@/api/common";
import { deptListReq } from '@/api/tree-archive/tree-archive'
const formRef = ref(null)
const showActionSheet = ref(false)
const currentIndex = ref(0)
const hasValidRoadId = ref(false)
const searchValue = ref('') // 搜索关键词 独立绑定
// 表单数据
const formData = reactive({
companyId: '',
})
// 接口数据变量
const companyId = ref('')
const belongCompanyData = ref([]) // 归属单位下拉数据
const depts = ref([]) // 归属班组列表
const roads = ref([]) // 当前选中班组的道路列表
const cateTabList = ref([]) // 左侧tab数据源
// 生命周期
onShow( async() => {
const res = await getCompanyList()
belongCompanyData.value = res
if (belongCompanyData.value.length > 0) {
formData.companyId = belongCompanyData.value[0].name
companyId.value = belongCompanyData.value[0].id.toString()
deptListQuery()
}
})
// 监听 CateTab 选中下标 数据联动
watch(currentIndex, () => {
if(depts.value.length > 0) {
roads.value = depts.value[currentIndex.value].roads
checkRoadDataValid()
}
})
// 搜索事件 - 点击搜索按钮/回车触发
const handleSearch = () => {
deptListQuery()
}
// 跳转道路档案记录页
const toNewPage = (roadId, treeCount) => {
uni.navigateTo({
url: `/pages-sub/data/tree-archive/treeRecord?roadId=${roadId}&count=${treeCount}`
})
}
// 查询班组+道路数据 & 格式化CateTab的数据源
const deptListQuery = async () => {
const params = {
companyId: companyId.value,
roadName: searchValue.value
}
currentIndex.value=0
const res = await deptListReq(params)
if (res.length ==0) {
depts.value = []
roads.value = []
cateTabList.value = []
hasValidRoadId.value = false
} else {
depts.value = res[0].depts
cateTabList.value = depts.value
roads.value = depts.value[0].roads
checkRoadDataValid()
}
}
// 左侧班组切换事件
const cateTabChange = (index) => {
currentIndex.value = index
roads.value = depts.value[index].roads
checkRoadDataValid()
}
// ActionSheet 选择归属单位的确认事件
const actionSheetSelect = (val) => {
formData.companyId = val.name
companyId.value = val.id.toString()
showActionSheet.value = false // 关闭弹窗
deptListQuery() // 重新查询数据
}
// 校验是否有有效道路数据
const checkRoadDataValid = () => {
hasValidRoadId.value = roads.value && roads.value.length > 0 && roads.value.some(item => {
return item.roadId !== null && item.roadId !== undefined && item.roadId
})
}
</script>
<style scoped lang="scss">
// 页面容器 满高布局
.container {
height: 100%;
display: flex;
flex-direction: column;
background: #fff;
box-sizing: border-box;
}
// 搜索框外层容器 间距不变
.search-wrap {
padding: 10rpx 15rpx;
}
.cate-layout {
flex: 1;
width: 100%;
height: calc(100vh - 44px);
}
.cate-left {
height: 100%;
padding: 0;
background: #f8f8f8;
box-sizing: border-box;
.left-scroll {
width: 100%;
height: 100%;
}
// 左侧列表项
.left-item {
padding: 24rpx 12rpx;
font-size: 28rpx;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
box-sizing: border-box;
}
// 选中项高亮 主题色和你一致 #5f5fe2
.left-item.active {
background: #ffffff;
color: #5f5fe2;
font-weight: 500;
border-left: 4rpx solid #5f5fe2;
}
}
.cate-right {
height: 100%;
padding: 0 10rpx;
box-sizing: border-box;
background: #ffffff;
.right-scroll {
width: 100%;
height: 100%;
}
}
// 道路列表容器
.road-list-wrap {
//padding-bottom: 30rpx;
}
// 道路卡片样式 完全复用你的原版
.card-wrap {
box-shadow:0 0 3px rgba(0, 0, 0, 0.2);
padding: 20rpx;
border-radius: 14rpx;
background: #fff;
margin:10px 6px;
}
// 公共样式 完全不变
.treeCount {
color: #5f5fe2;
min-width: 70px;
text-align: right;
}
.fs-flex__between {
display: flex;
justify-content: space-between;
align-items: center;
}
.fs-my8 { margin: 8rpx 0; }
</style>