<!--
 * @Descripttion: 地球-浙江
 * @Author: sujunling
 * @Date: 2025-05-22 16:16:53
-->
<template>
  <div class="widget-securityModule">
    <!--中心-->
    <Center v-if="centerInfo"
    :informationValue="centerInfo.informationValue"
    :objectiveValue="centerInfo.objectiveValue"
    :resourceValue="centerInfo.resourceValue"
    :benefitValue="centerInfo.benefitValue"
    :totolInfo="centerInfo.totolInfo"
    @changeData="changeData"
     />
    <!--隐患统计-->
    <div class="leftTopDiv">
      <StatisticalRisk 
      v-if="pageData&&pageData.information" 
      :contentTitle="pageData.information.contentTitle"
      :listTitle="pageData.information.listTitle"
      :contentItemTitleInfo="pageData.information.contentItemTitleInfo"
      :resultValue="pageData.information.resultValue"
      :listData="pageData.information.listData"
      :problemlist="pageData.information.problemlist"
      />
    </div>
    <div class="leftBottomDiv">
      <StatisticalRisk v-if="pageData&&pageData.objective" 
      :contentTitle="pageData.objective.contentTitle"
      :listTitle="pageData.objective.listTitle"
      :contentItemTitleInfo="pageData.objective.contentItemTitleInfo"
      :resultValue="pageData.objective.resultValue"
      :listData="pageData.objective.listData"
      :problemlist="pageData.objective.problemlist"
      />
    </div>
    <div class="rightTopDiv">
      <StatisticalRisk v-if="pageData&&pageData.resource" 
      :contentTitle="pageData.resource.contentTitle"
      :listTitle="pageData.resource.listTitle"
      :contentItemTitleInfo="pageData.resource.contentItemTitleInfo"
      :resultValue="pageData.resource.resultValue"
      :listData="pageData.resource.listData"
      :problemlist="pageData.resource.problemlist"
      />
    </div>
    <div class="rightBottomDiv">
      <StatisticalRisk v-if="pageData&&pageData.benefit" 
      :contentTitle="pageData.benefit.contentTitle"
      :listTitle="pageData.benefit.listTitle"
      :contentItemTitleInfo="pageData.benefit.contentItemTitleInfo"
      :resultValue="pageData.benefit.resultValue"
      :listData="pageData.benefit.listData"
      :problemlist="pageData.benefit.problemlist"
      />
    </div>
    <InspectionsNum v-if="centerInfo"
    :informationValue="centerInfo.informationValue"
    :objectiveValue="centerInfo.objectiveValue"
    :resourceValue="centerInfo.resourceValue"
    :benefitValue="centerInfo.benefitValue" />
  </div>
