Blame view

src/components/report/EditReportCustomComponent.vue 4.68 KB
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
1
2
3
4
5
6
7
8
9
10
11
12
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
  <template>
    <el-dialog
      :title="$t('common.edit')"
      :visible.sync="visible"
      width="80%"
      @close="handleClose"
    >
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="150px"
        label-position="right"
      >
        <el-form-item
          :label="$t('reportCustomComponent.table.name')"
          prop="name"
        >
          <el-input
            v-model="form.name"
            :placeholder="$t('reportCustomComponent.placeholder.requiredName')"
          />
        </el-form-item>
        <el-form-item
          :label="$t('reportCustomComponent.table.componentType')"
          prop="componentType"
        >
          <el-select
            v-model="form.componentType"
            :placeholder="$t('reportCustomComponent.placeholder.requiredType')"
            style="width: 100%"
            disabled
          >
            <el-option
              value="1001"
              :label="$t('reportCustomComponent.type.table')"
            />
            <el-option
              value="2002"
              :label="$t('reportCustomComponent.type.pie')"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          :label="$t('reportCustomComponent.table.queryModel')"
          prop="queryModel"
        >
          <el-select
            v-model="form.queryModel"
            :placeholder="$t('reportCustomComponent.placeholder.requiredQueryModel')"
            style="width: 100%"
          >
            <el-option value="1" label="SQL" />
            <el-option value="2" label="Java" />
          </el-select>
        </el-form-item>
        <el-form-item
          v-if="form.queryModel === '1'"
          label="SQL"
        >
          <el-input
            v-model="form.componentSql"
            type="textarea"
            :rows="15"
            :placeholder="$t('reportCustomComponent.placeholder.optionalSql')"
          />
        </el-form-item>
        <el-form-item
          v-if="form.queryModel === '2'"
          label="Java"
        >
          <el-input
            v-model="form.javaScript"
            type="textarea"
            :rows="15"
            :placeholder="$t('reportCustomComponent.placeholder.optionalJava')"
          />
        </el-form-item>
        <el-form-item
          :label="$t('reportCustomComponent.table.remark')"
        >
          <el-input
            v-model="form.remark"
            type="textarea"
            :placeholder="$t('reportCustomComponent.placeholder.optionalRemark')"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="visible = false">
          {{ $t('common.cancel') }}
        </el-button>
        <el-button type="primary" @click="handleSubmit">
          {{ $t('common.save') }}
        </el-button>
      </div>
    </el-dialog>
  </template>
  
  <script>
  import { updateReportCustomComponent } from '@/api/report/reportCustomComponentManageApi'
  
  export default {
    name: 'EditReportCustomComponent',
    props: {
      visible: {
        type: Boolean,
        default: false
      },
      formData: {
        type: Object,
        default: () => ({})
      }
    },
    data() {
      return {
        form: {
          componentId: '',
          name: '',
          componentType: '',
          queryModel: '',
          componentSql: '',
          javaScript: '',
          remark: ''
        },
        rules: {
          componentId: [
            { required: true, message: this.$t('reportCustomComponent.validate.requiredId'), trigger: 'blur' }
          ],
          name: [
            { required: true, message: this.$t('reportCustomComponent.validate.requiredName'), trigger: 'blur' },
            { max: 64, message: this.$t('reportCustomComponent.validate.maxName'), trigger: 'blur' }
          ],
          componentType: [
            { required: true, message: this.$t('reportCustomComponent.validate.requiredType'), trigger: 'change' },
            { max: 12, message: this.$t('reportCustomComponent.validate.maxType'), trigger: 'blur' }
          ],
          queryModel: [
            { required: true, message: this.$t('reportCustomComponent.validate.requiredQueryModel'), trigger: 'change' },
            { max: 1, message: this.$t('reportCustomComponent.validate.maxQueryModel'), trigger: 'blur' }
          ]
        }
      }
    },
    watch: {
      formData: {
        handler(val) {
          if (val) {
            this.form = { ...val }
          }
        },
        immediate: true
      }
    },
    methods: {
      handleClose() {
        this.$refs.form.resetFields()
      },
      async handleSubmit() {
        try {
          await this.$refs.form.validate()
          await updateReportCustomComponent(this.form)
          this.$message.success(this.$t('common.editSuccess'))
          this.$emit('success')
          this.$emit('update:visible', false)
        } catch (error) {
          if (error.message) {
            this.$message.error(error.message)
          }
        }
      }
    }
  }
  </script>