<script setup>
import Recharge from "./components/Recharge.vue";
import Reflect from "./components/Reflect.vue";
import {onMounted, reactive, ref} from "vue";
import useTableQuery from "../../../../hooks/useTableQuery.js";
import Api from "../../../../api/index.js";
import WithdrawAgain from "./components/WithdrawAgain.vue";

const activeKey = ref('Recharge');
const columns = [
    {
        title: '充值日期',
        dataIndex: 'rechargetime'
    },
    {
        title: '充值时间',
        dataIndex: 'rechargeday'
    },
    {
        title: '交易流水号',
        dataIndex: 'order_sn'
    },
    {
        title: '动账渠道',
        dataIndex: 'platform_name'
    },
    {
        title: '动账用途',
        dataIndex: 'dzyt',
        slotName: 'dzyt'
    },
    {
        title: '充值金额(元)',
        dataIndex: 'money'
    },
    {
        title: '付款人账户',
        dataIndex: 'money'
    },
    {
        title: '收款人账户',
        dataIndex: 'skrzh',
        slotName: 'skrzh'
    },
];
const columns2 = [
    {
        title: '提现日期',
        dataIndex: 'createday'
    },
    {
        title: '提现时间',
        dataIndex: 'createhour'
    },
    {
        title: '交易流水号',
        dataIndex: 'uid'
    },
    {
        title: '状态',
        dataIndex: 'status',
        slotName: 'status'
    },
    {
        title: '动账渠道',
        dataIndex: 'type_text'
    },
    {
        title: '动账用途',
        dataIndex: 'dzyt',
        slotName: 'dzyt'
    },
    {
        title: '提现金额(元)',
        dataIndex: 'money',
        slotName: 'money',
    },
    {
        title: '付款人账户',
        dataIndex: 'fkrzh',
        slotName: 'fkrzh',
    },
    {
        title: '收款人账户',
        dataIndex: 'account'
    }
];

const vo = reactive({
    page: '',
    rows: [],
    total: 0,
});
const po = reactive({
    wd: null,
});
const vo2 = reactive({
    page: '',
    rows: [],
    total: 0,
});
const po2 = reactive({
    wd: null,
});

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

const {
    loading: loading2,
    pagination: pagination2,
    initFetchData: initFetchData2,
    fetchData: fetchData2
} = useTableQuery({
    parameter: po2,
    api: Api.merchant.getWithdrawalLog,
    callback: (data) => {
        Object.assign(vo2, data);
        console.log(vo2);
    }
});

const businessInfo = reactive({
    money: 0,
    coin: 0,
    recharge: 0,
    withdrawal: 0,
    consume: 0,
});
const getData = async () => {
    const {data} = await Api.merchant.getBusinessInfo();
    Object.assign(businessInfo, data);
}
onMounted(() => {
    getData();
})
</script>

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

    <div class="flex-grow flex flex-col gap-[20px]">
        <div class="mock-card grid grid-cols-5 gap-[20px]" id="statistic-card">
            <div class="bg-[rgb(var(--arcoblue-1))] p-[20px]">
                <a-statistic title="钱包余额(元)" :value="businessInfo.money" :precision="2" :value-from="0"
                             animation></a-statistic>
            </div>
            <div class="bg-[rgb(var(--arcoblue-1))] p-[20px]">
                <a-statistic title="任务款余额(元)" :value="businessInfo.coin" :precision="2" :value-from="0"
                             animation></a-statistic>
            </div>
            <div class="bg-[rgb(var(--arcoblue-1))] p-[20px]">
                <a-statistic title="累计充值(元)" :value="businessInfo.recharge" :precision="2" :value-from="0"
                             animation></a-statistic>
            </div>
            <div class="bg-[rgb(var(--arcoblue-1))] p-[20px]">
                <a-statistic title="累计消耗(元)" :value="businessInfo.consume" :precision="2" :value-from="0"
                             animation></a-statistic>
            </div>
            <div class="bg-[rgb(var(--arcoblue-1))] p-[20px]">
                <a-statistic title="累计提现(元)" :value="businessInfo.withdrawal" :precision="2" :value-from="0"
                             animation></a-statistic>
            </div>
        </div>

        <a-card>
            <a-tabs type="rounded" v-model:active-key="activeKey">
                <a-tab-pane key="Recharge" title="我的充值">
                    <Recharge></Recharge>
                </a-tab-pane>
                <a-tab-pane key="Reflect" title="我的提现">
                    <Reflect :businessInfo="businessInfo" @success="getData"></Reflect>
                </a-tab-pane>
            </a-tabs>
        </a-card>

        <div class="mock-card" v-if="activeKey==='Recharge'">
            <div class="title">充值记录</div>
            <a-table
                @page-change="(e) => pagination.current = e"
                :pagination="pagination"
                :data="vo.rows"
                :loading="loading"
                :columns="columns">
                <template v-slot:dzyt>
                    余额充值
                </template>
                <template v-slot:skrzh>
                    平台账户
                </template>
            </a-table>
        </div>
        <div class="mock-card" v-else>
            <div class="title">提现记录</div>
            <a-table
                @page-change="(e) => pagination2.current = e"
                :pagination="pagination2"
                :data="vo2.rows"
                :loading="loading2"
                :columns="columns2">
                <template v-slot:status="{record}">
                    <div v-if="record.status===2" class="status success">{{ record.status_text }}</div>
                    <div v-if="record.status===0" class="status primary">{{ record.status_text }}</div>
                    <div v-if="record.status===1" class="status warning">{{ record.status_text }}</div>
                    <div v-if="record.status===-1" class="status danger">{{ record.status_text }}
                        <WithdrawAgain @success="fetchData2" :id="record.id"></WithdrawAgain>
                    </div>
                </template>
                <template v-slot:dzyt>
                    余额提现
                </template>
                <template v-slot:money="{record}">
                    -{{ record.money }}
                </template>
                <template v-slot:fkrzh>
                    我的钱包
                </template>
            </a-table>
        </div>
    </div>
</template>

<style lang="scss" scoped>
#statistic-card {
    :deep(.arco-statistic-value) {
        color: rgb(var(--arcoblue-6));
    }
}

.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>
