Blame view

pages-sub/data/tree-archive/addTree.vue 18.6 KB
8ddc6f6e   刘淇   登录 修改样式
1
  <template>
24c0bbe7   刘淇   登录账号密码 加密存储
2
    <view class="page-container">
8ddc6f6e   刘淇   登录 修改样式
3
4
      <up-form :model="formData" ref="formRef" label-width="140rpx" border-bottom>
        <up-form-item label="名称" prop="treetype" required>
12e66ec8   刘淇   新增树
5
          <up-input v-model.trim="formData.treetype" placeholder="请输入名称" maxlength="30" border="none"/>
8ddc6f6e   刘淇   登录 修改样式
6
7
        </up-form-item>
  
1d3624b0   刘淇   首页。养护任务
8
9
10
11
12
13
14
15
16
17
18
        <!-- 树种类型 底部弹窗选择 -->
        <!-- <up-form-item label="树种类型" prop="treeSpeciesType" required arrow @click="openTreeSpeciesType">
          <up-input
            v-model="formData.treeSpeciesTypeName"
            placeholder="请选择树种类型"
            readonly
            border="none"
            bg-color="transparent"
          />
        </up-form-item> -->
  
727bc60d   刘淇   新增树
19
20
21
22
        <view class="form-row-wrap">
          <up-row gutter="10">
            <up-col span="6">
              <up-form-item label="胸径" prop="dbh" required>
1d3624b0   刘淇   首页。养护任务
23
                <up-input v-model.trim="formData.dbh" placeholder="请输入" maxlength="10" border="none" input-align="left"/>
727bc60d   刘淇   新增树
24
                <template #right>
12e66ec8   刘淇   新增树
25
                  <text style="padding-left: 12rpx;color:#ccc;font-size:14px">厘米</text>
727bc60d   刘淇   新增树
26
27
28
29
30
                </template>
              </up-form-item>
            </up-col>
            <up-col span="6">
              <up-form-item label="高度" prop="treeheight">
1d3624b0   刘淇   首页。养护任务
31
                <up-input v-model.trim="formData.treeheight" placeholder="请输入" maxlength="10" border="none"
727bc60d   刘淇   新增树
32
33
34
35
36
37
38
39
                          input-align="left"/>
                <template #right>
                  <text style="padding-left: 12rpx;color:#ccc;font-size:14px;">米</text>
                </template>
              </up-form-item>
            </up-col>
          </up-row>
        </view>
8ddc6f6e   刘淇   登录 修改样式
40
41
  
        <up-form-item label="位置" prop="growlocation" required class="location-form-item" @click="openMap">
727bc60d   刘淇   新增树
42
          <up-input v-model="formData.growlocation" placeholder="请选择" readonly border="none"/>
8ddc6f6e   刘淇   登录 修改样式
43
44
45
46
47
48
49
          <template #right>
            <up-icon name="map" size="22"></up-icon>
          </template>
        </up-form-item>
  
        <up-row gutter="10">
          <up-col span="6">
12e66ec8   刘淇   新增树
50
            <up-form-item label="经度" :borderBottom="false">
727bc60d   刘淇   新增树
51
              <up-input v-model="formData.longitude" placeholder="" readonly border="none"/>
8ddc6f6e   刘淇   登录 修改样式
52
53
54
            </up-form-item>
          </up-col>
          <up-col span="6">
12e66ec8   刘淇   新增树
55
            <up-form-item label="纬度" :borderBottom="false">
727bc60d   刘淇   新增树
56
              <up-input v-model="formData.latitude" placeholder="" readonly border="none"/>
8ddc6f6e   刘淇   登录 修改样式
57
58
59
60
61
            </up-form-item>
          </up-col>
        </up-row>
  
        <up-form-item label="管护单位" prop="managedutyunit" required>
12e66ec8   刘淇   新增树
62
          <up-input v-model.trim="formData.managedutyunit" placeholder="请输入" maxlength="30" border="none"/>
8ddc6f6e   刘淇   登录 修改样式
63
64
        </up-form-item>
  
