<template>
  <div class="department-data">
    <diy-el-form ref="formRef"  v-bind="{'span-attrs':{span:4}}"   v-model:model-form="forms" :forms="formConfig">
      <template #searchBtn>
        <el-button  type="primary" :icon="Search" @click="getTableData()">查询</el-button>
      </template>
    </diy-el-form>
    <div class="department-content">
      <div class="left-echarts" ref="leftEcharts">

      </div>
      <div class="right-table">
        <my-table border
                  :has-operation="false"
                  :table-data="tableData"
                  :headers="departmentDataImputationSituationHeader">
        </my-table>
      </div>
    </div>
  </div>
</template>

<script>
import {proSelectXyxxSjtjNew} from "@/service/credit-data/data-imputation-push/data-imputation-push";
import {nextTick, onBeforeMount, onMounted, ref} from "vue";
import {matterImputationStaticsSituation} from "@/data/all-form";
import {Close, Delete, Document, Search, SuccessFilled} from "@element-plus/icons-vue";
import DiyElForm from "@/components/common/DiyElForm.vue";
import MyTable from "@/components/common/MyTable.vue";
import {departmentDataImputationSituationHeader} from "@/data/all-table-header";
import {departmentDataImputationEcharts} from "@/echarts/option";
import {getFullYear} from "@/units/use-method/veritification-tools";
import {InsertSyslog} from "@/units/use-method/user-log";
export default {
  name: "DepartmentDataImputationSituation",
  components:{MyTable, DiyElForm},
  computed: {
    Delete() {
      return Delete
    },
    Search() {
      return Search
    },
    Document() {
      return Document
    },
    SuccessFilled() {
      return SuccessFilled
    },
    Close() {
      return Close
    }
  },
  setup(){
    const forms = ref({});
    const formRef = ref(null);
    const formConfig = ref({...matterImputationStaticsSituation});
    const tableData = ref([]);
    const leftEcharts = ref(null);
    function getTableData(){
      proSelectXyxxSjtjNew({
        startM:forms.value.START_DATE,
        //startC:"2019-01-01",
        endM:forms.value.END_DATE,
        pageSize:10000,
        pageIndex:1
      }).then(res =>{
        InsertSyslog(localStorage.getItem("xyxx_usercode"),localStorage.getItem("xyxx_unitcode"), "信息查询", "数据归集推送查询成功", "数据归集推送", "")
        getEchartsAndTable(res);
      })
    }
    function getEchartsAndTable(data){
      tableData.value = [];
      let date = data.msg[0]
      //数据标题
      let dataTitle = ['市房管局', '市城管执法局', '市公积金管理中心', '市燃气处', '综管中心', '委行政服务中心'];
      let dataTitleT = ['委行政服务中心', '综管中心', '市燃气处', '市公积金管理中心', '市城管执法局', '市房管局'];
      let nowData = [
        { COUNTNUMBER: "0", XXSX: "市房管局", XDR: "法人" },
        { COUNTNUMBER: "0", XXSX: "市城管执法局", XDR: "法人" },
        { COUNTNUMBER: "0", XXSX: "市公积金管理中心", XDR: "法人" },
        { COUNTNUMBER: "0", XXSX: "市燃气处", XDR: "法人" },
        { COUNTNUMBER: "0", XXSX: "综管中心", XDR: "法人" },
        { COUNTNUMBER: "0", XXSX: "委行政服务中心", XDR: "法人" },
        { COUNTNUMBER: "0", XXSX: "市房管局", XDR: "自然人" },
        { COUNTNUMBER: "0", XXSX: "市城管执法局", XDR: "自然人" },
        { COUNTNUMBER: "0", XXSX: "市公积金管理中心", XDR: "自然人" },
        { COUNTNUMBER: "0", XXSX: "市燃气处", XDR: "自然人" },
        { COUNTNUMBER: "0", XXSX: "综管中心", XDR: "自然人" },
        { COUNTNUMBER: "0", XXSX: "委行政服务中心", XDR: "自然人" },
      ]
      //数据内容
      let dataLeft_bin = [];
      let dataRight_bin = [];
      let dataLeft_binN = [];
      let dataRight_binN = [];

      let dataLeft_binT = [];
      let dataRight_binT = [];
      let totalLeft = 0;
      let totalRight = 0;
      if(date.Rows != null && date.Rows != "null"){
        for (let i = 0; i < date.Rows.length; i++) {
          for (let j = 0; j < nowData.length; j++) {
            if (date.Rows[i].XXSX == nowData[j].XXSX && date.Rows[i].XDR == nowData[j].XDR)
              nowData[j].COUNTNUMBER = date.Rows[i].COUNTNUMBER;
          }
        }
        for (let p = 0; p < nowData.length; p++) {
          if (nowData[p].XDR == "法人") {
            dataLeft_bin.push(nowData[p])
          }
          if (nowData[p].XDR == "自然人") {
            dataRight_bin.push(nowData[p])
          }
        }
        for (let i = 0; i < dataTitle.length; i++) {
          for (let j=0; j < dataLeft_bin.length;j++){
            if (dataTitle[i] == dataLeft_bin[j].XXSX) {
              dataLeft_binN.push(dataLeft_bin[j].COUNTNUMBER * 1);
              totalLeft += dataLeft_bin[j].COUNTNUMBER * 1;

            }
          }
        }
        for (let i = 0; i < dataTitle.length; i++) {
          for (let j = 0; j < dataRight_bin.length; j++) {
            if (dataTitle[i] == dataRight_bin[j].XXSX) {
              dataRight_binN.push(dataRight_bin[j].COUNTNUMBER * 1);
              totalRight += dataRight_bin[j].COUNTNUMBER * 1;
            }
          }
        }

        for (let i = 0; i < dataTitleT.length; i++) {
          for (let j = 0; j < dataLeft_bin.length; j++) {
            if (dataTitleT[i] == dataLeft_bin[j].XXSX) {
              dataLeft_binT.push(dataLeft_bin[j].COUNTNUMBER * 1);
            }
          }
        }
        for (let i = 0; i < dataTitleT.length; i++) {
          for (let j = 0; j < dataRight_bin.length; j++) {
            if (dataTitleT[i] == dataRight_bin[j].XXSX) {
              dataRight_binT.push(dataRight_bin[j].COUNTNUMBER * 1);
            }
          }
        }
        for (let i = 0; i < dataTitleT.length; i++) {
          let obj ={
            XXLY:dataTitleT[i],
            FR:dataLeft_binT[i].toLocaleString(),
            ZRR:dataRight_binT[i].toLocaleString()
          }
          tableData.value.push(obj)
        }
        tableData.value.push({
          XXLY:"总计",
          FR:totalLeft.toLocaleString(),
          ZZR:totalRight.toLocaleString()
        })
      }else{
        dataTitle = ['市房管局', '市城管执法局', '市公积金管理中心', '市燃气处', '综管中心', '委行政服务中心'];
        dataLeft_binN = [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1];
        dataRight_binN = [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1];
      }
      debugger
      nextTick(() => {
        debugger
        departmentDataImputationEcharts(leftEcharts.value,dataTitle,dataLeft_binN,dataRight_binN);
      })
    }
    onMounted(()=>{
      forms.value.START_DATE = getFullYear("year") + "-01-01";
      forms.value.END_DATE = getFullYear("day");
      getTableData()
    })
    return {
      forms,
      formRef,
      formConfig,
      getTableData,
      tableData,
      departmentDataImputationSituationHeader,
      leftEcharts
    }
  }
}
</script>

<style scoped lang="scss">
.department-data{
  padding: 20px;
}
.department-content{
  display: flex;
  justify-content: space-between;
}
.left-echarts{
  height: 600px;
  width: 55%;
  padding-right: 50px;
  margin-right: 50px;
  border-right: 1px #DCDCDC solid;
}
.right-table{
  height: 100%;
  width: 40%;
}
</style>