<template>
    <div class="week">
        <div class="head">
            <div @click="zhou--">
                <img src="" alt="" />
                上一周
            </div>
            {{week.year}}年{{week.yue}}月
            <a-button type="primary" class="button" @click="navto()"> 月日历 </a-button>
            <div @click="zhou++">
                下一周
                <img src="" alt="" />
            </div>
        </div>
        <div class="week">
        <div class="heads">
            <div></div>
            <div :class="{ zhou: zhou == 0 && week.zhou == 1 }">
                周一<span>{{ week.date[0].day }}</span>
            </div>
            <div :class="{ zhou: zhou == 0 && week.zhou == 2 }">
                周二<span>{{ week.date[1].day }}</span>
            </div>
            <div :class="{ zhou: zhou == 0 && week.zhou == 3 }">
                周三<span>{{ week.date[2].day }}</span>
            </div>
            <div :class="{ zhou: zhou == 0 && week.zhou == 4 }">
                周四<span>{{ week.date[3].day }}</span>
            </div>
            <div :class="{ zhou: zhou == 0 && week.zhou == 5 }">
                周五<span>{{ week.date[4].day }}</span>
            </div>
            <div :class="{ zhou: zhou == 0 && week.zhou == 6 }">
                周六<span>{{ week.date[5].day }}</span>
            </div>
            <div :class="{ zhou: zhou == 0 && week.zhou == 0 }">
                周日<span>{{ week.date[6].day }}</span>
            </div>
        </div>
        <div class="body">
            <div class="row" v-for="item in 24" :key="item">
                <div class="day date">
                    {{ item > 10 ? item - 1 : "0" + (item - 1) }}:00-{{
                    item > 9 ? item : "0" + item
                    }}:00
                </div>
                <div v-for="i in 7" :key="i">
                    <div class="day">
                        <div :class="zhuangtai(week.date[i -1].list[item - 1].zhuangtai)" v-if="week.date[i -1].list[item - 1].title != ''">
                            <div class="one-line-hide" style="max-width: 1.5rem">
                                {{week.date[i -1].list[item - 1].title}}
                            </div>
                            <div>{{week.date[i -1].list[item - 1].time}}</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        </div>
    </div>
</template>
<style lang="scss" scoped>
.week {
    display: flex;
    flex-direction: column;
    align-items: center;
    .head {
        width: 1320px;
        height: 57px;
        background-color: #fff;
        display: flex;
        align-items: center;
        justify-content: center;
        position: relative;
        > div {
            display: flex;
            align-items: center;
            font-size: 13px;
            color: #0dbba4;
            > img {
                width: 7px;
                height: 11px;
            }
        }
        > div:first-child {
                margin-right: 90px;
            > img {
                margin-right: 11px;
            }
        }
        > div:last-child {
            margin-left: 90px;

            > img {
                margin-left: 11px;
            }
        }
        .button {
            width: 57px;
            height: 26px;
            background-color: #0dbba4;
            border-right: 4px;
            border: none;
            font-size: 10px;
            color: #fff;
            padding: 0;
            position: absolute;
            right: 40px;
        }
    }
    .week {
        .heads {
            width: 1320px;
            height: 63px;
            display: flex;
            > div {
                width: 100%;
                height: 100%;
                background-color: #f5fefd;
                text-align: center;
                line-height: 1;
                font-size: 13px;
                color: #08ae98;
                border-right: 1px solid #eee;
                box-sizing: border-box;
                display: flex;
                flex-direction: column;
                align-items: center;
                justify-content: center;

                > span {
                font-size: 11px;
                margin-top: 9px;
                color: #111;
                }
            }
            .zhou {
                color: #fff;
                background: #08ae98;
                > span {
                color: #fff;
                }
            }
        }
        .body {
            width: 100%;
            .row {
                background-color: #fff;
                height: 63px;
                width: 100%;
                display: flex;
                .date {
                    background-color: #f5fefd;
                    text-align: center;
                    line-height: 63px;
                    font-size: 11px;
                    color: #111;
                }
                > div {
                    width: 100%;
                    border-top: 1px solid #eee;
                    border-right: 1px solid #eee;
                    .day {
                        height: 100%;
                        display: flex;
                        flex-direction: column;
                        color: #111;

                        > div {
                            min-height: 100%;
                            width: 100%;
                            border-radius: 6px;
                            overflow: hidden;
                            display: flex;
                            flex-direction: column;
                            align-items: center;
                            justify-content: center;
                            font-size: 11px;
                            border-radius: 6px;
                            overflow: hidden;
                            > div:last-child {
                                font-size: 11px;
                                margin-top: 8px;
                            }
                        }
                        .old {
                            background-color: #f7f7f7;
                            color: #111;

                        }
                        .ing {
                            background-color: #0dbba4;
                            color: #fff;
                        }
                        .next {
                            background-color: #cef9f0;
                            color: #0dbba4;
                        }
                    }
                }
                > div::last-child {
                    border: unset;
                }
            }
        }
    }
}
</style>
<script lang="ts">
import { defineComponent, ref, watch } from "vue";
import { getDay, gethour, getminute, gettime, getweek } from "@/utils/date";
import store from '@/store';
import { getdatelist, userinfo } from '@/api';
import router from '@/router';

export default defineComponent({
    props: {},
    setup() {
        const zhou = ref(0);
        const week = ref<any>(getweek());
        const userid = store.state.userinfo.memberid;
        console.log(week.value);
        function getdates(userid: number){
            getdatelist(week.value.start, week.value.end, userid).then((res: any)=>{
                console.log(res)
                for(const i in res){
                    const day = getDay(res[i].dateline)
                    console.log(day)
                    for(const j in week.value.date){
                        console.log(getDay(week.value.date[j].day))
                        if(day == getDay(week.value.date[j].day)){
                            console.log("fuzhi")
                            week.value.date[j].list[gethour(res[i].dateline)].start = getminute(res[i].dateline);
                            week.value.date[j].list[gethour(res[i].dateline)].num = res[i].livetime
                            week.value.date[j].list[gethour(res[i].dateline)].title = res[i].title
                            week.value.date[j].list[gethour(res[i].dateline)].time = gettime(res[i].dateline, res[i].livetime)
                            week.value.date[j].list[gethour(res[i].dateline)].zhuangtai = res[i].livestatus
                        }
                    }
                }
                console.log(week.value)
            })
        }

        getdates(userid);
        
        watch(zhou, (value) => {
            week.value = getweek(value);
            console.log(week.value);
            getdates(userid)
        });

        function zhuangtai(index: number){
            switch (index) {
                case 0:
                    return 'next'
                case 1:
                    return 'ing'
                case 2:
                    return 'old'
                default:
                    return 'old'
            }
        }
        function navto(){
            router.push("/regime/date")
        }
        return {
            zhou,
            week,
            navto,
            zhuangtai
        };
    },
});
</script>