Blame view

pages-sub/daily/patrol-manage/add-patrol-record.vue 13.7 KB
a2702f6d   刘淇   巡查计划
1
  <template>
37c26bd3   刘淇   巡查计划
2
    <view class="u-page">
4c54ad5d   刘淇   转工单 选择是 传紧急程度和...
3
      <!-- 原有模板内容不变,仅调整表单校验相关配置 -->
420cb443   刘淇   快速工单列表
4
5
6
7
8
      <view class="inspect-form-content commonPageLRpadding">
        <up-form
            label-position="left"
            :model="inspectForm"
            ref="inspectFormRef"
e6a04285   刘淇   单图情况 宽高70*70
9
            labelWidth="200rpx"
a2702f6d   刘淇   巡查计划
10
        >
4c54ad5d   刘淇   转工单 选择是 传紧急程度和...
11
          <!-- 1. 巡查描述 -->
420cb443   刘淇   快速工单列表
12
          <up-form-item
dacff5e3   刘淇   养护员退回
13
              label="巡查描述"
420cb443   刘淇   快速工单列表
14
15
              prop="content"
              class="form-item"
fa775c6b   刘淇   养护计划调整
16
              required
420cb443   刘淇   快速工单列表
17
18
          >
            <up-textarea
fa775c6b   刘淇   养护计划调整
19
                v-model.trim="inspectForm.content"
420cb443   刘淇   快速工单列表
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
                placeholder="请输入巡查描述"
                maxlength="200"
                count
            ></up-textarea>
          </up-form-item>
  
          <!-- 2. 上传图片 -->
          <up-form-item
              label="上传图片"
              prop="images"
              required
              border-bottom
              class="form-item"
          >
            <up-upload
                :file-list="imagesList"
                @after-read="(event) => uploadImgs(event)"
                @delete="(event) => deleteImg(event)"
                @on-exceed="handleExceed"
                multiple
                :max-count="3"
                upload-text="选择图片"
                del-color="#ff4d4f"
                class="upload-wrap"
4c54ad5d   刘淇   转工单 选择是 传紧急程度和...
44
45
                width="70"
                height="70"
420cb443   刘淇   快速工单列表
46
            ></up-upload>
420cb443   刘淇   快速工单列表
47
48
          </up-form-item>
  
4c54ad5d   刘淇   转工单 选择是 传紧急程度和...
49
          <!-- 3. 转为工单 -->
420cb443   刘淇   快速工单列表
50
51
52
53
54
          <up-form-item
              label="转为工单"
              prop="isWorkOrder"
              required
              class="form-item"
37c26bd3   刘淇   巡查计划
55
          >
420cb443   刘淇   快速工单列表
56
57
58
59
60
            <up-radio-group
                v-model="inspectForm.isWorkOrder"
                active-color="#1989fa"
                direction="row"
                class="radio-group"
4c54ad5d   刘淇   转工单 选择是 传紧急程度和...
61
                @change="handleWorkOrderChange"
37c26bd3   刘淇   巡查计划
62
            >
420cb443   刘淇   快速工单列表
63
64
65
66
67
68
69
70
71
72
73
74
              <up-radio
                  :custom-style="{marginRight: '40rpx'}"
                  v-for="(item, index) in radioList"
                  :key="index"
                  :label="item.label"
                  :name="item.value"
              >
                {{ item.label }}
              </up-radio>
            </up-radio-group>
          </up-form-item>
  
4c54ad5d   刘淇   转工单 选择是 传紧急程度和...
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
          <!-- 紧急程度(仍为必填) -->
  <!--        v-if="inspectForm.isWorkOrder === '2'"-->
          <up-form-item
              v-if="inspectForm.isWorkOrder === '2'"
              label="紧急程度"
              prop="pressingTypeName"
              border-bottom
              required
              class="form-item"
              @click="handleActionSheetOpen('pressingType')"
          >
            <up-input
                v-model="inspectForm.pressingTypeName"
                disabled
                disabled-color="#ffffff"
                placeholder="请选择紧急程度"
                border="none"
  
            ></up-input>
            <template #right>
              <up-icon name="arrow-right" size="16"></up-icon>
            </template>
          </up-form-item>
  
          <!-- 希望完成时间(移除 required 属性,改为非必填) -->
  <!--        v-if="inspectForm.isWorkOrder === '2'"-->
          <up-form-item
              v-if="inspectForm.isWorkOrder === '2'"
              label="希望完成时间"
              prop="expectedFinishDate"
              class="form-item"
              @click="show = true;  uni.hideKeyboard()"
          >
          <up-input
              v-model="inspectForm.expectedFinishDate"
              border="none"
              readonly
              placeholder="点击选择时间"
