class simpleReq {
    constructor() {
     this._baseUrl = 'https://xzjl-api.windymuse.cn';
    }
    
    /**
     * GET类型的网络请求
     */
    getRequest(url, data) {
     return this.requestAll(url, data, 'GET')
    }
    
    /**
     * DELETE类型的网络请求
     */
    deleteRequest(url, data) {
     return this.requestAll(url, data, 'DELETE')
    }
    
    /**
     * PUT类型的网络请求
     */
    putRequest(url, data) {
     return this.requestAll(url, data, 'PUT')
    }
    
    /**
     * POST类型的网络请求
     */
    postRequest(url, data) {
     return this.requestAll(url, data, 'POST')
    }
    
    /**
     * 网络请求
     */
    requestAll(url, data, method) {
     return new Promise((resolve, reject) => {
      wx.request({
       url: this._baseUrl + url,
       data: data,
       method: method,
       success: (res => {
        if (res.statusCode === 200) {
         //200: 服务端业务处理正常结束
         resolve(res)
         wx.showToast({
            title:'扫描成功',
            icon: 'none',
            duration: 1000
          })
        } else {
         //其它错误，提示用户错误信息
         wx.showToast({
            title:'扫描失败',
            icon: 'none',
            duration: 1000
          })
         reject(res)
        }
       }),
       fail: (res => {
        reject(res)
       })
      })
     })
    }
   }
    
   export default simpleReq