<template>
  <base-model :config="model_cfg">
    <template slot="dialog-body">
      <el-form
        ref="anonymizationFrom"
        :model="form"
        :rules="rules"
        label-width="160px"
        size="small"
      >
        <el-form-item label="Group: " prop="Group">
          <el-input v-model="form.Group" />
        </el-form-item>
        <el-form-item label="Element: " prop="Group">
          <el-input v-model="form.Element" />
        </el-form-item>
        <el-form-item label="tag Description: " prop="Group">
          <el-input v-model="form.TagDescription" />
        </el-form-item>
        <el-form-item label="Tag DescriptionCN: " prop="Group">
          <el-input v-model="form.TagDescriptionCN" />
        </el-form-item>
        <el-form-item label="Value Representation: " prop="Group">
          <el-input v-model="form.ValueRepresentation" />
        </el-form-item>
        <el-form-item label="Is Fixed: ">
          <el-switch
            v-model="form.IsFixed"
            :active-value="true"
            :inactive-value="false"
          />
        </el-form-item>
        <el-form-item label="Replace Value: ">
          <el-input v-model="form.ReplaceValue" />
        </el-form-item>
        <el-form-item label="Is Enable: ">
          <el-switch
            v-model="form.IsEnable"
            :active-value="true"
            :inactive-value="false"
          />
        </el-form-item>
      </el-form>
    </template>
    <template slot="dialog-footer">
      <el-button :disabled="btnLoading" size="small" type="primary" @click="handleCancle">Cancel</el-button>
      <el-button size="small" type="primary" :loading="btnLoading" @click="handleSave">Save</el-button>
    </template>
  </base-model>
</template>
<script>
import { addOrUpdateSystemAnonymization } from '@/api/dictionary'
import BaseModel from '@/components/BaseModel'
const formDataDefault = () => {
  return {
    Group: '',
    Element: '',
    TagDescription: '',
    TagDescriptionCN: '',
    ValueRepresentation: '',
    ReplaceValue: '',
    IsEnable: false,
    IsAdd: false,
    IsFixed: false
  }
}
export default {
  name: 'AnonymizationFrom',
  components: { BaseModel },
  data() {
    return {
      isEnable: false,
      btnLoading: false,
      form: {
        Group: '',
        Element: '',
        TagDescription: '',
        TagDescriptionCN: '',
        ValueRepresentation: '',
        ReplaceValue: '',
        IsEnable: false,
        IsAdd: false
      },
      rules: {
        Group: [{ required: true, message: 'Please specify', trigger: 'blur' }]
      },
      model_cfg: { visible: false, showClose: true, width: '600px', title: '' }
    }
  },
  mounted() {
    // if (Object.keys(this.data).length && this.data.Id) {
    //   this.form = { ...this.data }
    // }
  },
  methods: {
    openDialog(title, data) {
      this.model_cfg.visible = true
      this.model_cfg.title = title
      if (Object.keys(data).length) {
        this.form = { ...data }
      } else {
        this.form = formDataDefault()
      }
    },
    handleSave() {
      this.$refs.anonymizationFrom.validate(valid => {
        if (valid) {
          this.btnLoading = true
          addOrUpdateSystemAnonymization(this.form).then(res => {
            this.btnLoading = false
            this.$message.success('Saved successfully!')
            this.model_cfg.visible = false
            this.$emit('getList')
          }).catch(() => {
            this.btnLoading = false
          })
        }
      })
    },
    handleCancle() {
      this.model_cfg.visible = false
    }
  }
}
</script>
