<template>
  <div class="data-info">
    <el-card>
      <el-form :model="dataForm" label-width="120px">
        <el-form-item label="权限编码:" v-if="dataForm.id==''||dataForm.type==999">
          <el-input v-model="dataForm.code"></el-input>
        </el-form-item>
        <el-form-item label="权限名称:">
          <el-input v-model="dataForm.name"></el-input>
        </el-form-item>
        <el-form-item label="权限路径:"  v-if="dataForm.id==''||dataForm.type==999">
          <el-input v-model="dataForm.path"></el-input>
        </el-form-item>
        <!-- <el-form-item label="文件路径:">
          <el-input v-model="dataForm.file_path"></el-input>
        </el-form-item> -->
        <el-form-item label="权限排序:">
          <el-input v-model="dataForm.sort"></el-input>
        </el-form-item>
        <el-form-item label="所属权限:" v-if="dataForm.id==''||dataForm.type==999">
          <el-select v-model="dataForm.parent_id"  placeholder="请选择所属权限" size="large"  style="width:100%;">
              <el-option
                v-for="item in authList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
        </el-form-item>
        <el-form-item label="角色状态:">
          <el-select v-model="dataForm.status"  placeholder="请选择状态" size="large"  style="width:100%;">
              <el-option
                v-for="item in statusOptions"
                :key="item.status"
                :label="item.name"
                :value="item.status"
              />
            </el-select>
        </el-form-item>
      </el-form>
    </el-card>
      <div style="text-align:right; margin-top:20px;">
          <el-button type="warning" @click="btnSave">确认保存</el-button>
      </div>
  </div>
</template>

<script>
  import {createAdminAuth,updateAdminAuth,getAdminAuthInfo,searchAdminAuth} from'@/api/AdminAuth'
  export default{
    emits:['onClose'],
    props:{
      id:{
        type:Number,
        default:0
      },
    },
    watch:{
      id:{
        handler(v){
            let _this=this;
            if(v==null || v<=0)return;
            _this.getInfo(v);
        },
        immediate: true,
        deep: true
      }
    },
    data(){
      return{
        activeName:'base',
        authList:[],
        dataForm:{
          id:'',
          code:'',
          name:'',
          parent_id:'',
          type:999,
          status:''
        },
        statusOptions:[
          {
            status:5,
            name:'启用'
          },
          {
            status:6,
            name:'禁用'
          },

        ],
        typeList:[
          {
            value:1,
            name:'项目管理'
          },
          {
            value:2,
            name:'客户管理'
          },
          {
            value:3,
            name:'产品管理'
          },
          {
            value:4,
            name:'文档管理'
          },
          {
            value:5,
            name:'系统设置'
          },

        ],
      }
    },

    mounted() {
      this.initAuthList();
    },
    methods:{

      initAuthList(){
        let _this=this;
        searchAdminAuth({page:1,pageSize:99999,status:5}).then(res=>{
          if(res.status!=200)return;
          _this.authList=res.data.dataList.filter(o=>o.parent_id==0 && o.type!=99 && o.type!=999);
        })
      },
      //保存更新
      btnSave(e){
          let _this=this;

          let data={..._this.dataForm};
          data.attrs=JSON.stringify(data.attrs);
          if(_this.dataForm.id>0){
            updateAdminAuth(data).then(res=>{
              if(res.status!=200)return;
              _this.$alert("更新权限信息成功");
              _this.$emit("onClose")
            })
          }else{
            createAdminAuth(data).then(res=>{
              if(res.status!=200)return;
              _this.$alert("创建权限信息成功");
              _this.$emit("onClose")
            })
          }
      },

      //产品详情
      getInfo(id){
          let _this=this;
          let par={
            id:id,
          };
          getAdminAuthInfo(par).then(res=>{
              if(!res)return;
              if(res.status!=200)return;
              _this.dataForm=res.data;
          })
      },

      onChangeStatus(e){
          this.dataForm.status=e;
      },



    }
  }
</script>

<style lang="scss">
 @import './dataInfo.scss'
</style>
