Blame view

src/components/inspection/AddInspectionItem.vue 2.77 KB
c7a5a78f   wuxw   加入巡检工鞥你
1
  <template>
b5dad34f   wuxw   巡检功能测试中
2
    <el-dialog :title="$t('inspectionItemManage.addTitle')" :visible.sync="visible" width="40%" @close="handleClose">
c7a5a78f   wuxw   加入巡检工鞥你
3
4
      <el-form ref="form" :model="formData" :rules="rules" label-width="120px">
        <el-form-item :label="$t('inspectionItemManage.itemNameLabel')" prop="itemName">
b5dad34f   wuxw   巡检功能测试中
5
          <el-input v-model="formData.itemName" :placeholder="$t('inspectionItemManage.requiredItem')" />
c7a5a78f   wuxw   加入巡检工鞥你
6
7
        </el-form-item>
        <el-form-item :label="$t('inspectionItemManage.remarkLabel')" prop="remark">
b5dad34f   wuxw   巡检功能测试中
8
9
          <el-input v-model="formData.remark" type="textarea" :rows="4"
            :placeholder="$t('inspectionItemManage.requiredRemark')" />
c7a5a78f   wuxw   加入巡检工鞥你
10
11
        </el-form-item>
      </el-form>
b5dad34f   wuxw   巡检功能测试中
12
  
c7a5a78f   wuxw   加入巡检工鞥你
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
      <span slot="footer" class="dialog-footer">
        <el-button @click="visible = false">
          {{ $t('inspectionItemManage.cancel') }}
        </el-button>
        <el-button type="primary" @click="handleSubmit" :loading="loading">
          {{ $t('inspectionItemManage.save') }}
        </el-button>
      </span>
    </el-dialog>
  </template>
  
  <script>
  import { saveInspectionItem } from '@/api/inspection/inspectionItemManageApi'
  import { getCommunityId } from '@/api/community/communityApi'
  
  export default {
    name: 'AddInspectionItem',
    data() {
      return {
        visible: false,
        loading: false,
        formData: {
          itemName: '',
          remark: '',
          communityId: ''
        },
        rules: {
          itemName: [
            { required: true, message: this.$t('inspectionItemManage.requiredItem'), trigger: 'blur' },
            { max: 256, message: this.$t('inspectionItemManage.maxLength256'), trigger: 'blur' }
          ],
          remark: [
            { required: true, message: this.$t('inspectionItemManage.requiredRemark'), trigger: 'blur' },
            { max: 512, message: this.$t('inspectionItemManage.maxLength512'), trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      open() {
        this.visible = true
        this.resetForm()
      },
      resetForm() {
        this.formData = {
          itemName: '',
          remark: '',
          communityId: getCommunityId()
        }
        if (this.$refs.form) {
          this.$refs.form.resetFields()
        }
      },
      handleClose() {
        this.resetForm()
      },
      async handleSubmit() {
        this.$refs.form.validate(async valid => {
          if (valid) {
            this.loading = true
            try {
              await saveInspectionItem(this.formData)
              this.$message.success(this.$t('inspectionItemManage.addSuccess'))
              this.visible = false
              this.$emit('success')
            } catch (error) {
              console.error('添加巡检项目失败:', error)
              this.$message.error(error.message || this.$t('inspectionItemManage.addFailed'))
            } finally {
              this.loading = false
            }
          }
        })
      }
    }
  }
  </script>