<template>
    <view>
        <view class="header">
            <view class="searchBox" :style="{ height: localHeight + 'px', paddingTop: top + 'px' }">
                <view class="searchBox_left" @click="back">
                    <u-icon name="arrow-left" size="20px" color="#000"></u-icon>
                </view>
                <view class="searchBox_mid">{{ topVal }}</view>
            </view>
        </view>

        <!-- 余额显示部分 -->
        <view class="balance-container">
            <view class="balance-content">
                <view>
                    <view class="balance-title">{{ topVal }}（元）</view>
                    <view class="balance-amount">{{ balance }}</view>
                    <view class="balance-icon">
                        <image src="http://localhost:8080/user_wallet2.png" mode="widthFix" />
                    </view>
                </view>
            </view>
        </view>

        <!-- 余额变动记录 -->
        <view class="records-container">
            <view class="records-title" v-if="topVal == '待收物业公积金'">物业费公积金变动记录</view>
            <view class="records-list">
                <view class="record-item" v-for="(record, index) in records" :key="index">
                    <view class="record-info">
                        <view class="record-name">{{ record.name }}</view>
                        <view class="record-time">{{ record.time }}</view>
                    </view>
                    <view class="record-amount">
                        <view class="record-balance" v-if="topVal == '应收'">{{ record.amount.startsWith('+') ? '收款' :
                            '退款' }}</view>
                        <view class="record-balance" v-else-if="topVal == '待收物业公积金'">待收</view>
                        <view class="record-balance" v-else-if="topVal == '手续费'">手续费</view>
                        <view>
                            <text :class="['amount-sign', record.amount.startsWith('+') ? 'positive' : 'negative']">{{
                                record.amount.startsWith('+') ? '+' : '-' }}</text>
                            <text :class="['amount-value', record.amount.startsWith('+') ? 'positive' : 'negative']">¥{{
                                record.amount.replace(/[+-]/, '') }}</text>
                        </view>
                    </view>
                </view>
            </view>
        </view>
    </view>
</template>
<script>
import { menuButtonInfo, NavgateTo, picUrl, request } from '../../../utils/index';
export default {
    data() {
        return {
            top: "",
            localHeight: "",
            topVal: "",
            balance: "160.80",
            records: [
                {
                    name: "退单-1312312317972",
                    time: "2025-08-12 13:00:00",
                    amount: "-1808.5",
                    remain: "286.79"
                },
                {
                    name: "退单-1312312317972",
                    time: "2025-08-12 13:00:00",
                    amount: "-1808.5",
                    remain: "286.79"
                }
            ]
        }
    },
    onLoad(options) {
        const meun = menuButtonInfo();
        this.top = meun.top;
        this.localHeight = meun.height;
        this.getTypeName(options.type);
        this.getWalletInfo();
    },
    methods: {
        back() {
            uni.navigateBack({
                delta: 1
            });
        },
        // 获取钱包类型名称
        getTypeName(type) {
            const numType = parseInt(type);
            switch (numType) {
                case 1:
                    this.topVal = '应收';
                    break;
                case 2:
                    this.topVal = '已收';
                    break;
                case 3:
                    this.topVal = '待收物业公积金';
                    break;
                case 4:
                    this.topVal = '手续费';
                    break;
            }
        },
        // 获取钱包信息
        getWalletInfo() {
            // 这里应该是真实的接口调用
            // 暂时使用模拟数据
            console.log('获取钱包信息');
            // 实际项目中应该调用接口获取余额和交易记录
            // request('/api/wallet/info', 'GET').then(res => {
            //     if (res.code === 0) {
            //         this.balance = res.data.balance;
            //         this.records = res.data.records;
            //     }
            // })
        }
    }
}
</script>
<style>
@import url("./index.css");
</style>