<!-- 结算管理-分润付款确认-详情-详情 -->
<template>
    <app-drawer :title="t('settlement.profitsharepay.details.details.title')" width="800" v-model:show="show">
        <app-table-details :data="data" :label-width="160" :cell-props="detailProps" :column="2" />
        <template #footer>
            <el-button @click="onCancel(false)">{{ t('operation.close') }}</el-button>
        </template>
    </app-drawer>
</template>

<script lang="ts" setup>
import { shallowRef, PropType } from 'vue'
import { ElMessage } from 'element-plus'
import { formatDate, handleNumberValue } from '@/filters'
import { useEnum } from '@/hooks/enum'
import { useRequest } from '@/hooks/request'
import { settlementDetail } from '@/services/api/settlement'
import { CellProp } from '@pc/components/base/table-details/types'
import AppDrawer from '@pc/components/base/drawer/index.vue'
import AppTableDetails from '@pc/components/base/table-details/index.vue'
import { i18n } from '@/stores'

const props = defineProps({
    selectedItem: {
        type: Object as PropType<Model.ViewTradingDayRsp>,
        required: true
    }
})

const roleTypeEnum = useEnum('roleType') // 分润机构角色
const ePayFlagEnum = useEnum('ePayFlag') // 支付状态

const { global: { t } } = i18n
const show = shallowRef(true)
const refresh = shallowRef(false)

const { data } = useRequest(settlementDetail, {
    params: {
        areaid: props.selectedItem.areaid,
        areatype: props.selectedItem.areatype,
        tradedate: props.selectedItem.tradedate
    },
    onError: (err) => {
        ElMessage.error(err)
    }
})

const detailProps: CellProp[] = [
    { prop: 'tradedate', label: 'settlement.profitsharepay.details.details.tradedate' },
    { prop: 'areaid', label: 'settlement.profitsharepay.details.details.areaid' },
    { prop: 'areatype', label: 'settlement.profitsharepay.details.details.areatype', formatValue: (val) => roleTypeEnum.getEnumTypeName(val) },
    { prop: 'totalcount', label: 'settlement.profitsharepay.details.details.totalcount' },
    { prop: 'totalfee', label: 'settlement.profitsharepay.details.details.totalfee' },
    { prop: 'divideamount', label: 'settlement.profitsharepay.details.details.divideamount' },
    { prop: 'paystatus', label: 'settlement.profitsharepay.details.details.paystatus', formatValue: (val) => ePayFlagEnum.getEnumTypeName(val) },
    { prop: 'payerid', label: 'settlement.profitsharepay.details.details.payerid', formatValue: (val) => handleNumberValue(val) },
    { prop: 'paytime', label: 'settlement.profitsharepay.details.details.paytime', formatValue: (val) => formatDate(val) },
    { prop: 'remark', label: 'settlement.profitsharepay.details.details.remark' },
]

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