727bc60d   刘淇   新增树
65
        <up-form-item label="权属分类" prop="oldtreeownershipText" required arrow @click="handleActionSheetOpen('ownership')">
12e66ec8   刘淇   新增树
66
67
          <up-input v-model.trim="formData.oldtreeownershipText" placeholder="请选择" readonly border="none"
                    bg-color="transparent"/>
8ddc6f6e   刘淇   登录 修改样式
68
69
        </up-form-item>
  
8ddc6f6e   刘淇   登录 修改样式
70
71
72
73
74
75
76
77
78
        <up-form-item label="图片信息" prop="treeImgList" required>
          <up-upload
              :file-list="treeImgs.imgList.value || []"
              @after-read="treeImgs.uploadImgs"
              @delete="treeImgs.deleteImg"
              multiple
              :width="70"
              :height="70"
              :max-count="treeImgs.uploadConfig.maxCount"
1d3624b0   刘淇   首页。养护任务
79
              :upload-text="treeImgs.uploadText"
8ddc6f6e   刘淇   登录 修改样式
80
81
82
              :size-type="treeImgs.uploadConfig.sizeType"
          ></up-upload>
        </up-form-item>
8ddc6f6e   刘淇   登录 修改样式
83
  
8ddc6f6e   刘淇   登录 修改样式
84
85
86
87
88
89
90
91
92
93
94
        <view
            class="animated-area"
            :style="{
            height: isShow ? contentHeight + 'px' : '0',
            opacity: isShow ? 1 : 0,
            overflow: 'hidden'
          }"
        >
          <up-row gutter="10">
            <up-col span="6">
              <up-form-item label="拉丁文" prop="latinname">
12e66ec8   刘淇   新增树
95
                <up-input v-model.trim="formData.latinname" placeholder="请输入" maxlength="30" border="none"/>
8ddc6f6e   刘淇   登录 修改样式
96
97
98
              </up-form-item>
            </up-col>
            <up-col span="6">
727bc60d   刘淇   新增树
99
              <up-form-item label="级别" arrow @click="handleActionSheetOpen('level')">
12e66ec8   刘淇   新增树
100
                <up-input v-model.trim="formData.treeleveltext" placeholder="请选择" readonly border="none"
727bc60d   刘淇   新增树
101
                          bg-color="transparent"/>
8ddc6f6e   刘淇   登录 修改样式
102
103
104
105
106
              </up-form-item>
            </up-col>
          </up-row>
  
          <up-form-item label="生长环境" prop="growthenvironment">
12e66ec8   刘淇   新增树
107
            <up-input v-model.trim="formData.growthenvironment" placeholder="请输入" maxlength="50" border="none"/>
8ddc6f6e   刘淇   登录 修改样式
108
109
          </up-form-item>
  
727bc60d   刘淇   新增树
110
111
112
          <view class="form-row-wrap">
            <up-row gutter="10">
              <up-col span="6">
ecbfbe06   刘淇   树巡检记录
113
114
115
                <!-- 栽种年月 年月选择器 -->
                <up-form-item label="栽种年月" arrow @click="openPlantDatePicker">
                  <up-input v-model.trim="formData.plantingDate" placeholder="请选择栽种年月" readonly border="none" bg-color="transparent"/>
727bc60d   刘淇   新增树
116
117
118
119
                </up-form-item>
              </up-col>
              <up-col span="6">
                <up-form-item label="干周" prop="weekday">
12e66ec8   刘淇   新增树
120
                  <up-input v-model.trim="formData.weekday" placeholder="请输入" maxlength="10" border="none"
727bc60d   刘淇   新增树
121
122
123
124
125
126
127
128
129
130
131
132
133
                            input-align="left"/>
                  <template #right>
                    <text style="padding-left:12rpx;color:#ccc;font-size:14px">厘米</text>
                  </template>
                </up-form-item>
              </up-col>
            </up-row>
          </view>
  
          <view class="form-row-wrap">
            <up-row gutter="10">
              <up-col span="6">
                <up-form-item label="东西冠幅" prop="canopyeastwest">
