<!--
 * @Description: 
 * @Author: 狼牙
 * @Email: huangxiaoming@winhc.cn
 * @Date: 2022-04-19 19:42:09
 * @LastEditTime: 2022-04-20 21:20:39
 * @LastEditors: 狼牙
-->
<template>
    <van-row :class="['fenxiansaomiaodet',loadingSkeleton?'oth':'']">
       <van-row class="fxsmmd-det">
          <van-row class='fxsmd-top'>
            <van-row class="fxsmd-top-left">
                <van-col class="fxsmd-top-left-img">
                    <Logo :name='$route.query.companyName' :companyId='$route.query.companyId' defaultPic='company' width='36px'/>
                </van-col>
                <van-col class="fxsmd-top-left-gs">{{companyName}}</van-col>
            </van-row>
          </van-row>
        <div class="bzDetail" v-if="sXData.numVOList">
            <div class="bz-top">
                <div class="its" v-for="(item,index) in numVOList" :key="index" @click="goNativeHandle(item)" :class="{'gray':(item.currentNum + item.historyNum) == 0}">
                    <p>{{filteTypes(item.creditPunishmentType)}}</p>
                    <p class="num" :class="{'gray':(item.currentNum) == 0}">{{item.currentNum}}<span :class="{'gray':(item.historyNum) == 0}">(历史{{item.historyNum}})</span></p>
                </div>
            </div>
            <div class="nz-btm" @click="goBzNativeHandle">
                <div class="its">
                    <p class="tp">累计被执行人总金额</p>
                    <p class="bt">{{sXData.totalExecAmount}}万元</p>
                </div>
                <div class="its">
                    <p class="tp">疑似当前欠款总金额</p>
                    <p class="bt">{{sXData.totalNoExecAmount}}万元</p>
                    <img src="@/assets/img/goRight.png" alt="" class="gright">
                </div>
            </div>
        </div>
        <van-skeleton title :row="20" :loading="loadingSkeleton"> 
            <van-tabs 
                v-model="activeName" 
                @change="onChangeTab"
                color="#088BFE"
                title-active-color="#088BFE"
                swipeable
                line-width='30px'
                sticky
            >
                <van-tab :title="'自身风险'+zsCount" name="zsfx" title-style="font-weight:bold" :style='minstyle'>
                   <yhc-zishenfenxian :zishenfengxianList='zishenfengxianList' :companyName ="companyName" :personName="personName" types="自身风险" fixed.sync="fixed" @getGuanLianData="getGuanLianData" :activeName="activeName" :showNoData="showZsNoData"></yhc-zishenfenxian>
                </van-tab>
                <van-tab :title="'关联风险'+glCount" name="glfx" title-style="font-weight:bold" :style='minstyle'>
                    <yhc-zishenfenxian :zishenfengxianList='guanlianfengxianList' :companyName ="companyName" :personName="personName" types="关联风险" fixed.sync="fixed" @getGuanLianData="getGuanLianData" :activeName="activeName" :showNoData="showGlNoData"></yhc-zishenfenxian>
                </van-tab>
                 
            </van-tabs>
        </van-skeleton>
       </van-row>
       <VipQuan :isShow='isShowQuan' @changeShow="changShow" :quanData="quanData" @refreshHandle="refreshHandle"></VipQuan>
    </van-row>
</template>