e6a04285   刘淇   单图情况 宽高70*70
113
114
          >
  
4c54ad5d   刘淇   转工单 选择是 传紧急程度和...
115
  
e6a04285   刘淇   单图情况 宽高70*70
116
          </up-input>
4c54ad5d   刘淇   转工单 选择是 传紧急程度和...
117
          <template #right>
e6a04285   刘淇   单图情况 宽高70*70
118
119
120
121
122
123
124
125
126
            <!-- 核心修复:用view包裹图标,添加双重@click.stop -->
            <view v-if="inspectForm.expectedFinishDate" @click.stop>
              <up-icon
                  name="close"
                  size="16"
                  @click.stop="clearExpectedFinishDate"
              ></up-icon>
            </view>
            <up-icon name="arrow-right" size="16" v-else></up-icon>
4c54ad5d   刘淇   转工单 选择是 传紧急程度和...
127
128
129
          </template>
          </up-form-item>
  
420cb443   刘淇   快速工单列表
130
131
        </up-form>
      </view>
a2702f6d   刘淇   巡查计划
132
133
  
      <!-- 底部提交按钮 -->
993d98fa   刘淇   工作台
134
      <view class="fixed-bottom-btn-wrap">
37c26bd3   刘淇   巡查计划
135
        <up-button
a2702f6d   刘淇   巡查计划
136
            type="primary"
420cb443   刘淇   快速工单列表
137
138
            text="提交"
            @click="submitInspect"
a2702f6d   刘淇   巡查计划
139
            :style="{ width: '100%', height: '88rpx', fontSize: '32rpx', borderRadius: 0 }"
420cb443   刘淇   快速工单列表
140
        ></up-button>
a2702f6d   刘淇   巡查计划
141
      </view>
4c54ad5d   刘淇   转工单 选择是 传紧急程度和...
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
  
      <!-- 紧急程度下拉弹窗 -->
      <up-action-sheet
          :show="showActionSheet"
          :actions="pressingTypeList"
          title="请选择紧急程度"
          @close="handleActionSheetClose"
          @select="handlePressingTypeSelect"
      ></up-action-sheet>
  
      <!-- 完成时间选择器 -->
      <up-datetime-picker
          :show="show"
          v-model="datetimeValue"
          mode="datetime"
          :min-date="new Date()"
          @cancel="show = false"
          @confirm="expectedFinishDateConfirm"
      ></up-datetime-picker>
a2702f6d   刘淇   巡查计划
161
162
163
    </view>
  </template>
  
420cb443   刘淇   快速工单列表
164
165
166
  <script setup lang="ts">
  import { ref } from 'vue'
  import type { UniFormRef } from '@/uni_modules/uview-plus/types'
420cb443   刘淇   快速工单列表
167
168
169
170
171
  const inspectFormRef = ref<UniFormRef>(null)
  </script>
  
  <script lang="ts">
  import { uploadImages } from '@/common/utils/upload';
5cb33b90   刘淇   完成巡查计划 详情
172
  import { inspectionCreate } from  "@/api/patrol-manage/patrol-plan";
4c54ad5d   刘淇   转工单 选择是 传紧急程度和...
173
  import { timeFormat } from '@/uni_modules/uview-plus'
