<script setup lang="tsx">
// 可疑案例处理
import { reactive, ref, unref } from 'vue'
import {
  getTransactionInfoListApi,
  delTransactionInfoListApi,
} from '@/api/amld/TransactionInfo/TransactionInfo'
import { TableData } from '@/api/amld/SuspiciousCaseDeal/SuspiciousCaseDeal/types'
import { useTable } from '@/hooks/web/useTable'
import { Table, TableColumn } from '@/components/Table'
import { ElButton, ElLink, ElLoading, ElPopconfirm, ElMessage } from 'element-plus'
import { Search } from '@/components/Search'
import { FormSchema } from '@/components/Form'
import { ContentWrap } from '@/components/ContentWrap'
import { useRouter } from 'vue-router'
import { useI18n } from '@/hooks/web/useI18n'
import { getWidth } from '@/utils';
import { propTypes } from '@/utils/propTypes'
const { push } = useRouter()
const { t } = useI18n()

const props = defineProps({  
  searchStatus:propTypes.bool.def(true),//搜索的搜索框是否显示
  tableColumns:propTypes.array.def([]),
  dataList:propTypes.array.def([]),
  SearchSchema:propTypes.array.def([]),
});  

let systemUse = reactive({
  SearchSchema:props.SearchSchema,

})

const ids = ref<string[]>([])
const searchParams = ref({})
const { tableRegister, tableState, tableMethods } = useTable({
  fetchDataApi: async () => {
    const { currentPage, pageSize } = tableState
    const res = await getTransactionInfoListApi({
      pageIndex: unref(currentPage),
      pageSize: unref(pageSize),
      ...unref(searchParams)
    })
    return {
      list: res.body.list,
      total: res.body.total
    }
  },
  fetchDelApi: async () => {
    const res = await delTransactionInfoListApi(unref(ids));
    return !!res;
  },
})
const { loading, dataList, total, currentPage, pageSize } = tableState
const { getList, getElTableExpose, delList, refresh } = tableMethods

// const searchSchema = reactive<FormSchema[]>([
//   {
//     field: 'attribute10',
//     label: '校验状态',
//     componentProps: {},
//     component: 'Select'
//   }
// ])



const tableColumns = reactive<TableColumn[]>([
  {
    field: 'selection',
    type: 'selection',
    fixed: true
  },
  {
    field: 'custCode',
    label: '客户号'
  },
  {
    field: 'custName',
    label: '客户名称'
  },
  {
    field: 'tranOrganname',
    label: '交易机构'
  },
  {
    field: 'tranAcct',
    label: '交易账户'
  },
  {
    field: 'tranType',
    label: '交易方式'
  },
  {
    field: 'tranTime',
    label: '交易时间'
  },
  {
    field: 'currencyCode',
    label: '币种'
  },
  {
    field: 'amount',
    label: '交易金额'
  },
  {
    field: 'sendcode',
    label: '资金收付标志'
  },
  {
    field: 'oppOrganname',
    label: '对方机构'
  },
  {
    field: 'oppName',
    label: '对手姓名'
  },
  {
    field: 'oppAcctt',
    label: '交易对手账号'
  },
  {
    field: 'attribute1',
    label: '校验状态'
  },
  {
    field: 'oplasttime',
    label: '操作人'
  },
  {
    field: 'opuser',
    label: '操作时间'
  },
  {
    field: 'action',
    label: t('tableDemo.action'),
    width: 160,
    fixed: 'right',
    slots: {
      default: (data: any) => {
        return (
          <>
            <ElLink type="primary" underline={false} onClick={() => action("/caseManageT/transicationInfoAddRecord",data.row, 'edit')}>
              {t('tableDemo.edit')}
            </ElLink>
            <ElPopconfirm
              title={t('common.delTableMsg')}
              width={200}
              v-slots={{
                reference: () => {
                  return (
                    <>
                      <ElLink type="primary" underline={false}>
                        {t('tableDemo.del')}
                      </ElLink>
                    </>
                  )
                }
              }}
              onConfirm={() => delData(data.row)}
            ></ElPopconfirm>
            <ElLink type="primary" underline={false} onClick={() => action("/caseManageT/transicationInfoAddRecord",data.row, 'detail')}>
              {t('tableDemo.detail')}
            </ElLink>
          </>
        )
      }
    }
  }
].map(item => ({ minWidth: item.label ? getWidth(item.label) : 120, ...item }) as TableColumn))


/**单行查询**/
const action = async (path: string, row: TableData, type: string) => {
  push(path);

}
const disabled = ref(true)

const onSelectionChange = (selection: TableData[]) => {
  disabled.value = selection.length === 0
}

const setSearchParams = (data: any) => {
  searchParams.value = data
  getList()
}
//  添加流水
const AddFlowWater = ()=>{

}
//明细下载
const downLoadDetail = () =>{

}
//批量校验检查
const batchCheck = ()=>{

}



</script>

<template>
  <ContentWrap>
    <Search :schema="systemUse.SearchSchema" @reset="setSearchParams" @search="setSearchParams" v-if="props.searchStatus" />
    <Table
      :columns="props.tableColumns"
      v-model:pageSize="pageSize"
      v-model:currentPage="currentPage"
      default-expand-all
      node-key="pkid"
      :data="props.dataList"
      :loading="loading"
      :pagination="{
        total
      }"
      @selection-change="onSelectionChange"
      @register="tableRegister"
      @refresh="refresh"
    >
      <!-- <template #buttons v-if="props.searchStatus">
        <ElButton type="primary" @click="AddFlowWater">添加流水</ElButton>
        <ElButton type="primary" @click="downLoadDetail">明细下载</ElButton>
        <ElButton type="primary" @click="batchCheck">批量校验检查</ElButton>
      </template> -->
    </Table>
  </ContentWrap>
</template>
   