<!-- 交易商管理-开户管理-开户复审 -->
<template>
    <app-view>
        <template #header>
            <app-filter :options="filterOptons" />
        </template>
        <app-table :data="dataList" :columns="tableColumns" :loading="loading">
            <template #headerLeft>
                <app-operation :data-list="getActionButtons(['investor_user_rereview_batch'])"
                    @click="openComponent" />
            </template>
            <!-- 操作 -->
            <template #operate="{ row }">
                <app-operation size="small" :data-list="getActionButtons(['investor_user_rereview_audit'])"
                    @click="(code: string) => openComponent(code, row)" circle />
            </template>
            <template #footer>
                <app-pagination :total="total" v-model:page-size="pageSize" v-model:page-index="pageIndex"
                    @change="onSearch" />
            </template>
        </app-table>
        <component :is="componentMap.get(componentId)" v-bind="{ record, audit: true }" @closed="closeComponent"
            v-if="componentId" />
    </app-view>
</template>

<script lang="ts" setup>
import { shallowRef } from 'vue'
import { ElMessage } from 'element-plus'
import { formatDate } from '@/filters'
import { useEnum } from '@/hooks/enum'
import { useRequest } from '@/hooks/request'
import { useDataFilter } from '@/hooks/datatable'
import { useOperation } from '@/hooks/operation'
import { queryInvestor } from '@/services/api/investor'
import AppTable from '@pc/components/base/table/index.vue'
import AppFilter from '@pc/components/base/table-filter/index.vue'
import AppPagination from '@pc/components/base/pagination/index.vue'
import AppOperation from '@pc/components/base/operation/index.vue'
import { i18n } from '@/stores'

const { global: { t } } = i18n
// 开户方式
const openmodeEnum = useEnum('openmode')
// 开户状态
const userstateEnum = useEnum('investorOpenStatus')

const { filterOptons, getQueryParams } = useDataFilter<Investor.InvestorReq>()

const { componentMap, componentId, record, openComponent, closeComponent, getActionButtons } = useOperation<Investor.InvestorRsp>({
    onClose: () => onSearch()
})

const { dataList, total, pageSize, pageIndex, loading, run } = useRequest(queryInvestor, {
    params: {
        pageNum: 1,
        pageSize: 20,
        show: 'audit',
        userState: 4
    },
    onError: (err) => {
        ElMessage.error(err)
    }
})

const tableColumns = shallowRef<Model.TableColumn[]>([
    { field: 'userName', label: 'investor.user.review.userName' },
    { field: 'memberUserName', label: 'investor.user.review.memberUserName' },
    { field: 'areaName', label: 'investor.user.review.areaName' },
    { field: 'openMode', label: 'investor.user.review.openMode', formatValue: (val) => openmodeEnum.getEnumTypeName(val) },
    { field: 'userState', label: 'investor.user.review.userState', formatValue: (val) => userstateEnum.getEnumTypeName(val) },
    { field: 'createTime', label: 'investor.user.review.createTime', formatValue: (val) => formatDate(val) },
    { field: 'operate', label: 'common.operate', fixed: 'right' }
])

filterOptons.inputList = [
    { label: t('investor.user.review.areaCode'), keys: ['areaCode'] },
    { label: t('investor.user.review.userName'), keys: ['userName'] }
]

filterOptons.buttonList = [
    { label: t('operation.search'), className: 'el-button--primary', onClick: () => onSearch() },
    { label: t('operation.reset'), className: 'el-button--primary', onClick: () => onSearch(true) }
]

const onSearch = (clear = false) => {
    const qs = getQueryParams(clear)
    run(qs)
}
</script>