12e66ec8   刘淇   新增树
134
                  <up-input v-model.trim="formData.canopyeastwest" placeholder="请输入" maxlength="10" border="none"
727bc60d   刘淇   新增树
135
136
137
138
139
140
141
142
                            input-align="left"/>
                  <template #right>
                    <text style="padding-left:12rpx;color:#ccc;font-size:14px">米</text>
                  </template>
                </up-form-item>
              </up-col>
              <up-col span="6">
                <up-form-item label="南北冠幅" prop="canopysouthnorth">
12e66ec8   刘淇   新增树
143
                  <up-input v-model.trim="formData.canopysouthnorth" placeholder="请输入" maxlength="10" border="none"
727bc60d   刘淇   新增树
144
145
146
147
148
149
150
151
                            input-align="left"/>
                  <template #right>
                    <text style="padding-left:12rpx;color:#ccc;font-size:14px">米</text>
                  </template>
                </up-form-item>
              </up-col>
            </up-row>
          </view>
8ddc6f6e   刘淇   登录 修改样式
152
153
        </view>
  
8ddc6f6e   刘淇   登录 修改样式
154
155
156
157
158
159
160
161
162
163
164
165
166
        <up-button
            @click="toggleArea"
            type="primary"
            plain
            size="large"
            style="margin-top:20rpx"
        >
          {{ isShow ? '- 隐藏区域' : '+ 显示区域' }}
        </up-button>
      </up-form>
  
      <view style="height: 60px;width: 100%"></view>
  
8ddc6f6e   刘淇   登录 修改样式
167
168
169
170
      <view class="fixed-bottom-btn-wrap">
        <up-button type="primary" @click="submit" :loading="loadingFlag" size="large" bold>提交</up-button>
      </view>
  
727bc60d   刘淇   新增树
171
172
173
174
175
176
177
      <up-action-sheet
          :show="showActionSheet"
          :actions="currentActionSheetData.list"
          :title="currentActionSheetData.title"
          @close="handleActionSheetClose"
          @select="handleActionSheetSelect"
      ></up-action-sheet>
8ddc6f6e   刘淇   登录 修改样式
178
  
ecbfbe06   刘淇   树巡检记录
179
180
181
182
183
184
185
186
187
188
      <!-- 年月选择弹窗 -->
      <up-datetime-picker
          v-model="plantingDate"
          :show="showDatePicker"
          :closeOnClickOverlay="true"
          mode="year-month"
          minDate="1000"
          @confirm="onSelectPlantDate"
          @cancel="showDatePicker=false"
      ></up-datetime-picker>
8ddc6f6e   刘淇   登录 修改样式
189
190
191
192
    </view>
  </template>
  
  <script setup>
ecbfbe06   刘淇   树巡检记录
193
  import { timeFormat } from '@/uni_modules/uview-plus';
8ddc6f6e   刘淇   登录 修改样式
194
  import { ref, reactive, nextTick } from 'vue'
c5fdc60a   刘淇   树详情
195
  import { onReady, onLoad, onShow, onUnload } from '@dcloudio/uni-app';
1d3624b0   刘淇   首页。养护任务
196
  
c5fdc60a   刘淇   树详情
197
  onUnload(() => {
c5fdc60a   刘淇   树详情
198
199
200
201
    uni.reLaunch({
      url: '/pages-sub/data/tree-archive/index'
    })
  })
1d3624b0   刘淇   首页。养护任务
202
  
8ddc6f6e   刘淇   登录 修改样式
203
  import { addTree } from "@/api/tree-archive/tree-archive.js";
8ddc6f6e   刘淇   登录 修改样式
204
205
206
  import { useUploadImgs } from '@/common/utils/useUploadImgs'
  import { useUserStore } from '@/pinia/user';
  
ecbfbe06   刘淇   树巡检记录
207
  // ========== 核心工具方法 ==========
12e66ec8   刘淇   新增树
208
209
210
211
212
  const isPureZero = (val) => {
    if (!val) return false;
    const pureZeroReg = /^0+$/;
    return pureZeroReg.test(val.trim());
  };