420cb443   刘淇   快速工单列表
174
175
176
177
  
  export default {
    data() {
      return {
420cb443   刘淇   快速工单列表
178
        imagesList: [],
420cb443   刘淇   快速工单列表
179
        radioList: [
fa775c6b   刘淇   养护计划调整
180
181
          { label: '否', value: '1' },
          { label: '是', value: '2' }
420cb443   刘淇   快速工单列表
182
        ],
4c54ad5d   刘淇   转工单 选择是 传紧急程度和...
183
        pressingTypeList: [],
420cb443   刘淇   快速工单列表
184
        inspectForm: {
4c54ad5d   刘淇   转工单 选择是 传紧急程度和...
185
186
187
188
189
          content: '',
          isWorkOrder: '1',
          pressingTypeName: '',
          pressingType: '',
          expectedFinishDate: '' // 非必填,可空
a2702f6d   刘淇   巡查计划
190
        },
4c54ad5d   刘淇   转工单 选择是 传紧急程度和...
191
192
193
194
        paramsOptins: {},
        showActionSheet: false,
        show: false,
        datetimeValue: Date.now(),
420cb443   刘淇   快速工单列表
195
196
197
198
199
200
201
        inspectFormRules: {
          images: [
            {
              required: true,
              message: '请上传图片',
              trigger: 'change',
              validator: (rule, value, callback) => {
420cb443   刘淇   快速工单列表
202
203
204
205
206
207
208
209
210
211
212
213
214
                const hasSuccessImg = this.imagesList.some(item => item.status === 'success')
                const imgCount = this.imagesList.filter(item => item.status === 'success').length
  
                if (!hasSuccessImg || imgCount < 1) {
                  callback(new Error('最少需要上传1张图片'))
                } else if (imgCount > 3) {
                  callback(new Error('最多只能上传3张图片'))
                } else {
                  callback()
                }
              }
            }
          ],
fa775c6b   刘淇   养护计划调整
215
216
217
          content: [
            { type: 'string', required: true, message: '请输入工单描述', trigger: ['change'] }
          ],
420cb443   刘淇   快速工单列表
218
219
          isWorkOrder: [
            { type: 'string', required: true, message: '请选择是否转为工单', trigger: ['change'] }
4c54ad5d   刘淇   转工单 选择是 传紧急程度和...
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
          ],
          pressingTypeName: [
            {
              required: true,
              message: '请选择紧急程度',
              trigger: 'change',
              validator: (rule, value, callback) => {
                if (this.inspectForm.isWorkOrder === '2' && !value) {
                  callback(new Error('请选择紧急程度'))
                } else {
                  callback()
                }
              }
            }
          ],
          // 关键修改:希望完成时间 移除必填校验,或改为非必填
          expectedFinishDate: [
            {
              // 移除 required: true,改为非必填
              message: '请选择有效的希望完成时间', // 仅当有值时,校验格式(可选)
              trigger: 'change',
              validator: (rule, value, callback) => {
                // 只有当字段有值时,才校验时间格式是否有效
                if (value && !/^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}$/.test(value)) {
                  callback(new Error('请选择有效的希望完成时间'))
                } else {
                  callback() // 无值时直接通过校验
                }
              }
            }
420cb443   刘淇   快速工单列表
250
251
          ]
        }
a2702f6d   刘淇   巡查计划
252
      }
420cb443   刘淇   快速工单列表
253
    },
5cb33b90   刘淇   完成巡查计划 详情
254
    onLoad(option){
5cb33b90   刘淇   完成巡查计划 详情
255
      this.paramsOptins = option
4c54ad5d   刘淇   转工单 选择是 传紧急程度和...
256
      this.getPressingTypeDict()
5cb33b90   刘淇   完成巡查计划 详情
257
    },
