c7744156
刘淇
录入树木
|
1
2
|
<template>
<view class="container">
|
b951d827
刘淇
树木详情
|
3
|
<tui-form ref="form" :show-message="false" :model="formData">
|
3bea8ade
刘淇
图片上传
|
4
|
<tui-form-item asterisk label="名称" prop="treetype">
|
c7744156
刘淇
录入树木
|
5
|
<tui-input padding="0" :borderBottom="false" placeholder="请输入名称" maxlength="30"
|
3bea8ade
刘淇
图片上传
|
6
|
v-model="formData.treetype"></tui-input>
|
c7744156
刘淇
录入树木
|
7
8
9
|
</tui-form-item>
<tui-row>
|
3bea8ade
刘淇
图片上传
|
10
11
12
13
|
<tui-col :span="12">
<tui-form-item label="高度" asterisk prop="treeheight" :position="3">
<tui-input padding="0" :borderBottom="false" placeholder="请输入" textRight maxlength="10"
v-model="formData.treeheight"></tui-input>
|
c7744156
刘淇
录入树木
|
14
|
<template v-slot:right>
|
3bea8ade
刘淇
图片上传
|
15
|
<text style="padding-left: 12rpx;color:#aaa;font-size:14px;">米</text>
|
c7744156
刘淇
录入树木
|
16
17
18
|
</template>
</tui-form-item>
</tui-col>
|
3bea8ade
刘淇
图片上传
|
19
20
|
<tui-col :span="12">
<tui-form-item label="胸径" asterisk prop="dbh" :position="3">
|
c7744156
刘淇
录入树木
|
21
|
<tui-input padding="0" :borderBottom="false" placeholder="请输入" textRight maxlength="10"
|
3bea8ade
刘淇
图片上传
|
22
|
v-model="formData.dbh"></tui-input>
|
c7744156
刘淇
录入树木
|
23
|
<template v-slot:right>
|
3bea8ade
刘淇
图片上传
|
24
|
<text style="padding-left: 12rpx;color:#aaa;font-size:14px">厘米</text>
|
c7744156
刘淇
录入树木
|
25
26
27
28
29
30
31
32
33
34
35
|
</template>
</tui-form-item>
</tui-col>
</tui-row>
<tui-form-item
asterisk
label="位置"
class="location-form-item"
@click="openMap"
|
3bea8ade
刘淇
图片上传
|
36
|
prop="growlocation"
|
c7744156
刘淇
录入树木
|
37
38
|
>
<tui-input padding="0" :borderBottom="false" placeholder="请选择" disabled
|
3bea8ade
刘淇
图片上传
|
39
|
v-model="formData.growlocation"></tui-input>
|
c7744156
刘淇
录入树木
|
40
41
42
|
<template v-slot:right>
<tui-icon name="gps" :size="20"></tui-icon>
</template>
|
c7744156
刘淇
录入树木
|
43
44
|
</tui-form-item>
|
21397afd
刘淇
树 新增
|
45
46
|
<tui-col :span="12">
<tui-form-item
|
b951d827
刘淇
树木详情
|
47
|
label="经度"
|
21397afd
刘淇
树 新增
|
48
|
class="location-form-item"
|
21397afd
刘淇
树 新增
|
49
50
|
prop="latitude"
>
|
b951d827
刘淇
树木详情
|
51
|
{{ formData.longitude }}
|
21397afd
刘淇
树 新增
|
52
53
54
55
|
</tui-form-item>
</tui-col>
<tui-col :span="12">
<tui-form-item
|
b951d827
刘淇
树木详情
|
56
57
|
label="纬度"
|
21397afd
刘淇
树 新增
|
58
|
class="location-form-item"
|
b951d827
刘淇
树木详情
|
59
|
|
21397afd
刘淇
树 新增
|
60
61
|
prop="latitude"
>
|
b951d827
刘淇
树木详情
|
62
|
{{ formData.latitude }}
|
21397afd
刘淇
树 新增
|
63
64
65
66
67
68
69
70
71
72
73
|
</tui-form-item>
</tui-col>
<tui-form-item asterisk label="管护单位" prop="managedutyunit">
<tui-input padding="0" :borderBottom="false" placeholder="请输入" maxlength="30"
v-model="formData.managedutyunit"></tui-input>
<!-- <tui-input padding="0" :borderBottom="false" placeholder="请选择" disabled-->
<!-- backgroundColor="transparent" v-model="formData.managedutyunit"></tui-input>-->
|
c7744156
刘淇
录入树木
|
74
|
</tui-form-item>
|
b951d827
刘淇
树木详情
|
75
|
<tui-form-item asterisk label="权属分类" arrow highlight prop="oldtreeownershipText" @click="pickerShow">
|
c7744156
刘淇
录入树木
|
76
|
<tui-input padding="0" :borderBottom="false" placeholder="请选择" disabled
|
b951d827
刘淇
树木详情
|
77
|
backgroundColor="transparent" v-model="formData.oldtreeownershipText"></tui-input>
|
c7744156
刘淇
录入树木
|
78
|
</tui-form-item>
|
c7744156
刘淇
录入树木
|
79
|
|
3bea8ade
刘淇
图片上传
|
80
|
<tui-form-item label="图片信息" asterisk prop="treeImgList">
|
c7744156
刘淇
录入树木
|
81
|
<!-- 使用ThorUI的tui-upload组件 -->
|
21397afd
刘淇
树 新增
|
82
|
<!-- @remove="handleRemove" :multiple="true" :value="formData.treeImgList"-->
|
c7744156
刘淇
录入树木
|
83
84
85
|
<tui-upload
:height="140"
:width="140"
|
21397afd
刘淇
树 新增
|
86
|
:value="formData.treeImgListFile"
|
c7744156
刘淇
录入树木
|
87
88
|
:serverUrl="serverURL" :header="{'Authorization': userToken}"
@complete="handleComplete"
|
f2ecd120
刘淇
树 修改
|
89
|
@remove="handleRemove"
|
c7744156
刘淇
录入树木
|
90
|
:limit="3"
|
c7744156
刘淇
录入树木
|
91
|
accept="image/*"
|
21397afd
刘淇
树 新增
|
92
93
94
95
|
>
<!-- 自定义上传按钮 -->
<view class="upload-btn">
<tui-icon name="plus" size="32" color="#999"></tui-icon>
|
21397afd
刘淇
树 新增
|
96
|
</view>
|
3bea8ade
刘淇
图片上传
|
97
|
</tui-upload>
|
c7744156
刘淇
录入树木
|
98
99
|
</tui-form-item>
|
c7744156
刘淇
录入树木
|
100
101
102
103
104
105
106
107
108
109
110
|
<!-- 动画区域(初始隐藏) -->
<view
class="animated-area"
:style="{
height: isShow ? contentHeight + 'px' : '0',
opacity: isShow ? 1 : 0,
overflow: 'hidden'
}"
>
<tui-row>
|
3bea8ade
刘淇
图片上传
|
111
112
|
<tui-col :span="12">
<tui-form-item label="拉丁文" prop="latinname">
|
c7744156
刘淇
录入树木
|
113
|
<tui-input padding="0" :borderBottom="false" placeholder="请输入" maxlength="30"
|
3bea8ade
刘淇
图片上传
|
114
|
v-model="formData.latinname"></tui-input>
|
c7744156
刘淇
录入树木
|
115
116
|
</tui-form-item>
</tui-col>
|
3bea8ade
刘淇
图片上传
|
117
|
<tui-col :span="12">
|
b951d827
刘淇
树木详情
|
118
|
<tui-form-item label="级别" arrow highlight prop="treeleveltext" @click="pickerLevelShow">
|
3bea8ade
刘淇
图片上传
|
119
|
<tui-input padding="0" :borderBottom="false" placeholder="请选择" disabled
|
b951d827
刘淇
树木详情
|
120
|
backgroundColor="transparent" v-model="formData.treeleveltext"></tui-input>
|
3bea8ade
刘淇
图片上传
|
121
|
</tui-form-item>
|
c7744156
刘淇
录入树木
|
122
123
124
|
</tui-col>
</tui-row>
|
3bea8ade
刘淇
图片上传
|
125
|
<tui-form-item label="生长环境" prop="growthenvironment">
|
c7744156
刘淇
录入树木
|
126
|
<tui-input padding="0" :borderBottom="false" placeholder="请输入" maxlength="50"
|
3bea8ade
刘淇
图片上传
|
127
|
v-model="formData.growthenvironment"></tui-input>
|
c7744156
刘淇
录入树木
|
128
129
130
131
|
</tui-form-item>
<tui-row>
|
3bea8ade
刘淇
图片上传
|
132
133
134
135
|
<tui-col :span="12">
<tui-form-item label="预估树龄" prop="estimationtreeage" :position="3">
<tui-input padding="0" :borderBottom="false" placeholder="请输入" textRight maxlength="10"
v-model="formData.estimationtreeage"></tui-input>
|
c7744156
刘淇
录入树木
|
136
|
<template v-slot:right>
|
3bea8ade
刘淇
图片上传
|
137
|
<text style="padding-left: 12rpx;color:#aaa;font-size: 14px">年</text>
|
c7744156
刘淇
录入树木
|
138
139
140
|
</template>
</tui-form-item>
</tui-col>
|
3bea8ade
刘淇
图片上传
|
141
142
143
144
|
<tui-col :span="12">
<tui-form-item label="干周" prop="weekday" :position="3">
<tui-input padding="0" :borderBottom="false" placeholder="请输入" textRight maxlength="10"
v-model="formData.weekday"></tui-input>
|
c7744156
刘淇
录入树木
|
145
|
<template v-slot:right>
|
3bea8ade
刘淇
图片上传
|
146
|
<text style="padding-left: 12rpx;color:#aaa;font-size: 14px">厘米</text>
|
c7744156
刘淇
录入树木
|
147
148
149
150
151
152
153
|
</template>
</tui-form-item>
</tui-col>
</tui-row>
<tui-row>
|
3bea8ade
刘淇
图片上传
|
154
155
156
157
|
<tui-col :span="12">
<tui-form-item label="东西冠幅" prop="canopyeastwest" :position="3">
<tui-input padding="0" :borderBottom="false" placeholder="请输入" textRight maxlength="10"
v-model="formData.canopyeastwest"></tui-input>
|
c7744156
刘淇
录入树木
|
158
159
160
161
162
|
<template v-slot:right>
<text style="padding-left: 12rpx;color:#aaa">米</text>
</template>
</tui-form-item>
</tui-col>
|
3bea8ade
刘淇
图片上传
|
163
164
165
166
|
<tui-col :span="12">
<tui-form-item label="南北冠幅" prop="canopysouthnorth" :position="3">
<tui-input padding="0" :borderBottom="false" placeholder="请输入" textRight maxlength="10"
v-model="formData.canopysouthnorth"></tui-input>
|
c7744156
刘淇
录入树木
|
167
|
<template v-slot:right>
|
3bea8ade
刘淇
图片上传
|
168
|
<text style="padding-left: 12rpx;color:#aaa;font-size: 14px">米</text>
|
c7744156
刘淇
录入树木
|
169
170
171
172
173
174
|
</template>
</tui-form-item>
</tui-col>
</tui-row>
|
c7744156
刘淇
录入树木
|
175
176
177
178
179
180
181
182
183
184
185
186
|
</view>
<!-- 触发按钮 -->
<tui-button
@click="toggleArea"
type="primary"
:loading="false"
height="80rpx"
plain
>
{{ isShow ? '- 隐藏区域' : '+ 显示区域' }}
</tui-button>
|
b951d827
刘淇
树木详情
|
187
|
</tui-form>
|
c7744156
刘淇
录入树木
|
188
|
|
b951d827
刘淇
树木详情
|
189
|
<view style="height: 60px;width: 100%"></view>
|
c7744156
刘淇
录入树木
|
190
|
|
b951d827
刘淇
树木详情
|
191
192
193
|
<view class="tui-btn__box">
<tui-button bold @click="submit">提交</tui-button>
</view>
|
21397afd
刘淇
树 新增
|
194
195
196
197
198
199
|
<tui-picker :show="show" :pickerData="treeOwnershipData" textField="dictLabel" valueField="dictValue"
@hide="pickerHide" @change="pickerChange">
</tui-picker>
<tui-picker :show="levelshow" :pickerData="treeLevelData" textField="dictLabel" valueField="dictValue"
@hide="pickerLevelHide" @change="pickerLevelChange">
|
c7744156
刘淇
录入树木
|
200
201
202
203
204
|
</tui-picker>
</view>
</template>
<script>
|
b951d827
刘淇
树木详情
|
205
|
import { uploadURL, OSSURL } from '@/config/app'
|
21397afd
刘淇
树 新增
|
206
|
import { treeOwnership, addTree, treeLevelReq } from "@/api/tree";
|
c7744156
刘淇
录入树木
|
207
|
const rules = [{
|
3bea8ade
刘淇
图片上传
|
208
|
name: "treetype",
|
c7744156
刘淇
录入树木
|
209
|
rule: ["required"],
|
3bea8ade
刘淇
图片上传
|
210
211
212
|
msg: ["请输入名称"]
}, {
name: "treeheight",
|
21397afd
刘淇
树 新增
|
213
214
|
rule: ["required", "maxLength:10", "isAmount"],
msg: ["请输入数高", "数高不能超过10个字符", "请输入正确"]
|
c7744156
刘淇
录入树木
|
215
|
}, {
|
3bea8ade
刘淇
图片上传
|
216
|
name: "dbh",
|
21397afd
刘淇
树 新增
|
217
218
|
rule: ["required", "maxLength:10", "isAmount"],
msg: ["请输入胸径", "胸径不能超过10个字符", "请输入正确"]
|
c7744156
刘淇
录入树木
|
219
|
}, {
|
21397afd
刘淇
树 新增
|
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
|
name: "estimationtreeage",
rule: ["maxLength:10", "isAmount"],
msg: ["胸径不能超过10个字符", "请输入正确"]
},
{
name: "weekday",
rule: ["maxLength:10", "isAmount"],
msg: ["胸径不能超过10个字符", "请输入正确"]
},
{
name: "canopyeastwest",
rule: ["maxLength:10", "isAmount"],
msg: ["胸径不能超过10个字符", "请输入正确"]
},
{
name: "canopysouthnorth",
rule: ["maxLength:10", "isAmount"],
msg: ["胸径不能超过10个字符", "请输入正确"]
}, {
name: "growlocation",
rule: ["required"],
msg: ["请地图选择位置"]
}, {
name: "managedutyunit",
rule: ["required"],
msg: ["请选择权属单位"]
}, {
|
b951d827
刘淇
树木详情
|
247
|
name: "oldtreeownershipText",
|
21397afd
刘淇
树 新增
|
248
249
250
251
252
253
254
255
256
257
258
|
rule: ["required"],
msg: ["请选择权属分类"]
}, {
name: "treeImgListFile",
rule: ["required", "custom"], // 增加required强制必选
msg: ["请上传图片", "请至少上传一张图片"], // 对应两个规则的提示
custom: function (value) {
// 即使required通过,再校验数组长度
return value.length > 0;
}
}];
|
c7744156
刘淇
录入树木
|
259
260
261
262
263
264
265
266
267
268
269
270
271
|
export default {
props: {
// 外部传入的已上传图片列表
value: {
type: Array,
default: () => []
}
},
data() {
return {
isShow: false, // 控制区域显示/隐藏
contentHeight: 200, // 内容区域高度
serverURL: uploadURL,
|
21397afd
刘淇
树 新增
|
272
273
|
treeOwnershipData: [],
treeLevelData: [], // 级别
|
c7744156
刘淇
录入树木
|
274
|
show: false,
|
21397afd
刘淇
树 新增
|
275
|
levelshow: false,
|
c7744156
刘淇
录入树木
|
276
277
|
//仅对部分数据进行收集演示
formData: {
|
3bea8ade
刘淇
图片上传
|
278
279
280
281
282
283
284
285
|
//数名
treetype: '',
//树高
treeheight: '',
//胸径
dbh: '',
//级别
treelevel: '',
|
b951d827
刘淇
树木详情
|
286
|
treeleveltext:'',
|
3bea8ade
刘淇
图片上传
|
287
288
289
290
|
//权属单位
managedutyunit: '',
//权属分类
oldtreeownership: '',
|
b951d827
刘淇
树木详情
|
291
|
oldtreeownershipText:'',
|
3bea8ade
刘淇
图片上传
|
292
293
|
latinname: '', // 拉丁名
estimationtreeage: '', // 估测树龄
|
21397afd
刘淇
树 新增
|
294
|
canopysouthnorth: '', // 冠幅南北
|
3bea8ade
刘淇
图片上传
|
295
296
|
canopyeastwest: '', // 冠幅东西
weekday: '', // 干周
|
21397afd
刘淇
树 新增
|
297
|
growlocation: '', // 位置
|
3bea8ade
刘淇
图片上传
|
298
|
growthenvironment: '', // 生长环境
|
21397afd
刘淇
树 新增
|
299
300
|
treeImgList: [], // 图片信息
treeImgListFile: [], // 图片信息
|
c7744156
刘淇
录入树木
|
301
302
|
address: '', // 位置名称
latitude: '', // 纬度
|
21397afd
刘淇
树 新增
|
303
304
|
longitude: '', // 经度
road: ''
|
c7744156
刘淇
录入树木
|
305
|
},
|
c7744156
刘淇
录入树木
|
306
307
|
}
},
|
b951d827
刘淇
树木详情
|
308
|
watch: {},
|
c7744156
刘淇
录入树木
|
309
310
|
onReady() {
//开启即时校验,开启后输入即校验【参数必传】,第一参数:是否开启;第二参数:校验规则
|
6cba22de
刘淇
图片上传
|
311
312
|
// 开启即时校验,参数:是否开启、校验规则
this.$refs.form && this.$refs.form.immediateValidate(true, rules);
|
c7744156
刘淇
录入树木
|
313
314
|
// this.$refs.form && this.$refs.form.immediateValidate(true, rules)
},
|
21397afd
刘淇
树 新增
|
315
316
317
318
319
320
321
|
onLoad(options) {
treeLevelReq().then(res => {
this.treeLevelData = res.data
})
this.formData.road = options.roadId
this.treeOwnership()
},
|
c7744156
刘淇
录入树木
|
322
|
methods: {
|
b951d827
刘淇
树木详情
|
323
|
// 权属分类
|
21397afd
刘淇
树 新增
|
324
325
326
327
328
329
|
treeOwnership() {
treeOwnership().then(res => {
console.log(res)
this.treeOwnershipData = res.data
})
},
|
c7744156
刘淇
录入树木
|
330
331
332
333
334
335
|
// 切换显示/隐藏状态
toggleArea() {
this.isShow = !this.isShow;
},
// 上传完成回调
handleComplete(e) {
|
21397afd
刘淇
树 新增
|
336
|
if (e.status == 1) {
|
3bea8ade
刘淇
图片上传
|
337
|
console.log(e)
|
6cba22de
刘淇
图片上传
|
338
|
// this.formData.treeImgList.push(e.imgArr);
|
21397afd
刘淇
树 新增
|
339
340
|
console.log(e.imgArr[0])
this.formData.treeImgListFile = e.imgArr
|
b951d827
刘淇
树木详情
|
341
|
this.formData.treeImgList = e.imgArr.map(item => OSSURL + item);
|
21397afd
刘淇
树 新增
|
342
343
|
console.log(this.formData.treeImgList)
// baseURL
|
6cba22de
刘淇
图片上传
|
344
345
|
// 手动触发treeImgList字段的校验
this.$refs.form.validateField("treeImgList");
|
21397afd
刘淇
树 新增
|
346
|
}
|
3bea8ade
刘淇
图片上传
|
347
|
// this.formData.treeImgList = e.imgArr;
|
c7744156
刘淇
录入树木
|
348
349
350
351
352
353
|
// 根据实际接口返回格式调整
// this.currentFiles.push(e.data);
},
// 删除图片回调
handleRemove(index) {
// 从列表中移除
|
3bea8ade
刘淇
图片上传
|
354
|
this.formData.treeImgList.splice(index, 1);
|
f2ecd120
刘淇
树 修改
|
355
|
this.formData.treeImgListFile.splice(index, 1);
|
3bea8ade
刘淇
图片上传
|
356
|
console.log(this.formData.treeImgList.length)
|
c7744156
刘淇
录入树木
|
357
|
},
|
c7744156
刘淇
录入树木
|
358
359
360
361
362
363
364
365
|
pickerShow() {
this.show = true
},
pickerHide() {
this.show = false
},
pickerChange(e) {
console.log(e)
|
b951d827
刘淇
树木详情
|
366
367
|
this.formData.oldtreeownership = e.dictValue
this.formData.oldtreeownershipText = e.dictLabel
|
21397afd
刘淇
树 新增
|
368
369
370
371
372
373
374
375
376
|
},
pickerLevelShow() {
this.levelshow = true
},
pickerLevelHide() {
this.levelshow = false
},
pickerLevelChange(e) {
console.log(e)
|
b951d827
刘淇
树木详情
|
377
378
379
|
this.formData.treelevel = e.dictValue
this.formData.treeleveltext = e.dictLabel
|
c7744156
刘淇
录入树木
|
380
381
|
},
submit() {
|
6cba22de
刘淇
图片上传
|
382
383
384
385
|
// 3. 打印提交时的数据
console.log("提交时treeImgList:", this.formData.treeImgList);
// 手动校验图片
if (!this.formData.treeImgList || this.formData.treeImgList.length === 0) {
|
21397afd
刘淇
树 新增
|
386
|
uni.showToast({title: "请上传图片", icon: "none"});
|
6cba22de
刘淇
图片上传
|
387
388
|
return; // 阻止提交
}
|
c7744156
刘淇
录入树木
|
389
390
391
392
393
|
//注:结合FormItem校验,validate方法第三个参数必须传true
this.$refs.form.validate(this.formData, rules, true).then(res => {
if (res.isPass) {
console.log(this.formData)
console.log('校验通过!')
|
21397afd
刘淇
树 新增
|
394
395
396
397
398
399
400
401
|
// addTree()
addTree({data: {...this.formData}}).then(res => {
console.log(res)
if (res.code == '200') {
uni.showToast({title: "新增成功", icon: "none"});
uni.$tui.href(`/subPackages/treePage/treeRecord?roadId=${this.formData.road}`)
}
})
|
c7744156
刘淇
录入树木
|
402
403
404
405
406
407
408
409
410
411
412
413
414
415
|
} else {
console.log(res)
}
}).catch(errors => {
console.log(errors)
})
},
// 打开地图选择
openMap() {
// 如果已有位置信息,默认显示该位置,否则使用当前位置
const options = {
latitude: this.formData.latitude ? Number(this.formData.latitude) : '',
longitude: this.formData.longitude ? Number(this.formData.longitude) : '',
scale: 16, // 地图缩放级别
|
3bea8ade
刘淇
图片上传
|
416
417
|
name: this.formData.growlocation || '', // 位置名称
address: this.formData.growlocation || '' // 详细地址
|
c7744156
刘淇
录入树木
|
418
419
420
421
422
|
};
// 调用微信小程序地图选择API
uni.chooseLocation({
...options,
success: (res) => {
|
3bea8ade
刘淇
图片上传
|
423
|
console.log(res)
|
c7744156
刘淇
录入树木
|
424
|
// 选择成功后更新位置信息
|
3bea8ade
刘淇
图片上传
|
425
426
427
|
this.formData.growlocation = res.address
this.formData.latitude = res.latitude
this.formData.longitude = res.longitude
|
c7744156
刘淇
录入树木
|
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
|
},
fail: (err) => {
console.error('地图选择失败', err);
if (err.errMsg.includes('auth deny')) {
uni.showToast({
title: '请授权位置权限',
icon: 'none'
});
}
}
});
}
}
}
</script>
<style>
.tui-title {
width: 100%;
font-size: 28rpx;
color: #888;
padding: 30rpx;
box-sizing: border-box;
}
.tui-btn__box {
width: 100%;
position: fixed;
bottom: 0;
}
.location-content {
font-size: 14px;
}
/* 动画区域样式 */
.animated-area {
height: 200rpx;
transition: all 0.3s ease-out; /* 动画过渡效果 */
}
</style>
|