import login from '../../utils/login'
import { VueLikePage } from '../../utils/page'
import Router from '../../utils/routes'
const app = getApp();
VueLikePage([], {
    options: {
        addGlobalClass: true,
    },
    data: {
        cu_items: [{
                title: '名片夹',
                icon: 'my_contacts',
                value: 'businessCard',
                needLogin: true
            },
            {
                title: '已收藏产品',
                icon: 'my_product',
                value: 'collectGoods',
                needLogin: true
            },
            // {
            //     title: '已收藏参展商',
            //     icon: 'my_enterprise',
            //     value: 'collectEnterprise',
            // },
            {
                title: '数据报表',
                icon: 'my_reportform',
                value: 'dataReport',
                needLogin: true
            },
            {
                title: '账号设置',
                icon: 'my_set',
                value: 'logout',
                needLogin: true
            },
        ],
        user_code: '',
        isLogined: app.globalData.token ? true : false,
        userinfo: app.globalData.userinfo
    },
    methods: {
        Navigator_to(e) {
            const { value } = e.currentTarget.dataset
            const item = this.data.cu_items.find(item => item.value === value)
            if (item.needLogin && !getApp().globalData.token) {
                Router.push('login')
                return
            }
            Router.push(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
            });
        },
        bindgetphonenumber(e) {
            login(e, this.data.user_code).then(res => {
                this.setData({
                    isLogined: app.globalData.token ? true : false,
                    userinfo: app.globalData.userinfo
                })
            })
        },
        toLogin () {
            Router.push('login')
        }
    }
})