420cb443   刘淇   快速工单列表
258
    onReady() {
420cb443   刘淇   快速工单列表
259
      this.$refs.inspectFormRef.setRules(this.inspectFormRules)
420cb443   刘淇   快速工单列表
260
261
    },
    methods: {
4c54ad5d   刘淇   转工单 选择是 传紧急程度和...
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
299
300
301
302
303
304
      getPressingTypeDict() {
        const dictList = uni.$dict.getDictSimpleList('workorder_pressing_type')
        this.pressingTypeList = uni.$dict.transformLabelValueToNameValue(dictList)
        console.log(this.pressingTypeList)
      },
  
      handleWorkOrderChange() {
        if (this.inspectForm.isWorkOrder === '1') {
          this.inspectForm.pressingTypeName = ''
          this.inspectForm.pressingType = ''
          this.inspectForm.expectedFinishDate = '' // 清空非必填字段
          this.$refs.inspectFormRef.validateField(['pressingTypeName', 'expectedFinishDate'])
        }
      },
  
  
      handleActionSheetOpen(type) {
        uni.hideKeyboard()
        console.log('showActionSheet')
        if (type === 'pressingType') {
          console.log('showActionSheet')
          this.showActionSheet = true
        }
        uni.hideKeyboard()
      },
  
      handleActionSheetClose() {
        this.showActionSheet = false
      },
  
      handlePressingTypeSelect(e) {
        console.log(e)
        this.inspectForm.pressingTypeName = e.name
        this.inspectForm.pressingType = e.value
        this.showActionSheet = false
        this.$refs.inspectFormRef.validateField('pressingTypeName')
      },
  
      expectedFinishDateConfirm(e) {
        this.inspectForm.expectedFinishDate = timeFormat(e.value, 'yyyy-mm-dd hh:MM:ss')
        this.show = false
        this.$refs.inspectFormRef.validateField('expectedFinishDate')
      },
e6a04285   刘淇   单图情况 宽高70*70
305
306
307
308
309
310
      // 新增:清除希望完成时间的方法
      clearExpectedFinishDate() {
        this.inspectForm.expectedFinishDate = ''
        // 清除后触发一次字段校验,确保校验状态更新
        this.$refs.inspectFormRef.validateField('expectedFinishDate')
      },
4c54ad5d   刘淇   转工单 选择是 传紧急程度和...
311
  
420cb443   刘淇   快速工单列表
312
      deleteImg(event) {
420cb443   刘淇   快速工单列表
313
        this.imagesList.splice(event.index, 1)
420cb443   刘淇   快速工单列表
314
315
316
        this.$refs.inspectFormRef.validateField('images')
        uni.showToast({ title: '图片删除成功', icon: 'success' })
      },
a2702f6d   刘淇   巡查计划
317
  
420cb443   刘淇   快速工单列表
318
      async uploadImgs(event) {
420cb443   刘淇   快速工单列表
319
320
        const fileList = Array.isArray(event.file) ? event.file : [event.file]
        const targetImgList = this.imagesList
a2702f6d   刘淇   巡查计划
321
  
420cb443   刘淇   快速工单列表
322
323
324
325
326
327
328
329
        const filePaths = fileList.map(item => item.url)
        const tempItems = fileList.map(item => ({
          ...item,
          status: 'uploading',
          message: '上传中'
        }))
        const startIndex = targetImgList.length
        targetImgList.push(...tempItems)
a2702f6d   刘淇   巡查计划
330
  
420cb443   刘淇   快速工单列表
331
332
333
334
335
        try {
          const uploadResultUrls = await uploadImages({
            filePaths: filePaths,
            ignoreError: true
          })
a2702f6d   刘淇   巡查计划
336
  
420cb443   刘淇   快速工单列表
337
338
339
340
341
342
343
344
345
346
          uploadResultUrls.forEach((url, index) => {
            if (targetImgList[startIndex + index]) {
              targetImgList.splice(startIndex + index, 1, {
                ...fileList[index],
                status: 'success',
                message: '',
                url: url
              })
            }
          })
a2702f6d   刘淇   巡查计划
347
  
420cb443   刘淇   快速工单列表
348
349
          if (uploadResultUrls.length < fileList.length) {
            const failCount = fileList.length - uploadResultUrls.length
420cb443   刘淇   快速工单列表
350
351
352
353
            uni.showToast({ title: `成功上传${uploadResultUrls.length}张,失败${failCount}张`, icon: 'none' })
          } else {
            uni.showToast({ title: `成功上传${fileList.length}张图片`, icon: 'success' })
          }
a2702f6d   刘淇   巡查计划
354
  
420cb443   刘淇   快速工单列表
355
356
357
358
359
360
361
362
363
364
365
366
367
          this.$refs.inspectFormRef.validateField('images')
        } catch (err) {
          console.error('图片上传失败:', err)
          for (let i = 0; i < fileList.length; i++) {
            if (targetImgList[startIndex + i]) {
              targetImgList.splice(startIndex + i, 1, {
                ...fileList[i],
                status: 'failed',
                message: '上传失败'
              })
            }
          }
          uni.showToast({ title: '图片上传失败,请重试', icon: 'none' })
420cb443   刘淇   快速工单列表
368
369
370
371
          this.$refs.inspectFormRef.validateField('images')
        }
      },
  
420cb443   刘淇   快速工单列表
372
373
374
375
      handleExceed() {
        uni.showToast({ title: '最多只能上传3张图片', icon: 'none' })
      },
  
420cb443   刘淇   快速工单列表
376
377
378
379
      getImgUrlList(imgList) {
        return imgList.filter(item => item.status === 'success').map(item => item.url)
      },
  
420cb443   刘淇   快速工单列表
380
381
382
      async submitInspect() {
        console.log('当前选择是否转为工单:', this.inspectForm.isWorkOrder)
        try {
420cb443   刘淇   快速工单列表
383
          await this.$refs.inspectFormRef.validate()
5cb33b90   刘淇   完成巡查计划 详情
384
          console.log(this.imagesList)
5cb33b90   刘淇   完成巡查计划 详情
385
  
4c54ad5d   刘淇   转工单 选择是 传紧急程度和...
386
387
          // 构造基础提交数据
          const baseSubmitData = {
5cb33b90   刘淇   完成巡查计划 详情
388
            "batchNo": this.paramsOptins.batchNo,
4c54ad5d   刘淇   转工单 选择是 传紧急程度和...
389
            "planNo": this.paramsOptins.planNo,
5cb33b90   刘淇   完成巡查计划 详情
390
391
392
            "imgHost": "1",
            "imgList": this.getImgUrlList(this.imagesList),
            "inspectionState": this.inspectForm.isWorkOrder,
4c54ad5d   刘淇   转工单 选择是 传紧急程度和...
393
            "transState": this.inspectForm.isWorkOrder === '1' ? '1' : '2',
5cb33b90   刘淇   完成巡查计划 详情
394
            "transWorkNo": "default'",
fa775c6b   刘淇   养护计划调整
395
            "remark": this.inspectForm.content.trim()
420cb443   刘淇   快速工单列表
396
397
          }
  
4c54ad5d   刘淇   转工单 选择是 传紧急程度和...
398
399
400
401
402
403
404
405
406
407
          // 构造最终提交数据
          let submitData = { ...baseSubmitData }
          if (this.inspectForm.isWorkOrder === '2') {
            // 紧急程度仍为必填,必传
            submitData.pressingType = this.inspectForm.pressingType
            // 关键修改:仅当希望完成时间有值时,才添加该参数
            if (this.inspectForm.expectedFinishDate) {
              submitData.expectedFinishDate = new Date(this.inspectForm.expectedFinishDate).getTime()
            }
          }
420cb443   刘淇   快速工单列表
408
  
4c54ad5d   刘淇   转工单 选择是 传紧急程度和...
409
          uni.showLoading({ title: '提交中...' })
5cb33b90   刘淇   完成巡查计划 详情
410
          await inspectionCreate(submitData)
a2702f6d   刘淇   巡查计划
411
  
420cb443   刘淇   快速工单列表
412
413
414
415
          uni.hideLoading()
          uni.showToast({
            title: '提交成功',
            icon: 'success',
5cb33b90   刘淇   完成巡查计划 详情
416
            duration: 1000
420cb443   刘淇   快速工单列表
417
          })
a2702f6d   刘淇   巡查计划
418
  
420cb443   刘淇   快速工单列表
419
          setTimeout(() => {
4fa8cf12   刘淇   巡查员结束工单
420
            uni.reLaunch({
b0e2f1a9   刘淇   快速工单和巡查计划样式优化
421
              url: '/pages-sub/daily/patrol-manage/index'
5cb33b90   刘淇   完成巡查计划 详情
422
423
            })
          }, 1000)
37c26bd3   刘淇   巡查计划
424
  
420cb443   刘淇   快速工单列表
425
        } catch (error) {
420cb443   刘淇   快速工单列表
426
          uni.hideLoading()
4c54ad5d   刘淇   转工单 选择是 传紧急程度和...
427
          if (!Array.isArray(error)) {
420cb443   刘淇   快速工单列表
428
429
430
431
432
433
434
435
436
437
438
439
440
441
            console.error('巡查表单提交失败:', error)
            uni.showToast({
              title: '提交失败,请重试',
              icon: 'none',
              duration: 2000
            })
          }
        }
      }
    }
  }
  </script>
  
  <style lang="scss" scoped>
420cb443   刘淇   快速工单列表
442
  .u-page {
4c54ad5d   刘淇   转工单 选择是 传紧急程度和...
443
    min-height: 100vh;
420cb443   刘淇   快速工单列表
444
445
  }
  
420cb443   刘淇   快速工单列表
446
447
448
449
  .inspect-form-content {
    background: #fff;
    padding: 20rpx;
  }
37c26bd3   刘淇   巡查计划
450
  
4c54ad5d   刘淇   转工单 选择是 传紧急程度和...
451
452
453
454
455
  .form-item {
    margin-bottom: 20rpx;
  }
  
  
a2702f6d   刘淇   巡查计划
456
  </style>