<template>
  <common-layout  ref="layoutRef" :table-attrs="{
     'has-operation':false
   }" :form-attrs="{
     'span-attrs':{
       span:4
     }
   }" :table-header="dataLogHomeHeader" :get-table-list="getTableData" :filter-form="formConfig">
    <template #DATE_COUNT="{data}">
      <span v-if="data.UNIT_CODE == 'AH0000'" >{{data.DATE_COUNT}}</span>
      <span v-else class="to_detail" @click="getDetail('0',data)" >{{data.DATE_COUNT}}</span>
    </template>
    <template #GJ_COUNT_S="{data}">
      <span v-if="data.TABLE_NAME == 'AH0000'" >{{data.GJ_COUNT_S}}</span>
      <span v-else class="to_detail" @click="getDetail('2',data)" >{{data.GJ_COUNT_S}}</span>
    </template>
    <template #ZJBTG_S="{data}">
      <span v-if="data.TABLE_NAME == 'SUMMARY'" >{{data.ZJBTG_S}}</span>
      <span v-else  :class="[data.ZJBTG_S >0?'to_detail_red':'to_detail']"  @click="getDetail('5',data)" >{{data.ZJBTG_S}}</span>
    </template>
  </common-layout>
</template>

<script>
import {onBeforeMount, ref} from "vue";
import {commissionCreditInformationManageHome} from "@/data/all-form";
import {dataLogHomeHeader} from "@/data/all-table-header";
import commonLayout from "@/components/CommonLayout.vue";
import {
  queryUnitList
} from "@/service/credit-information/commission-credit-information-manage/commission-credit-information-manage";
import {queryLogDateInsert} from "@/service/credit-data/data-log/data-log";
import {InsertSyslog} from "@/units/use-method/user-log";
export default {
  name: "DataLogHome",
  components:{commonLayout},
  setup(props,{emit}) {
    const layoutRef = ref(null);
    const formConfig = ref({...commissionCreditInformationManageHome});
    const topEcharts = ref(null)
    const bottomEcharts = ref(null)
    function getTableData(){
      debugger
      queryLogDateInsert({
        unitCode:layoutRef.value.form.UNITCODE==undefined?'':layoutRef.value.form.UNITCODE,
        stateDate:layoutRef.value.form.START_DATE==undefined?'':layoutRef.value.form.START_DATE,
        endDate:layoutRef.value.form.END_DATE==undefined?'':layoutRef.value.form.END_DATE,
        pageIndex:layoutRef.value.pageIndex,
        pageSize:layoutRef.value.pageSize
      }).then(res =>{
        InsertSyslog(localStorage.getItem("xyxx_usercode"),localStorage.getItem("xyxx_unitcode"), "信息查询", "数据日志查询成功", "数据日志", "")
        layoutRef.value.getResData(res.msg[0].Rows,res.msg[0].TotalRowCount);
      })
    }
    function getUnitOption(){
      queryUnitList({}).then(res =>{
        let tempOption = res.msg[0].Rows;
        let returnOption = [];
        returnOption =  tempOption.map(i => ({
          ...i,
          label:i.UNIT_NAME,
          value:i.UNIT_CODE,
        }))
        let option = [
          {
            value:'',
            label:'请选择'
          }
        ].concat(returnOption);
        const unitcodeItem = formConfig.value.formItemsArr.find(i => i.modelValue === "UNITCODE");
        unitcodeItem.options = [...option]
      })
    }
    function getDateMatterTypeName(type){
      switch (type){
        case "1":
          return "许可";
          break;
        case "2":
          return "处罚";
          break;
        case "3":
          return "逾期";
          break;
        default:
          return type;
          break;
      }
    }
    function getDetail(type,data){
      if(data["UNIT_CODE"] == "AH0000"){  //委当日小结
        return;
      }
      let tempObj = {
        "businessTime": data["RKSJ"],
        "timeType": "2",
        "DATE_MATTER_TYPE": data["DATE_MATTER_TYPE"],
        "dateType": type,
        "unitCode":data["UNIT_CODE"]
      }
      emit('changeOperation','detail',tempObj)
    }
    function getPercent(num, total){
      num = parseFloat(num);
      total = parseFloat(total);
      if (isNaN(num) || isNaN(total)) {
        return "-";
      }
      return total <= 0? "0%" : Math.round((num / total) * 10000) / 100.0 + "%";
    }
    function getNowDate(){  //获取当前时间
      let date = new Date();
      let nowDate = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" +(date.getDate());
      let nowDa
    }
    onBeforeMount(()=>{
      getUnitOption()
    })
    return {
      layoutRef,
      getTableData,
      dataLogHomeHeader,
      formConfig,
      getDateMatterTypeName,
      getDetail,
      getPercent,
      topEcharts,
      bottomEcharts
    }
  }
}
</script>

<style scoped lang="scss">
.to_detail{
  text-decoration: underline;
  color: #1c84c6;
  cursor: pointer;
}
.to_detail_red{
  text-decoration: underline;
  color: red;
  cursor: pointer;
}
.fixed-part{
  height: 1800px;
  .table-part{
    height: 800px;
  }
}
.top-echarts,.bottom-echarts{
  flex: 1;
  height: 500px;
  overflow: hidden;
}
</style>