import { loginByUserInfo,loginByUserInfo1 } from '../../utils/login'
const app = getApp();
Page({
    options: {
        addGlobalClass: true,
    },
    /**
     * 页面的初始数据
     */
    data: {
        grid_list: [
            { name: '分享', icon:'https://4d-tjw.oss-cn-shenzhen.aliyuncs.com/4dHouse/nav.svg', url:"/pages/share-history/share-history", needLogin: true },
            { name: '关注', icon:'https://4d-tjw.oss-cn-shenzhen.aliyuncs.com/4dHouse/follow.svg', url:"/pages/follow-list/follow-list", needLogin: true },
            { name: '浏览', icon:'https://4d-tjw.oss-cn-shenzhen.aliyuncs.com/4dHouse/history.svg', url:"/pages/view-history/view-history", needLogin: true },
        ],
        cu_items: [
            { title: '反馈问题', icon: 'feedback',  bottomType: 'feedback' },
            { title: '关注公众号', icon: 'guanzhu', value: '/pages/contact/contact', tip: '获取最新资讯，咨询' },
            { title: '客服电话', icon: 'call', tip: '+8618025428379', value: '8618025428379', action: 'call'},
            { title: '关于我们', icon: 'about', value: '/pages/about/about' },
        ],
        user_code: '',
        isLogined: app.globalData.token ? true : false,
        userinfo: app.globalData.userinfo
    },

    Navigator_to(e){
        const { value, action } = e.currentTarget.dataset
        if (value) {
            if (action === 'call') {
                wx.makePhoneCall({
                    phoneNumber: value
                })
                return
            }
            console.log(value)
            wx.navigateTo({
                url: value,
            })
        }
    },
    toModifyUser () {
        if (!this.data.isLogined) {
            return
        }
        wx.navigateTo({
          url: '/pages/user-info/user-info',
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (e) {
        
        wx.login({
            success: (res) => {
                this.setData({
                    user_code: res.code
                })
            }
        })
    },
    onShow: function () {
      
        this.setData({
            isLogined: app.globalData.token ? true : false,
            userinfo: app.globalData.userinfo
        });
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },
    bindgetuserinfo (e) {
        loginByUserInfo(e, this.data.user_code).then(res => {
            this.setData({
                isLogined: app.globalData.token ? true : false,
                userinfo: app.globalData.userinfo
            })
        })
    },
    bindgetuserinfo1 (e) {
        // wx.getUserProfile({
            // desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
            // success: (res) => {
                loginByUserInfo1().then(res => {
                    this.setData({
                        isLogined: app.globalData.token ? true : false,
                        userinfo: app.globalData.userinfo
                    })
                })
                // this.setData({
                //     isLogined: app.globalData.token ? true : false,
                //     userinfo: app.globalData.userinfo
                // })
            // }
        //   })
      
    },
})
