index.js 3.48 KB
import { imgUrlMixin } from '~/mixins/index'
const navStyle = 'background-color: transparent;'
import ActivityApi from '~/api/activityApi/index'
Component({
    behaviors: [imgUrlMixin],
    properties: {},
    data: {
        loading: true,
        navStyle,
        tab: [],
        roadTodayNum: 0,
        roadCountNum: 0,
        tabIndex: 0,
        to: '',
        showMenu: false,
        totals_zc: 0,
        ids: [],
        currentServiceType: 0,
        usedCarFlag: 0,
    },
    methods: {
        // 获取众筹总数
        getTotal(e) {
            const { type, total } = e.detail
            if (e && e.detail && type == 0) {
                this.setData({
                    totals_zc: total
                })
            }

        },

        hideEmpSelect() {
            wx.$eventbus.emit("hideEmpSelect")
        },
        // 点击菜单按钮切换到对应的tab
        getCurrentMenu(e) {
            let { tab } = this.data
            const index = tab.findIndex(item => item.serviceType == e.detail)
            this.setData({
                tabIndex: index,
                to: `to-${index}`,
                currentServiceType: e.detail || 0,
            })
        },
        // 展示菜单列表
        showMenuList() {
            this.setData({
                showMenu: true
            })
        },

        navbarReady(e) {
            let { height } = e.detail
            this.setData({
                navHeight: height
            })
        },
        // 切换tab
        async click(e) {
            let { index } = e.currentTarget.dataset
            let { tab } = this.data
            const TEMP = tab[index]

            this.setData({
                tabIndex: index,
                to: `to-${index}`,
                currentServiceType: TEMP.serviceType || 0,
            })
        },

        onLoad(options) {
            const { merchantId, merchantName, usedCarFlag } = options;
            this.setData({ merchantId, merchantName, usedCarFlag })
            this.getSubscribeConfig(options)
            this.addEvent()
        },
        // 获取活动订阅配置
        getSubscribeConfig(obj) {
            let tab = [
                { serviceTypeName: '精品升级', serviceType: 1 },
                { serviceTypeName: '售后众筹', serviceType: 0 },
                { serviceTypeName: '会员权益/升级', serviceType: 2 },
                { serviceTypeName: '二手车', serviceType: 7 }]
            const index = tab.findIndex(item => item.serviceType == obj.type) || 0
            this.setData({
                tab,
                fresh: obj && obj.fresh,
                currentServiceType: obj.type || 0,
                tabIndex: index,
                to: `to-${index}`,
            })
            console.log(Date.now())
            setTimeout(() => {
                this.configHttpCount = false
                this.setData({
                    fresh: false,
                })
            }, 300)
        },
        // 添加evevtbus通知刷新订阅
        addEvent() {
            wx.$eventbus.on("RESFRESH_SUBCRIBE", (obj) => {
                this.getSubscribeConfig(obj)
            });
        },
        // 跳转发现页面
        toDoscoverPage() {
            wx.$router.getPageInstance().changeTabBar({
                detail: 1,
                myTabIdx: 1
            })
        },
        // 检查是否开通福利官
        checkOpenPrivate(e) {
            this.setData({
                openPravite: e.detail
            })
        }
    }
})