<template>
    <view>
        <nav-bar :navbarData="navbarData"></nav-bar>
        <view class="schedule" :style="'margin-top: ' + (height * 2 + 10) + 'rpx; height: calc(100vh - ' + (height * 2 + 10) + 'rpx)'">
            <view class="picker-border defaultColor">
                <picker @change="bindAccountChange" :value="accountIndex" :range="accounts" range-key="descripts">
                    <mp-cell link hover value="选择排班" :footer="selectedAccountDesc"></mp-cell>
                </picker>
            </view>

            <!-- 日历年月 -->
            <view class="defaultColor">
                <!-- <view class="calendar_head">{{monthstr[month-1]}}月</view> -->
                <view class="calendar_title">
                    <view class="icon" @tap="lastMonth" :data-time="year + '/' + month + '/' + 1">
                        <view :class="nowYearMonth == '' + year + month ? 'lastMonthed' : 'lastMonth'">上个月</view>
                    </view>
                    <view class="yearMonth_title">{{ year }}年{{ month }}月</view>
                    <view class="icon nextIcon" @tap="nextMonth">
                        <text class="nextMonth">下个月</text>
                        <!-- <text class="batchScheduling" bindtap='batchScheduling'>批量排班</text> -->
                    </view>
                </view>
            </view>

            <!-- 日历主体 -->
            <view class="calendar">
                <view class="header">
                    <view :class="index == todayIndex && isTodayWeek ? 'weekMark' : ''" v-for="(item, index) in date" :key="index">
                        <label :class="index == 0 || index == date.length - 1 ? 'changeColor' : ''">{{ item }}</label>
                    </view>
                </view>

                <view class="date-box">
                    <block v-for="(item, index) in dateArr" :key="index">
                        <view :class="getScheduleDateClass(item.isToday, isToday, endDate)">
                            <!-- <view class='{{isToday == item.isToday ? "nowDay" : ""}}'> -->
                            <view
                                :class="(nowYearMonthDate <= item.nowYearMonthDate ? 'date-head' : 'date-headpast') + ' '"
                                @tap="lookHuoDong"
                                :data-year="year"
                                :data-month="month"
                                :data-datenum="item.dateNum"
                                :data-time="item.nowYearMonthDate"
                            >
                                <view class="head-number">
                                    {{ item.dateNum }}
                                    <text class="startTip">{{ item.isToday == isToday && endDate != '' ? '始' : '' }}</text>
                                    <text class="endTip">{{ item.isToday == endDate && endDate != '' ? '末' : '' }}</text>
                                </view>
                                <block v-if="item.textCode == 'U'">
                                    <view class="head-text textU">{{ item.dateSub }}</view>
                                </block>
                                <block v-else-if="item.textCode == 'N'">
                                    <view class="head-text textN">{{ item.dateSub }}</view>
                                </block>
                                <block v-else>
                                    <view class="head-text textS">{{ item.dateSub }}</view>
                                </block>
                                <!-- <block></block> -->
                                <!-- {{ item.textCode == "U" && <view class="head-text textU">{{item.dateSub}}</view> }} -->
                                <!-- {{ item.textCode == "N" && <view class="head-text textN">{{item.dateSub}}</view> }}
						{{ item.textCode == "S" && <view class="head-text textS">{{item.dateSub}}</view> }} -->
                            </view>
                        </view>
                    </block>
                </view>
            </view>
            <mp-cells v-if="endDate == ''" :title="'(' + lookDate + ')排班情况'" class="scheduling-bottom">
                <block v-for="(item, index) in schedulingsArr" :key="index">
                    <mp-cell link hover :value="item.timeRange" :footer="item.status" @tap.native="handleScheduling($event, { item })" :data-item="item"></mp-cell>
                </block>
            </mp-cells>
            <view v-else>
                <mp-cells class="scheduling-range">
                    <mp-cell link hover @tap.native="handleSchedulingRange" :value="formatShortDate(isToday) + '—' + formatShortDate(endDate)" footer="点击批量排班"></mp-cell>
                </mp-cells>
            </view>
            <!-- <view class="rangeTitle" bindtap="handleSchedulingRange"></view> -->
            <!-- <mp-cells wx:for='{{rangeSchedulingsArr}}' title="{{item.date}}" class="scheduling-bottom" wx:key='index'>
  			<block wx:for='{{item.resList}}' wx:for-item="itemDetail" wx:key='timeRangeID'>
  				<mp-cell value='{{itemDetail.timeRange}}' footer='{{itemDetail.status}}' data-item='{{itemDetail}}'></mp-cell>
  			</block>
  		</mp-cells> -->
        </view>
    </view>
