var baseUrl = ''
if(process.env.NODE_ENV === 'development'){//开发环境
  // baseUrl= 'http://pay.tuyoyoo.com/'
  baseUrl='http://192.168.0.213:7888/'
}else{
  baseUrl= 'https://manager.pangdly.com/'
}
const request = (url = '', data = {},showLoad) => {
  data.reqId = new Date().getTime() //获取时间戳
  let show=showLoad||false
  return new Promise((resolve, reject) => {
    if(!show){
      uni.showLoading({
        title:'加载中',
        mask:true
      })
    }
    uni.request({
      method: 'POST',
      url: baseUrl + url+'?token='+uni.getStorageSync('token'),
      data:data,
      dataType: 'json',
      success(res) {
        uni.hideLoading()
        if(res.statusCode=='200'){
          //请求成功，状态成功
          resolve(res.data)
        }else{
          //请求成功，状态不对
          reject(res)
          uni.showToast({
					  title: res.message,
					  icon: 'none',
            duration:4000
          })
        }
      },
      fail(err) {
        //请求超时，没有网络等
        uni.hideLoading()
        uni.getNetworkType({//首次判断网络状态
          success: (res) => {
            let networkType = res.networkType
            if (networkType === 'none') {//none是没有网络
              uni.showToast({
							  title:'网络断开',
							  icon: 'none',
							  duration:4000
              })
            }else{
              uni.showToast({
							  title:'请求超时',
							  icon: 'none',
							  duration:4000
              })
              reject(err)
            }
          }
        })
      }
    })
  })
}
export default request