</template>
<script>
import { Vue, Component, Prop } from 'vue-property-decorator'
import StatisticalRisk from './StatisticalRisk.vue'
import StatisticalSecurity from './StatisticalSecurity.vue'
import RiskAndSecurityNew from './RiskAndSecurityNew.vue'
import InspectionsNum from './InspectionsNum.vue'
import Center from './Center.vue'
import {getResultList}  from 'staticPub/config'
export default {
  name: 'xtpj',
  components: { StatisticalRisk, RiskAndSecurityNew, InspectionsNum, StatisticalSecurity, Center },
  data() {
    return {
      pageData:null,
      centerInfo:null,
    }
  },
  mounted() {
    this.changeDom()
    this.getAllPageInfo();
  },

  methods: {
    changeDom() {
      var dom = document.querySelector('.widget-SectorToolbar')
      if (dom) {
        dom.style.display = 'none'
      }
      var dom2 = document.querySelector('.widget-Legend')
      if (dom2) {
        dom2.style.display = 'none'
      }
    },
    getPageInfo(){
      return new Promise((resolve, reject) => {
        fetch(getResultList.coordinatedEvaluationUrl)
        .then(response => {
          if (!response.ok) {
            throw new Error('请求数据失败');
          }
          return response.json(); // 将响应解析为 JSON 格式
        })
        .then(data => {
          // 处理返回的数据
          console.log(data);
          if(data.code==1){
            resolve(data.result)
          }else{
            resolve(null);
          }
        })
        .catch(error => {
          // 处理错误
          console.error(error);
          resolve(null);
        });
      })
      
    },
    getAllPageInfo(){
      Promise.all([this.getPageInfo(),this.getProblemInfo()]).then(data=>{
        this.changeData(data);
      })
    },
    changeData(data){
      let tempData=null;
        if(data[0]){
          tempData=this.renderData(data[0])
        }
        if(data[1]){
          tempData=this.renderProblemInfo(data[1],tempData)
        }
        this.pageData=tempData
    },
    //数据处理
    renderData(result){
      this.pageData=null;
      this.centerInfo=null;
      //中间球行的数据
      const centerData={
        informationValue:{
          value:"",
          remark:"信息协同"
        },
        objectiveValue:{
          value:"",
          remark:"目标协同"
        },
        benefitValue:{
          value:"",
          remark:"利益协同"
        },
        resourceValue:{
          value:"",
          remark:"资源协同"
        },
        totolInfo:{
          value:"",
          remark:"整体等级"
        }
      }
      const centerTemp=result['子系统协同度'];
      for(let item in centerData){
        const itemData=centerData[item];
        if(centerTemp[itemData.remark]){
          itemData.value=(centerTemp[itemData.remark]*100).toFixed(0);
        }
      }
      centerData.totolInfo.value=result[centerData.totolInfo.remark]||"";
      const centerObj={};
      for(let item in centerData){
        centerObj[item]=centerData[item].value;
      }
      this.centerInfo=centerObj;
      // //四个角的数据
      // const pageData={
      //   information:{
      //     contentTitle:"信息",
      //     listTitle:"信息分析结果",
      //     contentItemTitleInfo:"",
      //     resultValue:"",
      //     listData:[],
      //     remarkOne:"信息协同",
      //     remarkTwo:"信息协同"
      //   }
      // }

      //四个角面板的数据
      const data={
        //信息数据
        information:{
          contentTitle:"信息",
          listTitle:"信息分析结果",
          contentItemTitleInfo:"",
          resultValue:"",
          listData:[],
          remarkOne:"信息协同",
          remarkName:"文件名",
          problemlist:[],
        },
        //利益数据
        benefit:{
          contentTitle:"利益",
          listTitle:"利益分析结果",
          contentItemTitleInfo:"",
          resultValue:"",
          listData:[],
          remarkOne:"利益协同",
          remarkName:"文件名",
          problemlist:[],
        },
        //目标数据
        objective:{
          contentTitle:"目标",
          listTitle:"目标分析结果",
          contentItemTitleInfo:"",
          resultValue:"",
          listData:[],
          remarkOne:"目标协同",
          remarkName:"文件名",
          problemlist:[],
        },
        //资源数据
        resource:{
          contentTitle:"资源",
          listTitle:"资源分析结果",
          contentItemTitleInfo:"",
          resultValue:"",
          listData:[],
          remarkOne:"资源协同",
          remarkName:"文件名",
          problemlist:[],
        },
      }
      for(let item in data){
        const tempData=data[item];
        const tempResult=result["最低得分情况表述"];
        if(tempResult){
          const renderData=this.getcontentItemTitleInfoAndresultValue(tempResult[tempData.remarkOne]);
          tempData.contentItemTitleInfo=renderData.contentItemTitle;
          tempData.resultValue=renderData.resultValue;
        }
        const tempResult2=result["文件结果"];
        if(tempResult2){
          for(let i=0;i<tempResult2.length;i++){
            const value=tempResult2[i][tempData.remarkOne];
            const name=this.renderFileName(tempResult2[i][tempData.remarkName]);
            tempData.listData.push({
              name:name.trim(),
              value:(value*100).toFixed(0),
              item:tempData.remarkOne+i,
            })
          }
        }
      }
      return data;
    },
    renderProblemInfo(res,data){
      const tempData={};
        const best_matches=res.best_matches;
        if(best_matches){
          for(let i=0;i<best_matches.length;i++){
            const item=best_matches[i];
            const name=this.renderFileName(item['出处文件']).trim()+item['问题类型'].trim();
            if(tempData[name]){
              tempData[name].push(item)
            }else{
              tempData[name]=[item];
            }
          }
        }
        for(let item in data){
          const showItem=data[item];
          const getDataList=tempData[showItem['contentItemTitleInfo']+showItem['contentTitle']]
          if(getDataList){
            getDataList.forEach(dataItem=>{
              const tempItem={
                problem:dataItem['问题句'],
                correction:dataItem['策略句']
              }
              showItem.problemlist.push(tempItem)
            })
          }
        }
        return data
    },
    //获取问题信息
    getProblemInfo(){
      return new Promise((resolve,reject)=>{
        fetch(getResultList.problemUrl).then(response => {
          if (!response.ok) {
            throw new Error('请求数据失败');
          }
          return response.json(); // 将响应解析为 JSON 格式
        }) .then(data => {
          // 处理返回的数据
          console.log(data);
          if(data.code==1){
            resolve(data.result)
          }else{
            resolve(null);
          }
        })
          .catch(error => {
            // 处理错误
            console.error(error);
            resolve(null);
          });
      })
    },
    //获取最低评分信息
    getcontentItemTitleInfoAndresultValue(data){
      if(!data){
        return {
          contentItemTitle:"",
          resultValue:""
        }
      }
      let contentItemTitle= this.renderFileName(data.split("文件名:")[1].split(", 得分")[0]);
      let resultValue= data.split("情况: ")[1];
      return {
        contentItemTitle:contentItemTitle.trim(),
        resultValue:resultValue.trim()
      }
    },
    //处理后缀
    renderFileName(data){
      if(data){
        return data.replace('.docx', "").replace('.txt', "").replace('doc',"");
      }else{
        return "";
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.widget-securityModule {
  width: 100%;
  height: 100%;
  position: fixed;
  background: url('~@/assets/images/jczc/xtpj_bg1.png') no-repeat center center;
  background-size: 1920px 1080px;
}

.leftTopDiv{
  z-index: 2;
  top: 72px;
  left: 0px;
  position: absolute;
  height: calc((100% - 102px) / 2);
  width:420px;
  padding-top: 20px;
  padding-left: 20px;
  padding-bottom: 10px;
}
.rightTopDiv{
  z-index: 2;
  top: 72px;
  right: 0px;
  position: absolute;
  height: calc((100% - 102px) / 2);
  width:420px;
  padding-top: 20px;
  padding-right: 20px;
  padding-bottom: 10px;
}
.leftBottomDiv{
  z-index: 2;
  bottom: 15px;
  left: 0px;
  position: absolute;
  height: calc((100% - 102px) / 2);
  width:420px;
  padding-left: 20px;
  padding-bottom: 10px;
}
.rightBottomDiv{
  z-index: 2;
  bottom: 15px;
  right: 0px;
  position: absolute;
  height: calc((100% - 102px) / 2);
  width:420px;
  padding-right: 20px;
  padding-bottom: 10px;
}
/deep/ .leftTopDiv .title .icon{
  background: url('~@/assets/images/jczc/stopDate.png') no-repeat center center !important;
}
/deep/ .rightTopDiv .title .icon{
  background: url('~@/assets/images/jczc/stopDate.png') no-repeat center center !important;
}
/deep/ .leftBottomDiv .title .icon{
  background: url('~@/assets/images/jczc/headerImage1.png') no-repeat center center !important;
}
/deep/ .rightBottomDiv .title .icon{
  background: url('~@/assets/images/jczc/headerImage1.png') no-repeat center center !important;
}
</style>