12e66ec8   刘淇   新增树
213
214
215
216
217
218
219
220
221
222
  const trimFormData = (obj) => {
    for (const key in obj) {
      if (Object.prototype.hasOwnProperty.call(obj, key)) {
        const val = obj[key];
        if (typeof val === 'string') {
          obj[key] = val.trim();
        }
      }
    }
  };
12e66ec8   刘淇   新增树
223
  const emojiReg = /[\uD83C\uD83D\uD83E][\uDC00-\uDFFF]+|[\u2702\u2705\u2708-\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763-\u2767\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299\ufe0f\u200d]+/g;
12e66ec8   刘淇   新增树
224
225
226
227
  const filterEmoji = (val) => {
    if (typeof val !== 'string') return val;
    return val.replace(emojiReg, '');
  };
12e66ec8   刘淇   新增树
228
229
230
231
232
  const hasEmoji = (val) => {
    if (!val) return false;
    return emojiReg.test(val);
  };
  
8ddc6f6e   刘淇   登录 修改样式
233
234
  // ========== 状态管理 ==========
  const userStore = useUserStore();
8ddc6f6e   刘淇   登录 修改样式
235
236
  const formRef = ref(null)
  const isShow = ref(false)
727bc60d   刘淇   新增树
237
  const contentHeight = ref(200)
8ddc6f6e   刘淇   登录 修改样式
238
239
  const treeOwnershipData = ref([])
  const treeLevelData = ref([])
1d3624b0   刘淇   首页。养护任务
240
  const treeSpeciesTypeList = ref([])
8ddc6f6e   刘淇   登录 修改样式
241
  const loadingFlag = ref(false)
727bc60d   刘淇   新增树
242
243
  const showActionSheet = ref(false);
  const currentActionSheetData = reactive({ type: '', list: [], title: '' });
ecbfbe06   刘淇   树巡检记录
244
245
  const showDatePicker = ref(false);
  const plantingDate = ref(Date.now())
8ddc6f6e   刘淇   登录 修改样式
246
  
727bc60d   刘淇   新增树
247
  // 图片上传配置
8ddc6f6e   刘淇   登录 修改样式
248
249
250
251
252
253
254
  const treeImgs = useUploadImgs({
    maxCount: 3,
    uploadText: '选择图片',
    sizeType: ['compressed'],
    formRef: formRef,
    fieldName: 'treeImgList'
  })
8ddc6f6e   刘淇   登录 修改样式
255
256
  if (!Array.isArray(treeImgs.rawImgList.value)) treeImgs.rawImgList.value = [];
  
1d3624b0   刘淇   首页。养护任务
257
  // 表单数据:treeSpeciesType 存编码,treeSpeciesTypeName 页面展示文字
8ddc6f6e   刘淇   登录 修改样式
258
259
  const formData = reactive({
    treetype: '',
1d3624b0   刘淇   首页。养护任务
260
261
    // treeSpeciesType: '',
    treeSpeciesTypeName: '',
8ddc6f6e   刘淇   登录 修改样式
262
263
264
265
266
267
268
269
    treeheight: '',
    dbh: '',
    treelevel: '',
    treeleveltext: '',
    managedutyunit: '',
    oldtreeownership: '',
    oldtreeownershipText: '',
    latinname: '',
1d3624b0   刘淇   首页。养护任务
270
    plantingDate: '',
8ddc6f6e   刘淇   登录 修改样式
271
272
273
274
275
276
277
278
279
280
281
282
283
    canopysouthnorth: '',
    canopyeastwest: '',
    weekday: '',
    growlocation: '',
    growthenvironment: '',
    treeImgList: [],
    address: '',
    latitude: '',
    longitude: '',
    road: '',
    maintainunit: ''
  })
  
1d3624b0   刘淇   首页。养护任务
284
  // 表单校验规则
