<template>
  <el-dialog
    title="确认说明"
    :close-on-click-modal="false"
    :visible.sync="visible"
    width="600px">
    <el-form 
      :model="dataForm" 
      :rules="dataRule" 
      ref="dataForm" 
      @keyup.enter.native="dataFormSubmit()" 
      label-width="80px" 
      size="mini"
      style="margin-left: 20px;width: 500px">
      <el-form-item label="确认描述" prop="verifyDescription">
        <el-input
          type="textarea"
          :rows="8"
          v-model="dataForm.verifyDescription">
        </el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="mini" @click="visible = false">关闭</el-button>
      <el-button size="mini" type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    props: ["thresholdTypes"],
    data () {
      return {
        visible: false,
        dataForm: {
          id: '',
          verifyDescription: ''
        },
        dataRule: {
          verifyDescription: [
            { required: true, message: '确认描述不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      // 在ealarm.vue调用该方法
      init (id) {
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          this.dataForm.id = id
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl('/management/warningInfo/verity'),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'verifyDescription': this.dataForm.verifyDescription
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.visible = false
                this.$emit('refreshDataList')
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
