、
<template>
  <div class="app-container">
    <el-container>
      <el-header>
        <div>白名单配置</div>
        <el-divider/>
      </el-header>
      <el-main>
        <div class="form-main">
          <el-form ref="configForm" :model="configForm" :rules="configRules" label-width="120px">
            <el-form-item label="添加方式" prop="configName">
              <el-radio-group v-model="configForm.addMode">
                <el-radio
                  :label="1"
                >手动添加
                </el-radio>
                <el-radio
                  :label="2"
                >批量添加
                </el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="白名单类型" prop="whiteListType">
              <el-select v-model="configForm.whiteListType" clearable placeholder="请选择白名单类型">
                <el-option label="白名单人员" value="0"/>
                <el-option label="白名单设备" value="1"/>
              </el-select>
            </el-form-item>
            <template v-if="configForm.addMode==1">
              <el-form-item v-if="configForm.whiteListType==0" label="用户ID" prop="userId">
                <el-input v-model="configForm.userId" placeholder="请输入用户ID" type="textarea"/>
              </el-form-item>
              <el-form-item v-if="configForm.whiteListType==1" label="白名单设备" prop="equepid">
                <el-input v-model="configForm.equepid" placeholder="请输入设备信息" type="textarea"/>
              </el-form-item>
            </template>
            <el-form-item v-else-if="configForm.addMode==2" label="白名单文件" prop="file">


              <image-upload v-model="configForm.file" :fileType="['txt']" :limit="1"
                            :listType="'text'"
              />
            </el-form-item>
            <el-form-item label="备注" prop="remark">
              <el-input v-model="configForm.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, updateConfig } from '@/api/system/config'

export default {
  name: 'WhiteAddConfig',
  data() {

    return {
      form: {},
      tokenId: '',
      // 文件存放的路径
      fileList: [],
      configForm: {
        addMode: 1,
        whiteListType: '',
        whitelistIds: '',
        remark: '',
        equepid: '',
        file: []
      },
      configRules: {
        addMode: [
          { required: true, message: '添加方式不能为空', trigger: 'change' }
        ],
        whiteListType: [
          { required: true, message: '白名单类型不能为空', trigger: 'change' }
        ],
        userId: [
          { required: true, message: '用户Id不能为空', trigger: 'blur' }
        ],
        equepid: [
          { required: true, message: '设备信息不能为空', trigger: 'blur' }
        ],
        file: [
          { required: true, message: '白名单文件不能为空', trigger: 'change' }
        ]

      }
    }
  },
  computed: {},
  methods: {
    reset() {
      this.form = {
        addMode: undefined,
        whiteListType: undefined,
        userId: undefined,
        equepid: undefined,
        file: undefined
      }
      this.resetForm('form')
    },
    /** 提交按钮 */
    submitAddForm: function() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.configId != undefined) {
            updateConfig(this.form).then(response => {
              this.$modal.msgSuccess('修改成功')
            })
          } else {
            addConfig(this.form).then(response => {
              this.$modal.msgSuccess('新增成功')

            })
          }
          this.$router.push({ path: '/build/whiteListManagement' })
        }
      })
    },

    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>
