<script setup lang="tsx">
import { PropType } from 'vue';
import { TableData } from '@/api/csck/CsckDataCheckResult/types';
import { Table, TableColumn } from '@/components/Table'
import { ref } from 'vue'
import { getCsckDataCheckDataApi } from '@/api/csck/CsckDataCheckResult';
// 使用正则表达式将数字按千位分组
const props = defineProps({
  currentRow: {
    type: Object as PropType<TableData>,
    default: () => { },
  },
  searchParams: {
    type: Object as PropType<any>,
    default: () => { },
  }
});



const columns: TableColumn[] = [
  {
    field: 'organName',
    label: '',
    headerAlign: 'right',
    align: 'right',
    formatter: (_: Recordable, __: TableColumn, cellValue: number, index: number) => {
      return (
        index === 0 ? <div style={{ textAlign: 'left' }}>{cellValue}</div> : cellValue
      )
    }
  },
  {
    field: 'leftValue',
    label: '左值',
    headerAlign: 'right',
    align: 'right'
  },
  {
    field: 'rightValue',
    label: '右值',
    headerAlign: 'right',
    align: 'right'
  },
  {
    field: 'diffValue',
    label: '差值',
    headerAlign: 'right',
    align: 'right',
    hidden:true
  },
]

const loading = ref(true)

let tableDataList = ref<TableData[]>([])
const getTableList = async () => {
  const { pkid, orgCode, dataDate } = props.currentRow;
  const res = await getCsckDataCheckDataApi({
    pkid,
    organCode: orgCode,
    dataDate,
  })
    .catch(() => { })
    .finally(() => {
      loading.value = false
    })
  if (res) {
    const searchParams = props.searchParams;
    if (searchParams.systemGroupCode) {
      if (searchParams.systemGroupCode == 'EAST-1104') {
        const columnLeftIndex = columns.findIndex(column => column.field === 'leftValue');
        if (columnLeftIndex !== -1) {
          columns[columnLeftIndex].label = '1104(左值)';
        }
        const columnRightIndex = columns.findIndex(column => column.field === 'rightValue');
        if (columnRightIndex !== -1) {
          columns[columnRightIndex].label = 'EAST(右值)';
        }
      }
      if (searchParams.systemGroupCode === 'EAST-CQCS') {
        const columnLeftIndex = columns.findIndex(column => column.field === 'leftValue');
        if (columnLeftIndex !== -1) {
          columns[columnLeftIndex].label = '客户风险(左值)';
        }
        const columnRightIndex = columns.findIndex(column => column.field === 'rightValue');
        if (columnRightIndex !== -1) {
          columns[columnRightIndex].label = 'EAST(右值)';
        }
      }
      if (searchParams.systemGroupCode === 'PBOC-PBOCD') {
        const columnLeftIndex = columns.findIndex(column => column.field === 'leftValue');
        if (columnLeftIndex !== -1) {
          columns[columnLeftIndex].label = '大集中(左值)';
        }
        const columnRightIndex = columns.findIndex(column => column.field === 'rightValue');
        if (columnRightIndex !== -1) {
          columns[columnRightIndex].label = '金融基础数据(右值)';
        }
      }
      if (searchParams.systemGroupCode === 'PBOCD-DIIS') {
        const columnLeftIndex = columns.findIndex(column => column.field === 'leftValue');
        if (columnLeftIndex !== -1) {
          columns[columnLeftIndex].label = '金融基础数据(左值)';
        }
        const columnRightIndex = columns.findIndex(column => column.field === 'rightValue');
        if (columnRightIndex !== -1) {
          columns[columnRightIndex].label = '存保系统(右值)';
        }
      }
      if (searchParams.systemGroupCode === 'PBOC-DIIS') {
        const columnLeftIndex = columns.findIndex(column => column.field === 'leftValue');
        if (columnLeftIndex !== -1) {
          columns[columnLeftIndex].label = '大集中(左值)';
        }
        const columnRightIndex = columns.findIndex(column => column.field === 'rightValue');
        if (columnRightIndex !== -1) {
          columns[columnRightIndex].label = '存保系统(右值)';
        }
      }
      if (searchParams.systemGroupCode === 'PBOC-1104') {
        const columnLeftIndex = columns.findIndex(column => column.field === 'leftValue');
        if (columnLeftIndex !== -1) {
          columns[columnLeftIndex].label = '大集中(左值)';
        }
        const columnRightIndex = columns.findIndex(column => column.field === 'rightValue');
        if (columnRightIndex !== -1) {
          columns[columnRightIndex].label = '1104(右值)';
        }
      }
      if (searchParams.systemGroupCode === '1104-CQCS') {
        const columnLeftIndex = columns.findIndex(column => column.field === 'leftValue');
        if (columnLeftIndex !== -1) {
          columns[columnLeftIndex].label = '1104(左值)';
        }
        const columnRightIndex = columns.findIndex(column => column.field === 'rightValue');
        if (columnRightIndex !== -1) {
          columns[columnRightIndex].label = '客户风险(右值)';
        }
      }
    }

    tableDataList.value = res?.body?.list
  }
}

getTableList()
</script>

<template>
  <div class="mb-4px">
    左侧规则描述：{{ props?.currentRow?.sourceRuleDesc }}
  </div>
  <div class="mb-8px">
    右侧规则描述：{{ props?.currentRow?.targetRuleDesc }}
  </div>
  <Table :columns="columns" :data="tableDataList" :loading="loading" :showAction="false" border />
</template>
