module.exports = {
    HttpRequst: HttpRequst,
}
const baseUrl = "https://xcx.885505.com/api/";

 function HttpRequst(url, params, method, callBack, fail, loading) {
    if (loading == true) {
        wx.showToast({
            title: '加载中...',
            icon: 'loading'
        })
    }
   
   var token = wx.getStorageSync('access_token');
     var header = {
        'content-type': 'application/x-www-form-urlencoded',
        'Authorization': 'Bearer ' + token.access_token
     };

    wx.request({
        url: baseUrl + url,
        data: params,
        dataType: "json",
        header: header,
        method: method,
        success: function (res) {
            if (loading == true) {
                wx.hideToast();
            }

            // callBack(res.data);
            callBack(res);
        },
        complete: function () {
            if (loading == true) {
                wx.hideToast();
            } 
            wx.stopPullDownRefresh();//停止下来刷新
        },
        fail:function(res){
            if (loading == true) {
                wx.hideToast();
            }
            if ( typeof(fail) == "function" ){
                fail(res);
            }            
        }
    })
}

