<template>
  <div class="data-dictionary h100">
    <diy-el-form ref="formRef"  v-model:model-form="forms" :forms="formConfig">
      <template #searchBtn>
        <el-button  type="primary" :icon="Search" @click="initSearch">查询</el-button>
      </template>
    </diy-el-form>
    <el-table
        :cell-style="{textAlign:'center'}"
        :header-cell-style="{textAlign:'center'}"
        :data="tableData"
        style="width: 100%">
      <el-table-column label="全市住建领域信用修复情况">
        <el-table-column prop="NAME" label="" width="120" />
        <el-table-column label="已修复">
          <el-table-column prop="ALL_NUM" label="总计" width="120">
            <template #default="scope">
                <span class="table-num" @click="getDetail(scope.row,'ALL_NUM')">{{ scope.row.ALL_NUM }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="JS_NUM" label="建管" width="120" >
            <template #default="scope">
              <span class="table-num" @click="getDetail(scope.row,'JS_NUM')">{{ scope.row.JS_NUM }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="CGZFJ_NUM" label="城管执法" >
            <template #default="scope">
              <span class="table-num" @click="getDetail(scope.row,'CGZFJ_NUM')">{{ scope.row.CGZFJ_NUM }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column prop="JJXF_NUM" label="拒绝修复" width="120" >
          <template #default="scope">
            <span class="table-num" @click="getDetail(scope.row,'JJXF_NUM')">{{ scope.row.JJXF_NUM }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="BYSL_NUM" label="不予修复" width="120" >
          <template #default="scope">
            <span class="table-num" @click="getDetail(scope.row,'BYSL_NUM')">{{ scope.row.BYSL_NUM }}</span>
          </template>
        </el-table-column>
      </el-table-column>

    </el-table>
  </div>
</template>

<script>
import DiyElForm from "@/components/common/DiyElForm.vue";
import {Plus, Search} from "@element-plus/icons-vue";
import {onBeforeMount, ref} from "vue";
import {creditRepairHome} from "@/data/all-form";
import {selectAdsZjwXyxfSqxfbCount} from "@/service/credit-data/credit-repair/credit-repair";
import {InsertSyslog} from "@/units/use-method/user-log";
export default {
  name: "CreditRepairHome",
  components:{DiyElForm},
  computed: {
    Search() {
      return Search
    },
    Plus(){
      return Plus
    }
  },
  setup(props,{emit}){
    const tableData = ref([])
    const formRef = ref(null);
    const forms = ref({});
    const formConfig = ref({...creditRepairHome});
    const tableCode = ["310115","310106","310104","310112","310101","310105","310107","310109","310110","310113","310114","310117","310118","310120","310151","310116","ZJ"]
    function sort(prop){
      return function (obj1,obj2){
        let val1 = obj1[prop];
        let val2 = obj2[prop];
        if(!isNaN(Number(val1))&&!isNaN(Number(val2))){
          val1 = Number(val1);
          val2 = Number(val2);
        }
        if(val1 < val2){
          return -1;
        }else if(val1 > val2){
          return 1
        }else{
          return 0
        }
      }
    }
    function getDetail(obj,type){
      debugger
      let tempObj = {
        "START_TIME":forms.value.START_DATE,
        "END_TIME":forms.value.END_DATE,
        "CFJGQX":obj.CFJGQX,
        "TYPE":type
      }
      emit('changeOperation','detail',tempObj)
    }
    function initSearch(){
      selectAdsZjwXyxfSqxfbCount({
        "START_TIME":forms.value.START_DATE,
        "END":forms.value.END_DATE
      }).then(res =>{
        debugger
        InsertSyslog(localStorage.getItem("xyxx_usercode"),localStorage.getItem("xyxx_unitcode"), "信息查询", "信用修复查询成功", "信用修复", "")
        let msg = res.msg[0];
        if(msg.TotalRowCount  > 0){
          let tempData = msg.Rows;
          tempData.forEach(item =>{
            let sortId = tableCode.indexOf(item.CFJGQX);
            item.sortId = sortId;
          });
          debugger
          let sortArr =  tempData.sort(sort('sortId'));
          tableData.value = sortArr;
        }else{
          tableData.value = [];
        }
      })
    }
    onBeforeMount(()=>{
      initSearch()
    })
    return {
      formRef,
      forms,
      formConfig,
      initSearch,
      tableData,
      getDetail
    }
  }

}
</script>

<style scoped lang="scss">
.table-num{
  color:#23527c
}
.data-dictionary{
  padding: 30px 20px 20px 20px;
}
</style>