let Parse = getApp().Parse
const company = getApp().globalData.company
import dataSource from '../../../service/data';
import dateServ from '../../../service/date';
const rechText = require('../../../../utils/rech-text')
Page({

    /**
     * 页面的初始数据
     */
    data: {
        roomId: null,
        room: {},
        note: {
            "title": '订房必读',
            "desc": '为响应《关于南昌市旅游住宿业不主动提供一次性周品的侣仪书》，消费者减少一次性塑料制品使用，南昌市旅游住宿单位不再主动向消费者提供牙刷、牙膏、香皂、浴液、拖鞋、梳子等一次性易耗品和一次性碗、杯、盘、餐具等餐饮用具，如有需要请提前向酒店咨询。',
            "arrowtext": '查看全部',
            'detail': `城市通知\t为响应《关于南昌市旅游住宿业不主动提供一次性周品的侣仪书》，消费者减少一次性塑料制品使用，南昌市旅游住宿单位不再主动向消费者提供牙刷、牙膏、香皂、浴液、拖鞋、梳子等一次性易耗品和一次性碗、杯、盘、餐具等餐饮用具，如有需要请提前向酒店咨询。\n\n
            
        外宾政策\t商家仅接待大陆客人。
        预提示：您填写的预订信息和联系方式是商家或供应商提供相关服务所需的必要信息，美团会基于履约必要的范围向商家或供应商提供。
        如您预订的产品涉及实名制要求（如包含有实名制需求的景区门票产品），需要您填写出行人真实有效的证件信息，用于出游时的身份验证。美团会基于履约必要的范围向供应商提供。
        订单等商家或供应商确认后才生效，订单确认结果以美团短信或邮件通知为准；请在订单生效后再至商家前台办理入住。
        业务实际运营和相应责任由门店签约主体公司负责。
        入住时间：14:00以后；离店时间：12:00以前，如需提前入住或延迟退房请联系商家。
        宠物携带：允许携带宠物。`
        },
        date: '', // 入住时间
        defaultDate: [], // 日历默认时间
        startTime: null, // 入住开始时间
        endTime: null, // 入住结束时间
        count: 1, // 入住几晚
        columns: [], // 入住人数可选数组
        peopleNum: 1, // 入住人数
        showNote: false,
        showDate: false,
        showNumPicker: false,
        showPayment: false,
        customers: [], // 住客信息
        priceInfoArr: [], // 房费详细信息
        formatter: null, // 日历格式化
        // checkedFormatter: null,// 日历相关数据处理
        CountArray: [], // 房型可选日期及已订数量数组 [{date: '',count: 0}]
        CountObj: [], // 房型可选日期及已订数量对象 {date: count}
        start:'',
        end:'',
        objectId:'',
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        const {
            objectId,
            date_start,
            date_end,
        } = options;
        const date_start1 = decodeURIComponent(date_start);
        const date_end1 = decodeURIComponent(date_end);
        this.setData({
            start:date_start1,
            end:date_end1,
            objectId

        })
        console.log('123', date_start1, date_end1);
        this.getdate()
        this.initData(objectId)

    },
    getdate() {
        let {
            startTime,
            endTime
        } = this.formatTimeArea(this.data.start, this.data.end)
        console.log('开始时间', startTime, '结束时间', endTime);
        var dataAll = dateServ.getDayAll(startTime, endTime);
        dataAll.pop(); // 最后一天为退房，不算在内
        console.log(dataAll);
        console.log(this.formatDate(startTime), this.formatDate(endTime))
        let dateStr = this.formatDate(startTime) + '-' + this.formatDate(endTime)
        console.log(dateStr)
        this.setData({
            showDate: false,
            date: `${this.formatDate(startTime)} - ${this.formatDate(endTime)}`,
            startTime: new Date(startTime),
            endTime: new Date(endTime),
            priceInfoArr: dataAll,
            count: dataAll.length
        })

        console.log(this.data.priceInfoArr);
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        this.setData({
            customers: this.data.customers
        })
        console.log(this.data.customers);
    },
    initData(roomId) {
        dataSource.getRoomById(roomId).then(room => {
            room.desc = room.tags.join(" ") // 标签
            this.data.note.detail = rechText.formatRichText((room.note || '')); // 订房必读
            let merber = room.merber; // 房间容纳人数
            let columns = [...new Array(merber + 1).keys()] // 入住人数可选数组
            columns.shift(0)
            console.log(columns);
            // 日期相关数据初始化
            // let defaultDate = this.initDate()
            // 订单开始时间结束时间  默认下午两点 方便无房时间对比
            // let today = new Date();
            // let tommrrow = dateServ.getStrByTimeIncreaseDay(today,1)
            // let {startTime,endTime}=this.formatTimeArea(today,tommrrow)
            // console.log(startTime,endTime);
            // let priceInfoArr = dateServ.getDayAll(startTime,endTime)// 订单时间跨度数组
            // priceInfoArr.pop();// 最后一天为退房 不计入
            // console.log(priceInfoArr);
            // let count= priceInfoArr.length;
            this.setData({
                roomId,
                room,
                columns,
                // date:defaultDate,
                peopleNum: merber,
                // priceInfoArr,
                // count,
                // startTime,
                // endTime,
            })
            console.log('房间',this.data.room);

        })
    },
    dayAddOne(time) {
        time = new Date(time)
        let year = time.getFullYear()
        let month = time.getMonth() + 1
        let day = time.getDate()
        return new Date(`${year}-${month}-${day + 1} 14:00:00`);
    },
    formatTimeArea(start, end) {
        start = new Date(start)
        end = new Date(end)
        console.log(start, end);
        let year = start.getFullYear()
        let month = start.getMonth() + 1
        let day = start.getDate()
        let year2 = end.getFullYear()
        let month2 = end.getMonth() + 1
        let day2 = end.getDate()
        console.log(year, month, day);
        let obj = {
            startTime: new Date(`${year}/${month}/${day} 14:00:00`),
            endTime: new Date(`${year2}/${month2}/${day2} 14:00:00`)
        }
        console.log(obj);
        return obj
    },
    navigate(event){
        console.log(event);
        let type = event.currentTarget.dataset.type;
        switch (type) {
            case 'room':
                console.log('暂时无详细页面');
                //暂时无详细页面
                // wx.navigateTo({
                //     url: `/nova-tourism/pages/homestay/room-detail/index?id=${this.data.roomId}`
                // })  
                break;
                case 'customer':
                    //跳转到信息页面
                    wx.navigateTo({
                        url: `../customer/select-customer/index`
                    })  
                    break;
            default:
                break;
        }

    },
    // 显示订房必读
    showNotePop() {
        this.setData({
            showNote: true
        })
    },
    closeModal() {
        this.setData({
            showNote: false
        });
    },

    // 日期
    initDate() {
        let month = new Date().getMonth() + 1;
        let start = new Date().getDate();
        let end = new Date().getDate() + 1;
        return `${month}月${start} 日 - ${month}月${end} 日`;
    },
    checkDate() {
        this.initCalenderData()
        this.setData({
            showDate: true
        })
    },
    closeDate() {
        this.setData({
            showDate: false
        })
    },
    enterDate(event) {
        const [start, end] = event.detail;
        console.log(11111, event.detail)
        let {
            startTime,
            endTime
        } = this.formatTimeArea(start, end)
        console.log('开始时间', startTime, '结束时间', endTime);
        var dataAll = dateServ.getDayAll(startTime, endTime);
        dataAll.pop(); // 最后一天为退房，不算在内
        console.log(dataAll);
        console.log(this.formatDate(startTime), this.formatDate(endTime))
        let dateStr = this.formatDate(startTime) + '-' + this.formatDate(endTime)
        console.log(dateStr)
        this.setData({
            showDate: false,
            date: `${this.formatDate(startTime)} - ${this.formatDate(endTime)}`,
            startTime: new Date(startTime),
            endTime: new Date(endTime),
            priceInfoArr: dataAll,
            count: dataAll.length
        })

        console.log(this.data.priceInfoArr);
    },
    formatDate(date) {
        date = new Date(date);
        return `${date.getMonth() + 1}/${date.getDate()}`;
    },

    /*****
     * 已知：用户选择房型、时间段，房型的可用数量
     * 查询：范围内是否有空房
     * 
     * 入住时间：当天占用房间
     * 离店时间：当天房间可用
     
     let CountArray = [
         {日期:20220419,数量:1},
         {date:20220419,count:1},
     ]

     function addOrdertoArray(currentDate){
        let currentIdx = CountArray.findIndex(item=>item.date == currentDate)

        if(currentIdx&&currentIdx>=0){
            CountArray[currentIdx].count += 1
        }else{
            CountArray.push({date:currentDate,count:1})
        }
     }
     function getDateByTime() // 同时获取14点校准时间


     RoomOrderList.forEach(order=>{
         let startDate = getDateByTime(order.get("startTime"));
         let endDate = getDateByTime(order.get("endTime"));
         let breakDate = 

         for(currentDate; currentDate + 1day; currentDate=breakDate){
            addOrdertoArray(currentDate);
         }
     })
     */




    /*** 日期组件初始化
     * 1、获取日历可选时间区间内 所有已生成订单  生成日期对应订单数量对象 {date:count}
     * 1、设置默认日期  （组件默认时间为当前时间及后一天 需修改为非无房状态日期）
     * 2、无房状态显示禁点
     * 3、已选择开始日期时，日期往后推 无房日期之后均为禁点
     */
    async initCalenderData() {
        // 获取日历可选时间区间内 所有已生成订单
        console.log(111)
        let orders = await this.getRoomOrdersByRoomId(this.data.roomId)
        orders.forEach(order => {
            let startDate = dateServ.getDateStrByTime(order.get("startTime"));
            let endDate = dateServ.getDateStrByTime(order.get("endTime"));
            let breakDate = dateServ.getStrByTimeIncreaseDay(order.get("endTime"), -1);
            console.log(startDate, endDate, breakDate);
            // 遍历单个订单下已订时间 将订单覆盖时间推入CountObject
            let dateArr = dateServ.getDayAll(startDate, breakDate)
            console.log(dateArr)
            for (let index = 0; index < dateArr.length; index++) {
                let datastr = dateArr[index];
                this.addOrdertoArray(datastr)
            }
        })
        console.log(this.data.CountArray, this.data.CountObj);
        this.setData({
            orders,
            defaultDate: [], // 默认日期
            CountArray: this.data.CountArray,
            CountObj: this.data.CountObj
        })
        this.checkedFormatter('init')

    },
    selectDay(date, type) {
        let day = {
            date,
            text: '20',
            type: '',
            bottomInfo: undefined
        }
        console.log('ddddddd', type);
        this.formatter(day, type)
    },
    getOrderDate(date) {
        console.log(this.data.CountObj[date], this.data.room.total);
        if (!this.data.CountObj[date]) {
            return date
        }
        if (this.data.CountObj[date] && this.data.CountObj[date] < this.data.room.total) {
            return date
        }
        if (this.data.CountObj[date] && this.data.CountObj[date] >= this.data.room.total) {
            return false
        }

    },
    addOrdertoArray(currentDate) {
        // currentDate = new Date(currentDate)
        let currentIdx = this.data.CountArray.findIndex(item => item.date == currentDate)
        if (currentIdx && currentIdx >= 0) {
            this.data.CountArray[currentIdx].count += 1
        } else {
            this.data.CountArray.push({
                date: currentDate,
                count: 1
            }) // 日期，已订数量
        }

        this.data.CountObj[currentDate] ? this.data.CountObj[currentDate] += 1 : this.data.CountObj[currentDate] = 1;
        console.log(this.data.CountObj)
    },
    // 组件日期订单数量达到总数时，type设置为disabled 
    // 组件默认start为当前日期，end为当前日期后一天  当前日期无房情况下需将最近的非disabled日期设为start
    // 当start 后一天为 无房日期时，该日期type改为''   ,无房日期 不可为start
    type: null,
    start: null,
    end: null,
    disabled: null,
    // start后的第一个无房日期
    checkedFormatter(type) {
        if (this.end) {
            this.disabled = null;
        }
        let that = this;
        this.status = null;
        let formatter = function (day, type) { //
            const month = day.date.getMonth() + 1;
            const date = day.date.getDate();
            if (month < 7) {
                if (date == 4 || date == 5 || date == 20 || date == 21 || date == 30) {
                    // console.log(day,day.date,day.type);
                }
                let CountObj = that.data.CountObj
                let datestr = dateServ.getDateStrByTime(day.date);
                let endstr = null;
                let disabledstr = null;
                let startstr = null;
                if (that.end) {
                    endstr = dateServ.getDateStrByTime(that.end);
                }
                if (that.disabled) {
                    disabledstr = dateServ.getDateStrByTime(that.disabled);
                }
                if (that.start) {
                    startstr = dateServ.getDateStrByTime(that.start);
                }

                // 1、该日期订单数量达到房间总量且非结束日期  显示无房 禁点
                if (CountObj[datestr] && CountObj[datestr] >= that.data.room.total && endstr != datestr) {
                    day.bottomInfo = '无房';
                    day.type = 'disabled';
                    // that.disabled = day.date;
                    // 4.1无房后日期禁点1 无离店日期时 入住日期后最近无房日期保存为disabled  
                    // console.log(startstr, datestr,that.disabled);
                    if (startstr < datestr && !that.end && (!that.disabled || disabledstr > datestr)) {
                        // console.log(startstr, datestr,that.disabled);
                        that.disabled = day.date
                    }
                }
                // 已有end时，记录end 
                if (day.type == 'end') {
                    that.end = day.date;
                    that.disabled = null;
                }
                // 4.2无房后日期禁点2  已选入住日期 无离店日期 时，离入住日期最近无房日期后所有日期type 设为 disabled  
                // console.log(day.config,that.start,that.end,datestr,disabledstr,startstr);
                if (that.start && !that.end && (datestr > disabledstr) && (startstr < datestr)) {
                    // console.log(datestr,disabledstr);
                    day.type = 'disabled'
                }
                // 2、设置默认入住日期：无start时，最近一天非disabled日期设为start  设为默认日期
                if (day.type != 'disabled' && !that.start) { //&& !that.data.defaultDate[0]
                    day.type = 'start'
                    that.start = day.date;
                    // that.data.defaultDate[0] = day.date.getTime()
                    // console.log(that.data.defaultDate);
                    // that.setData({
                    //     defaultDate:that.data.defaultDate
                    // })
                }
                // 已有start时，记录start 原无房日期type为start时，不存
                if (day.type == 'start') {
                    console.log(day, 'start');
                    that.type = 'start';
                    that.start = day.date;
                    if (CountObj[datestr] && CountObj[datestr] >= that.data.room.total) {
                        day.type = 'disabled';
                        that.start = null;

                    }
                }
                // 3.1、有start无end时,后一天如果为disabled，type设为'' 
                if (that.start && day.type == 'disabled' && month < 6) {
                    let leavSelect = dateServ.getStrByTimeIncreaseDay(that.start, 1)
                    // 日历day 时间为00:00:00,需把时间转换为 00:00:00 进行对比
                    let isSame = dateServ.isSameDay(day.date, leavSelect)
                    // console.log(startstr,CountObj[startstr] , that.data.room.total , !CountObj[startstr] || CountObj[startstr] <that.data.room.total);
                    if (isSame && datestr != endstr && (!CountObj[startstr] || CountObj[startstr] < that.data.room.total)) {
                        // console.log(datestr,endstr);
                        // console.log('ddddddddddddddddddddd');
                        // console.log(day,day.date,day.type);
                        day.type = ''
                    }
                }
                // 3.2、如果离店日期为无房日期，点击该日期 不修改入住和离店日期
                if (datestr == endstr) {
                    console.log(datestr, endstr);
                    if (CountObj[datestr] && CountObj[datestr] >= that.data.room.total) {
                        day.type == 'end'
                    }
                }


                if (day.type === 'start') {
                    day.bottomInfo = '入住';
                } else if (day.type === 'end') {
                    day.bottomInfo = '离店';
                }
            }
            return day;
        }
        // return formatter()
        // if(!this.defaultDate){
        //     this.setData({
        //         defaultDate:[this.start,this.end]
        //     })
        // }
        this.setData({
            checkedFormatter: formatter
        })
    },
    unselectDate(event) {
        console.log(event);

    },
    selectDate(event) {
        console.log(event);
        let dates = event.detail;
        this.start = dates[0]
        this.end = dates[1]
        if (this.end) {
            this.disabled = null;
            console.log(this.disabled);
        }
        this.checkedFormatter()
    },
    formatter(day, type) {
        const month = day.date.getMonth() + 1;
        if (month < 6) {
            console.log(day, type);
        }
        let CountObj = this.data.CountObj
        let datestr = dateServ.getDateStrByTime(day.date);
        // 该日期已有订单 且数量达到房间总量 显示无房 禁点
        if (CountObj[datestr] && CountObj[datestr] >= this.data.room.total) {
            day.bottomInfo = '无房';
            day.type = 'disabled'
        }
        if (day.type === 'start') {
            day.bottomInfo = '入住';
        } else if (day.type === 'end') {
            day.bottomInfo = '离店';
        }
        if (type) {
            day.type = type;
        }
        return day;
    },
    select: {
        start: null,
        end: null
    },
    // defaultDate(){
    //     // 已知： 有订单时间对象数组 this.CountObj this.CountArray   房间数量 this.room.total
    //     // 求： 最近订单数量小于房间数量时间
    //      let arr = this.getTimeArr()
    //      console.log(arr);
    //      return arr
    //     // format(day,type){
    //     //     if(type){
    //     //         day.type == type
    //     //     }
    // },
    getTimeArr() {
        let arr = [...new Array(30).keys()] // 日期遍历以30天为周期遍历
        let date = new Date();
        for (let i = 0; i < arr.length; i++) {
            let startstr = new Date(dateServ.getStrByTimeIncreaseDay(date, 0))
            let start = this.getOrderDate(startstr)
            date = new Date(dateServ.getStrByTimeIncreaseDay(date, 1))
            if (start) { // 最近可订的时间  
                console.log(start);
                this.selectDay(start, 'start')
                console.log(start);
                let end = new Date(dateServ.getStrByTimeIncreaseDay(start, 1))
                let endstr = dateServ.getStrByTimeIncreaseDay(start, 1)
                let select = this.getOrderDate(endstr)
                console.log(select);
                if (!select) { // 处于禁用状态
                    this.selectDay(end, 'end')
                }
                return [start, end]
            }
            if (i + 1 == arr.length) {
                this.getTimeArr()
            }
        }
    },

    // formatter (day) {
    //     const month = day.date.getMonth() + 1;
    //     const date = day.date.getDate();
    //     // console.log(month,date);
    //     // if (month === 5) {
    //     //   if (date === 1) {
    //     //     day.topInfo = '劳动节';
    //     //   } else if (date === 4) {
    //     //     day.topInfo = '五四青年节';
    //     //   } else if (date === 11) {
    //     //     day.text = '今天';
    //     //   }
    //     // }
    //     if(month === 4){
    //         if(date === 18 || date === 19 || date === 20 || date === 21){
    //             console.log(day);
    //         }
    //         if(day.type == 'start'){
    //             console.log('start');
    //             this.type = 'start';
    //             // type = 'start';
    //         }
    //         if (day.type === 'start') {
    //             day.bottomInfo = '入住';
    //           } else if (day.type === 'end') {
    //             day.bottomInfo = '离店';
    //           }
    //           let CountObj = this.data.CountObj
    //           let datestr = dateServ.getDateStrByTime(day.date);
    //           if(CountObj[datestr] && CountObj[datestr]>= this.data.room.total){// 该日期已有订单 且数量达到房间总量 显示无房 禁点
    //               day.bottomInfo = '无房';
    //               day.type = 'disabled'

    //           }
    //           if(date === 18 || date === 19 || date === 20 || date === 21){
    //             console.log(day);
    //         }

    //     }
    //     return day;
    // },
    // 入住人数选择
    checkNum() {
        this.setData({
            showNumPicker: true
        })
    },
    numPickerChange(event) {
        // console.log(event,event.detail);
        // this.setData({
        //     peopleNum:event.detail
        // })
    },
    numPickerEnter(event) {
        const {
            picker,
            value,
            index
        } = event.detail;
        console.log(picker, value, index);
        console.log(`当前值：${value}, 当前索引：${index}`);
        this.setData({
            peopleNum: value,
            showNumPicker: false
        })
    },

    numPickerCancel() {
        console.log('取消');
        this.setData({
            showNumPicker: false
        })
    },
    async checkOrderCount() {
        //   start1  end1   现在选择
        //   start2  end2     已有订单时间
        //   start1 < start2              end1 < end2
        //   start1 > start2              end1 > end2
        //   start1 = start2              end1 = end2
        let now = dateServ.changeDateTime(new Date(), '14:00:00')
        let Order = new Parse.Query("RoomOrder")
        Order.equalTo("room", this.data.roomId)
        Order.equalTo("company", company)
        Order.exists("status")
        Order.notEqualTo("status", 100)
        Order.notEqualTo("status", 400)
        Order.notEqualTo("status", 601)
        Order.notEqualTo("status", 700)
        Order.greaterThanOrEqualTo("startTime", this.data.endTime) //20  23    21 22  
        Order.lessThanOrEqualTo("endTime", this.data.startTime)
        Order.select("startTime", "endTime")
        let count = await Order.count()
        console.log(count);
        return count
    },
    async submit() {
        if (!this.data.startTime || !this.data.endTime) {
            wx.showToast({
                title: '请选择入住时间',
                icon: 'none',
            })
            return
        }
        if (this.data.customers.length == 0) {
            wx.showToast({
                title: '请选择入住人',
                icon: 'none',
            })
            return
        }
        let count = await this.checkOrderCount()
        if (count >= this.data.room.total) {
            console.log(count);
            wx.showToast({
                title: '当前日期，已无剩余房间，请重新选择',
                icon: 'none',
            })
            return
        }
        let tradeNo = this.getTradeNo()
        let order = await this.setOrder(tradeNo)
        if (order) {
            this.setData({
                activeOrder: order,
                tradeNo,
                showPayment: true,
            })
        }
    },
    async acceptResult(e) {
        let {
            activeOrder
        } = this.data
        let that = this
        let {
            params,
            no
        } = e.detail;
        that.setData({
            showPayment: false
        })
        try {
            if (params == "ok") {
                activeOrder.set("status", 100)
                activeOrder.set("isPay", true)
                await activeOrder.save()
                wx.showToast({
                    title: '支付成功',
                    icon: 'none',
                    duration: 1500,
                    mask: false,
                });
                wx.navigateBack({
                    delta: 1,
                })
            } else {
                wx.showToast({
                    title: '支付失败，取消订单',
                    icon: 'none',
                    duration: 1500,
                    mask: false,
                });
            }
        } catch (error) {
            console.log(error)
            wx.showToast({
                title: "支付失败",
                icon: "error",
                duration: 1500,
            });
            wx.hideLoading()
        }
    },
    //生成订单号
    getTradeNo() {
        let now = new Date()
        let tradeNo = "C" +
            String(now.getFullYear()) +
            (now.getMonth() + 1) +
            now.getDate() +
            now.getHours() +
            now.getMinutes() +
            now.getSeconds() +
            Math.random().toString().slice(-6); //生成六位随机数
        return tradeNo
    },
    //   创建待支付订单
    async setOrder(tradeNo) {
        let currentUser = Parse.User.current()
        let Order = Parse.Object.extend("RoomOrder");
        let order = new Order()
        try {
            order.set("details", this.data.room.details);
            order.set("user", {
                __type: 'Pointer',
                className: '_User',
                objectId: currentUser.id
            });
            order.set("orderNum", tradeNo);
            order.set("room", {
                __type: 'Pointer',
                className: 'ShopRoom',
                objectId: this.data.roomId
            });
            console.log(this.data.startTime, this.data.endTime);
            order.set("startTime", this.data.startTime);
            order.set("endTime", this.data.endTime);
            order.set("price", this.data.count * this.data.room.price);
            order.set("shopStore", {
                __type: 'Pointer',
                className: 'ShopStore',
                objectId: this.data.room.shop.objectId
            });
            order.set("company", {
                __type: 'Pointer',
                className: 'Company',
                objectId: company
            })
            order.set("name", this.data.customers[0]['realname']);
            order.set("mobile", this.data.customers[0]['mobile']);
            order.set("merber", this.data.peopleNum);
            order = await order.save()
        } catch (error) {
            console.log(error);
            wx.showToast({
                title: error.errMsg,
                icon: 'none'
            })
        }
        return order
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },
    async getRoomOrdersByRoomId(roomId) {
        let time1 = dateServ.changeDateTime(new Date(), '00:00:00');
        let time2 = this.timeaddsix(dateServ.changeDateTime(new Date(), '23:59:59'));
        console.log("time1", time1, "time2", time2)
        let Order = new Parse.Query("RoomOrder")
        Order.equalTo("room", roomId)
        Order.equalTo("company", company)
        Order.exists("status")
        Order.greaterThanOrEqualTo("startTime", time1)
        Order.lessThanOrEqualTo("startTime", time2)
        Order.select("startTime", "endTime")
        let orders = await Order.find()
        console.log(orders);
        return orders

    },
    timeaddsix(str) {
        // 创建日期对象，并初始化，完成文本转日期
        var date = new Date(str);
        //日期转文本方式一：
        // str = date.format("yyyy-MM-dd");
        var year = date.getFullYear(); //年
        var month = date.getMonth() + 7; //月 +6个月  因为js里month从0开始，所以要加1
        if (month > 12) {
            year++;
            month -= 12;
        }
        if (month < 10) {
            month = "0" + month;
        }
        var date2 = new Date(year, month, 0); //新的年月
        var day1 = date.getDate();
        var day2 = date2.getDate();
        if (day1 > day2) { //防止+6月后没有31天
            day1 = day2;
        }
        str = year + '/' +
            month + '/' +
            day1;
        return str
    },

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

    },

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

    },

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

    },

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

    },

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

    },
    // getRoom(){
    //     this.getRoom
    // }
})