8ddc6f6e   刘淇   登录 修改样式
285
  const rules = reactive({
12e66ec8   刘淇   新增树
286
    treetype: [
1d3624b0   刘淇   首页。养护任务
287
288
      {
        validator: (rule, val, callback) => {
12e66ec8   刘淇   新增树
289
290
          if (val && hasEmoji(val)) return callback(new Error('禁止输入表情符号'));
          callback();
1d3624b0   刘淇   首页。养护任务
291
292
293
294
        }, trigger: ['blur', 'change', 'input'], priority: 10
      },
      { required: true, message: '请输入名称', trigger: ['blur', 'change', 'input'] },
      { max: 30, message: '名称最多输入30个字符', trigger: ['blur', 'change', 'input'] }
12e66ec8   刘淇   新增树
295
    ],
1d3624b0   刘淇   首页。养护任务
296
297
298
    // treeSpeciesType: [
    //   { required: true, message: '请选择树种类型', trigger: ['change'] }
    // ],
12e66ec8   刘淇   新增树
299
    treeheight: [
1d3624b0   刘淇   首页。养护任务
300
301
302
303
      { max: 10, message: '树高不能超过10个字符', trigger: ['blur', 'change', 'input'] },
      { pattern: /^\d+(\.\d{1,2})?$/, message: '格式不正确,支持数字或两位小数', trigger: ['blur', 'change', 'input'] },
      {
        validator: (rule, val, callback) => {
12e66ec8   刘淇   新增树
304
305
          if (isPureZero(val)) return callback(new Error('不能输入纯0无效值'));
          callback();
1d3624b0   刘淇   首页。养护任务
306
307
        }, trigger: ['blur', 'change', 'input']
      }
12e66ec8   刘淇   新增树
308
309
    ],
    dbh: [
1d3624b0   刘淇   首页。养护任务
310
311
      {
        validator: (rule, val, callback) => {
12e66ec8   刘淇   新增树
312
313
          if (val && hasEmoji(val)) return callback(new Error('禁止输入表情符号'));
          callback();
1d3624b0   刘淇   首页。养护任务
314
315
316
317
318
319
320
        }, trigger: ['blur', 'change', 'input'], priority: 10
      },
      { required: true, message: '请输入胸径', trigger: ['blur', 'change', 'input'] },
      { max: 10, message: '胸径不能超过10个字符', trigger: ['blur', 'change', 'input'] },
      { pattern: /^\d+(\.\d{1,2})?$/, message: '格式不正确,支持数字或两位小数', trigger: ['blur', 'change', 'input'] },
      {
        validator: (rule, val, callback) => {
12e66ec8   刘淇   新增树
321
322
          if (isPureZero(val)) return callback(new Error('不能输入纯0无效值'));
          callback();
1d3624b0   刘淇   首页。养护任务
323
324
        }, trigger: ['blur', 'change', 'input']
      }
12e66ec8   刘淇   新增树
325
    ],
12e66ec8   刘淇   新增树
326
    weekday: [
1d3624b0   刘淇   首页。养护任务
327
328
329
330
      { max: 10, message: '干周不能超过10个字符', trigger: ['blur', 'change', 'input'] },
      { pattern: /^\d+(\.\d{1,2})?$/, message: '格式不正确,支持数字或两位小数', trigger: ['blur', 'change', 'input'] },
      {
        validator: (rule, val, callback) => {
12e66ec8   刘淇   新增树
331
332
          if (isPureZero(val)) return callback(new Error('不能输入纯0无效值'));
          callback();
1d3624b0   刘淇   首页。养护任务
333
334
        }, trigger: ['blur', 'change', 'input']
      }
12e66ec8   刘淇   新增树
335
336
    ],
    canopyeastwest: [
1d3624b0   刘淇   首页。养护任务
337
338
339
340
      { max: 10, message: '东西冠幅不能超过10个字符', trigger: ['blur', 'change', 'input'] },
      { pattern: /^\d+(\.\d{1,2})?$/, message: '格式不正确,支持数字或两位小数', trigger: ['blur', 'change', 'input'] },
      {
        validator: (rule, val, callback) => {
12e66ec8   刘淇   新增树
341
342
          if (isPureZero(val)) return callback(new Error('不能输入纯0无效值'));
          callback();
1d3624b0   刘淇   首页。养护任务
343
344
        }, trigger: ['blur', 'change', 'input']
      }
12e66ec8   刘淇   新增树
345
346
    ],
    canopysouthnorth: [
1d3624b0   刘淇   首页。养护任务
347
348
349
350
      { max: 10, message: '南北冠幅不能超过10个字符', trigger: ['blur', 'change', 'input'] },
      { pattern: /^\d+(\.\d{1,2})?$/, message: '格式不正确,支持数字或两位小数', trigger: ['blur', 'change', 'input'] },
      {
        validator: (rule, val, callback) => {
12e66ec8   刘淇   新增树
351
352
          if (isPureZero(val)) return callback(new Error('不能输入纯0无效值'));
          callback();
1d3624b0   刘淇   首页。养护任务
353
354
        }, trigger: ['blur', 'change', 'input']
      }
12e66ec8   刘淇   新增树
355
    ],
1d3624b0   刘淇   首页。养护任务
356
    growlocation: [{ required: true, message: '请选择地图位置', trigger: ['blur', 'change', 'manual'] }],
12e66ec8   刘淇   新增树
357
    managedutyunit: [
1d3624b0   刘淇   首页。养护任务
358
359
      {
        validator: (rule, val, callback) => {
12e66ec8   刘淇   新增树
360
361
          if (val && hasEmoji(val)) return callback(new Error('禁止输入表情符号'));
          callback();
1d3624b0   刘淇   首页。养护任务
362
363
364
365
        }, trigger: ['blur', 'change', 'input'], priority: 10
      },
      { required: true, message: '请输入管护单位', trigger: ['blur', 'change', 'input'] },
      { max: 30, message: '管护单位最多输入30个字符', trigger: ['blur', 'change', 'input'] }
12e66ec8   刘淇   新增树
366
    ],
1d3624b0   刘淇   首页。养护任务
367
    oldtreeownershipText: [{ required: true, message: '请选择权属分类', trigger: ['blur', 'change'] }],
12e66ec8   刘淇   新增树
368
    latinname: [
1d3624b0   刘淇   首页。养护任务
369
370
      {
        validator: (rule, val, callback) => {
12e66ec8   刘淇   新增树
371
372
          if (val && hasEmoji(val)) return callback(new Error('禁止输入表情符号'));
          callback();
1d3624b0   刘淇   首页。养护任务
373
374
375
        }, trigger: ['blur', 'change', 'input'], priority: 10
      },
      { max: 30, message: '拉丁文最多输入30个字符', trigger: ['blur', 'change', 'input'] }
12e66ec8   刘淇   新增树
376
377
    ],
    growthenvironment: [
1d3624b0   刘淇   首页。养护任务
378
379
      {
        validator: (rule, val, callback) => {
12e66ec8   刘淇   新增树
380
381
          if (val && hasEmoji(val)) return callback(new Error('禁止输入表情符号'));
          callback();
1d3624b0   刘淇   首页。养护任务
382
383
384
        }, trigger: ['blur', 'change', 'input'], priority: 10
      },
      { max: 50, message: '生长环境最多输入50个字符', trigger: ['blur', 'change', 'input'] }
12e66ec8   刘淇   新增树
385
    ],
727bc60d   刘淇   新增树
386
    treeImgList: [treeImgs.imgValidateRule]
8ddc6f6e   刘淇   登录 修改样式
387
388
  })
  
