const util = require('../utils/util.js');
// 登录状态
const rzStatus = () => {
  return new Promise((resolve, reject) => {
    wx.login({
      success: (res) => {
        if (res.code) {
          wx.request({
            url: util.globalData.publicUrl + '/wx/getAppletOpenId',
            method: "GET",
            data: {
              cid: 'applet',
              code: res.code
            },
            success: res => {
              if (res.data.status == 200) {
                wx.setStorageSync('openId', res.data.data.openid)
                wx.request({
                  url: util.globalData.publicUrl + '/applet/isExist',
                  method: "GET",
                  data: {
                    appletsId: wx.getStorageSync('openId')
                  },
                  success: (res) => {
                    console.log('是否绑定', res.data.code);
                    resolve(res);
                  },
                  fail: (res) => {
                    reject(res)
                  }
                })
              }
            }
          });
        } else {
          console.log('获取用户登录态失败！' + res.errMsg);
        }
      }
    })
  })
};
const finishInfo = () => {
  return new Promise((resolve, reject) => {
    wx.request({
      url: util.globalData.publicUrl + '/user/isPerfect',
      method: "GET",
      header: {
        appletsId: wx.getStorageSync('openId')
      },
      success: (res) => {
        console.log(res.data)
        resolve(res)
      },
      fail: (re) => {
        reject(re)
      }
    })
  })
};
module.exports = {
  rzStatus,
  finishInfo
}