/**
 * 获取当前是本月第几周
 * @returns {number}
 */
export function getCurrentWeekNum() {
    // 获取当前日期
    var currentDate = new Date();

    // 获取本月的第一天
    var firstDayOfMonth = new Date(currentDate.getFullYear(), currentDate.getMonth(), 1);

    // 获取本月的第一天是星期几
    var firstDayOfWeek = firstDayOfMonth.getDay();

    // 计算当前日期是本月的第几周
    var weekNumber = Math.ceil((currentDate.getDate() + firstDayOfWeek) / 7);

    // console.log("当前时间是本月的第 " + weekNumber + " 周");
    return weekNumber;
}

/**
 * 获取一周日期
 * @param weekType 本周/下周
 * @returns {{year, month, firstDayOfTheWeek, secondDayOfThisWeek, thirdDayOfTheWeek, fourthDayOfTheWeek, fifthDayOfTheWeek, sixthDayOfTheWeek, seventhDayOfTheWeek}}
 */
export function getWeek2(weekType) {
    console.log(weekType, 888888888);
    var date = [];
    let weekIndex = new Date().getDay();
    //可得到当前日期以及之前的
    for (let i = weekIndex - 1; i >= 0; i--) {
        if (weekType === '本周') {
            date.push(getNowWeek(-i))
        } else {
            date.push(getNextWeek(-i))
        }
    }
    for (let i = 1; i <= 7 - weekIndex; i++) {
        if (weekType === '本周') {
            date.push(getNowWeek(i))
        } else {
            date.push(getNextWeek(i))
        }
    }
    return {
        year: date[0].year,
        month: date[0].month,
        day: date[0].day,
        firstDayOfTheWeek: date[0].result,
        secondDayOfThisWeek: date[1].result,
        thirdDayOfTheWeek: date[2].result,
        fourthDayOfTheWeek: date[3].result,
        fifthDayOfTheWeek: date[4].result,
        sixthDayOfTheWeek: date[5].result,
        seventhDayOfTheWeek: date[6].result
    }

}

//本周日期
export function getNowWeek(day) {
    var today = new Date();
    var ts = today.getTime();//转化为时间戳毫秒数
    var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;
    today.setTime(targetday_milliseconds);
    var tYear = today.getFullYear();
    var tMonth = today.getMonth();
    var tDate = today.getDate();
    tMonth = tMonth + 1;
    tDate = tDate;
    //ios的格式判断
    if (uni.getSystemInfoSync().platform == 'ios') {
        //周几
        let time = tYear + "-" + tMonth + "-" + tDate
        let weekIndex = new Date(time).getDay();
        //改变今天的选中状态
        var d = new Date()
        var days = d.getDate()
        let daylist = {
            day: tDate, // 天
            isToday: tDate == days ? true : false, // 是否选中
            month: tMonth, // 月份
            result: tYear + "-" + tMonth + "-" + tDate, // 日期整体值
            week: weekIndex, //星期
            year: tYear, // 年份
        }
        return daylist
    } else {
        //周几
        let time = tYear + "-" + tMonth + "-" + tDate
        let weekIndex = new Date(time).getDay();
        //改变今天的选中状态
        var d = new Date()
        var days = d.getDate()
        let daylist = {
            day: tDate, // 天
            isToday: tDate == days ? true : false, // 是否选中
            month: tMonth, // 月份
            result: tYear + "-" + tMonth + "-" + tDate, // 日期整体值
            week: weekIndex, //星期
            year: tYear, // 年份
        }
        return daylist
    }
}

//下周日期
export function getNextWeek(day) {
    var today = new Date();
    var ts = today.getTime();//转化为时间戳毫秒数
    var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;
    today.setTime(targetday_milliseconds + 1000 * 60 * 60 * 24 * 7);
    var tYear = today.getFullYear();
    var tMonth = today.getMonth();
    var tDate = today.getDate();
    tMonth = tMonth + 1;
    tDate = tDate;
    //ios的格式判断
    if (uni.getSystemInfoSync().platform == 'ios') {
        //周几
        let time = tYear + "-" + tMonth + "-" + tDate
        let weekIndex = new Date(time).getDay();
        //改变今天的选中状态
        var d = new Date()
        var days = d.getDate()
        let daylist = {
            day: tDate, // 天
            isToday: tDate == days ? true : false, // 是否选中
            month: tMonth, // 月份
            result: tYear + "-" + tMonth + "-" + tDate, // 日期整体值
            week: weekIndex, //星期
            year: tYear, // 年份
        }
        return daylist
    } else {
        //周几
        let time = tYear + "-" + tMonth + "-" + tDate
        let weekIndex = new Date(time).getDay();
        //改变今天的选中状态
        var d = new Date()
        var days = d.getDate()
        let daylist = {
            day: tDate, // 天
            isToday: tDate == days ? true : false, // 是否选中
            month: tMonth, // 月份
            result: tYear + "-" + tMonth + "-" + tDate, // 日期整体值
            week: weekIndex, //星期
            year: tYear, // 年份
        }
        return daylist
    }
}