<template>

  <el-dialog :modal-append-to-body="false" :title="title" v-bind="$attrs" width="500px"
             v-on="$listeners"
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-form-item v-if="type==1" label="用户Id" prop="userId">
        <el-input v-model="form.userId" placeholder="请输入用户Id"/>
      </el-form-item>

      <el-form-item v-else label="设备号" prop="equepid">
        <el-input v-model="form.equepid" placeholder="请输入设备号"/>
      </el-form-item>

    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitAddForm()">保 存</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { updateConfig } from '@/api/system/config'

export default {
  name: 'EditWhiteList',
  props: {
    //类型
    type: {
      type: Number,
      default: 1
    }
  },
  data() {
    return {
      configName: undefined,
      form: {},
      title: '编辑',
      // 详情信息
      rules: {
        userId: [
          { required: true, message: '用户Id不能为空', trigger: 'blur' }
        ],
        equepid: [
          { required: true, message: '设备号不能为空', trigger: 'blur' }
        ]
      }
    }

  },
  methods: {
    /** 提交按钮 */
    submitAddForm: function() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          updateConfig(this.form).then(response => {
            this.$modal.msgSuccess('修改成功')
            this.closeModal()
          })
        }
      })
    },
    reset() {
      this.form = {
        userId: undefined,
        equepid: undefined
      }
      this.resetForm('form')
    },
    // 取消按钮
    cancel() {
      this.reset()
      this.closeModal()
    },
    closeModal() {
      this.$emit('close')
    }
  }
}
</script>
