let _Http = getApp().globalData.http
Page({
    data: {
        verification: false,
        password: "",
        logins: []
    },
    onLoad(options) {
        if (_Http.ENV != 'develop') {
            this.setData({
                verification: true
            })
        } else {
            this.init();
        }
        this.setData({
            logins: wx.getStorageSync('logins') || []
        })
    },
    init() {
        this.setData({
            runtimeEnvironment: _Http.ENV == 'develop' ? '开发环境' : '生产环境',
            "baseUrl": _Http.baseUrl,
            urls: _Http.urls,
            verification: false
        })
    },
    onInput(e) {
        this.setData({
            password: e.detail
        })
    },
    enterInto() {
        if (this.data.password != 'jxys@12345') return wx.showToast({
            title: '密码错误',
            icon: "none"
        })
        this.init()
    },
    onChange({
        detail
    }) {
        console.log(detail)
        let that = this;
        wx.showModal({
            title: getApp().globalData.Language.getMapText('提示'),
            content: `是否确定将服务地址修改为“${detail}”?`,
            cancelText: getApp().globalData.Language.getMapText('取消'),
            confirmText: getApp().globalData.Language.getMapText('确定'),
            complete: (res) => {
                if (res.cancel) that.setData({
                    baseUrl: that.data.baseUrl
                })
                if (res.confirm) {
                    that.setData({
                        baseUrl: detail
                    })
                    _Http.baseUrl = detail;
                    wx.showToast({
                        title: '修改成功',
                    })
                }
            }
        })
    },
    quickLogin(e) {
        let {
            item
        } = e.currentTarget.dataset, page = getCurrentPages()[0].selectComponent("#login"), that = this;
        if (item.baseUrl != _Http.baseUrl) {
            wx.showModal({
                title: '提示',
                content: `是否确定将服务地址修改为“${item.baseUrl}”?`,
                cancelText: "取消",
                confirmText: "确定登录",
                complete: (res) => {
                    if (res.confirm) {
                        that.setData({
                            baseUrl: item.baseUrl
                        })
                        _Http.baseUrl = item.baseUrl;
                        page.setData({
                            ...item
                        })
                        page.allowOrNot();
                        page.handleLogin();
                    }
                }
            })

        } else {
            page.setData({
                ...item
            })
            page.allowOrNot();
            page.handleLogin();
        }
    }
})