c7744156
刘淇
录入树木
|
1
2
3
|
<template>
<view class="container">
<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>
|
3bea8ade
刘淇
图片上传
|
45
|
<tui-form-item asterisk label="管护单位" arrow highlight prop="managedutyunit" @click="pickerShow">
|
c7744156
刘淇
录入树木
|
46
|
<tui-input padding="0" :borderBottom="false" placeholder="请选择" disabled
|
3bea8ade
刘淇
图片上传
|
47
|
backgroundColor="transparent" v-model="formData.managedutyunit"></tui-input>
|
c7744156
刘淇
录入树木
|
48
|
</tui-form-item>
|
3bea8ade
刘淇
图片上传
|
49
|
<tui-form-item asterisk label="权属分类" arrow highlight prop="oldtreeownership" @click="pickerShow">
|
c7744156
刘淇
录入树木
|
50
|
<tui-input padding="0" :borderBottom="false" placeholder="请选择" disabled
|
3bea8ade
刘淇
图片上传
|
51
|
backgroundColor="transparent" v-model="formData.oldtreeownership"></tui-input>
|
c7744156
刘淇
录入树木
|
52
|
</tui-form-item>
|
c7744156
刘淇
录入树木
|
53
|
|
3bea8ade
刘淇
图片上传
|
54
|
<tui-form-item label="图片信息" asterisk prop="treeImgList">
|
c7744156
刘淇
录入树木
|
55
|
<!-- 使用ThorUI的tui-upload组件 -->
|
3bea8ade
刘淇
图片上传
|
56
|
<!-- @remove="handleRemove" :multiple="true" :value="formData.treeImgList"-->
|
c7744156
刘淇
录入树木
|
57
58
59
|
<tui-upload
:height="140"
:width="140"
|
3bea8ade
刘淇
图片上传
|
60
|
:value="formData.treeImgList"
|
c7744156
刘淇
录入树木
|
61
62
|
:serverUrl="serverURL" :header="{'Authorization': userToken}"
@complete="handleComplete"
|
3bea8ade
刘淇
图片上传
|
63
|
|
c7744156
刘淇
录入树木
|
64
|
:limit="3"
|
3bea8ade
刘淇
图片上传
|
65
|
|
c7744156
刘淇
录入树木
|
66
|
accept="image/*"
|
3bea8ade
刘淇
图片上传
|
67
68
69
70
71
72
73
74
75
76
|
>
<!-- 自定义上传按钮 -->
<view class="upload-btn">
<tui-icon name="plus" size="32" color="#999"></tui-icon>
</view>
<!-- 提示信息 -->
<!-- <view class="upload-tips">-->
<!-- 最多上传3张图片,单张不超过5MB-->
<!-- </view>-->
|
c7744156
刘淇
录入树木
|
77
|
|
c7744156
刘淇
录入树木
|
78
|
|
3bea8ade
刘淇
图片上传
|
79
|
</tui-upload>
|
c7744156
刘淇
录入树木
|
80
81
82
83
84
85
|
<!-- 提示信息 -->
<!-- <view class="upload-tips">-->
<!-- 最多上传3张图片,单张不超过5MB-->
<!-- </view>-->
</tui-form-item>
|
c7744156
刘淇
录入树木
|
86
87
88
89
90
91
92
93
94
95
96
|
<!-- 动画区域(初始隐藏) -->
<view
class="animated-area"
:style="{
height: isShow ? contentHeight + 'px' : '0',
opacity: isShow ? 1 : 0,
overflow: 'hidden'
}"
>
<tui-row>
|
3bea8ade
刘淇
图片上传
|
97
98
|
<tui-col :span="12">
<tui-form-item label="拉丁文" prop="latinname">
|
c7744156
刘淇
录入树木
|
99
|
<tui-input padding="0" :borderBottom="false" placeholder="请输入" maxlength="30"
|
3bea8ade
刘淇
图片上传
|
100
|
v-model="formData.latinname"></tui-input>
|
c7744156
刘淇
录入树木
|
101
102
|
</tui-form-item>
</tui-col>
|
3bea8ade
刘淇
图片上传
|
103
104
105
106
107
|
<tui-col :span="12">
<tui-form-item label="级别" arrow highlight prop="treelevel" @click="pickerShow">
<tui-input padding="0" :borderBottom="false" placeholder="请选择" disabled
backgroundColor="transparent" v-model="formData.treelevel"></tui-input>
</tui-form-item>
|
c7744156
刘淇
录入树木
|
108
109
110
|
</tui-col>
</tui-row>
|
3bea8ade
刘淇
图片上传
|
111
|
<tui-form-item label="生长环境" prop="growthenvironment">
|
c7744156
刘淇
录入树木
|
112
|
<tui-input padding="0" :borderBottom="false" placeholder="请输入" maxlength="50"
|
3bea8ade
刘淇
图片上传
|
113
|
v-model="formData.growthenvironment"></tui-input>
|
c7744156
刘淇
录入树木
|
114
115
116
117
|
</tui-form-item>
<tui-row>
|
3bea8ade
刘淇
图片上传
|
118
119
120
121
|
<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
刘淇
录入树木
|
122
|
<template v-slot:right>
|
3bea8ade
刘淇
图片上传
|
123
|
<text style="padding-left: 12rpx;color:#aaa;font-size: 14px">年</text>
|
c7744156
刘淇
录入树木
|
124
125
126
|
</template>
</tui-form-item>
</tui-col>
|
3bea8ade
刘淇
图片上传
|
127
128
129
130
|
<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
刘淇
录入树木
|
131
|
<template v-slot:right>
|
3bea8ade
刘淇
图片上传
|
132
|
<text style="padding-left: 12rpx;color:#aaa;font-size: 14px">厘米</text>
|
c7744156
刘淇
录入树木
|
133
134
135
136
137
138
139
|
</template>
</tui-form-item>
</tui-col>
</tui-row>
<tui-row>
|
3bea8ade
刘淇
图片上传
|
140
141
142
143
|
<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
刘淇
录入树木
|
144
145
146
147
148
|
<template v-slot:right>
<text style="padding-left: 12rpx;color:#aaa">米</text>
</template>
</tui-form-item>
</tui-col>
|
3bea8ade
刘淇
图片上传
|
149
150
151
152
|
<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
刘淇
录入树木
|
153
|
<template v-slot:right>
|
3bea8ade
刘淇
图片上传
|
154
|
<text style="padding-left: 12rpx;color:#aaa;font-size: 14px">米</text>
|
c7744156
刘淇
录入树木
|
155
156
157
158
159
160
|
</template>
</tui-form-item>
</tui-col>
</tui-row>
|
c7744156
刘淇
录入树木
|
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
|
</view>
<!-- 触发按钮 -->
<tui-button
@click="toggleArea"
type="primary"
:loading="false"
height="80rpx"
plain
>
{{ isShow ? '- 隐藏区域' : '+ 显示区域' }}
</tui-button>
<view class="tui-btn__box">
<tui-button bold @click="submit">提交</tui-button>
</view>
</tui-form>
<tui-picker :show="show" :pickerData="areaData" @hide="pickerHide" @change="pickerChange">
</tui-picker>
</view>
</template>
<script>
import { uploadURL } from '@/config/app'
const rules = [{
|
3bea8ade
刘淇
图片上传
|
187
|
name: "treetype",
|
c7744156
刘淇
录入树木
|
188
|
rule: ["required"],
|
3bea8ade
刘淇
图片上传
|
189
190
191
192
193
|
msg: ["请输入名称"]
}, {
name: "treeheight",
rule: ["required", "maxLength:10"],
msg: ["请输入数高", "数高不能超过10个字符"]
|
c7744156
刘淇
录入树木
|
194
|
}, {
|
3bea8ade
刘淇
图片上传
|
195
196
197
|
name: "dbh",
rule: ["required", "maxLength:10"],
msg: ["请输入胸径", "胸径不能超过10个字符"]
|
c7744156
刘淇
录入树木
|
198
|
}, {
|
3bea8ade
刘淇
图片上传
|
199
200
201
|
name: "growlocation",
rule: ["required"],
msg: ["请地图选择位置"]
|
c7744156
刘淇
录入树木
|
202
|
}, {
|
3bea8ade
刘淇
图片上传
|
203
|
name: "managedutyunit",
|
c7744156
刘淇
录入树木
|
204
|
rule: ["required"],
|
3bea8ade
刘淇
图片上传
|
205
|
msg: ["请选择权属单位"]
|
c7744156
刘淇
录入树木
|
206
|
}, {
|
3bea8ade
刘淇
图片上传
|
207
|
name: "oldtreeownership",
|
c7744156
刘淇
录入树木
|
208
|
rule: ["required"],
|
3bea8ade
刘淇
图片上传
|
209
|
msg: ["请选择权属分类"]
|
6cba22de
刘淇
图片上传
|
210
|
},{
|
3bea8ade
刘淇
图片上传
|
211
|
name: "treeImgList",
|
6cba22de
刘淇
图片上传
|
212
213
214
215
216
217
|
rule: ["required", "custom"], // 增加required强制必选
msg: ["请上传图片", "请至少上传一张图片"], // 对应两个规则的提示
custom: function(value) {
// 即使required通过,再校验数组长度
return value.length > 0;
}
|
c7744156
刘淇
录入树木
|
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
|
}];
export default {
props: {
// 外部传入的已上传图片列表
value: {
type: Array,
default: () => []
}
},
data() {
return {
isShow: false, // 控制区域显示/隐藏
contentHeight: 200, // 内容区域高度
serverURL: uploadURL,
areaData: [{
text: "中国",
value: "1001"
}, {
text: "美国",
value: "1002"
}, {
text: "俄罗斯",
value: "1003"
}],
show: false,
//仅对部分数据进行收集演示
formData: {
|
3bea8ade
刘淇
图片上传
|
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
|
//数名
treetype: '',
//树高
treeheight: '',
//胸径
dbh: '',
//级别
treelevel: '',
//权属单位
managedutyunit: '',
//权属分类
oldtreeownership: '',
latinname: '', // 拉丁名
estimationtreeage: '', // 估测树龄
canopysouthnorth:'', // 冠幅南北
canopyeastwest: '', // 冠幅东西
weekday: '', // 干周
growlocation:'', // 位置
growthenvironment: '', // 生长环境
treeImgList:[], // 图片信息
|
c7744156
刘淇
录入树木
|
265
266
267
268
|
address: '', // 位置名称
latitude: '', // 纬度
longitude: '' // 经度
},
|
3bea8ade
刘淇
图片上传
|
269
270
|
// currentFiles: [...this.value], // 当前已上传文件列表
// value: []
|
c7744156
刘淇
录入树木
|
271
272
273
274
|
}
},
watch: {
// 监听外部传入的value变化
|
3bea8ade
刘淇
图片上传
|
275
276
277
|
// value(newVal) {
// this.currentFiles = [...newVal];
// }
|
c7744156
刘淇
录入树木
|
278
279
280
|
},
onReady() {
//开启即时校验,开启后输入即校验【参数必传】,第一参数:是否开启;第二参数:校验规则
|
6cba22de
刘淇
图片上传
|
281
282
|
// 开启即时校验,参数:是否开启、校验规则
this.$refs.form && this.$refs.form.immediateValidate(true, rules);
|
c7744156
刘淇
录入树木
|
283
284
285
286
287
288
289
290
291
|
// this.$refs.form && this.$refs.form.immediateValidate(true, rules)
},
methods: {
// 切换显示/隐藏状态
toggleArea() {
this.isShow = !this.isShow;
},
// 上传完成回调
handleComplete(e) {
|
3bea8ade
刘淇
图片上传
|
292
293
294
|
if (e.status == 1){
console.log(e)
|
6cba22de
刘淇
图片上传
|
295
296
297
298
299
|
// this.formData.treeImgList.push(e.imgArr);
this.formData.treeImgList = e.imgArr;
// 手动触发treeImgList字段的校验
this.$refs.form.validateField("treeImgList");
|
3bea8ade
刘淇
图片上传
|
300
301
302
303
304
|
console.log(this.formData.treeImgList)
console.log(this.formData.treeImgList.length)
}
// this.formData.treeImgList = e.imgArr;
|
c7744156
刘淇
录入树木
|
305
306
307
308
309
310
|
// 根据实际接口返回格式调整
// this.currentFiles.push(e.data);
},
// 删除图片回调
handleRemove(index) {
// 从列表中移除
|
3bea8ade
刘淇
图片上传
|
311
312
|
this.formData.treeImgList.splice(index, 1);
console.log(this.formData.treeImgList.length)
|
c7744156
刘淇
录入树木
|
313
314
315
316
|
// // 通知父组件更新
// this.$emit('input', this.currentFiles);
// this.$emit('remove', index);
},
|
3bea8ade
刘淇
图片上传
|
317
|
|
c7744156
刘淇
录入树木
|
318
319
320
321
322
323
324
325
|
pickerShow() {
this.show = true
},
pickerHide() {
this.show = false
},
pickerChange(e) {
console.log(e)
|
3bea8ade
刘淇
图片上传
|
326
327
328
|
this.formData.oldtreeownership = e.text
this.formData.managedutyunit = e.text
|
c7744156
刘淇
录入树木
|
329
330
|
},
submit() {
|
6cba22de
刘淇
图片上传
|
331
332
333
334
335
336
337
|
// 3. 打印提交时的数据
console.log("提交时treeImgList:", this.formData.treeImgList);
// 手动校验图片
if (!this.formData.treeImgList || this.formData.treeImgList.length === 0) {
uni.showToast({ title: "请上传图片", icon: "none" });
return; // 阻止提交
}
|
c7744156
刘淇
录入树木
|
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
|
//注:结合FormItem校验,validate方法第三个参数必须传true
this.$refs.form.validate(this.formData, rules, true).then(res => {
if (res.isPass) {
console.log(this.formData)
console.log('校验通过!')
} 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
刘淇
图片上传
|
357
358
|
name: this.formData.growlocation || '', // 位置名称
address: this.formData.growlocation || '' // 详细地址
|
c7744156
刘淇
录入树木
|
359
360
361
362
363
|
};
// 调用微信小程序地图选择API
uni.chooseLocation({
...options,
success: (res) => {
|
3bea8ade
刘淇
图片上传
|
364
|
console.log(res)
|
c7744156
刘淇
录入树木
|
365
|
// 选择成功后更新位置信息
|
3bea8ade
刘淇
图片上传
|
366
367
368
|
this.formData.growlocation = res.address
this.formData.latitude = res.latitude
this.formData.longitude = res.longitude
|
c7744156
刘淇
录入树木
|
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
|
},
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>
|