// pages/withdraw/withdraw-records.js — 提现记录独立页
import { createPage, request } from '../../utils/base-page.js';

Page(createPage({
    data: {
        pageMode: 0,
        loadError: false,
    },

    onLoad() {
        this.fetchPageMode();
    },

    async fetchPageMode() {
        try {
            const res = await request({
                url: '/peizhi/hqtxzsym',
                method: 'POST',
            });
            if (res.statusCode === 200 && res.data && res.data.code === 0) {
                const mode = parseInt(res.data.data.mode, 10);
                this.setData({
                    pageMode: (mode === 1 || mode === 2) ? mode : 1,
                    loadError: false,
                });
            } else {
                this.setData({ pageMode: 1, loadError: false });
            }
        } catch (err) {
            console.error('获取展示模式失败:', err);
            this.setData({ loadError: true });
        }
    },

    retryFetch() {
        this.setData({ loadError: false, pageMode: 0 });
        this.fetchPageMode();
    },

    onPullDownRefresh() {
        const mode = this.data.pageMode;
        const compId = mode === 1 ? '#record-mode2' : mode === 2 ? '#record-mode1' : null;
        if (!compId) {
            wx.stopPullDownRefresh();
            return;
        }
        const comp = this.selectComponent(compId);
        const p = comp && comp.onPullDownRefresh ? comp.onPullDownRefresh() : Promise.resolve();
        Promise.resolve(p).finally(() => wx.stopPullDownRefresh());
    },
}));
