<template>
  <el-dialog title="封禁IP" :close-on-click-modal="false" :visible.sync="open" width="700px" append-to-body>
    <el-form ref="form" :model="form" :rules="rules" label-width="100px">
      <el-form-item label="封禁IP"  prop="ip">
        <el-input v-model="form.ip" />
      </el-form-item>
      <el-form-item label="封禁时长" prop="forbidTime">
        <el-radio-group v-model="form.forbidTime">
          <el-radio
              v-for="dict in forbidTimeList"
              :key="dict.value"
              :label="dict.value"
          >{{dict.label}}</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="理由" prop="remark">
        <el-input v-model="form.remark" placeholder="请输入理由"   type="textarea" :rows="2"/>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="open = false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import ImageUpload from '@/components/ImageUpload/index'
import {forbidStatusList, forbidTimeList, forbidTypeList} from "@/constant/statusMap";
import {forbidIp} from "@/api/cai/userForbid";

export default {
  components: {
    ImageUpload,
  },
  data () {
    return {
      forbidTimeList,
      forbidTypeList,forbidStatusList,
      open: false,
      title: '',
      form:{
        ip: undefined,
        forbidTime: undefined,
        remark: undefined,
      },
      info:{

      },
      // 表单校验
      rules: {
        ip: [
          { required: true, message: "数据不能为空", trigger: "blur" }
        ],
        forbidTime: [
          { required: true, message: "数据不能为空", trigger: "blur" }
        ],
        remark: [
          { required: true, message: "数据不能为空", trigger: "blur" }
        ]
      },
      buttonLoading: false,
    }
  },
  created() {
  },
  methods: {
    init () {
      this.form.forbidTime = undefined
      this.form.ip = undefined
      this.form.remark = undefined
      this.open = true;
    },
    // 表单提交
    submitForm () {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.buttonLoading = true;
          forbidIp(this.form).then(data => {
            this.$modal.msgSuccess("操作成功");
            this.buttonLoading = false;
            this.open = false
            this.$emit('refreshDataList')
          }).finally(() => {
            this.buttonLoading = false;
          });
        }
      })
    },
  }
}
</script>
<style lang="scss" scoped>
.context-avatar-center {
  display: flex;
  align-items: center; /* 垂直居中 */
  //justify-content: center; /* 水平居中 */
}
</style>
