<template>
  <div class="app-container">
    <el-container>
      <el-header>
        <div>新增白名单</div>
        <el-divider/>
      </el-header>
      <el-main>
        <div class="form-main">
          <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-form-item label="白名单名称" prop="whiteListName">
              <el-input v-model="form.whiteListName" placeholder="请输入白名单名称"/>
            </el-form-item>
            <el-form-item label="白名单类型" prop="whiteListType">
              <el-select v-model="form.whiteListType" clearable placeholder="请选择白名单类型">
                <el-option label="白名单人员" value="0"/>
                <el-option label="白名单设备" value="1"/>
              </el-select>
            </el-form-item>

            <el-form-item label="白名单模式" prop="whitePattern">
              <el-select v-model="form.whitePattern" clearable placeholder="请选择白名单模式">
                <el-option label="正则模式" value="0"/>
                <el-option label="普通模式" value="1"/>
              </el-select>
            </el-form-item>


            <el-form-item label="备注">
              <el-input v-model="form.remark" placeholder="请输入内容" type="textarea"/>
            </el-form-item>
          </el-form>
        </div>
        <div class="page-footer">
          <el-button type="primary" @click="submitAddForm()">保 存</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </el-main>
    </el-container>
  </div>

</template>
<script>
import { addConfig } from '@/api/system/config'

export default {
  name: 'WhiteAdd',
  dicts: ['sys_yes_no'],
  data() {

    return {
      form: {},
      tokenId: '',
      // 文件存放的路径
      fileList: [],
      rules: {
        whiteListName: [
          { required: true, message: '白名单名称不能为空', trigger: 'blur' }
        ],
        whiteListType: [
          { required: true, message: '白名单类型不能为空', trigger: 'change' }
        ],
        whitePattern: [
          { required: true, message: '白名单模式不能为空', trigger: 'change' }
        ]
      }
    }
  },
  computed: {},
  mounted() {
    this.reset()
  },
  methods: {
    reset() {
      this.form = {
        whiteListType: undefined,
        whiteListName: undefined,
        whitePattern: undefined,
        remark: undefined
      }
      this.resetForm('form')
    },
    /** 新增按钮 */
    submitAddForm: function() {
      this.$refs['form'].validate(valid => {
        if (valid) {

          addConfig(this.form).then(response => {
            this.$modal.msgSuccess('新增成功')
          })
          this.$router.push({ path: '/build/whiteListManagement' })
          // if (this.form.configId != undefined) {
          //   updateConfig(this.form).then(response => {
          //     this.$modal.msgSuccess('修改成功')
          //   })
          // } else {
          //   addConfig(this.form).then(response => {
          //     this.$modal.msgSuccess('新增成功')
          //   })
          // }
        }
      })
    },
    cancel() {
      this.$router.push({ path: '/build/whiteListManagement' })
    }
  }
}
</script>
<style lang="scss" scoped>
.app-container {
  background: #ffffff;
  margin: 24px;
}

.form-main {
  width: 700px;
  margin: 0 auto;
}

::v-deep .el-input.is-disabled .el-input__inner, .el-textarea.is-disabled .el-textarea__inner {
  border: 1px solid #E4E7ED !important;
}

.tag-group {
  .el-tag {
    cursor: pointer;

  }
}

.el-tag + .el-tag {
  margin-left: 10px
}

.page-footer {
  margin: 0 auto;
  width: 700px;
  justify-content: center;
  display: flex;
}
</style>
