/**
 * 左边树，右边网格明细查询
 * @param {*} saveDataset 保存数据集，命名规范 ds_[数组下标]_[对话框id]
 * @param {*} conf 组件定义配置项
 * @returns 
 */
 import { StringUtil } from "@birt/funclib/StringUtil.js";
import { treeEditFilter } from "../compose/org-tree-edit.jsx";
import { FormStyleFactory } from "../compose/FormStyleFactory.js";
import { TableStyleFactory } from "../compose/TableStyleFactory.js";
import { BirtModelFactory } from "../BirtModelFactory";

export function TreeTabTableQuery(conf) {
  const dlgId = StringUtil.randomString(6);
  // 设置数据集id
  var treeDataset = conf.treeDataset;
  var mainDataset = conf.mainDataset;
  var subDatasets = conf.subDatasets;

  // 编辑过滤树
  let treeEdit = treeEditFilter(dlgId, treeDataset.controlId, conf.treeEditFilter);
    let treeChildren = treeEdit[1].children
    if(treeChildren){
      treeChildren.map(item =>{
        let birtModel = {
           birtModel: item.birtModel
        } 
        item.birtModel = BirtModelFactory.buildModel(birtModel)
       return item
    })
    }
  // 操作工具条
  var hcFormToolbar = {
    controlName: "HcFormToolbar",
    controlId: "HcFormToolbar",
    dataset: mainDataset.controlId,
    layout: ["cancel", "save"],
    saveSucced:function(saveData){
      debugger
      // 获取树数据集
      let wb = this.getWorkBook()
      var dsTree = wb.dataset.dsTree
      //  清除树数据
      dsTree.clear()
      //  重新加载树数据集
      dsTree.query()
      var node = wb.param.node
      let elTree = this.getRefCompt('HcTree_org')
      elTree.defaultExpandedKeys.push(node.data.FORGGUID)
      let parent = node.parent;
      while (parent) {
        elTree.defaultExpandedKeys.push(parent.data.FORGGUID)
        parent = parent.parent
      }
      //  更新右边form的当前值
      let dsSubPsm = wb.dataset.dsSubPsm
      let dsMain = wb.dataset.dsMain;
      if(node.data.FORGKIND == '.PSM'){
        dsSubPsm.load({
          join: "and",
          items: [{
              sign: "eq",
              name: "FORGGUID",
              dataType: "string",
              value: node.data.FORGGUID,
              enable: true,
          }]
        })
      }else{
        dsMain.load({
          join: "and",
          items: [{
              sign: "eq",
              name: "FORGGUID",
              dataType: "string",
              value: node.data.FORGGUID,
              enable: true,
          }]
      })
      }
    },
    doSave:function(){
      debugger
      var cData = this.store.getCurtRecord()
      var curtData = JSON.parse(JSON.stringify(cData))
      var saveData = this._getSaveData(this.stores)
      var dirtyData = this.store.getDirtyData()
      var delList = []
      if(dirtyData && dirtyData[0]){
        let dData = dirtyData[0]
        if(dData.SysOrgBizEntityChildren && dData.SysOrgBizEntityChildren.data.length > 0){
          let arr = dData.SysOrgBizEntityChildren.data
          arr.forEach(d =>{
            if(d.$state == 'rsDelete'){
              delList.push(d.FORGNAME)
            }
          })
        }
        if(dData.SysOrgPtmEntityChildren && dData.SysOrgPtmEntityChildren.data.length > 0){
          let arr = dData.SysOrgPtmEntityChildren.data
          arr.forEach(d =>{
            if(d.$state == 'rsDelete'){
              delList.push(d.FORGNAME)
            }
          })
        }
        if(dData.SysOrgPsmEntityChildren && dData.SysOrgPsmEntityChildren.data.length > 0){
          let arr = dData.SysOrgPsmEntityChildren.data
          arr.forEach(d =>{
            if(d.$state == 'rsDelete'){
              delList.push(d.FORGNAME)
            }
          })
        }
      }
      if(delList.length > 0){
        var msg = delList.toString()
        this.$confirm(`此次操作会删除子节点<p style="color: red;margin-left:5px;">${msg}<p/>确定保存吗`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          dangerouslyUseHTMLString: true
        }).then(() => {
          if(curtData.FORGKIND == '.PTM' && saveData && saveData[0].data[0].FROLENAME){
            // 岗位节点修改岗位时，其子节点岗位信息也修改
            if(curtData.SysOrgBizEntityChildren && curtData.SysOrgBizEntityChildren.length > 0){
              for(var i = 0; i < curtData.SysOrgBizEntityChildren.length; i++){
                curtData.SysOrgBizEntityChildren[i].FROLENAME = curtData.FROLENAME
                curtData.SysOrgBizEntityChildren[i].FROLEGUID = curtData.FROLEGUID
                curtData.SysOrgBizEntityChildren[i].FROLEID = curtData.FROLEID
              }
            }
            if(curtData.SysOrgPtmEntityChildren && curtData.SysOrgPtmEntityChildren.length > 0){
              for(var i = 0; i < curtData.SysOrgPtmEntityChildren.length; i++){
                curtData.SysOrgPtmEntityChildren[i].FROLENAME = curtData.FROLENAME
                curtData.SysOrgPtmEntityChildren[i].FROLEGUID = curtData.FROLEGUID
                curtData.SysOrgPtmEntityChildren[i].FROLEID = curtData.FROLEID
              }
            }
            if(curtData.SysOrgPsmEntityChildren && curtData.SysOrgPsmEntityChildren.length > 0){
              for(var i = 0; i < curtData.SysOrgPsmEntityChildren.length; i++){
                curtData.SysOrgPsmEntityChildren[i].FROLENAME = curtData.FROLENAME
                curtData.SysOrgPsmEntityChildren[i].FROLEGUID = curtData.FROLEGUID
                curtData.SysOrgPsmEntityChildren[i].FROLEID = curtData.FROLEID
              }
            }
    
            var dirtData = saveData[0].data[0]
            if(dirtData.SysOrgBizEntityChildren && dirtData.SysOrgBizEntityChildren.data.length > 0){
              for(var i = 0; i < dirtData.SysOrgBizEntityChildren.data.length; i++){
                dirtData.SysOrgBizEntityChildren.data[i].FROLENAME = dirtData.FROLENAME
                dirtData.SysOrgBizEntityChildren.data[i].FROLEGUID = dirtData.FROLEGUID
                dirtData.SysOrgBizEntityChildren.data[i].FROLEID = dirtData.FROLEID
              }
            }
            if(dirtData.SysOrgPtmEntityChildren && dirtData.SysOrgPtmEntityChildren.data.length > 0){
              for(var i = 0; i < dirtData.SysOrgPtmEntityChildren.data.length; i++){
                dirtData.SysOrgPtmEntityChildren.data[i].FROLENAME = dirtData.FROLENAME
                dirtData.SysOrgPtmEntityChildren.data[i].FROLEGUID = dirtData.FROLEGUID
                dirtData.SysOrgPtmEntityChildren.data[i].FROLEID = dirtData.FROLEID
              }
            }
            if(dirtData.SysOrgPsmEntityChildren && dirtData.SysOrgPsmEntityChildren.data.length > 0){
              for(var i = 0; i < dirtData.SysOrgPsmEntityChildren.data.length; i++){
                dirtData.SysOrgPsmEntityChildren.data[i].FROLENAME = dirtData.FROLENAME
                dirtData.SysOrgPsmEntityChildren.data[i].FROLEGUID = dirtData.FROLEGUID
                dirtData.SysOrgPsmEntityChildren.data[i].FROLEID = dirtData.FROLEID
              }
            }
            saveData[0].data[0] = dirtData
            this.axios.post(this.saveUrl, { __body: JSON.stringify(saveData), __version: "1.0.0" }).then((res) => {
              // 保存成功回调
              this._afterSaveSucced(this.stores, this.saveSucced, saveData, res);
              this.store.setCurtRecord(curtData)
            });
          }else{
            // 禁用父节点时子节点同步禁用
            if(saveData && saveData[0].data[0].FSTATE){
              if(curtData.SysOrgBizEntityChildren && curtData.SysOrgBizEntityChildren.length > 0){
                for(var i = 0; i < curtData.SysOrgBizEntityChildren.length; i++){
                  curtData.SysOrgBizEntityChildren[i].FSTATE = 0
                }
              }
              if(curtData.SysOrgPtmEntityChildren && curtData.SysOrgPtmEntityChildren.length > 0){
                for(var i = 0; i < curtData.SysOrgPtmEntityChildren.length; i++){
                  curtData.SysOrgPtmEntityChildren[i].FSTATE = 0
                }
              }
              if(curtData.SysOrgPsmEntityChildren && curtData.SysOrgPsmEntityChildren.length > 0){
                for(var i = 0; i < curtData.SysOrgPsmEntityChildren.length; i++){
                  curtData.SysOrgPsmEntityChildren[i].FSTATE = 0
                }
              }
    
              var dirtData = saveData[0].data[0]
              if(dirtData.SysOrgBizEntityChildren && dirtData.SysOrgBizEntityChildren.data.length > 0){
                for(var i = 0; i < dirtData.SysOrgBizEntityChildren.data.length; i++){
                  dirtData.SysOrgBizEntityChildren.data[i].FSTATE = 0
                }
              }
              if(dirtData.SysOrgPtmEntityChildren && dirtData.SysOrgPtmEntityChildren.data.length > 0){
                for(var i = 0; i < dirtData.SysOrgPtmEntityChildren.data.length; i++){
                  dirtData.SysOrgPtmEntityChildren.data[i].FSTATE = 0
                }
              }
              if(dirtData.SysOrgPsmEntityChildren && dirtData.SysOrgPsmEntityChildren.data.length > 0){
                for(var i = 0; i < dirtData.SysOrgPsmEntityChildren.data.length; i++){
                  dirtData.SysOrgPsmEntityChildren.data[i].FSTATE = 0
                }
              }
              saveData[0].data[0] = dirtData
              this.axios.post(this.saveUrl, { __body: JSON.stringify(saveData), __version: "1.0.0" }).then((res) => {
                // 保存成功回调
                this._afterSaveSucced(this.stores, this.saveSucced, saveData, res);
                this.store.setCurtRecord(curtData)
              });
            }else if(saveData && saveData[0].data[0].FORGIDPATH){
              // 父节点idpath修改后，子节点idpath随之改变
              if(curtData.SysOrgBizEntityChildren && curtData.SysOrgBizEntityChildren.length > 0){
                for(var i = 0; i < curtData.SysOrgBizEntityChildren.length; i++){
                  var idpath = curtData.SysOrgBizEntityChildren[i].FORGIDPATH
                  var arr = idpath.split('/')
                  var newpath = curtData.FORGIDPATH + '/' + arr[arr.length - 1]
                  curtData.SysOrgBizEntityChildren[i].FORGIDPATH = newpath
                }
              }
              if(curtData.SysOrgPtmEntityChildren && curtData.SysOrgPtmEntityChildren.length > 0){
                for(var i = 0; i < curtData.SysOrgPtmEntityChildren.length; i++){
                  var idpath = curtData.SysOrgPtmEntityChildren[i].FORGIDPATH
                  var arr = idpath.split('/')
                  var newpath = curtData.FORGIDPATH + '/' + arr[arr.length - 1]
                  curtData.SysOrgPtmEntityChildren[i].FORGIDPATH = newpath
                }
              }
              if(curtData.SysOrgPsmEntityChildren && curtData.SysOrgPsmEntityChildren.length > 0){
                for(var i = 0; i < curtData.SysOrgPsmEntityChildren.length; i++){
                  var idpath = curtData.SysOrgPsmEntityChildren[i].FORGIDPATH
                  var arr = idpath.split('/')
                  var newpath = curtData.FORGIDPATH + '/' + arr[arr.length - 1]
                  curtData.SysOrgPsmEntityChildren[i].FORGIDPATH = newpath
                }
              }
              var dirtData = saveData[0].data[0]
              if(dirtData.SysOrgBizEntityChildren && dirtData.SysOrgBizEntityChildren.data.length > 0){
                for(var i = 0; i < dirtData.SysOrgBizEntityChildren.data.length; i++){
                  var idpath = dirtData.SysOrgBizEntityChildren.data[i].FORGIDPATH
                  var arr = idpath.split('/')
                  var newpath = dirtData.FORGIDPATH + '/' + arr[arr.length - 1]
                  dirtData.SysOrgBizEntityChildren.data[i].FORGIDPATH = newpath
                }
              }
              if(dirtData.SysOrgPtmEntityChildren && dirtData.SysOrgPtmEntityChildren.data.length > 0){
                for(var i = 0; i < dirtData.SysOrgPtmEntityChildren.data.length; i++){
                  var idpath = dirtData.SysOrgPtmEntityChildren.data[i].FORGIDPATH
                  var arr = idpath.split('/')
                  var newpath = dirtData.FORGIDPATH + '/' + arr[arr.length - 1]
                  dirtData.SysOrgPtmEntityChildren.data[i].FORGIDPATH = newpath
                }
              }
              if(dirtData.SysOrgPsmEntityChildren && dirtData.SysOrgPsmEntityChildren.data.length > 0){
                for(var i = 0; i < dirtData.SysOrgPsmEntityChildren.data.length; i++){
                  var idpath = dirtData.SysOrgPsmEntityChildren.data[i].FORGIDPATH
                  var arr = idpath.split('/')
                  var newpath = dirtData.FORGIDPATH + '/' + arr[arr.length - 1]
                  dirtData.SysOrgPsmEntityChildren.data[i].FORGIDPATH = newpath
                }
              }
              saveData[0].data[0] = dirtData
              this.axios.post(this.saveUrl, { __body: JSON.stringify(saveData), __version: "1.0.0" }).then((res) => {
                // 保存成功回调
                this._afterSaveSucced(this.stores, this.saveSucced, saveData, res);
                this.store.setCurtRecord(curtData)
              });
            }else{
              this.save({}, this.saveSucced);
            }
          }
        }).catch(() => {
        });
      }else{
        if(curtData.FORGKIND == '.PTM' && saveData && saveData[0].data[0].FROLENAME){
          // 岗位节点修改岗位时，其子节点岗位信息也修改
          if(curtData.SysOrgBizEntityChildren && curtData.SysOrgBizEntityChildren.length > 0){
            for(var i = 0; i < curtData.SysOrgBizEntityChildren.length; i++){
              curtData.SysOrgBizEntityChildren[i].FROLENAME = curtData.FROLENAME
              curtData.SysOrgBizEntityChildren[i].FROLEGUID = curtData.FROLEGUID
              curtData.SysOrgBizEntityChildren[i].FROLEID = curtData.FROLEID
            }
          }
          if(curtData.SysOrgPtmEntityChildren && curtData.SysOrgPtmEntityChildren.length > 0){
            for(var i = 0; i < curtData.SysOrgPtmEntityChildren.length; i++){
              curtData.SysOrgPtmEntityChildren[i].FROLENAME = curtData.FROLENAME
              curtData.SysOrgPtmEntityChildren[i].FROLEGUID = curtData.FROLEGUID
              curtData.SysOrgPtmEntityChildren[i].FROLEID = curtData.FROLEID
            }
          }
          if(curtData.SysOrgPsmEntityChildren && curtData.SysOrgPsmEntityChildren.length > 0){
            for(var i = 0; i < curtData.SysOrgPsmEntityChildren.length; i++){
              curtData.SysOrgPsmEntityChildren[i].FROLENAME = curtData.FROLENAME
              curtData.SysOrgPsmEntityChildren[i].FROLEGUID = curtData.FROLEGUID
              curtData.SysOrgPsmEntityChildren[i].FROLEID = curtData.FROLEID
            }
          }
  
          var dirtData = saveData[0].data[0]
          if(dirtData.SysOrgBizEntityChildren && dirtData.SysOrgBizEntityChildren.data.length > 0){
            for(var i = 0; i < dirtData.SysOrgBizEntityChildren.data.length; i++){
              dirtData.SysOrgBizEntityChildren.data[i].FROLENAME = dirtData.FROLENAME
              dirtData.SysOrgBizEntityChildren.data[i].FROLEGUID = dirtData.FROLEGUID
              dirtData.SysOrgBizEntityChildren.data[i].FROLEID = dirtData.FROLEID
            }
          }
          if(dirtData.SysOrgPtmEntityChildren && dirtData.SysOrgPtmEntityChildren.data.length > 0){
            for(var i = 0; i < dirtData.SysOrgPtmEntityChildren.data.length; i++){
              dirtData.SysOrgPtmEntityChildren.data[i].FROLENAME = dirtData.FROLENAME
              dirtData.SysOrgPtmEntityChildren.data[i].FROLEGUID = dirtData.FROLEGUID
              dirtData.SysOrgPtmEntityChildren.data[i].FROLEID = dirtData.FROLEID
            }
          }
          if(dirtData.SysOrgPsmEntityChildren && dirtData.SysOrgPsmEntityChildren.data.length > 0){
            for(var i = 0; i < dirtData.SysOrgPsmEntityChildren.data.length; i++){
              dirtData.SysOrgPsmEntityChildren.data[i].FROLENAME = dirtData.FROLENAME
              dirtData.SysOrgPsmEntityChildren.data[i].FROLEGUID = dirtData.FROLEGUID
              dirtData.SysOrgPsmEntityChildren.data[i].FROLEID = dirtData.FROLEID
            }
          }
          saveData[0].data[0] = dirtData
          this.axios.post(this.saveUrl, { __body: JSON.stringify(saveData), __version: "1.0.0" }).then((res) => {
            // 保存成功回调
            this._afterSaveSucced(this.stores, this.saveSucced, saveData, res);
            this.store.setCurtRecord(curtData)
          });
        }else{
          // 禁用父节点时子节点同步禁用
          if(saveData && curtData.FSTATE){
            if(curtData.SysOrgBizEntityChildren && curtData.SysOrgBizEntityChildren.length > 0){
              for(var i = 0; i < curtData.SysOrgBizEntityChildren.length; i++){
                curtData.SysOrgBizEntityChildren[i].FSTATE = 1
              }
            }
            if(curtData.SysOrgPtmEntityChildren && curtData.SysOrgPtmEntityChildren.length > 0){
              for(var i = 0; i < curtData.SysOrgPtmEntityChildren.length; i++){
                curtData.SysOrgPtmEntityChildren[i].FSTATE = 1
              }
            }
            if(curtData.SysOrgPsmEntityChildren && curtData.SysOrgPsmEntityChildren.length > 0){
              for(var i = 0; i < curtData.SysOrgPsmEntityChildren.length; i++){
                curtData.SysOrgPsmEntityChildren[i].FSTATE = 1
              }
            }
  
            var dirtData = saveData[0].data[0]
            if(dirtData.SysOrgBizEntityChildren && dirtData.SysOrgBizEntityChildren.data.length > 0){
              for(var i = 0; i < dirtData.SysOrgBizEntityChildren.data.length; i++){
                dirtData.SysOrgBizEntityChildren.data[i].FSTATE = 1
              }
            }
            if(dirtData.SysOrgPtmEntityChildren && dirtData.SysOrgPtmEntityChildren.data.length > 0){
              for(var i = 0; i < dirtData.SysOrgPtmEntityChildren.data.length; i++){
                dirtData.SysOrgPtmEntityChildren.data[i].FSTATE = 1
              }
            }
            if(dirtData.SysOrgPsmEntityChildren && dirtData.SysOrgPsmEntityChildren.data.length > 0){
              for(var i = 0; i < dirtData.SysOrgPsmEntityChildren.data.length; i++){
                dirtData.SysOrgPsmEntityChildren.data[i].FSTATE = 1
              }
            }
            saveData[0].data[0] = dirtData
            this.axios.post(this.saveUrl, { __body: JSON.stringify(saveData), __version: "1.0.0" }).then((res) => {
              // 保存成功回调
              this._afterSaveSucced(this.stores, this.saveSucced, saveData, res);
              this.store.setCurtRecord(curtData)
            });
          }else if(saveData && saveData[0].data[0].FORGIDPATH){
            // 父节点idpath修改后，子节点idpath随之改变
            if(curtData.SysOrgBizEntityChildren && curtData.SysOrgBizEntityChildren.length > 0){
              for(var i = 0; i < curtData.SysOrgBizEntityChildren.length; i++){
                var idpath = curtData.SysOrgBizEntityChildren[i].FORGIDPATH
                var arr = idpath.split('/')
                var newpath = curtData.FORGIDPATH + '/' + arr[arr.length - 1]
                curtData.SysOrgBizEntityChildren[i].FORGIDPATH = newpath
              }
            }
            if(curtData.SysOrgPtmEntityChildren && curtData.SysOrgPtmEntityChildren.length > 0){
              for(var i = 0; i < curtData.SysOrgPtmEntityChildren.length; i++){
                var idpath = curtData.SysOrgPtmEntityChildren[i].FORGIDPATH
                var arr = idpath.split('/')
                var newpath = curtData.FORGIDPATH + '/' + arr[arr.length - 1]
                curtData.SysOrgPtmEntityChildren[i].FORGIDPATH = newpath
              }
            }
            if(curtData.SysOrgPsmEntityChildren && curtData.SysOrgPsmEntityChildren.length > 0){
              for(var i = 0; i < curtData.SysOrgPsmEntityChildren.length; i++){
                var idpath = curtData.SysOrgPsmEntityChildren[i].FORGIDPATH
                var arr = idpath.split('/')
                var newpath = curtData.FORGIDPATH + '/' + arr[arr.length - 1]
                curtData.SysOrgPsmEntityChildren[i].FORGIDPATH = newpath
              }
            }
            var dirtData = saveData[0].data[0]
            if(dirtData.SysOrgBizEntityChildren && dirtData.SysOrgBizEntityChildren.data.length > 0){
              for(var i = 0; i < dirtData.SysOrgBizEntityChildren.data.length; i++){
                var idpath = dirtData.SysOrgBizEntityChildren.data[i].FORGIDPATH || dirtData.SysOrgBizEntityChildren.data[i].$old.FORGIDPATH
                var arr = idpath.split('/')
                var newpath = dirtData.FORGIDPATH + '/' + arr[arr.length - 1]
                dirtData.SysOrgBizEntityChildren.data[i].FORGIDPATH = newpath
              }
            }
            if(dirtData.SysOrgPtmEntityChildren && dirtData.SysOrgPtmEntityChildren.data.length > 0){
              for(var i = 0; i < dirtData.SysOrgPtmEntityChildren.data.length; i++){
                var idpath = dirtData.SysOrgPtmEntityChildren.data[i].FORGIDPATH || dirtData.SysOrgPtmEntityChildren.data[i].$old.FORGIDPATH
                var arr = idpath.split('/')
                var newpath = dirtData.FORGIDPATH + '/' + arr[arr.length - 1]
                dirtData.SysOrgPtmEntityChildren.data[i].FORGIDPATH = newpath
              }
            }
            if(dirtData.SysOrgPsmEntityChildren && dirtData.SysOrgPsmEntityChildren.data.length > 0){
              for(var i = 0; i < dirtData.SysOrgPsmEntityChildren.data.length; i++){
                var idpath = dirtData.SysOrgPsmEntityChildren.data[i].FORGIDPATH || dirtData.SysOrgPsmEntityChildren.data[i].$old.FORGIDPATH
                var arr = idpath.split('/')
                var newpath = dirtData.FORGIDPATH + '/' + arr[arr.length - 1]
                dirtData.SysOrgPsmEntityChildren.data[i].FORGIDPATH = newpath
              }
            }
            saveData[0].data[0] = dirtData
            this.axios.post(this.saveUrl, { __body: JSON.stringify(saveData), __version: "1.0.0" }).then((res) => {
              // 保存成功回调
              this._afterSaveSucced(this.stores, this.saveSucced, saveData, res);
              this.store.setCurtRecord(curtData)
            });
          }else{
            this.save({}, this.saveSucced);
          }
        }
      }
    },
    size: "mini",
    style: "padding:5px;"
  }
  // 人员form数据集不一样，另开一个工具条
  var hcFormToolbarPsm = {
    controlName: "HcFormToolbar",
    controlId: "HcFormToolbarPsm",
    dataset: 'dsSubPsm',
    vshow: false,
    layout: ["cancel", "save"],
    saveSucced:function(saveData){
      // 获取树数据集
      var dsTree = this.getWorkBook().dataset.dsTree
      //  清楚树数据
      dsTree.clear()
      //  重新加载树数据集
      dsTree.query()
      var node = this.getWorkBook().param.node
      var elTree = this.getRefCompt('HcTree_org')
      elTree.defaultExpandedKeys.push(node.data.FORGGUID)
      let parent = node.parent;
      while (parent) {
        elTree.defaultExpandedKeys.push(parent.data.FORGGUID)
        parent = parent.parent
      }
    },
    size: "mini",
    style: "padding:5px;"
  }
  // 应用表单个性化配置
  Object.assign(hcFormToolbar, conf.hcFormToolbar || {});
  Object.assign(hcFormToolbarPsm, conf.hcFormToolbar || {});

  // 编辑表单列表
  let hcForms = false;
  if (conf.hcForms) {
    hcForms = [];
    conf.hcForms.forEach((frm, i) => {
      let hcForm = {
        controlName: "HcForm",
        controlId: "HcForm_" + i,
        dataset: i == 2 ? subDatasets[2].controlId : mainDataset.controlId,
        labelWidth: "80px",
        vshow: function () {
          return i == 0
        },
        rules: {
        },
        children: [],
      };
      // 应用表单个性化配置
      Object.assign(hcForm, FormStyleFactory.buildForm(frm) || {});
      hcForms.push(hcForm);
    })
  }

  // 子节点网格
  let hcTables = false;
  if (conf.hcTables) {
    hcTables = [];
    conf.hcTables.forEach((tbl, i) => {
      if (!(tbl.isEdit === false)) {
        tbl.isEdit = true;
      }
      var hcTable = TableStyleFactory.buildTable(i, subDatasets[i].controlId, { hcTable: Object.assign(tbl,{style: 'width: 100%',height: function (parentHeight) {
        return parentHeight - 450;
      }})  });
      hcTables.push(hcTable);
    })
  }

  //  子节点选项卡
  var tabsChildren = []
  hcTables.forEach((tbl,i)=>{
    tabsChildren.push({
        controlName: "HcTabPane",
        controlId: "HcTabPane_list_" + i,
        label: tbl.title || ("列表" + i),
        name: "list_" + i,
        disabled: i != 0,
        children: [].concat(hcTables[i])
    })
  })
  var hcTabs = {
    controlName: "HcTabs",
    controlId: "HcTabs_org",
    tabPosition: "top",
    activeTabName: "list_0",
    style:'width: 90%;margin: auto;',
    events: {
      // click: function () {
       
      // }
    },
    children: [
    ].concat(tabsChildren),
  }

  // 系统表单自动填充字段
  var hcSysForm = false;
  if (conf.hcSysForm) {
    var hcSysForm = {
      controlName: "HcForm",
      controlId: "HcForm_sys_" + dlgId,
      dataset: mainDataset.controlId,
      labelWidth: "80px",
      rules: {
      },
      children: [],
    };
    // 应用系统字段表单个性化配置
    Object.assign(hcSysForm, FormStyleFactory.buildForm(conf.hcSysForm) || {});
  }

  // 应用报表模型
  var birtWorkBook = Object.assign({
    controlName: "BirtWorkBook",
    controlId: "BirtWorkBook_" + dlgId,
    showToolBar: false,
    totalPage: 1,
    renderType: "pages",
    height: function (parentHeight) {
      return parentHeight - 10;
    }
  }, conf.birtWorkBook || {})
  // 添加布局结构
  birtWorkBook.children = [{
    controlName: "BirtSheet",
    controlId: "BirtSheet_" + dlgId,
    name: "sheet_" + dlgId,
    pageIndex: 0,
    dataSets: [treeDataset, mainDataset].concat(subDatasets),
    children: [{
      controlName: "BirtFormSheet",
      controlId: "BirtFormSheet_" + dlgId,
      children: [{
        controlName: "HcRow",
        gutter: 10,
        children: [
          {
            controlName: "HcCol",
            span: 6,
            children: treeEdit,
          },
          {
            controlName: "HcCol",
            controlId: "HcCol_01_right",
            span: 18,
            children: []
              .concat(hcFormToolbar)
              .concat(hcFormToolbarPsm)
              .concat(hcForms)
              .concat(hcTabs)
              .concat(hcSysForm)
          }
        ]
      }]
    }]
  }]
  return birtWorkBook
}