<script lang="ts">
import $axios from '@/api'
import fxcomponent from './components/tabs.vue';
import Logo from '@/components/Global/Avatar.vue';
import { $goDetail ,$openBuyVipPopup} from "@/utils/utils"
import VipQuan from '@/components/Global/VipQuan.vue'
export default {
    data() {
        return {
            loadingSkeleton:true,
            personName:this.$route.query.personName,
            companyName:this.$route.query.companyName,//河南亚华安全玻璃有限公司
            minstyle:{
                minHeight:(document.body.clientHeight-90)+'px'
            },
            fixed:false,
            activeName: 'zsfx',
            zsCount:0,
            glCount:0,
            guanlianfengxianList:[],
            zishenfengxianList:[],
            showZsNoData:false,
            showGlNoData:false,
            isFirstZs:true,
            isFirstGl:true,
            isMonitor:false,

            numVOList:[],
            sXData:{},
            isShowQuan:false,
            quanData:{},
            voucherCode:''
        }
    },
    components: {
        Logo,
        'yhc-zishenfenxian':fxcomponent,
        VipQuan
    },
    mounted () {
        document.title = '风险扫描'
        //获取是自身风险还是个人风险
        this.activeName = this.$route.query.fengxianType || 'zsfx'
        this.zsCount = this.$route.query.zsCount || 0;
        this.glCount = this.$route.query.glCount || 0;
        
        this.loadingSkeleton = true;
        window.callBackOpenVipPopup= this.getGuanLianData;
        if(this.$signTagKey){
            this.voucherCode = this.$signTagKey;
        }
        this.getRiskInfo();
        this.getBzDataInfo();
        this.getGuanLianData();

        window.addEventListener('scroll', this.handleScroll, true);
    },
    destroyed () {
        window.removeEventListener('scroll', this.handleScroll, true);
    },
    methods: {
        changShow(){
            this.isShowQuan = false;
        },
        refreshHandle(data){
            this.isShowQuan = false;
            this.voucherCode = data;
            this.$nextTick(()=>{
                this.getGuanLianData()
            })
        },
        handleScroll () {
            let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
            // console.log("scrollTop====",scrollTop)
            let limitTop = this.sXData.numVOList?220:57;
            if(scrollTop >= limitTop){
                this.fixed = true;
            }else{
                this.fixed =false
            }
        },
        goNativeHandle(item){
            if(item.currentNum + item.historyNum == 0){
                return
            }
            if(item.currentNum != 0 ){
                $goDetail(item.currentRouting)
                return
            }
            if(item.currentNum == 0 && item.historyNum > 0){
                $goDetail(item.historyRouting)
                return
            }
        },
        goBzNativeHandle(){
            let sXData = this.sXData;
            $goDetail(`SxXgDataDet?totalExecAmount=${sXData.totalExecAmount}&totalNoExecAmount=${sXData.totalNoExecAmount}&zxrTotalExecAmount=${sXData.zxrTotalExecAmount}&finalCaseExecAmount=${sXData.finalCaseExecAmount}&finalCaseNoExecAmount=${sXData.finalCaseNoExecAmount}&noExecPercent=${sXData.noExecPercent || ''}`)
        },

        //获取失信限制高数据
        async getBzDataInfo(){
            try {
                let sendData = {
                    // 'entityId':this.$route.query.companyId,
                    'entityName':this.companyName,
                    'entityType':0
                }
                let res = await $axios.post('winhc-justice-service/credit/count',sendData)
                console.log("失信限高=",res)
                this.sXData = res || {};
                this.numVOList = res.numVOList;
                    
            } catch (error) {
                
            }
        },

        async getRiskInfo(){//获取自身和关联风险数量
            try {
                let sendData = {
                    'entityType':'2',
                    'keyWord':this.companyName
                }
                let res = await $axios.get('lawyer-workbench/risk/summary',{params:sendData})
                 console.log('风险数量=',res);
                 res.forEach((e)=>{
                    if(e.riskScanType == '1'){
                        this.zsCount = e.total || 0;
                    }else if(e.riskScanType == '2'){
                        this.glCount = e.total || 0;
                    }
                })
            } catch (error) {
                
            }
        },

        getGuanLianData:async function(data={}){
            let sendData = {
                    entityType:'2',
                    riskScanType:this.activeName == 'zsfx'?'1':this.activeName == 'glfx'?'2':'',
                    entityId:this.$route.query.companyId,
                    entityName:this.companyName
            }
            sendData = {...sendData,...data}
            if(this.voucherCode){
                sendData.voucherCode = this.voucherCode;
            }
             try {
                let res = await $axios.post('lawyer-workbench/risk/summary/infos',sendData)
                console.log('企业风险扫描=',res);
                if(this.activeName == 'zsfx'){
                    this.isFirstZs = false;
                    if(res.length == 0){
                        this.showZsNoData = true;
                    }else{
                        this.showZsNoData = false;
                    }
                    this.zishenfengxianList = res;
                }else if(this.activeName == 'glfx'){
                    this.isFirstGl = false;
                    if(res.length == 0){
                        this.showGlNoData = true;
                    }else{
                        this.showGlNoData = false;
                    }
                    this.guanlianfengxianList = res ;
                }
                   
                this.loadingSkeleton = false;
            } catch (error) {
                this.loadingSkeleton = false;
                if(error.errorCode == '79'){
                    let tempData = JSON.parse(error.errorMsg)
                    if(tempData.voucherCount > 0){
                        this.isShowQuan = true;
                        this.quanData = tempData;
                    }else{//VIP购买弹框
                        $openBuyVipPopup(12)
                    }
                }
            }
        },
        onChangeTab(name,title) {
            // console.log('name=',name)+'---' +title;
            this.activeName = name;
            if(name == 'zsfx'){
                if(this.isFirstZs){
                    this.getGuanLianData()
                }
            }else if(name == 'glfx'){
                if(this.isFirstGl){
                     this.getGuanLianData()
                }
            }
           
        },
        getXZCFNum(list){
            let num = 0;
            if(list.__proto__.constructor == Array){//instanceof
                 list.forEach(e => {
                    num +=e.count*1;
                });
               
            }else{
                num = list
            }
            return num
        },
        filteTypes(val){
            let type = ""
            if(val){
                switch (val) {
                    case 1:type = '被执行人'; break;
                    case 2:type = '失信信息'; break;
                    case 3:type = '限制高消费'; break;
                    case 4:type = '终本案件'; break;
                    
                }
            }
            return type
        }
    },
    
    
}
</script>

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