<template>
  <common-layout  ref="layoutRef" :table-attrs="{
     'has-operation':true
   }" :form-attrs="{
     'span-attrs':{
       span:4
     }
   }" :immediate-search=false :table-header="headerConfig" :get-table-list="getTableData" :filter-form="formConfig">
    <template #operation="{data}">
      <el-button  type="info" @click="$emit('changeOperation','detail',data)">查看</el-button>
    </template>
  </common-layout>
</template>

<script>
import {onBeforeMount, ref} from "vue";
import CommonLayout from "@/components/CommonLayout.vue";
import {relativePersonSearchHome} from "@/data/all-form";
import {relativePersonSearchHomeHeaderFr,relativePersonSearchHomeHeaderZrr} from "@/data/all-table-header";
import {
  creditInfoBaseXDR
} from "@/service/credit-information/commission-credit-information-database-search/relative-person-search/relative-person-search";
import {useRootStore} from "@/pinia/useStore";
import {InsertSyslog} from "@/units/use-method/user-log";

export default {
  name: "RelativePersonSearchHome",
  components: {CommonLayout},
  setup(){
    const layoutRef = ref(null);
    const formConfig = ref({...relativePersonSearchHome});
    const headerConfig = ref(null);
    const store = useRootStore();
    function getDifferentFormByType(type){
      let xdrdmItem = formConfig.value.formItemsArr.find(i => i.modelValue ==="XDRDM");
      if(type=="0"){
        xdrdmItem.isHide = true;
      }else if(type =="1"){
        xdrdmItem.isHide = false;
      }
    }
    function getDifferentHeaderByType(type){
      if(type=="0"){
        headerConfig.value = relativePersonSearchHomeHeaderFr;
      }else if(type =="1"){
        headerConfig.value = relativePersonSearchHomeHeaderZrr;
      }
    }
    function getTableData(){
      debugger
      layoutRef.value.isValidate(queryData)
    }
    function queryData(){
      creditInfoBaseXDR({
        "xdr":layoutRef.value.form.XDR == "0"?"法人":"自然人",
        "xdrmc":layoutRef.value.form.XDRMC,
        "XDRDM":layoutRef.value.form.XDRDM,
        "appkey":store.userInfo.xyxx_userkeycode
      }).then(res=>{
        InsertSyslog(localStorage.getItem("xyxx_usercode"),localStorage.getItem("xyxx_unitcode"), "信息查询", "委信用信息查询成功", "委信用信息", "");
        layoutRef.value.getResData(res.msg[0].Rows,res.msg[0].TotalRowCount)
      })
    }
    onBeforeMount(()=>{
      getDifferentHeaderByType("0")
      let xdrlxItem = formConfig.value.formItemsArr.find(i => i.modelValue ==="XDR");
      xdrlxItem.events = {
        'change'(val){
          getDifferentFormByType(val);
          getDifferentHeaderByType(val);
        }
      }
    })
    return{
      layoutRef,
      formConfig,
      headerConfig,
      getTableData
    }
  }
}
</script>

<style scoped>

</style>