<!-- 结算管理-分润付款确认 -->
<template>
    <app-view>
        <template #header>
            <el-form ref="formRef" class="el-form--filter">
                <el-form-item :label="t('settlement.profitsharepay.date')" prop="date">
                    <el-date-picker v-model="queryParams.tradedate" :placeholder="t('common.pleasechoice')" value-format="YYYYMMDD" />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="onSearch()">{{ t('operation.search') }}</el-button>
                    <el-button type="primary" @click="queryParams.tradedate = ''">{{ t('operation.reset') }}</el-button>
                </el-form-item>
            </el-form>
        </template>
        <app-table :data="dataList" :columns="tableColumns" :loading="loading">
            <template #headerLeft>
                <app-operation :data-list="getActionButtons(['settlement_profitsharepay_export'])"
                    @click="openComponent" />
            </template>
            <!-- 操作 -->
            <template #operate="{ row }">
                <app-operation size="small" :data-list="getActionButtons(['settlement_profitsharepay_details'])"
                    @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, queryParams }" @closed="closeComponent"
            v-if="componentId" />
    </app-view>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import { ElMessage } from 'element-plus'
import { useRequest } from '@/hooks/request'
import { sharedayquery } from '@/services/api/settlement'
import { useOperation } from '@/hooks/operation'
import AppTable from '@pc/components/base/table/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 queryParams = ref<Model.ShareDayQueryReq>({})

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

const { dataList, total, pageSize, pageIndex, loading, run } = useRequest(sharedayquery, {
    params: {
        pageNum: 1,
        pageSize: 20,
    },
    onError: (err) => {
        ElMessage.error(err)
    }
})

const tableColumns = ref<Model.TableColumn[]>([
    { field: 'tradedate', label: 'settlement.profitsharepay.tradedate' },
    { field: 'totalcount', label: 'settlement.profitsharepay.totalcount' },
    { field: 'divideamount', label: 'settlement.profitsharepay.divideamount' },
    { field: 'totalpay', label: 'settlement.profitsharepay.totalpay' },
    { field: 'operate', label: 'common.operate', fixed: 'right' }
])

const onSearch = () => {
    run(queryParams.value)
}
</script>