<template>
  <div>
    <title-bar title="企业图谱" @clickLef="onClick">
      <van-icon slot="left" name="cross" size="24" />
    </title-bar>
    <div class="tree-parent-container">
      <tree-graph-cmp :data="treeData" :format="formatLabel"></tree-graph-cmp>
    </div>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import TitleBar from "@/components/general/TitleBar.vue";
import TreeGraphCmp from '@/components/general/TreeGraphCmp.vue';
import { NativeUI } from "@/public/ts/NativeUI";
import nettyApi from "@/constants/api/ms-netty/netty.api";
import Public from "@/public/ts/Public";
/**
 * @Description 企业图谱
 * @Author JiangTao
 * @Date 2021-11-10 下午 03:15
 */
@Component({
  name: "EnterpriseMap",
  components: {
    TitleBar,
    TreeGraphCmp
  },
})
export default class EnterpriseMap extends Vue {
  pageTitle = ""; // 页面标题
  array: any = {
    name: this.$store.getters.getCusInfo.cus_name,
    children: []
  };
  arrayh: any = {
    name: '法人代表',
    children: []
  };
  arraya: any = {
    name: '股东及出资信息',
    children: []
  };
  arrayb: any = {
    name: '企业对外投资',
    children: []
  };
  /*  arrayc = {
    name:'经济依存',
    children:[]
  };*/
  arrayd: any = {
    name: '高管人员',
    children: []
  };
  /* arraye: any = {
    name: '股东及出资信息',
    children: []
  };*/
  arrayf: any = {
    name: '受益所有人',
    children: []
  };
  arrayg: any = {
    name: '分支机构信息',
    children: []
  };
  arrayi: any = {
    name: '疑似实际控制人',
    children: []
  };

  children: any[] = [];
  treeData: any = {};
  param = {
    CUST_FULL_NAME: this.$store.getters.getCusInfo.cus_name,
    CERT_ARRAY_INFO: [
      {
        CERT_TYPE: '', //Public.getGScode(this.$store.getters.getCusInfo.cert_type), //'200',
        CERT_NO: '' //this.$store.getters.getCusInfo.cert_code //'77454934-7'
      }
    ],
    GS_QUERY_OPTION_ARRAY: [
      {
        GS_QUERY_OPTION_LIST: '1'
      },
      {
        GS_QUERY_OPTION_LIST: '2'
      },
      {
        GS_QUERY_OPTION_LIST: '3'
      }
    ],
    ProdId: Public.getProdId(),
    SvrCode: Public.getSvrCode(nettyApi.TRADE_CODE.selectGSXXCX),
    ClientNo: this.$store.getters.getCusInfo.cus_id,
    tc: nettyApi.TRADE_CODE.selectGSXXCX
  };
  paramb = {
    CUST_FULL_NAME: this.$store.getters.getCusInfo.cus_name,
    CERT_ARRAY_INFO: [
      {
        CERT_TYPE: '', //Public.getGScode(this.$store.getters.getCusInfo.cert_type), //'200',
        CERT_NO: '' //this.$store.getters.getCusInfo.cert_code //'77454934-7'
      }
    ],
    GS_QUERY_OPTION_ARRAY: [
      {
        GS_QUERY_OPTION_LIST: '23'
      },
      {
        GS_QUERY_OPTION_LIST: '16'
      }
    ],
    ProdId: Public.getProdId(),
    SvrCode: Public.getSvrCode(nettyApi.TRADE_CODE.selectGSXXCX),
    ClientNo: this.$store.getters.getCusInfo.cus_id,
    tc: nettyApi.TRADE_CODE.selectGSXXCX
  };
  parma = {
    CUST_FULL_NAME: this.$store.getters.getCusInfo.cus_name,
    CERT_ARRAY_INFO: [
      {
        CERT_TYPE: '', //Public.getGScode(this.$store.getters.getCusInfo.cert_type), //'200',
        CERT_NO: '' //this.$store.getters.getCusInfo.cert_code //'77454934-7'
      }
    ],
    GS_QUERY_OPTION_ARRAY: [
      {
        GS_QUERY_OPTION_LIST: '23'
      },
      {
        GS_QUERY_OPTION_LIST: '16'
      },
      {
        GS_QUERY_OPTION_LIST: '1'
      }
    ],
    ProdId: Public.getProdId(),
    SvrCode: Public.getSvrCode(nettyApi.TRADE_CODE.selectGSXXCX),
    ClientNo: this.$store.getters.getCusInfo.cus_id,
    tc: nettyApi.TRADE_CODE.selectGSXXCX
  };
  parmDw = {
    CUST_FULL_NAME: this.$store.getters.getCusInfo.cus_name,
    CERT_ARRAY_INFO: [
      {
        CERT_TYPE: '', //Public.getGScode(this.$store.getters.getCusInfo.cert_type), //'200',
        CERT_NO: '' //this.$store.getters.getCusInfo.cert_code //'77454934-7'
      }
    ],
    GS_QUERY_OPTION_ARRAY: [
      {
        GS_QUERY_OPTION_LIST: '14'
      },
      {
        GS_QUERY_OPTION_LIST: '15'
      }
    ],
    ProdId: Public.getProdId(),
    SvrCode: Public.getSvrCode(nettyApi.TRADE_CODE.selectGSXXCX),
    ClientNo: this.$store.getters.getCusInfo.cus_id,
    tc: nettyApi.TRADE_CODE.selectGSXXCX
  };
  parms = {
    key: this.$store.getters.getCusInfo.cus_name,
    ProdId: Public.getProdId(),
    SvrCode: Public.getSvrCode(nettyApi.TRADE_CODE.selectSY),
    ClientNo: this.$store.getters.getCusInfo.cus_id,
    tc: nettyApi.TRADE_CODE.selectSY
  };
  onClick() {
    // this.$router.back();
    this.$router.go(-1);
  };

