<template>
  <div style="height: 100%">
    <complex-view-rendering
        :resource-id="resourceId"
        :data-permis="dataPermis"
        :operate-permis="operatePermis"
        :list-out-param="listOutParam"
        :tabSettingArr="tabSettingArr"
        :isCompositeView="isCompositeView"
        :equilibriumObj="paramTabObj"
        :parentFormData="parentFormData"
        :equiliInfoObj="equiliInfoObj"
        :compositeObj="compositeObj"
        :compositeFormOperate="compositeFormOperate"
         v-if="falg">
    </complex-view-rendering>
  </div>
</template>
<script>
import {Replace} from "sasp-base";
export default {
  name: "composite-view",
  components:{
  },
  props:{
    comView:{type:String,default:"",required:true},//复合视图id
    tabSettingArr:{type:Array,default:() => {return [];},required:true},//页签
    listOutParam:{type:Object,default:() => {return {};}}, //外部传入参数
    paramTabObj:{type:Object,default:() => {return {};}}, //外部传入参数
    parentFormData:{type:Object,default:() => {return {};}}, //父级表单对象
    equiliInfoObj:{type:Object,default:() => {return {};}}, //外部传入参数(简易)
    compositeObj:{type:Object,default:() => {return {};}}, //复合视图变化对象
    callfillParamArr:{type:Array,default:() => {return [];},required:true},//页签
    compositeFormOperate:{type:String,default:""},//表单状态
  },
  data(){
    return {
      resourceId:"",//资源id
      dataPermis:"",//数据权限
      operatePermis:"",//操作权限
      falg:false,
      isCompositeView:true,
    };
  },
  created(){
    this.getPermis(this.comView,this.tabSettingArr);
  },
  watch:{
      compositeObj:{
          handler:function() {
              //刷新复合视图
              this.callfillParamArr.forEach(item =>{
                  let paramValue = "";
                  if(item.paramType =='formField'){ //表单字段
                      paramValue = this.parentFormData[item.paramValue] || '';
                  }else if(item.paramType =='sysData' || item.paramType =='diy'){ //数据字典 自定义
                      paramValue = item.paramValue || '';
                  }else if(item.paramType =='default'){ //缺省值
                      if ((item.paramValue || "").toLowerCase().indexOf('loginuser') > -1) {
                          paramValue = Replace.text(this.loginUser, item.paramValue);
                      }
                      if ((item.paramValue || "").toLowerCase().indexOf('logindept') > -1) {
                          paramValue = Replace.text(this.userDept, item.paramValue);
                      }
                  }else if(item.paramType =='external'){ //外部参数
                      if(this.outParam[item.paramValue || '']){
                          paramValue = this.outParam[item.paramValue || ''];
                      }else if(this.listOutParam[item.paramValue || '']){
                          paramValue = this.listOutParam[item.paramValue || ''];
                      }
                  }else if(item.paramType == 'formOperate'){ //表单状态
                      paramValue = this.operate;
                  }
                  if(!this.paramTabObj[item.paramTab]){
                      this.$set(this.paramTabObj,item.paramTab,[]);
                  }
                  this.paramTabObj[item.paramTab].push({
                      paramKey:item.paramKey,
                      paramValue:paramValue
                  });
                  this.equiliInfoObj[item.paramTab +"_"+item.paramKey] = paramValue;
                  this.falg = false;
                  this.$nextTick(()=>{
                      this.falg = true; //刷新
                  })
              });
          },
          deep: true
      }
  },
  methods:{
    getPermis(id,tabArr){
      this.spcpFormAxios.post(this.api.resources.findResources,{'rSource':'cview','rStatus':'1','rKey':id}).then(res=> {//获取绑定资源数据
        if(res && res.data){
          let  data = res.data.operateObj[0];
          this.resourceId =data.id;
          let dataArr = [];
          (data.dataPermisList || []).forEach(item=>{//数据权限
            dataArr.push(item.id);
          });
          let arr = [];
          (data.operatePermisList || []).forEach(item=>{//操作权限
            /*tabArr.forEach(data=>{
              if(item.powerName == data){*/
                arr.push(item.id);
            /*  }
            })*/
          })
          this.operatePermis = arr.join(",");
          this.dataPermis = dataArr.join(",");
          this.falg = true;
        }
      });
    },

  }
}
</script>

<style scoped>

</style>
