import {
    ApiModel
} from "../utils/api";
const _Http = new ApiModel();
Component({
    /**
     * 组件的属性列表
     */
    properties: {},
    lifetimes: {
        attached() {},
        ready: function () {
            // 在组件实例进入页面节点树时执行
        },
    },
    /**
     * 组件的初始数据
     */
    data: {
        active: 0,
        tabbarList: [{
                icon: 'https://bwj.obs.cn-east-2.myhuaweicloud.com/resources/WeChat/tabbar-icon/home.png',
                iconA: 'https://bwj.obs.cn-east-2.myhuaweicloud.com/resources/WeChat/tabbar-icon/home-a.png',
                text: '首页',
                url: '/pages/tabbar-pages/home/index'
            },
            {
                icon: 'https://bwj.obs.cn-east-2.myhuaweicloud.com/resources/WeChat/tabbar-icon/service.png',
                iconA: 'https://bwj.obs.cn-east-2.myhuaweicloud.com/resources/WeChat/tabbar-icon/service-a.png',
                text: '客服投诉',
                url: '/pages/tabbar-pages/customer-service-staff/index'
            },
            {
                icon: 'https://bwj.obs.cn-east-2.myhuaweicloud.com/resources/WeChat/tabbar-icon/bazaar.png',
                iconA: 'https://bwj.obs.cn-east-2.myhuaweicloud.com/resources/WeChat/tabbar-icon/bazaar-a.png',
                text: '供需广场',
                url: '/pages/tabbar-pages/supplyAndDemand/index'
            },
            {
                icon: 'https://bwj.obs.cn-east-2.myhuaweicloud.com/resources/WeChat/tabbar-icon/message.png',
                iconA: 'https://bwj.obs.cn-east-2.myhuaweicloud.com/resources/WeChat/tabbar-icon/message-a.png',
                text: '消息',
                url: '/pages/tabbar-pages/message/index',
                fcount: '0'
            },
            {
                icon: 'https://bwj.obs.cn-east-2.myhuaweicloud.com/resources/WeChat/tabbar-icon/user.png',
                iconA: 'https://bwj.obs.cn-east-2.myhuaweicloud.com/resources/WeChat/tabbar-icon/user-a.png',
                text: '我的',
                url: '/pages/tabbar-pages/user/index'
            }
        ],
        show: false,
        phoneNumber: '',
    },

    /**
     * 组件的方法列表
     */
    methods: {
        /* tabbar */
        onChange(event) {
            if (this.data.phoneNumber == '') this.setData({
                phoneNumber: wx.getStorageSync('servicehotline')
            });
            if (event.target.dataset.index == 1) return this.setData({
                show: true
            })
            this.setData({
                active: event.target.dataset.index
            });
            wx.switchTab({
                url: this.data.tabbarList[event.target.dataset.index].url
            });
        },
        init() {
            const page = getCurrentPages().pop();
            this.setData({
                active: this.data.tabbarList.findIndex(item => item.url === `/${page.route}`)
            });
        },
        /* 呼叫电话 */
        CallOut() {
            wx.makePhoneCall({
                phoneNumber: wx.getStorageSync('servicehotline')
            }).catch((e) => {})
        },
        onClose() {
            this.setData({
                show: false
            })
        },
        /* 获取未阅读消息数量查询 */
        unReadMessageCount() {
            _Http.basic({
                "accesstoken": wx.getStorageSync('userData').token,
                "classname": "system.message.Message",
                "method": "unReadMessageCount",
                "content": {}
            }).then(res => {
                if (res.msg != '成功') console.log('未读消息数量查询失败')
                const fcount = (res.data[0].fcount == 0) ? '' : res.data[0].fcount;
                getApp().globalData.msgFcount = fcount;
            })
        }
    },
})