  mounted() {
    this.pageTitle = this.$route.meta?.name;
    console.log("chaxun");
    this.getAll();
  };


  formatLabel(item: any) {
    if (item.flag == '1') {
      return item.vaub;
    } else if (item.flag == '2') {
      return item.value;
    } else if (item.flag == '3') {
      return item.labVal;
    } else if (item.flag == '7') {
      return item.laName;
    } else if (item.flag == '6') {
      return item.laName;
    } else if (item.flag == '8') {
      return item.laName;
    } else if (item.flag == '9') {
      return item.laName;
    } else {
      return;
    }
  };
  //查询分支机构信息
  selectJg() {
    return this.$IF.transferDataInter(nettyApi.commonRq, this.paramb).then((res: any) => {
      console.log(this.paramb);
      return res;
    });
  };
  //查询股东，高管信息
  selectZb() {
    return this.$IF.transferDataInter(nettyApi.commonRq, this.param).then((res: any) => {
      console.log(res);
      return res;
    });
  };
  //客户详情法人对外投资及任职
  selectLegalPeople() {
    return this.$IF.transferDataInter(nettyApi.commonRq, this.parma).then((res: any) => {
      return res;
    });
  };
  //查询受益人，疑似实际控制人parmDw
  selectControl() {
    return this.$IF.transferDataInter(nettyApi.commonRq, this.parms).then((res: any) => {
      return res;
    });
  };
  //法人对外任职投资
  selectDw() {
    return this.$IF.transferDataInter(nettyApi.commonRq, this.parmDw).then((res: any) => {
      return res;
    });
  };
  //查询所有图谱接口
  getAll() {
    NativeUI.showWaiting('正在查询....');
    Promise.all([
      this.selectZb(),
      this.selectJg(),
      this.selectLegalPeople(),
      this.selectControl(),
      this.selectDw()
    ]).then(([resa, resc, resd, resCon, resdw]) => {
      NativeUI.closeWaiting();
      /**
       * authour： pd
       *2021年11月25日19:14:33
       *股东出资
       * */
      if (resa.rc == '1') {
        this.array.name = this.$store.getters.getCusInfo.cus_name;
        if (resa.GS_ZBGCXX_ARRAY != '' && resa.GS_ZBGCXX_ARRAY) {
          for (let obj of resa.GS_ZBGCXX_ARRAY) {
            var objc:any = {};
            objc.name = obj.INV_NAME;
            objc.vaua = obj.CON_AMT;
            objc.vaub = obj.PROP_TOT_INV;
            objc.labelShow = true;
            objc.flag = '1';
            this.arraya.children.push(objc);
          }
          this.array.children.push(this.arraya);
        }
        /**
         * authour： pd
         *2021年11月25日19:14:33
         *高管
         * */
        if (resa.GS_ZYRYXX_ARRAY != '' && resa.GS_ZYRYXX_ARRAY) {
          for (let obj of resa.GS_ZYRYXX_ARRAY) {
            var obje:any = {};
            obje.name = obj.NAME;
            obje.value = obj.POSITION;
            obje.labelShow = true;
            obje.flag = '2';
            this.arrayd.children.push(obje);
          }
          this.array.children.push(this.arrayd);
        }
      } else {
        if (resa.ret_code != '4999999') {
          NativeUI.toast(resa.msg);
        }
      }
      /**
       * author:pd
       *企业对外投资
       *2021年11月25日19:16:16
       * */
      if (resc.rc == '1') {
        if (resc.ENT_INVEST_INFO != '' && resc.ENT_INVEST_INFO) {
          for (let obj of resc.ENT_INVEST_INFO) {
            let vargc:any = {};
            vargc.name = obj.ENT_JG_NAME;
            vargc.labVal = obj.FUNDED_RATIO;
            vargc.labelShow = true;
            vargc.flag = '3';
            this.arrayb.children.push(vargc);
          }
          this.array.children.push(this.arrayb);
        }

        if (resc.BRANCH_ORG_INFO != '' && resc.BRANCH_ORG_INFO) {
          for (let objJG of resc.BRANCH_ORG_INFO) {
            let objSingleJG:any = {};
            objSingleJG.name = objJG.BR_NAME;
            objSingleJG.labelShow = false;
            objSingleJG.flag = '4';
            this.arrayg.children.push(objSingleJG);
          }
          this.array.children.push(this.arrayg);
        }
      } else {
        if (resc.ret_code != '4999999') {
          NativeUI.toast(resc.msg);
        }
      }
      /**
       * author：pd
       * 查询法人对外投资及任职、客户详情
       * 2021年11月25日19:47:31
       * */

      if (resd.rc == '1') {
        console.log(resdw);
        let objLegal:any = {};
        objLegal.name = resd.REPR_NAME;
        objLegal.labelShow = false;
        objLegal.flag = '5';
        objLegal.children = [];
        if (resdw.rc == '1') {
          let arrayDWtz:any = {
            name: '对外投资',
            children: []
          };
          let arrayDWrz:any = {
            name: '对外任职',
            children: []
          };
          if (resdw.FRINV_INFO != '') {
            for (let objdw of resdw.FRINV_INFO) {
              let objDW:any = {};
              objDW.name = objdw.ENT_NAME;
              objDW.flag = '8';
              objDW.laName = objdw.FUNDED_RATIO;
              objDW.labelShow = true;
              arrayDWtz.children.push(objDW);
            }
            objLegal.children.push(arrayDWtz);
          }
          if (resdw.FRPOSITION_INFO != '') {
            for (let objrz of resdw.FRPOSITION_INFO) {
              let objRZ:any = {};
              objRZ.name = objrz.ENT_NAME;
              objRZ.flag = '9';
              objRZ.laName = objrz.POSITION;
              objRZ.labelShow = true;
              arrayDWrz.children.push(objRZ);
            }
            objLegal.children.push(arrayDWrz);
          }
        }
        this.arrayh.children.push(objLegal);
        this.array.children.push(this.arrayh);
      } else {
        if (resd.ret_code != '4999999') {
          NativeUI.toast(resd.msg);
        }
      }

      /**
       * 收益所有人，疑似实际控制人
       * ahthor：pd
       * 2021年11月29日10:20:35
       */
      if (resCon.rc == '1') {
        if (resCon.DATA[0].GRAPH[0].BENEFICIARY != '' && resCon.DATA[0].GRAPH[0].CONTROLLER) {
          for (let obj of resCon.DATA[0].GRAPH[0].BENEFICIARY) {
            let objSY:any = {};
            objSY.name = obj.NAME;
            objSY.labelShow = true;
            objSY.laName = obj.HOLDRATIO;
            objSY.flag = '6';
            this.arrayf.children.push(objSY);
          }
          this.array.children.push(this.arrayf);
        }
        if (resCon.DATA[0].GRAPH[0].CONTROLLER != '' && resCon.DATA[0].GRAPH[0].CONTROLLER) {
          console.log(resCon);
          for (let obj of resCon.DATA[0].GRAPH[0].CONTROLLER) {
            let objCON: any = {};
            objCON.name = obj.NAME;
            objCON.labelShow = true;
            objCON.laName = obj.HOLDRATIO;
            objCON.flag = '7';
            this.arrayi.children.push(objCON);
          }
          this.array.children.push(this.arrayi);
        }
      } else {
        if (resCon.ret_code != '4999999') {
          NativeUI.toast(resCon.msg);
        }
      }
      this.treeData = this.array;
      console.log("this.treeData", this.treeData);
    });
  }
}
</script>

<style scoped>
.tree-parent-container {
  width: 100%;
  height: calc(100vh - 60px);
}
</style>