</template>
<script>
import navBar from '@/pages/components/navbar/index';
// pages/scheduling/scheduling.js
import { $http } from '../../../../config/https.js';
import Cache from '../../../../utils/cache';
const app = getApp();
export default {
    components: {
        navBar
    },
    computed: {
        selectedAccountDesc() {
            const selectedAccount = this.accounts[Number(this.accountIndex) || 0];
            return selectedAccount ? selectedAccount.descripts : '';
        }
    },
    data() {
        return {
            year: 0,
            month: 0,
            monthstr: ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'],
            date: ['日', '一', '二', '三', '四', '五', '六'],
            dateArr: [],
            isToday: 0,
            isTodayWeek: false,
            todayIndex: 0,

            // 当前年月时间
            nowYearMonth: '',

            nowYearMonthDate: 0,
            nowYearAndMonth: 0,

            // 下拉选项
            accounts: [],

            accountIndex: 0,

            // 排班日历
            schedulings: [],

            // 排班情况列表
            schedulingsArr: [],

            // 初始状态
            isOnload: false,

            // 查看的日期 不使用isToday判断
            lookDate: '',

            endDate: '',

            //按照时间段排班
            // 时间段内的排班情况列表
            rangeSchedulingsArr: [],

            navbarData: {
                background: '',
                title: '我的排班',
                //导航栏 中间的标题
                height: '100',
                bottom: true,
                isGoBack: true
            },

            height: app.globalData.height,
            descripts: ''
        };
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.onInitData();
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {
        // console.log("页面状态=",1);
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function (e) {
        // console.log("页面状态=",2,this.data.myTemp);
        if (this.isOnload) {
            this.onInitData();
        }
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {
        // console.log("页面状态=",3);
    },
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {
        // console.log("页面状态=",4);
    },
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {
        // console.log("页面状态=",5);
    },
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        // console.log("页面状态=",6);
    },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {},
    methods: {
        pad2: function (value) {
            return String(value).padStart(2, '0');
        },

        formatDateKey: function (year, month, day) {
            return '' + year + this.pad2(month) + this.pad2(day);
        },

        formatDateForApi: function (year, month, day) {
            return year + '-' + this.pad2(month) + '-' + this.pad2(day);
        },

        normalizeScheduleDate: function (date) {
            if (!date) return '';
            const parts = String(date).replace(/\//g, '-').split('-');
            if (parts.length < 3) return String(date);
            return parts[0] + '-' + this.pad2(parts[1]) + '-' + this.pad2(parts[2]);
        },

        buildScheduleMap: function (schedulings) {
            const list = Array.isArray(schedulings) ? schedulings : [];
            return list.reduce((map, item) => {
                if (item && item.date) {
                    map[this.normalizeScheduleDate(item.date)] = item;
                }
                return map;
            }, {});
        },

        getScheduleText: function (schedule) {
            if (schedule && schedule.text) {
                return schedule.text;
            }
            return schedule && schedule.textCode && schedule.textCode != 'U' ? '已排' : '未排';
        },

        getScheduleCode: function (schedule) {
            return schedule && schedule.textCode ? schedule.textCode : 'U';
        },

        getScheduleDateClass: function (date, isToday, endDate) {
            if (date == isToday || date == endDate) {
                return 'nowDay';
            }
            if (endDate != '' && date > isToday && date < endDate) {
                return 'middleDay';
            }
            return '';
        },

        formatShortDate: function (str) {
            return str ? str.substring(4, 6) + '/' + str.substring(6, 8) : '';
        },

        onInitData: function () {
            let now = new Date();
            let year = now.getFullYear();
            let month = now.getMonth() + 1;
            let isToday = '' + year + month + now.getDate();
            if (month < 10) {
                isToday = '' + year + ('0' + month) + now.getDate();
            }
            if (now.getDate() < 10) {
                isToday = '' + year + month + '0' + now.getDate();
            }
            if (month < 10 && now.getDate() < 10) {
                isToday = '' + year + '0' + month + '0' + now.getDate();
            }
            this.setData({
                year: year,
                month: month,
                isToday: isToday,
                endDate: '',
                lookDate: year + '-' + month + '-' + now.getDate(),
                nowYearMonth: '' + year + month,
                nowYearAndMonth: new Date(year + '/' + month + '/' + 1).getTime(),
                nowYearMonthDate: new Date(year + '/' + month + '/' + now.getDate()).getTime()
            });
            this.dateInit(year, month - 1);
            this.getSchedulingType();
        },

        // 排班类型
        getSchedulingType: function () {
            let userData = Cache.get('userData');
            let { hospID } = userData;
            let data = {
                params: [
                    {
                        hospID: hospID
                    }
                ]
            };
            $http.post('urlDeault', this, {
                code: '03100079',
                data: data,
                success: function (res) {
                    if (res.errorCode == '0') {
                        const schedulingTypes = Array.isArray(res.result) ? res.result : [];
                        if (schedulingTypes.length > 0) {
                            this.setData(
                                {
                                    accounts: schedulingTypes
                                },
                                () => {
                                    let tempIndex = '';
                                    schedulingTypes.forEach((item, index) => {
                                        if (item.defaultFlag) {
                                            if (item.defaultFlag == 'Y') {
                                                tempIndex = index;
                                            }
                                        }
                                    });
                                    if (tempIndex !== '') {
                                        this.setData(
                                            {
                                                accountIndex: tempIndex,
                                                isOnload: true
                                            },
                                            () => {
                                                this.changeCalendarAndDetail();
                                            }
                                        );
                                    } else {
                                        this.changeCalendarAndDetail();
                                        this.setData({
                                            isOnload: true
                                        }); //首次通过load加载
                                    }
                                }
                            );
                        } else {
                            this.setData({
                                accounts: [],
                                schedulings: [],
                                schedulingsArr: [],
                                isOnload: true
                            });
                            this.dateInit(this.year, this.month - 1);
                        }
                    } else {
                        this.setData({
                            accounts: [],
                            schedulings: [],
                            schedulingsArr: [],
                            isOnload: true
                        });
                        this.dateInit(this.year, this.month - 1);
                    }
                },
                fail: function () {
                    this.setData({
                        accounts: [],
                        schedulings: [],
                        schedulingsArr: [],
                        isOnload: true
                    });
                    this.dateInit(this.year, this.month - 1);
                }
            });
        },

        // 排班日历
        getSchedulingCalendar: function (setYear, setMonth) {
            const year = setYear || this.year || new Date().getFullYear();
            const month = setMonth || this.month || new Date().getMonth() + 1;
            const resourceTypeID = this.getIndexId();
            if (!resourceTypeID) {
                this.setData({
                    schedulings: []
                });
                this.dateInit(year, month - 1);
                return;
            }
            let userData = Cache.get('userData');
            let { hospID, userID, groupID, locID } = userData;
            let obj = {
                params: [
                    {
                        userID: userID,
                        groupID: groupID,
                        locID: locID,
                        hospID: hospID,
                        resourceTypeID: resourceTypeID,
                        //出诊类型ID
                        year: year,
                        month: month
                    }
                ]
            };
            $http.post('urlDeault', this, {
                code: '03100044',
                data: obj,
                success: function (res) {
                    if (res.errorCode == '0') {
                        this.setData(
                            {
                                schedulings: Array.isArray(res.result) ? res.result : []
                            },
                            () => {
                                this.dateInit(year, month - 1);
                            }
                        );
                    } else {
                        this.setData(
                            {
                                schedulings: []
                            },
                            () => {
                                this.dateInit(year, month - 1);
                            }
                        );
                    }
                },
                fail: function () {
                    this.setData(
                        {
                            schedulings: []
                        },
                        () => {
                            this.dateInit(year, month - 1);
                        }
                    );
                }
            });
        },

        // 获取出诊类型ID
        getIndexId: function () {
            let array = this.accounts;
            if (array.length > 0) {
                const selectedAccount = array[Number(this.accountIndex) || 0];
                return selectedAccount && selectedAccount.id;
            }
        },

        dateInit: function (setYear, setMonth) {
            //全部时间的月份都是按0~11基准，显示月份才+1
            let dateArr = []; //需要遍历的日历数组数据
            let arrLen = 0; //dateArr的数组长度
            let now = setYear ? new Date(setYear, setMonth) : new Date();
            let year = setYear !== undefined && setYear !== null ? Number(setYear) : now.getFullYear();
            let displayMonth = 0;
            let nextYear = 0;
            let month = setMonth || now.getMonth(); //没有+1方便后面计算当月总天数
            let nextMonth = month + 1 > 11 ? 1 : month + 1;
            let startWeek = new Date(year + '/' + (month + 1) + '/' + 1).getDay(); //目标月1号对应的星期
            let dayNums = new Date(year, nextMonth, 0).getDate(); //获取目标月有多少天
            let obj = {};
            let num = 0;
            if (month + 1 > 11) {
                nextYear = year + 1;
                dayNums = new Date(nextYear, nextMonth, 0).getDate();
            }
            if (setMonth !== undefined && setMonth !== null) {
                month = Number(setMonth);
            }
            displayMonth = month + 1;
            startWeek = new Date(year, month, 1).getDay();
            dayNums = new Date(year, month + 1, 0).getDate();
            const scheduleMap = this.buildScheduleMap(this.schedulings);
            const hasDateField = Object.keys(scheduleMap).length > 0;
            arrLen = startWeek + dayNums;
            for (let i = 0; i < arrLen; i++) {
                if (i >= startWeek) {
                    num = i - startWeek + 1;
                    let isToday = this.formatDateKey(year, displayMonth, num);
                    const scheduleDate = this.formatDateForApi(year, displayMonth, num);
                    const sObj = hasDateField ? scheduleMap[scheduleDate] : this.schedulings[num - 1];
                    obj = {
                        isToday: isToday,
                        dateNum: num,
                        nowYearMonthDate: new Date(year, month, num).getTime(),
                        dateSub: this.getScheduleText(sObj),
                        textCode: this.getScheduleCode(sObj)
                    };
                } else {
                    obj = {};
                }
                dateArr[i] = obj;
            }
            this.setData({
                dateArr: dateArr
            });

            // let nowDate = new Date();
            // let nowYear = nowDate.getFullYear();
            // let nowMonth = nowDate.getMonth() + 1;
            // let nowWeek = nowDate.getDay();
            // let getYear = setYear || nowYear;
            // let getMonth = setMonth >= 0 ? (setMonth + 1) : nowMonth;
            // if (nowYear == getYear && nowMonth == getMonth) {
            //   this.setData({
            //     isTodayWeek: true,
            //     todayIndex: nowWeek
            //   })
            // } else {
            //   this.setData({
            //     isTodayWeek: false,
            //     todayIndex: -1
            //   })
            // }
        },

        /**
         * 上月切换
         */
        lastMonth: function (e) {
            //全部时间的月份都是按0~11基准，显示月份才+1
            let year = this.month - 2 < 0 ? this.year - 1 : this.year;
            let month = this.month - 2 < 0 ? 11 : this.month - 2;
            let now = new Date();
            let nowyear = now.getFullYear();
            let nowmonth = now.getMonth() + 1;
            if (nowyear + '-' + nowmonth == this.year + '-' + (this.month - 1)) {
                let lookDate = nowyear + '-' + nowmonth + '-' + now.getDate();
                let isToday = '' + nowyear + nowmonth + now.getDate();
                if (month < 10) {
                    isToday = '' + nowyear + ('0' + nowmonth) + now.getDate();
                }
                // if (num < 10) {
                //   isToday = '' + nowyear + nowmonth + ('0' + now.getDate());
                // }
                // if ((num < 10) && (month < 10)) {
                //   isToday = '' + nowyear + ('0' + (nowmonth)) + ('0' + now.getDate());
                // }

                this.setData({
                    year: year,
                    month: month + 1,
                    isToday: isToday,
                    lookDate: lookDate
                });
                this.getSchedulingCalendar(year, month + 1);
                this.getSchedulingInfo(lookDate);
            } else {
                let { time } = e.currentTarget.dataset;
                if (this.nowYearAndMonth < this.getSelectTime(time)) {
                    let isToday = '' + year + (month + 1) + 1;
                    if (month + 1 < 10) {
                        isToday = '' + year + ('0' + (month + 1)) + '01';
                    }
                    let lookDate = year + '-' + (month + 1) + '-' + '1';
                    this.setData({
                        year: year,
                        month: month + 1,
                        isToday: isToday,
                        //默认选中1号
                        lookDate: lookDate
                    });
                    // this.dateInit(year, month);
                    this.getSchedulingCalendar(year, month + 1);
                    this.getSchedulingInfo(lookDate);
                } else {
                    uni.showToast({
                        title: '历史月份排班，不允许修改',
                        icon: 'none'
                    });
                }
            }
        },

        getSelectTime: function (str) {
            let selectNumber = new Date(str).getTime();
            return selectNumber;
        },

        // 当前年月日
        getYearMonthDateTime: function (year, month, date) {
            let selectNumber = new Date(year + '/' + month + '/' + date).getTime();
            return selectNumber;
        },

        /**
         * 下月切换
         */
        nextMonth: function () {
            //全部时间的月份都是按0~11基准，显示月份才+1
            let year = this.month > 11 ? this.year + 1 : this.year;
            let month = this.month > 11 ? 0 : this.month;
            let lookDate = year + '-' + (month + 1) + '-' + '1';
            let isToday = '' + year + (month + 1) + '01'; //默认选中1号
            if (month + 1 < 10) {
                isToday = '' + year + ('0' + (month + 1)) + '01'; //默认选中1号
            }

            this.setData({
                year: year,
                month: month + 1,
                isToday: isToday,
                //默认选中1号
                lookDate: lookDate,
                endDate: ''
            });
            // this.dateInit(year, month);
            this.getSchedulingCalendar(year, month + 1);
            this.getSchedulingInfo(lookDate);
        },

        bindAccountChange: function (e) {
            this.setData(
                {
                    accountIndex: e.detail.value
                },
                () => {
                    this.changeCalendarAndDetail();
                }
            );
        },

        lookHuoDong: function (e) {
            let { year, month, datenum, time } = e.currentTarget.dataset;
            let lookDate = year + '-' + month + '-' + datenum;
            let { isToday, endDate } = this;
            let currentDay = '' + year + month + datenum;
            if (month < 10) {
                currentDay = '' + year + ('0' + month) + datenum;
            }
            if (datenum < 10) {
                currentDay = '' + year + month + ('0' + datenum);
            }
            if (datenum < 10 && month < 10) {
                currentDay = '' + year + ('0' + month) + ('0' + datenum);
            }
            if (this.nowYearMonthDate <= time) {
                this.getSchedulingInfo(lookDate);
                if (endDate == '') {
                    if (Number(isToday) < Number(currentDay)) {
                        this.setData(
                            {
                                endDate: currentDay,
                                lookDate: lookDate
                            },
                            () => {
                                //this.getRangeSchedulingInfo();
                            }
                        );
                    } else {
                        this.setData({
                            isToday: currentDay,
                            lookDate: lookDate
                        });
                    }
                } else {
                    this.setData({
                        endDate: '',
                        lookDate: lookDate,
                        isToday: currentDay
                    });
                }
            } else {
                uni.showToast({
                    title: '历史日期排班，不允许修改',
                    icon: 'none'
                });
            }
        },

        // 点击获取时间段内的排班信息
        getRangeSchedulingInfo: function () {
            let userData = Cache.get('userData');
            let { hospID, userID, locID } = userData;
            let { isToday, endDate } = this;
            let obj = {
                params: [
                    {
                        userID: userID,
                        locID: locID,
                        hospID: hospID,
                        resourceTypeID: this.getIndexId(),
                        //出诊类型ID
                        stDate: isToday.substring(0, 4) + '-' + isToday.substring(4, 6) + '-' + isToday.substring(6, 8),
                        endDate: endDate.substring(0, 4) + '-' + endDate.substring(4, 6) + '-' + endDate.substring(6, 8)
                    }
                ]
            };
            $http.post('urlDeault', this, {
                code: '03100134',
                data: obj,
                success: function (res) {
                    if (res.errorCode == '0') {
                        this.setData({
                            rangeSchedulingsArr: res.result
                        });
                    }
                }
            });
        },

        // 点击日历获取排班信息
        getSchedulingInfo: function (lookDate) {
            let userData = Cache.get('userData');
            let { hospID, userID, locID } = userData;
            let obj = {
                params: [
                    {
                        userID: userID,
                        locID: locID,
                        hospID: hospID,
                        resourceTypeID: this.getIndexId(),
                        //出诊类型ID
                        date: lookDate
                    }
                ]
            };
            $http.post('urlDeault', this, {
                code: '03100045',
                data: obj,
                success: function (res) {
                    if (res.errorCode == '0') {
                        this.setData({
                            schedulingsArr: res.result,
                            rangeSchedulingsArr: []
                        });
                    }
                }
            });
        },

        handleScheduling: function (e, _dataset) {
            /* ---处理dataset begin--- */
            this.handleDataset(e, _dataset);
            /* ---处理dataset end--- */
            let { item } = e.currentTarget.dataset;
            let transData = JSON.stringify(item);
            let lookDate = this.lookDate;
            let url = '';
            let resourceTypeID = this.getIndexId(); //初诊类型ID
            if (item.status == '未排班') {
                url = '../schedulingHandle/schedulingHandle?transData=' + transData + '&date=' + lookDate + '&resourceTypeID=' + resourceTypeID;
            } else {
                url = '../schedulingQuery/schedulingQuery?transData=' + transData + '&date=' + lookDate + '&resourceTypeID=' + resourceTypeID;
            }
            uni.navigateTo({
                //目的页面地址
                url: url,
                success: function (res) {}
            });
        },

        /**
         * 批量排班
         */
        batchScheduling: function () {
            let url = '';
            let resourceTypeID = this.getIndexId(); //出诊类型ID
            let resourceTypeDesc = '';
            if (this.accounts.length > 0) {
                resourceTypeDesc = this.accounts.filter((item) => item.id === resourceTypeID)[0].descripts;
            }
            url = '../batchScheduling/batchScheduling?resourceTypeID=' + resourceTypeID + '&resourceTypeDesc=' + resourceTypeDesc;
            //pages\oneselfCenter\page\batchScheduling
            uni.navigateTo({
                //目的页面地址
                url: url,
                success: function (res) {}
            });
        },

        handleSchedulingRange: function (e) {
            let url = '';
            let { isToday, endDate, schedulings } = this;
            let startDate = Number(isToday);
            let endDateNum = Number(endDate);
            let alearySchedule = false;
            for (var i = startDate; i < endDateNum + 1; i++) {
                let stringi = '' + i;
                let date = stringi.substring(0, 4) + '-' + stringi.substring(4, 6) + '-' + stringi.substring(6, 8);
                for (var j = 0; j < schedulings.length; j++) {
                    if (schedulings[j].date == date && schedulings[j].textCode != 'U') {
                        alearySchedule = true;
                    }
                }
            }
            if (alearySchedule) {
                uni.showToast({
                    title: '该时间段已有排班，不能选择该日期范围',
                    icon: 'none'
                });
                return;
            }
            let resourceTypeID = this.getIndexId(); //初诊类型ID
            url = '../schedulingRange/schedulingRange?resourceTypeID=' + resourceTypeID + '&stDate=' + isToday + '&endDate=' + endDate;
            uni.navigateTo({
                //目的页面地址
                url: url,
                success: function (res) {}
            });
        },

        // 排班切换修改日历和排班情况
        changeCalendarAndDetail: function () {
            this.getSchedulingCalendar();
            // 默认选择排班
            let now = new Date();
            let year = now.getFullYear();
            let month = now.getMonth() + 1;
            let isToday = '' + year + month + now.getDate();
            if (month < 10) {
                isToday = '' + year + '0' + month + now.getDate();
            }
            if (now.getDate() < 10) {
                isToday = '' + year + month + '0' + now.getDate();
            }
            if (month < 10 && now.getDate() < 10) {
                isToday = '' + year + '0' + month + '0' + now.getDate();
            }
            this.setData({
                year: year,
                month: month,
                isToday: isToday
            });
            let lookDate = year + '-' + month + '-' + now.getDate();
            this.getSchedulingInfo(lookDate);
        }
    }
};
</script>
<style>
/* 日历 */
page {
    height: 100%;
}

.schedule {
    width: 100%;
    overflow: auto;
}

.calendar_head {
    text-align: center;
}

.calendar_title {
    display: flex;
    /* justify-content: space-around; */
    height: 100rpx;
    line-height: 100rpx;
    padding: 0px 10px;
}
.icon {
    flex: 1;
}
.nextIcon {
    text-align: end;
}
.batchScheduling {
    margin-left: 28rpx;
    color: #0079fe;
}

.calendar {
    width: 100%;
    background: #fff;
    border-bottom-right-radius: 20rpx;
    border-bottom-left-radius: 20rpx;
    font-family: FZZhunYuan-M02S;
}

.header {
    font-size: 0;
    margin: 0 auto;
    border-top: 1px solid var(--weui-FG-3);
    border-bottom: 1px solid var(--weui-FG-3);
    padding: 0 20rpx;
}

.header > view {
    display: inline-block;
    width: 14.285%;
    color: #666;
    font-size: 30rpx;
    text-align: center;
    padding: 20rpx 0;
}

.weekMark {
    position: relative;
    margin: 0 auto;
}

.weekMark view {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    border-bottom: 2px solid #69f;
}

.date-box {
    font-size: 0;
    margin: 0 auto;
    padding: 0 20rpx;
}

.date-box > view {
    position: relative;
    display: inline-block;
    width: 14.285%;
    color: #666;
    text-align: center;
    vertical-align: middle;
}

.date-head {
    font-size: 10pt;
}

.date-head .head-number {
    color: #333333;
    font-size: 18px;
}

.date-head .head-text {
    font-size: 12px;
}

.date-head .textN {
    color: #1890ff;
}

.date-head .textU {
    color: #cccccc;
}

.date-head .textS {
    color: #ff0000;
}

.date-headpast {
    font-size: 10pt;
}

.date-headpast .head-number {
    color: #cccccc;
    font-size: 18px;
}

.date-headpast .head-text {
    color: #cccccc;
    font-size: 12px;
}

.nowDay .date-head {
    background-color: #1890ff;
    color: #fff;
    border-radius: 5px;
}

.nowDay .date-head .head-number {
    color: #fff;
    font-size: 18px;
}

.nowDay .date-head .head-text {
    color: #fff;
}

/* 排班 */
.picker-border {
    border-bottom: 1px solid var(--weui-FG-3);
}

.picker-border .weui-cell__bd {
    color: #666666;
}

.picker-border .weui-cell__ft {
    color: #666666;
}

.yearMonth_title {
    color: #333333;
    flex: 1;
}

.lastMonth {
    color: #0079fe;
    flex: 1;
}

.lastMonthed {
    color: #666666;
}

.nextMonth {
    color: #0079fe;
}

.changeColor {
    color: #ff7200;
}

.scheduling-bottom .weui-cells__title {
    color: #333333;
    font-weight: bold;
    height: 100rpx;
    background-color: #f5f4f4;
    line-height: 100rpx;
    margin: 0;
}

.scheduling-range .weui-cell_access .weui-cell__ft {
    color: #0079fe;
}

.startDate {
    background-color: #ff0000;
}

.endDate {
    background-color: #ff0000;
}

.startTip {
    font-size: 22rpx;
    float: right;
    padding-right: 5rpx;
}

.endTip {
    font-size: 22rpx;
    float: right;
    padding-right: 5rpx;
}

.middleDay .date-head {
    background-color: #e6f2ff;
    color: #0079fe;
}

.middleDay .date-head .head-number {
    color: #0079fe;
    font-size: 18px;
}

.middleDay .date-head .head-text {
    color: #0079fe;
}

.rangeTitle {
    color: #0079fe;
    font-weight: 600;
    font-size: 34rpx;
    height: 100rpx;
    line-height: 100rpx;
    border-bottom: 1px solid #eee;
    border-top: 1px solid #eee;
}

.defaultColor {
    background-color: #ffffff;
}
</style>
