<template>
  <div class="catalogue">
    <el-form ref="form" :model="form" label-width="100px">
      <div class="flex-wrap fr-list">
        <el-form-item class="flex1" label="是否显示">
          <el-select size="small" clearable v-model="form.is_show" placeholder="请选择是否显示">
            <el-option label="是" :value="1"></el-option>
            <el-option label="否" :value="0"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="flex1" label="权限编码">
          <el-input size="small" clearable placeholder="请输入权限编码" v-model="form.auth_ident"></el-input>
        </el-form-item>
        <el-form-item class="flex1" label="图标">
          <el-select size="small" clearable v-model="form.show_icon" placeholder="请选择图标">
            <el-option v-for="(item,index) in icons" :key="index" :label="item.name" :value="item.value">
              <i :class="item.name"></i>
            </el-option>
          </el-select>
        </el-form-item>
      </div>
      <div class="flex-wrap fr-list">
        <el-form-item class="flex1" label="页面地址">
          <el-input style="width: 265px;" size="small" clearable placeholder="请输入页面地址" v-model="form.route_info"></el-input>
        </el-form-item>
      </div>
      <el-form-item class="flex1" label="权限描述">
        <el-input size="small" type="textarea" :rows="5" placeholder="请输入权限描述" v-model="form.auth_comment"></el-input>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'Catalogue',
  props: {
    icons: {
      type: Array,
      default: () => []
    },
    authObj: {
      type: Object,
      default: () => { }
    },
    authType: {
      type: String,
      default: ''
    },
  },
  data () {
    return {
      form: {
        is_show: '',
        auth_ident: '',
        show_icon: '',
        route_info: '',
        auth_comment: ''
      },
    }
  },
  watch: {
    authType: {
      handler (val) {
        if (val == 'add') {
          this.clearForm()
        }
      },
      immediate: true
    },
    authObj: {
      handler (obj) {
        this.form = obj
      },
      immediate: true
    }
  },
  methods: {
    //清空表单
    clearForm () {
      const data = this.form
      for (const key in data) {
        if (Object.hasOwnProperty.call(data, key)) {
          data[key] = ''
        }
      }
    },
  }
}
</script>

<style lang="scss" scoped>
.catalogue {
  .fr-list {
    .el-form-item {
      margin-right: 105px;
      &:last-child {
        margin-right: 0;
      }
    }
  }
  .el-select {
    width: 100%;
  }
}
</style>
