//let host = 'https://biformall.youlane.cn/B'
//let host = 'http://17168c59.ngrok.io/B'
let host = ''

const postRequest = (url, token, message, postData, doSuccess, doFail) => {
  let body = { ...postData };
  if (message != "") {
    wx.showLoading({
      title: message,
    })
  }
  wx.request({
    //项目的真正接口，通过字符串拼接方式实现
    url: host + url,
    header: {
      "content-type": "application/json;charset=UTF-8",
      "token": token
    },
    data: body,
    method: 'POST',
    success: function (res) {
      //参数值为res.data,直接将返回的数据传入
      if (message != "") {
        wx.hideLoading()
      };
      doSuccess(res.data);
    },
    fail: function (res) {
      if (message != "") {
        wx.hideLoading()
      };
      wx.showToast({
        title: '网络错误',
        icon:"none"
      })
    },
  })
}
const getRequest = (url, token, message, getData, doSuccess, doFail) => {
  let body = { ...getData };
  if (message != "") {
    wx.showLoading({
      title: message,
    })
  }
  wx.request({
    url: host + url,
    header: {
      "content-type": "application/json;charset=UTF-8",
      "token": token
    },
    data: body,
    method: 'GET',
    success: function (res) {
      if (message != "") {
        wx.hideLoading()
      };
      doSuccess(res.data);
    },
    fail: function (res) {
      if (message != "") {
        wx.hideLoading()
      };
      wx.showToast({
        title: '网络错误',
        icon:"none"
      })
    },
  })
}
module.exports = {
  postRequest: postRequest,
  getRequest: getRequest
}