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

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