<template>
  <div>
    <title-bar title="关联方" @clickLef="onClick">
      <van-icon slot="left" name="cross" size="24" />
    </title-bar>
    <tree-graph-cmp :data="treeData" :format="formatLabel"></tree-graph-cmp>
  </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: "RelatedParty",
  components: {
    TitleBar,
    TreeGraphCmp
  },
})
export default class RelatedParty extends Vue {
  pageTitle = ""; // 页面标题
  treeData:any = {};
  array:any = {
    name: '',
    children: []
  };
  arrayFinal:any = {
    name: '最终控股股东',
    children: []
  };
  arrayMix:any = {
    name: '合营或者联营企业',
    children: []
  };
  arrayToge:any = {
    name: '共同控股投资方',
    children: []
  };
  arrayMoth:any = {
    name: '母公司',
    children: []
  };
  arrayChild:any = {
    name: '子公司',
    children: []
  };
  arrayToCon:any = {
    name: '共同控制',
    children: []
  };
  arrayMain:any = {
    name: '主要投资个人',
    children: []
  };
  arrayControlCompany:any = {
    name: '企业控股',
    children: []
  };
  arrayGC:any = {
    name: '母公司管理人员',
    children: []
  };
  onClick() {
    this.$router.back();
  }
  mounted() {
    this.pageTitle = this.$route.meta?.name;
    this.getRelation();
  }
  formatLabel(item:any) {
    if (item.flag == '1' || item.flag == '2') {
      return '持股比例：' + item.final_cgzb;
    } else return;
  };
  /**
   *author:pd
   * 查询关联方
   * 2021年11月29日10:49:30
   */
  getRelation() {
    this.array.name = this.$store.getters.getCusInfo.cus_name;
    let parm = {
      tc: nettyApi.TRADE_CODE.selectRelation,
      creditcode: this.$store.getters.getCusInfo.cert_code, //'915101007092429550',//this.$store.getters.getCusInfo.cert_code, //'91110108551385082Q',
      entname: this.$store.getters.getCusInfo.cus_name, //'四川蓝光发展股份有限公司',//this.$store.getters.getCusInfo.cus_name, //'小米科技有限责任公司',
      entid: '',
      regno: '',
      pageIndex: '1',
      ProdId: Public.getProdId(),
      SvrCode: Public.getSvrCode(nettyApi.TRADE_CODE.selectRelation),
      ClientNo: this.$store.getters.getCusInfo.cus_id
    };
    NativeUI.showWaiting('正在查询....');
    this.$IF.transferDataInter(nettyApi.commonRq, parm).then((res: any) => {
      NativeUI.closeWaiting();
      if (res.rc == '1') {
        if (res.final_person_and_relation_person != '' && res.final_person_and_relation_person) {
          for (let obj of res.final_person_and_relation_person) {
            let objInfo:any = {};
            objInfo.name = obj.name;
            objInfo.final_cgzb = obj.final_cgzb * 100 + '%';
            objInfo.labelShow = true;
            objInfo.flag = '1';
            objInfo.children = [];

            if (res.final_person_out_ctrl != '' && res.final_person_out_ctrl) {
              for (let obj of res.final_person_out_ctrl) {
                let objCom:any = {};
                objCom.name = obj.entname;
                objCom.labelShow = false;
                objInfo.children.push(objCom);
                // this.arrayControlCompany.children.push(objCom);
              }
              this.arrayFinal.children.push(objInfo);
              this.array.children.push(this.arrayFinal);
            }
          }
        }

        /* if(res.result[0].final_person_out_ctrl!= ''){
          for(let obj of res.result[0].final_person_out_ctrl){
            console.log(obj.entname);
            let objCom = {}
            objCom.name = obj.entname;
            objCom.labelShow = false;
            this.arrayControlCompany.children.push(objCom);
          }
        }
        this.array.children.push(this.arrayControlCompany)*/
        if (res.joint_venture_ent_inv != '' && res.joint_venture_ent_inv) {
          for (let obj of res.joint_venture_ent_inv) {
            let objCom:any = {};
            objCom.name = obj.name;
            objCom.labelShow = false;
            this.arrayMix.children.push(objCom);
          }
          this.array.children.push(this.arrayMix);
        }

        /* if (res.result[0].common_shareholder != '') {
          for (let obj of res.result[0].parent) {
            let objTZ = {};
            objTZ.name = obj.entname;
            objTZ.labelShow = false;
            this.arrayToge.children.push(objTZ);
          }
        }
        this.array.children.push(this.arrayToge);*/
        if (res.parent != '' && res.parent) {
          let objMO:any = {};
          objMO.name = res.parent.name;
          objMO.labelShow = false;
          objMO.children = [];
          if (res.staff_and_relation_person != '' && res.staff_and_relation_person) {
            for (let objPerson of res.staff_and_relation_person) {
              let objPersons:any = {};
              objPersons.name = objPerson.name;
              objPersons.labelShow = false;
              objMO.children.push(objPersons);
            }
          }
          this.arrayMoth.children.push(objMO);
          this.array.children.push(this.arrayMoth);
        }

        if (res.member != '' && res.member) {
          for (let objinfo of res.member.members) {
            let objCH:any = {};
            objCH.name = objinfo.name;
            objCH.labelShow = false;
            this.arrayChild.children.push(objCH);
          }
          this.array.children.push(this.arrayChild);
        }
        //  this.array.children.push(this.arrayToCon);
        if (res.major_person_inv_and_relation_person != '' && res.major_person_inv_and_relation_person) {
          for (let obj of res.major_person_inv_and_relation_person) {
            let objSingle:any = {};
            objSingle.name = obj.name;
            objSingle.final_cgzb = obj.conprop;
            objSingle.labelShow = true;
            objSingle.flag = '2';
            this.arrayMain.children.push(objSingle);
          }
          this.array.children.push(this.arrayMain);
        }
        this.treeData = this.array;
      } else {
        if (res.ret_code != '4999999') {
          NativeUI.toast(res.msg);
        }
        this.treeData = this.array;
      }
    });
  }
}
</script>

<style scoped></style>
