const app = getApp()
const OneID = require('../../utils/gtoneid-ali-min')
Page({
  data: {
    appid: 'LLNstWgyGm8UM2SsherlU3',
    version: '',
    oneid: '',
  },
  onLoad: function () {
    let that = this
    this.setData({
      version: OneID.getVersion()
    })
    OneID.init({
      // appId: 'LLNstWgyGm8UM2SsherlU3',
      appId: 'rA2G1vfKeE7NlXKPHZrr73',
      onSuccess: function (res) {
        let r = JSON.stringify(res)
        console.log('OneID init success', r)
        that.setData({
          oneid: 'OneID init success' + r
        })
      },
      onFailure: function (res) {
        console.log('OneID init failure', res)
        that.setData({
          oneid: 'OneID init failure' + res
        })
      }
    })
  },
  queryLbs: function () {
    OneID.queryLBS(5, {
      onSuccess: function (res) {
        let r = JSON.stringify(res)
        console.log('OneID queryLBS success', r)
      },
      onFailure: function (res) {
        let r = JSON.stringify(res)
        console.log('OneID queryLBS failure', r)
      }
    })
  },
  getLocation() {
    if (my.getLocation) {
      console.log("getLocation")
      my.getLocation({
        type: 0, // 获取经纬度
        success: (res) => {
          console.log('定位成功：', res);
        },
        fail: (error) => {
          console.error('定位失败: ', JSON.stringify(error));
        },
        complete: () => {
          console.log("complete")
        },
      });

    } else {
      console.log("当前支付宝版本过低，无法使用此功能，请升级最新版本支付宝")
    }
  }
})