Blame view

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