const api = require("../../api/index.js")
const app = getApp()
// index.js
const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'

Page({
  data: {
    phone:app.globalData.phone,
    motto: 'Hello World',
    userInfo: {
      avatarUrl: defaultAvatarUrl,
      nickName: '',
    },
    hasUserInfo: false,
    canIUseGetUserProfile: wx.canIUse('getUserProfile'),
    canIUseNicknameComp: wx.canIUse('input.type.nickname'),
    keyword:'',
    btnList:[
      {
        type:'1',
        label:'我要查风险',
        color:'#4095e5',
        page:'/pages/riskAssessment/riskAssessment'
      },
      {
        type:'2',
        label:'我要申诉',
        color:'#fcca00',
        page:'/pages/form/appeal/appeal'
      },
      {
        type:'3',
        label:'我要维权',
        color:'#bd3124',
        page:'/pages/form/rightsProtection/rightsProtection'
      },
      {
        type:'4',
        label:'我要申请',
        color:'#000a7b',
        page:'/pages/form/application/application'
      }
    ],
    visible1:false
  },
  bindViewTap() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onReady(){
   
  },
  onLoad(){
    // wx.navigateTo({
    //   url: '/pages/login/login',
    // })
  //  api.search().then(res=>{
  //    console.log(res)
  //  })
   var a = wx.getStorageSync('showDialog')
   this.setData(
     {
      visible1:a
     }
   )
  },
  onClose1(){
    this.setData(
      {
       visible1:false
      }
    )
    wx.setStorageSync('showDialog', false)
  },

  makePhoneCall(){
    wx.makePhoneCall({
      phoneNumber: this.data.phone
    })
  },
  //修改输入的关键词
  changeKeyword(e){
    this.setData(
      {
        keyword:e.detail
      }
    )
  },
  //点击输入框内部图标
  clickInnerIcon(e){
    // console.log(e)
  },
  //点击搜索按钮
  search(e){
    // console.log(e)
    // this.setData(
    //   {
    //     result:this.data.keyword
    //   }
    // )
  },
  //点击四个功能按钮（我要查风险）
  btnClick:function(e){
    console.log(e)
    var page = e.currentTarget.dataset.page
    console.log(page)
    wx.navigateTo({
      url:page
    })
  },
  onChooseAvatar(e) {
    const { avatarUrl } = e.detail
    const { nickName } = this.data.userInfo
    this.setData({
      "userInfo.avatarUrl": avatarUrl,
      hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl,
    })
  },
  onInputChange(e) {
    const nickName = e.detail.value
    const { avatarUrl } = this.data.userInfo
    this.setData({
      "userInfo.nickName": nickName,
      hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl,
    })
  },
  
})
