// pages/mine/index.js
import {getUserData} from '../../api/login.js'
import {messageSum} from '../../api/mine.js'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        userInfo: {}, // 用户授权信息
        list: [
            {title: '个人信息', type: 'userinfo', path: '/package_mine/pages/userInfo/index', info: '修改个人信息'},
            {title: '护河身份', type: 'myid', path: '/package_mine/pages/myId/index', info: '全民护河 全民参与'},
        ],
        otherList: [
            {title: '河湖问题反馈', type: 'feedback', path: '/package_mine/pages/records/index', info: '问题反馈'},
            {title: '消息通知', type: 'notice', path: '/package_mine/pages/notice/index',info: '', showNumbers: true},
            {title: '我的兑换', type: 'exchange', path: '/package_mine/pages/exchange/index', info: ''}
        ],
        myId: '', // 身份
        integral: 0, // 积分
        numbers: 0
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.getTabBar().setData({
            selected: 2
        })
        
    },
    onShow:function() {
        this.getUserInfo()
        this.getUnReadNums()
    },

    goRecords(e) {
        const path = e.currentTarget.dataset.path
        wx.navigateTo({
            url: path,
        })
    },
    // 获取
    getUserInfo() {
        const params = {}
        params.tenantId = wx.getStorageSync('tenant').tenantId
        params.openid = wx.getStorageSync('openid')
        getUserData(params).then(success=> {
            const userInfo = success.data
            wx.setStorage({
                key: 'userInfo',
                data:userInfo
            })
            this.setData({userInfo})
        })
    },
    getUnReadNums(){
        const openId = wx.getStorageSync('openid')
        messageSum({openId}).then(res=>{
            this.setData({
                numbers: res.data || 0
            })
        })
    },
    // 进入申请身份页面
    goApprove() {
        wx.navigateTo({
          url: '/package_mine/pages/IdList/index',
        })
    },
    handlePointDetail(){
        wx.navigateTo({
            url: '/package_mine/pages/history/index',
        })
    }
})