// pages/meeting-cover/meeting-cover.js
const app = getApp();
const util = require('../../utils/util.js');

Page({

    /**
     * 页面的初始数据
     */
    data: {
        imgPath: app.globalData.imgPath,
        location: '重庆市城市管理局会议厅1楼105会议室',
        title: '',
        receptionTime: '',
        item: {},
        showBack: true,
        showPart1: true,
        showPart2: false,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let that = this;
        console.info(options)
        if (options) {
            that.setData({
                id: options.id
            });
        }
        util.get({
            url: '/api/meeting/info/getByIdNotAuth?id=' + options.id,
            success: (res) => {
                wx.hideLoading();
                console.info('res', res);
                // util.toast(JSON.stringify(res))
                let datas = res.data.data;
                that.setData({
                    title: datas.title,
                    receptionTime: util.formatDate(datas.receptionTime, 'yyyy年MM月dd日 HH:mm'),
                    receptionContent: datas.receptionContent
                });
            }
        });
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
        // util.toast('点击分享');
        let that = this;
        that.setData({
            showBack: false
        });
        setTimeout(() => {
            that.setData({
                showBack: true
            });
        }, 10000);
        return {
            title: '会议分享',
            path: '/pages/meeting-cover/meeting-cover?id=' + that.data.id,
            // imageUrl: '/images/call2x.png'
        }
    },

    /**
     * 触摸开始事件
     */
    touchStart: function (e) {
        this.setData({
            moveFlag: true,
            startY: e.touches[0].pageY,
        });
    },

    /**
     * 触摸移动事件
     */
    touchMove: function (e) {
        let that = this;
        let endY = e.touches[0].pageY;
        let startY = that.data.startY;
        if (that.data.moveFlag) {
            // 下滑
            if (endY - startY > 50) {
                console.log("pullDown")
                that.setData({
                    moveFlag: false,
                });
                if (!that.data.showPart1 && that.data.showPart2) {
                    let ani = wx.createAnimation({
                        delay: 0,
                        duration: 1000,
                    });
                    ani.opacity(0.5).step();
                    that.setData({
                        showPart1: true,
                        showPart2: false,
                        ani: ani.export()
                    });
                    ani.opacity(1).step();
                    that.setData({
                        ani: ani.export()
                    });
                }
            }
            // 上滑
            if (startY - endY > 50) {
                console.log("pullup")
                that.setData({
                    moveFlag: false,
                });
                if (that.data.showPart1 && !that.data.showPart2) {
                    let ani = wx.createAnimation({
                        delay: 0,
                        duration: 1000,
                    });
                    ani.opacity(0.5).step();
                    that.setData({
                        showPart1: false,
                        showPart2: true,
                        ani: ani.export()
                    });
                    ani.opacity(1).step();
                    that.setData({
                        ani: ani.export()
                    });
                }
            }
        }
    },

    /**
     * 触摸结束事件
     */
    touchEnd: function (e) {
        this.setData({
            moveFlag: true,
        });
    },
})