727bc60d   刘淇   新增树
389
  // 生命周期
8ddc6f6e   刘淇   登录 修改样式
390
391
392
  onLoad((options) => {
    formData.road = options.roadId
  })
1d3624b0   刘淇   首页。养护任务
393
  
8ddc6f6e   刘淇   登录 修改样式
394
  onShow(async () => {
727bc60d   刘淇   新增树
395
    treeLevelData.value = uni.$dict.transformLabelValueToNameValue(uni.$dict.getDictSimpleList('tree_level'))
1d3624b0   刘淇   首页。养护任务
396
397
    treeOwnershipData.value = uni.$dict.transformLabelValueToNameValue(uni.$dict.getDictSimpleList('tree_ownership'))
    treeSpeciesTypeList.value = uni.$dict.transformLabelValueToNameValue(uni.$dict.getDictSimpleList('tree_species_type'))
8ddc6f6e   刘淇   登录 修改样式
398
  })
1d3624b0   刘淇   首页。养护任务
399
  
8ddc6f6e   刘淇   登录 修改样式
400
401
402
403
404
405
  onReady(() => {
    nextTick(() => {
      formRef.value?.setRules(rules);
    });
  });
  
ecbfbe06   刘淇   树巡检记录
406
  // 打开栽种年月选择器
