editTree.vue
8.3 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
<template>
<view class="container">
<!-- ✅ 顶部固定吸顶Tabs区域 - 核心新增 -->
<up-sticky bg-color="#ffffff">
<view class="header-wrap">
<up-tabs
v-model="activeTab"
:list="tabList"
active-color="#1989fa"
inactive-color="#666"
font-size="30rpx"
@click="handleTabChange"
:scrollable="false"
/>
</view>
</up-sticky>
<!-- ✅ Tab0 基本信息页面 (树木的详情编辑页,保留你原编辑页核心结构,这里给你做了标准基础版,可直接加表单) -->
<view v-show="activeTab === 0" class="base-info-wrap">
<up-card :border="false" :show-head="false" class="base-card">
<view class="card-body-inner">
<view class="record-list-left" :style="`background-image: url(${treeInfo.treephoto});`"></view>
<view class="record-list-right">
<view class="record-list-right-title">
<view class="u-line-1 treetypeName">{{ treeInfo.treetype }}</view>
</view>
<view class="fs-mt8 fs-align__center">
<img src="../../../static/imgs/tree/tree-high.png" style="width: 14px;height: 14px;margin-right: 6px;" alt=""> 高度:{{ treeInfo.treeheight }} 米
</view>
<view class="fs-mt8 fs-align__center">
<img src="../../../static/imgs/tree/treearound.png" style="width: 14px;height: 14px;margin-right: 6px;" alt="">胸径:{{ treeInfo.dbh }} 厘米
</view>
<view class="fs-mt8 fs-align__center">
<text>树木编号:{{ treeInfo.treenumber }}</text>
</view>
</view>
</view>
<!-- 这里可以继续加你的 编辑表单/其他基本信息 -->
</up-card>
</view>
<!-- ✅ Tab1 变更日志页面 - 和列表页布局完全一致 + 无新增按钮 + 点击卡片跳转详情 -->
<view v-show="activeTab === 1" class="log-wrap">
<up-empty v-if="logRows.length === 0" text="暂无变更日志"></up-empty>
<view class="record-wrap" v-else>
<up-card
v-for="item in logRows"
:key="item.id"
:border="false"
:show-head="false"
class="tree-card"
:foot-border-top="false"
@click="toLogDetailPage(item)"
>
<template #body>
<view class="card-body-inner">
<!-- ✅ 保留你要求的背景图写法 -->
<view class="record-list-left" :style="`background-image: url(${item.treephotoone});`"></view>
<view class="record-list-right">
<view class="record-list-right-title">
<view class="u-line-1 treetypeName">{{ item.treetype }}</view>
<view style="text-align: right">{{ timeFormat(item.updatetime) }}</view>
</view>
<view class=" fs-align__center" style="margin: 5px 0">
<img src="../../../static/imgs/tree/tree-high.png" style="width: 14px;height: 14px;margin-right: 6px;" alt=""> 高度:{{ item.treeheight }} 米
</view>
<view class=" fs-align__center">
<img src="../../../static/imgs/tree/treearound.png" style="width: 14px;height: 14px;margin-right: 6px;" alt="">胸径:{{ item.dbh }} 厘米
</view>
</view>
</view>
<view class="treenumber-no">
树木编号:{{ item.treenumber }}
</view>
</template>
</up-card>
</view>
</view>
<!-- ✅ 新增按钮 只在【基本信息Tab】显示,变更日志Tab自动隐藏,无需手动处理 -->
<view class="fixed-bottom-btn-wrap">
<up-button
type="primary"
@click="toAddTreePage"
v-show="count > 0 && count > rows.length && activeTab === 0"
>
新增树木录入
</up-button>
</view>
</view>
</template>
<script setup>
import { ref, reactive } from 'vue'
import { onReady, onLoad, onShow, onUnload } from '@dcloudio/uni-app';
onUnload(() => {
// 关闭所有页面,直接打开【行道树档案】主页面 【微信小程序完美兼容,无任何报错】
uni.reLaunch({
url: '/pages-sub/data/tree-archive/index'
})
})
import { treeRoadReq,treeLogReq } from "@/api/tree-archive/tree-archive.js";
import { timeFormat } from '@/uni_modules/uview-plus';
// ========== 基础变量 ==========
const rows = ref([])
const roadId = ref('')
const count = ref(0)
const treeId = ref('')
// ========== Tab切换核心变量 ==========
const activeTab = ref(0); // 0=基本信息 1=变更日志
const tabList = ref([
{ name: '基本信息' },
{ name: '变更日志' }
]);
// ========== 数据变量 ==========
const treeInfo = reactive({ // 基本信息-单棵树详情
treephoto: '',
treetype: '',
treeheight: '',
dbh: '',
treenumber: '',
updatetime: ''
})
const logRows = ref([]) // 变更日志列表数据
// ========== 生命周期 ==========
onLoad((options) => {
console.log('编辑页入参', options)
roadId.value = options.roadId || ''
count.value = options.count || 0
treeId.value = options.id || '' // 树木主键ID
})
onShow(() => {
treeRoadQuery()
if(activeTab.value === 0){
// getTreeDetail() // 进入页面默认加载基本信息
}
})
// ========== Tab切换事件 ==========
const handleTabChange = (item) => {
activeTab.value = item.index
// 切换到哪个tab,加载对应的数据
if(activeTab.value === 0){
getTreeDetail() // 加载基本信息
}else if(activeTab.value === 1){
getTreeLogList() // 加载变更日志列表
}
}
// ========== 接口请求 ==========
// 树木列表查询
const treeRoadQuery = async () => {
const res = await treeRoadReq( {road: roadId.value})
rows.value = res.list
}
// // 获取单棵树的基本信息
// const getTreeDetail = async () => {
// const res = await treeDetailReq({ id: treeId.value })
// Object.assign(treeInfo, res)
// }
// 获取树木的变更日志列表
const getTreeLogList = async () => {
const res = await treeLogReq({ treeid: treeId.value })
logRows.value = res.list
}
// ========== 页面跳转 ==========
// 前往修改页面(原有)
const toEditPage = (id) => {
uni.navigateTo({
url: `/pages-sub/data/tree-archive/editTree?id=${id}&roadId=${roadId.value}`
})
}
// 前往新增页面(原有)
const toAddTreePage = () => {
uni.navigateTo({
url: `/pages-sub/data/tree-archive/addTree?roadId=${roadId.value}`
})
}
// ✅ 新增:点击变更日志卡片 前往日志详情页面
const toLogDetailPage = (i) => {
uni.navigateTo({
// url: `/pages-sub/data/tree-archive/logDetail?id=${logId}&treeId=${treeId.value}`
url: `/pages-sub/data/tree-archive/logDetail`,
events: {
sendBackData: (data) => {
console.log('B页面回传的数据:', data);
}
},
// 2. 向B页面传递数据
success: (res) => {
// 通过 eventChannel 发送数据,key
res.eventChannel.emit('logData', i);
}
})
}
</script>
<style scoped lang="scss">
.container {
min-height: 100vh;
}
// ✅ 顶部tabs吸顶样式
.header-wrap {
background-color: #fff;
padding: 10rpx 0;
box-shadow: 0 2rpx 4rpx rgba(0,0,0,0.03);
}
// 基本信息样式
.base-info-wrap {
padding: 20rpx 10rpx;
}
.base-card {
background: #fff;
border-radius: 6px;
padding: 10px;
}
// 变更日志样式 和列表页完全一致
.log-wrap {
min-height: calc(100vh - 120rpx);
}
.record-wrap {
padding-bottom: 20px;
}
.treetypeName {
flex: 1;
font-size: 16px;
font-weight: bold;
}
.record-list-left {
height: 70px;
width: 70px;
background-size: 100% 100%;
background-repeat: no-repeat;
background-position: center;
}
.record-list-right {
margin-left: 20px;
flex: 1;
overflow: hidden;
}
.record-list-right-title {
display: flex;
justify-content: space-between;
}
.treenumber-no {
padding: 3px 10px;
background: #bdefd0;
font-size: 12px;
margin-top: 8px;
}
// up-card样式适配
.tree-card {
//margin: 15px 10px 0;
//padding: 10px;
//border-radius: 6px;
//font-size: 14px;
//box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.04);
//background-color: #ffffff;
}
.card-body-inner{
display: flex;
}
.addTree {
width: 100%;
position: fixed;
bottom: 0;
}
.fs-align__center {
display: flex;
align-items: center;
}
</style>