<template>
  <el-dialog :close-on-click-modal="false" title="新增ip" width="500px" :visible.sync="visible">
    <el-form ref="form" :model="form" :rules="rules" size="small" label-width="40px">
      <el-form-item label="ip" prop="ip">
        <el-input
          type="textarea"
          :autosize="{ minRows: 6, maxRows: 6}"
          placeholder="支持多条批量录入，ip间用英文逗号间隔"
          v-model="form.ip">
        </el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="text" @click="doCancel">取消</el-button>
      <el-button type="primary" @click="doSubmit">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {
  addBlack
} from '@/api/risk'
export default {
  name: 'AdForm',
  data () {
    return {
      visible: false,
      form: {
        ip: '',
        type: 1,
      },
      rules: {
        ip: [
          { required: true, message: '请输入ip', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    // 打开弹出窗
    show (row) {
      this.form = {
        ip: '',
        type: 1,
      }
      this.visible = true
    },
    // 取消
    doCancel () {
      this.visible = false
    },
    // 提交
    doSubmit () {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          addBlack(this.form).then(res => {
            this.$message({
              message: '新增成功',
              type: 'success'
            })
            this.$emit('reset')
            this.visible = false
          }).catch(err => {
            this.visible = false
          })
        }
      })
    }
  }
}
</script>