1d3624b0   刘淇   首页。养护任务
407
  const openPlantDatePicker = () => {
ecbfbe06   刘淇   树巡检记录
408
409
    showDatePicker.value = true
  }
1d3624b0   刘淇   首页。养护任务
410
411
412
413
  
  // 年月选择回调
  const onSelectPlantDate = () => {
    formData.plantingDate = timeFormat(plantingDate.value, 'yyyy-mm')
ecbfbe06   刘淇   树巡检记录
414
415
    showDatePicker.value = false
  }
c5fdc60a   刘淇   树详情
416
  
1d3624b0   刘淇   首页。养护任务
417
  // 展开/收起更多区域
8ddc6f6e   刘淇   登录 修改样式
418
419
420
421
  const toggleArea = () => {
    isShow.value = !isShow.value
  }
  
1d3624b0   刘淇   首页。养护任务
422
  // 打开权属/级别选择弹窗
727bc60d   刘淇   新增树
423
424
425
426
427
428
429
430
431
  const handleActionSheetOpen = (type) => {
    const configMap = {
      ownership: { title: '请选择权属分类', list: treeOwnershipData.value },
      level: { title: '请选择树木级别', list: treeLevelData.value }
    };
    Object.assign(currentActionSheetData, configMap[type], { type });
    showActionSheet.value = true;
  };
  
1d3624b0   刘淇   首页。养护任务
432
433
434
435
436
437
438
439
440
441
442
  // 打开树种类型选择弹窗
  const openTreeSpeciesType = () => {
    Object.assign(currentActionSheetData, {
      title: '请选择树种类型',
      list: treeSpeciesTypeList.value,
      type: 'treeSpecies'
    })
    showActionSheet.value = true
  }
  
  // 关闭弹窗
727bc60d   刘淇   新增树
443
444
445
446
447
  const handleActionSheetClose = () => {
    showActionSheet.value = false;
    Object.assign(currentActionSheetData, { type: '', list: [], title: '' });
  };
  
1d3624b0   刘淇   首页。养护任务
448
  // 弹窗选中回调
727bc60d   刘淇   新增树
449
450
451
452
453
454
455
456
457
  const handleActionSheetSelect = (e) => {
    const { type } = currentActionSheetData;
    if (type === 'ownership') {
      formData.oldtreeownership = e.value
      formData.oldtreeownershipText = e.name
      formRef.value?.validateField('oldtreeownershipText');
    } else if (type === 'level') {
      formData.treelevel = e.value
      formData.treeleveltext = e.name
1d3624b0   刘淇   首页。养护任务
458
459
460
461
    } else if (type === 'treeSpecies') {
      formData.treeSpeciesType = e.value
      formData.treeSpeciesTypeName = e.name
      formRef.value?.validateField('treeSpeciesType');
727bc60d   刘淇   新增树
462
463
464
    }
    handleActionSheetClose();
  };
8ddc6f6e   刘淇   登录 修改样式
465
  
12e66ec8   刘淇   新增树
466
  // 地图选址
