// pages/withdraw/withdraw.js
import { createPage, request } from '../../utils/base-page.js';
import PopupService from '../../services/popupService.js';

const app = getApp();

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

    onLoad(options) {
        this.setData({
            pageOptions: options || {}
        });
        this.fetchPageMode();
    },

    onShow() {
        this.registerNotificationComponent();
        PopupService.checkAndShow(this, 'tixian');
    },

    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);
                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();
    },

    stopPropagation() {}
}))
