<script setup>
import Filter from "../../../../components/Filter/index.vue";
import {computed, reactive} from "vue";
import useTableQuery from "../../../../hooks/useTableQuery.js";
import Api from "../../../../api/index.js";

const columns = [
    {
        title: '动账日期',
        dataIndex: 'createtime1'
    },
    {
        title: '动账时间',
        dataIndex: 'createtime2'
    },
    {
        title: '交易流水号',
        dataIndex: 'sn'
    },
    {
        title: '动账渠道',
        dataIndex: 'platform_name'
    },
    {
        title: '状态',
        dataIndex: 'status',
        slotName: 'status'
    },
    {
        title: '动账用途',
        dataIndex: 'purpose_name'
    },
    {
        title: '动账金额(元)',
        dataIndex: 'money'
    },
    {
        title: '付款人账户',
        dataIndex: 'account'
    },
    {
        title: '收款人账户',
        dataIndex: 'receive'
    },
    {
        title: '关联任务ID',
        dataIndex: 'task_id'
    },
    {
        title: '子任务ID',
        dataIndex: 'task_children_id'
    },
    {
        title: '钱包余额(元) ',
        dataIndex: 'business_money'
    },
    {
        title: '任务款余额(元)',
        dataIndex: 'business_coin'
    },
    {
        title: '资产合计(元)',
        dataIndex: 'sum',
        slotName: 'sum'
    },
];
const FilterConfig = computed(() => [
    {
        key: 'platform',
        type: 'select',
        label: '动账渠道',
        placeholder: '全部',
        api: async () => ({
            data: [
                {
                    name: '全部',
                    id: 0,
                },
                {
                    name: '支付宝',
                    id: 1,
                },
                {
                    name: '/',
                    id: 2,
                },
            ]
        })
    },
    {
        key: 'purpose',
        type: 'select',
        label: '动账用途',
        placeholder: '全部',
        api: async () => Api.merchant.getPurpose()
    },
    {
        key: 'task_id',
        type: 'input',
        label: '关联ID',
        placeholder: '请输入任务ID',
    },
    {
        key: 'rangeTime',
        start: 'start_time',
        end: 'end_time',
        type: 'datetime',
        label: '动账日期',
    },
]);
const vo = reactive({
    page: '',
    rows: [],
    total: 0,
});
const po = reactive({
    wd: null,
});

const {loading, pagination, initFetchData} = useTableQuery({
    parameter: po,
    api: Api.merchant.getBusinessMoneyLog,
    callback: (data) => {
        Object.assign(vo, data);
        console.log(vo);
    }
});
</script>

<template>
    <!-- 动账明细 -->
    <div class="mb-[20px]">
        <a-breadcrumb
            :routes="[{path: '/home/my-wallet', label: '我的钱包'}, {path: '/', label: '动账明细'},]">
        </a-breadcrumb>
    </div>

    <div class="mock-card mb-[20px]">
        <Filter
            title="查询动账明细"
            v-model:from="po"
            :config="FilterConfig"
            @search="initFetchData">
        </Filter>
    </div>

    <a-card>
        <div class="title">动账明细</div>

        <a-table
            @page-change="(e) => pagination.current = e"
            :pagination="pagination"
            :data="vo.rows"
            :loading="loading"
            class="flex-grow"
            :columns="columns">
            <template v-slot:status="{record}">
                <div v-if="record.status===1" class="status success">成功</div>
                <div v-if="record.status===0" class="status warning">失败</div>
            </template>
            <template v-slot:sum="{record}">
                {{ (record.business_money + record.business_coin).toFixed(2) }}
            </template>
        </a-table>
    </a-card>
</template>

<style lang="scss" scoped>
.title {
    color: rgb(29, 33, 41);
    font-size: 16px;
    font-weight: 400;
    line-height: 24px;
    letter-spacing: 0;
    margin-bottom: 20px;
}

.status {
    @apply flex whitespace-nowrap items-center gap-[6px];
    &::before {
        content: '';
        @apply block size-[6px] rounded-[50%];
    }
}

.success {
    &::before {
        @apply bg-[rgb(var(--green-6))];
    }
}

.danger {
    &::before {
        @apply bg-[rgb(var(--red-6))];
    }
}

.warning {
    &::before {
        @apply bg-[rgb(var(--orange-6))];
    }
}

.primary {
    &::before {
        @apply bg-[rgb(var(--arcoblue-6))];
    }
}
</style>