8ddc6f6e   刘淇   登录 修改样式
467
468
  const openMap = () => {
    uni.chooseLocation({
12e66ec8   刘淇   新增树
469
      success: async (res) => {
8ddc6f6e   刘淇   登录 修改样式
470
471
472
        formData.growlocation = res.address
        formData.latitude = res.latitude
        formData.longitude = res.longitude
12e66ec8   刘淇   新增树
473
474
        await nextTick()
        formRef.value?.validateField('growlocation');
8ddc6f6e   刘淇   登录 修改样式
475
476
477
478
      },
      fail: (err) => {
        console.error('地图选择失败', err);
        if (err.errMsg.includes('auth deny')) {
1d3624b0   刘淇   首页。养护任务
479
          uni.showToast({ title: '请授权位置权限', icon: 'none' });
8ddc6f6e   刘淇   登录 修改样式
480
481
482
483
484
        }
      }
    });
  }
  
1d3624b0   刘淇   首页。养护任务
485
  // 提交表单
8ddc6f6e   刘淇   登录 修改样式
486
487
  const submit = async () => {
    if (loadingFlag.value) return
12e66ec8   刘淇   新增树
488
  
12e66ec8   刘淇   新增树
489
490
491
492
493
494
    for (const key in formData) {
      if (typeof formData[key] === 'string') {
        formData[key] = filterEmoji(formData[key]).trim();
      }
    }
  
8ddc6f6e   刘淇   登录 修改样式
495
496
    const valid = await formRef.value.validate()
    if (!valid) return
12e66ec8   刘淇   新增树
497
  
8ddc6f6e   刘淇   登录 修改样式
498
    const uploadImgUrls = treeImgs.getSuccessImgUrls()
12e66ec8   刘淇   新增树
499
    formData.maintainunit = userStore.userInfo.user.companyId
727bc60d   刘淇   新增树
500
    formData.treeImgList = uploadImgUrls
8ddc6f6e   刘淇   登录 修改样式
501
    loadingFlag.value = true
8ddc6f6e   刘淇   登录 修改样式
502
    try {
1d3624b0   刘淇   首页。养护任务
503
504
505
      await addTree(formData)
      uni.showToast({ title: "新增成功", icon: "success" });
      uni.redirectTo({ url: '/pages-sub/data/tree-archive/index' });
8ddc6f6e   刘淇   登录 修改样式
506
    } catch (err) {
1d3624b0   刘淇   首页。养护任务
507
      uni.showToast({ title: "新增失败,请重试", icon: "none" });
8ddc6f6e   刘淇   登录 修改样式
508
509
510
511
512
513
514
515
      console.error(err)
    } finally {
      loadingFlag.value = false
    }
  }
  </script>
  
  <style scoped lang="scss">
24c0bbe7   刘淇   登录账号密码 加密存储
516
  .page-container {
cf70629b   刘淇   养护计划 照片 自己写样式
517
    padding: 15px;
8ddc6f6e   刘淇   登录 修改样式
518
519
520
521
522
523
524
525
    box-sizing: border-box;
    background: #fff;
  }
  
  .animated-area {
    transition: all 0.3s ease-out;
    margin-top: 10rpx;
  }
727bc60d   刘淇   新增树
526
  
8ddc6f6e   刘淇   登录 修改样式
527
528
529
  .location-form-item {
    padding-right: 10rpx;
  }
727bc60d   刘淇   新增树
530
  
727bc60d   刘淇   新增树
531
532
533
534
  .form-row-wrap {
    width: 100%;
    display: flex;
    flex-direction: column;
727bc60d   刘淇   新增树
535
536
537
538
    :deep(.u-form-item) {
      position: relative;
      margin-bottom: 0 !important;
    }
1d3624b0   刘淇   首页。养护任务
539
    :deep(.u-form-item__body__right__message) {
727bc60d   刘淇   新增树
540
541
542
543
544
545
546
547
548
549
      position: absolute;
      left: 0;
      bottom: -20rpx;
      line-height: 20rpx;
      font-size: 22rpx;
      color: #f56c6c;
      width: 100%;
      box-sizing: border-box;
    }
  }
1d3624b0   刘淇   首页。养护任务
550
  
727bc60d   刘淇   新增树
551
552
553
  .form-row-wrap + .u-form-item {
    margin-top: 25rpx !important;
  }
8ddc6f6e   刘淇   登录 修改样式
554
  </style>