//index.js
//获取应用实例
const app = getApp()

import mock from './mock.js'//拿到的数据

Page({
    data: {
        items: mock,
        slide: [{image: '../../images/banner.png'}, {image: '../../images/banner.png'}],
        images: [{src: '../../images/duantu@2x.png', text: '短途郊游'},
            {src: '../../images/changtu@2x.png', text: '长途旅游'},
            {src: '../../images/finecanting@2x.png', text: 'Fine Dining 餐厅'},
            {src: '../../images/huwai@2x.png', text: '户外运动'},
            {src: '../../images/juhui@2x.png', text: '聚会'},
            {src: '../../images/yinyuejie@2x.png', text: '音乐节'},
            {src: '../../images/dianying@2x.png', text: '电影'},
            {src: '../../images/qingshe@2x.png', text: '轻奢餐厅'},
            {src: '../../images/zhanlan@2x.png', text: '展览'},
            {src: '../../images/wutaiju@2x.png', text: '舞台剧'},
        ],
        banner: [{image: '../../images/banner.png'}, {image: '../../images/b1@2x (1).png'}, {image: '../../images/b1@2x (2).png'}, {image: '../../images/banner.png'}],
        currentBannerIndex:0,
        tabcurrent: {tab: 0,bubble: ''},
        noticeList:[{url:'',name:'https://github.com/wux-weapp/wux-weapp'},
            {url:'',name:'北京首展11奥拉维尔·埃利亚松北京首展北京首展11奥拉维尔·埃利亚松北京首展'},
            {url:'',name:'https://github.com/wux-weapp/wux-weapphttps://github.com/wux-weapp/wux-weapp'},
            {url:'',name:'奥拉维尔'},
            {url:'',name:'奥拉维尔https://github.com/wux-weapp/wux-weapp'},
            {url:'',name:'奥拉维尔·埃利亚松北京首展https://github.com/wux-weapp/wux-weapp'},
        ],

        motto: 'Hello World',
        userInfo: {},
        hasUserInfo: false,
        canIUse: wx.canIUse('button.open-type.getUserInfo')
    },
    onClick() {
        wx.navigateTo({
            url: '/pages/search/search',
        })
    },
    //搜索
    search() {
        wx.navigateTo({
            url: '/pages/search/search',
        })
    },
    bannerChange(e){
        // console.log(e,'current', current);
        const current = e.detail.current;
        this.setData({currentBannerIndex: current})
    },

    //事件处理函数
    bindViewTap: function () {
        wx.navigateTo({
            url: '../logs/logs'
        })
    },
    onLoad: function () {
        this._doRefreshMasonry(this.data.items)
    },

    onReachBottom: function () {
        this._doAppendMasonry(this.data.items)
    },

    _doRefreshMasonry(items) {
        this.masonryListComponent = this.selectComponent('#masonry');
        this.masonryListComponent.start(items).then(() => {
            console.log('refresh completed')
        })
    },

    _doAppendMasonry(items) {
        this.masonryListComponent = this.selectComponent('#masonry')
        // 获取接口数据后使用瀑布流组件append方法,当append完成后调用then,是否可触底价在的标志位可以在这里处理
        this.masonryListComponent.append(items).then(() => {
            console.log('refresh completed,加载更多')
        })
    },
    //首页-导航
    service(e) {
        var tindex = e.currentTarget.dataset.tindex;
        var tabcurrent = this.data.tabcurrent;
        if (tabcurrent == tindex) {
            return false
        } else {
            this.setData({
                tabcurrent: tindex
            })
            wx.redirectTo({
                url: '/pages/index/index',
            })
        }
    },


    //拼单-导航
    consult(e) {
        var tindex = e.currentTarget.dataset.tindex
        var tabcurrent = this.data.tabcurrent
        if (tabcurrent == tindex) {
            return false
        } else {
            this.setData({
                tabcurrent: tindex
            })
            // wx.showToast({
            //     title: '该功能正在开发中',
            //     icon: 'none'
            // })
            wx.redirectTo({
                url: '/pages/spell-list/spell-list',
            })
        }
    },
    //发布按钮
    release(e) {
        let that = this;
        that.setData({
            releasepopup: true
        })
    },
    //取消发布弹窗
    cancelPopup() {
        let that = this;
        that.setData({
            releasepopup: false
        })
    },
    //订单-导航
    wish(e) {
        var tindex = e.currentTarget.dataset.tindex
        var tabcurrent = this.data.tabcurrent
        if (tabcurrent == tindex) {
            return false
        } else {
            this.setData({
                tabcurrent: tindex
            })
            // wx.showToast({
            //     title: '该功能正在开发中',
            //     icon: 'none'
            // })
            wx.redirectTo({
                url: '/pages/order/order',
            })
        }
    },
    //我的-导航
    my(e) {
        var tindex = e.currentTarget.dataset.tindex
        var tabcurrent = this.data.tabcurrent
        if (tabcurrent == tindex) {
            return false
        } else {
            this.setData({
                tabcurrent: tindex
            })
            wx.redirectTo({
                url: '/pages/my/my',
            })
        }
    },
})