<!-- 会员机构管理-机构管理-机构资料管理-资金账户-签解约流水 -->
<template>
    <app-drawer :title="t('member.institution.user.account.signstatement.title')" width="1200" v-model:show="show">
        <app-table :data="dataList" :columns="tableColumns">
            <template #headerLeft>
                <span>{{ t('member.institution.user.account.signstatement.accountid') }}{{ record.accountId }}</span>
            </template>
            <template #headerRight>
                <app-filter :option="filterOption" />
            </template>
            <template #footer>
                <app-pagination :total="total" v-model:page-size="pageSize" v-model:page-index="pageIndex"
                    @change="onSearch" />
            </template>
        </app-table>
        <template #footer>
            <el-button @click="onCancel">{{ t('operation.close') }}</el-button>
        </template>
    </app-drawer>
</template>

<script lang="ts" setup>
import { shallowRef, PropType } from 'vue'
import { ElMessage } from 'element-plus'
import { useRequest } from '@/hooks/request'
import { useDataFilter } from '@/hooks/datatable-v2'
import { querySignlog } from '@/services/api/member'
import AppDrawer from '@pc/components/base/drawer/index.vue'
import AppTable from '@pc/components/base/table/index.vue'
import AppFilter from '@pc/components/base/table-filter-v2/index.vue'
import AppPagination from '@pc/components/base/pagination/index.vue'
import { i18n } from '@/stores'

const props = defineProps({
    record: {
        type: Object as PropType<Member.OrganTaaccountRsp>,
        required: true
    }
})

const { global: { t } } = i18n

const show = shallowRef(true)

const { dataList, total, pageSize, pageIndex, run } = useRequest(querySignlog, {
    params: {
        accountId: props.record.accountId,
        pageNum: 1,
        pageSize: 20,
        querytype: 0
    },
    onError: (err) => {
        ElMessage.error(err)
    }
})

const tableColumns = shallowRef<Model.TableColumn[]>([
    { field: 'accountcode', label: 'member.institution.user.account.signstatement.accountcode' },
    { field: 'cusbankid', label: 'member.institution.user.account.signstatement.cusbankid' },
    { field: 'signtype', label: 'member.institution.user.account.signstatement.signtype' },
    { field: 'dealstatus', label: 'member.institution.user.account.signstatement.dealstatus' },
    { field: 'createtime', label: 'member.institution.user.account.signstatement.createtime' },
    { field: 'bankaccountno', label: 'member.institution.user.account.signstatement.bankaccountno' },
    { field: 'currency', label: 'member.institution.user.account.signstatement.currency' }
])

const { filterOption, getQueryParams } = useDataFilter<Member.SignlogReq>({
    filters: [
        {
            field: 'querytype',
            label: t('member.institution.user.account.signstatement.querytype'),
            value: 0,
            options: () => [
                { label: t('common.current'), value: 0 },
                { label: t('common.history'), value: 1 },
            ],
        }
    ],
    buttons: [
        { label: t('operation.search'), className: 'el-button--primary', onClick: () => onSearch() },
    ]
})

const onSearch = () => {
    const qs = getQueryParams()
    run(qs)
}

const onCancel = () => {
    show.value = false
}
</script>