// const baseUrl = "https://test.buwanjia.com/bwj/rest/webclientrest";
const baseUrl = "https://www.buwanjia.com/bwj/rest/webclientrest";
class HTTP {
    request({
        url,
        data = {},
        method = "POST",
        header = {
            'content-type': 'application/json'
        },
        loading = true
    }) {
        return new Promise((resolve, reject) => {
            this._request(url, resolve, reject, data, method, header, loading);
        })
    }
    _request(url, resolve, reject, data, method, header, loading) {
        if (loading) wx.showLoading({
            title: '加载中...',
            mask: true
        })
        wx.request({
            url: baseUrl + url,
            data: data,
            method: method,
            header: header,
            timeout: 20000,
            success: (res) => {
                resolve(res.data);
                if (loading) wx.hideLoading()
            },
            fial: (err) => {
                reject(err);
                if (loading) wx.hideLoading()
            },
            complete: (res) => {
                if (res.errMsg != 'request:ok') {
                    wx.hideLoading()
                    wx.showToast({
                        title: '网络异常，请稍后再试',
                        icon: "none"
                    })
                }
            }
        })
    }
}
export {
    HTTP
}