// app.js

const { baseUrl } = require('./config.js');

App({

// config.service.pathUrl
// https://mpapitest.gululuq.com/

  data: {
    loginSuccess: false,
  },

  globalData: {
    storeId: null,
    mUser: null,
  },

  onLaunch() {

    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
        console.log("code", res);
        if (res.code){
          wx.request({
            url: baseUrl + '/api/store/wxlogin',
            method: 'POST',
            data: {
              code: res.code
            },
            header: {
              'content-type': 'application/x-www-form-urlencoded',
              // 'X-Referrer-Id': codeUrl[1] || '',
              // 'X-Store-Id': codeUrl[0] || ''
              'X-Referrer-Id': '',
              'X-Store-Id': ''
            },
            success:(res)=> {
              console.log(res);
              // this.globalData.mUser = res.data.data;
              // this.globalData.storeId = '';
              // this.data.loginSuccess = true;
            },
            fail: function(res){
              console.log(res);
            }
          })
        }
      },
      fail: function(e){
        console.log(e);
      }
    })
  },
})


wx.login({
  success: res => {
    // 发送 res.code 到后台换取 openId, sessionKey, unionId
  },
})