const app = getApp()
const navigationBarHeight = (getApp().statusBarHeight + 50) + "px";
const Http = require("../utils/HttpBasics");
const config = require("../config/config");
const imgurl = require("../utils/imgurl");
Page({
  data: {
    navigationBarHeight,
    showPhoem: false,
    text: "授权手机号",
    avatarUrl: "",
    nickName: "",
    mouldType:1,
  },
  showPhoemBtn() {

    tt.navigateTo({
      url: '/pages/getPhone/getPhone?mineFlag=mine',
    });
  },
  go(e) {

    let url = e.currentTarget.dataset.url
    console.log(url);
    if (url == '/pages/order/index/index?id=all') {
      app.globalData.ifshowtab=false
      tt.navigateTo({
        url: url,
        success: (res) => {

        },
        fail: (res) => {

        },
      });
    } else {
      tt.navigateTo({
        url: url, // 指定页面的 url
        success: (res) => {

        },
        fail: (res) => {

        },
      });
    }



  },
  setPhone(paramData) {//子组件调用这个方法说明手机号已经授权成功
    this.setData({
      showPhoem: paramData.detail,
    })
    tt.showToast({
      title: '授权成功', // 内容
      icon: 'none', // 图标
      success: (res) => {

      },
      fail: (res) => {

      },
    });
  },
  getmemberId: function (token) {
    Http.get({
      url: config.api.getScore,
      data: {
        token: token
      }
    }).then(res => {
      if (res.data.avatarUrl || res.data.nickName) {
        this.setData({
          avatarUrl: res.data.avatarUrl,
          nickName: res.data.nickName,
        })
      }
    }).catch(err => {
      tt.showModal({
        title: '提示',
        content: err.message,
        showCancel: false
      })
    })
  },

  setBox(paramData) {
    this.setData({
      showPhoem: paramData.detail
    })
    tt.reLaunch({
      url: "/index/index",
        success(res) {
          console.log(`${res}`);
          app.globalData.selected = 0
        },
        fail(err) {
          console.log(`navigateTo调用失败`,err);
        },
    });
    // tt.showToast({
    //   title: '取消授权', // 内容
    //   icon: 'none', // 图标
    //   success: (res) => {
       
    //   },
    //   fail: (res) => {

    //   },
    // });
  },
  onShow: function (options) {
    this.setData({
      mouldType:app.globalData.mouldType
    })
    this.getmemberId()
    Http.get({
      url: config.api.checkUserStatus,
      data: {
        token: app.globalData.token
      }
    }).then(res => {
      Http.get({
        url: config.api.checkPhoneStatus,

      }).then(res => {
        this.setData({
          text:res.data.phone
        })
      }).catch(err => {
        
        if(app.globalData.ifCongPh==1){
          tt.navigateTo({
            url: '/pages/getPhone/getPhone?mineFlag=mine',
          });
        }else{
          this.setData({
            showPhoem:true
          })
        }
        
      })
    }).catch(err => {

      if (err.code == 11004) {//未授权抖音
        app.globalData.type = 'uc'
        tt.navigateTo({
          url: '/pages/getuserinfo/getuserinfo',

        });

      }
    })
  }
})