const app = getApp()

import Notify from '@vant/weapp/notify/notify';

import {
    selectShowroomRecordRq,
} from "../../../../../api/meeting/exhibition.js"

import {
    selfFormatTimeYMD,
    selfFormatTimeHM
} from "../../../../../utils/util.js"

Page({

    /**
     * 页面的初始数据
     */
    data: {
        IMG_NAME: app.IMG_NAME,
        userDetail: {},
        // 预约
        pageNum: 1,
        pageSize: 10,
        dataList: [],
        isAll: false,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let _this = this;
        let userDetail = wx.getStorageSync('user')
        _this.setData({
            ...options,
            userDetail,
        })

        // 获取数据
        _this.getDataList()
    },

    // 获取数据
    getDataList() {
        let _this = this;
        if (_this.data.isAll) {
            return;
        }
        selectShowroomRecordRq({
            userId: _this.data.userDetail.id,
            pageNum: _this.data.pageNum,
            pageSize: _this.data.pageSize,
        }).then(res => {
            console.log('selectShowroomRecordRq', res);
            let dataList = res.data.records
            if (dataList && dataList.length > 0) {
                dataList = _this.data.dataList.concat(_this.formartData(dataList))
                _this.setData({
                    dataList,
                    pageNum: _this.data.pageNum + 1,
                })
            } else {
                _this.setData({
                    isAll: true
                })
            }
        })
    },

    // 格式化数据
    formartData(list) {
        return list.map(item => {
            let color = "#3794FF"
            if (item.status == 0) { // 待审核
                color = "#3794FF"
            } else if (item.status == 1) { // 审核通过
                color = "#62c855"
            } else if (item.status == 2) { // 审核驳回
                color = "red"
            }
            item.timeSlot = selfFormatTimeYMD(item.startTime) + ' ' + selfFormatTimeHM(item.startTime) + '~' + selfFormatTimeHM(item.endDate);
            console.log('item.timeSlot', item.timeSlot);
            item.statusColor = color;
            return item;
        })
    },

    // 跳转-详情、修改
    goDetail(e) {
        console.log('goDetail', e);
        let id = e.currentTarget.dataset.id
        wx.navigateTo({
            url: '/pages/meeting/reservationRecord/exhibitionRecord/detail/detail?id=' + id
        })
    },

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

    },

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

    },

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

    },

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

    },

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

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {
        console.log('onReachBottom');
        let _this = this;
        // 获取数据
        _this.getDataList()
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    },
})