Lius
2024-12-13 b4a53d0cf96ee1520a942d092762fabaf9471e5b
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
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
250
251
252
<template>
  <a-modal
    :title="title"
    :maskClosable="true"
    :width="modalWidth"
    @cancel="visible=false"
    :visible="visible">
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :form="form" :model="model" :rules="validatorRules" :labelCol="labelCol"
                    :wrapperCol="wrapperCol">
 
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-model-item prop="controlSystemType" label="驱动类型">
              <a-select v-model="model.controlSystemType" @change="handleDriveTypeChange"
                        placeholder="请选择驱动类型">
                <a-select-option v-for="(item,index) in driveTypeList" :key="index" :value="item">
                  {{item}}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
 
          <a-col :span="12">
            <a-form-model-item prop="chineseName" label="参数">
              <a-select v-model="model.chineseName" placeholder="请选择参数">
                <a-select-option v-for="item in paramList" :key="item.value" :value="item.value">
                  {{item.label}}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
        </a-row>
 
        <a-row :gutter="24">
 
          <a-col :span="12">
            <a-form-model-item prop="maxThreshold" label="阈值上限">
              <a-input-number v-model="model.maxThreshold" placeholder="请输入阈值上限" style="width: 100%"></a-input-number>
            </a-form-model-item>
          </a-col>
 
          <a-col :span="12">
            <a-form-model-item prop="minThreshold" label="阈值下限">
              <a-input-number v-model="model.minThreshold" placeholder="请输入阈值下限" style="width: 100%"></a-input-number>
            </a-form-model-item>
          </a-col>
 
        </a-row>
 
      </a-form-model>
    </a-spin>
 
 
    <template slot="footer">
      <a-popconfirm title="确定放弃操作?" @confirm="visible=false" okText="确定" cancelText="取消">
        <a-button style="margin-right: .8rem">取消</a-button>
      </a-popconfirm>
      <a-button @click="handleSubmit" type="primary" :loading="confirmLoading">提交</a-button>
    </template>
 
  </a-modal>
 
</template>
 
<script>
  import pick from 'lodash.pick'
  import api from '@/api/mdc'
 
  export default {
    name: 'ParamThresholdModal',
    components: {},
    props: {
      driveTypeList: {
        type: Array
      }
    },
    data() {
      return {
        modalWidth: 700,
        form: this.$form.createForm(this),
        validatorRules: {
          controlSystemType: [
            {
              required: true, message: '请选择驱动类型'
            }
          ],
          chineseName: [
            {
              required: true, message: '请选择参数'
            }
          ],
          minThreshold: [
            {
              required: true, message: '请输入阈值上限'
            },
            {
              pattern: /^[0-9]+$/,
              message: '请输入阿拉伯数字'
            }
          ],
          maxThreshold: [
            {
              required: true, message: '请输入阈值下限'
            },
            {
              pattern: /^[0-9]+$/,
              message: '请输入阿拉伯数字'
            }
          ]
        },
        title: '操作',
        visible: false,
        model: {
          controlSystemType: '',
          chineseName: '',
          minThreshold: '',
          maxThreshold: ''
        },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 6 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 15 }
        },
        confirmLoading: false,
        url: {
          userId: '/sys/user/generateUserId' // 引入生成添加用户情况下的url
        },
        paramList: []
      }
    },
    created() {
 
    },
    methods: {
      add() {
        this.visible = true
        this.model = {
          controlSystemType: this.driveTypeList[0],
          chineseName: '',
          minThreshold: '',
          maxThreshold: ''
        }
        console.log('driveType',this.driveTypeList)
        this.handleDriveTypeChange(this.driveTypeList[0])
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model, 'controlSystemType', 'chineseName', 'minThreshold', 'maxThreshold'))
        })
      },
 
      edit(record) {
        this.visible = true
        this.model = Object.assign({}, record)
        api.getParamListByDriveTypeApi(record.controlSystemType)
          .then(res => {
            if (res.success) {
              this.paramList = res.result
            }
          })
        this.model.chineseName = `${record.englishName}(${record.chineseName})`
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model, 'controlSystemType', 'chineseName', 'minThreshold', 'maxThreshold'))
        })
      },
 
      handleSubmit() {
        const that = this
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            if (this.model.maxThreshold > this.model.minThreshold) {
              that.confirmLoading = true
              let obj
              if (this.title == '新增') {
                obj = api.addParamThresholdApi(this.model)
              } else {
                obj = api.editParamThresholdApi(this.model)
              }
              obj.then((res) => {
                if (res.success) {
                  that.$notification.success({
                    message: '消息',
                    description: res.message
                  })
                  that.$emit('ok')
                } else {
                  that.$notification.warning({
                    message: '消息',
                    description: res.message
                  })
                }
              }).finally(() => {
                that.confirmLoading = false
                this.visible = false
              })
            } else {
              this.$notification.warning({
                message: '消息',
                description: '阈值上限不能小于等于阈值下限'
              })
            }
 
          } else {
            return false
          }
        })
      },
 
      /**
       * 联想输入框筛选功能
       * @param input 输入的内容
       * @param option 配置
       * @returns {boolean} 判断是否筛选
       */
      filterOption(input, option) {
        return (
          option.componentOptions.children[0].text.toUpperCase().indexOf(input.toUpperCase()) >= 0
        )
      },
 
      /**
       * 驱动参数类型选中后渲染相应的参数列表
       * @param value 驱动参数类型选中项
       */
      handleDriveTypeChange(value) {
        api.getParamListByDriveTypeApi(value)
          .then(res => {
            if (res.success) {
              this.paramList = res.result
              this.model.chineseName = res.result.length ? res.result[0].value : undefined
              if (this.model.chineseName) this.$refs.form.clearValidate('chineseName')
            }
          })
      },
 
      /**
       * 编辑或查看详情数据时清除抽屉表单验证
       */
      removeValidate() {
        if (this.$refs.form) this.$refs.form.clearValidate()
      }
    }
 
  }
</script>
 
<style scoped>
 
</style>