<template>
    <div class="Detail">
        <header class="header">
            <el-page-header @back="goBack" content="产床信息" />
            <div class="title">
                <h4></h4>
                <span class="title">{{ $route.query.roomNum }}</span>
                <el-date-picker
                    v-model="date"
                    @change="pickerChange"
                    type="date"
                    value-format="yyyy-MM-dd"
                    :picker-options="pickerOptions"
                    placeholder="选择日期"
                ></el-date-picker>
            </div>
        </header>

        <section class="section">
            <article class="left">

                <div v-if="roomType==1||roomType==2" class="contianer">
                    <el-carousel height="300px" indicator-position="none" :interval="1800">
                        <el-carousel-item v-for="(item, index) in empty.a" :key="item + index">
                            <img :src="item.url" />
                        </el-carousel-item>
                    </el-carousel>
                </div>

                <div v-else-if="$route.query.type==3||$route.query.type==4" class="contianer">
                    <el-carousel height="300px" indicator-position="none" :interval="1800">
                        <el-carousel-item v-for="(item, index) in number.a" :key="item + index">
                            <img @click="toSowDetail(index)" :src="item" />
                        </el-carousel-item>
                    </el-carousel>
                </div>

                <div v-else class="contianer">
                    <el-carousel height="300px" indicator-position="none" :interval="1800">
                        <el-carousel-item v-for="(item, index) in number.a" :key="item + index">
                            <img @click="toSowDetail(index)" :src="item" />
                        </el-carousel-item>
                    </el-carousel>
                </div>
            </article>

            <article class="right">
                <ul class="ul" v-if="roomType==1">
                    <li class="li">
                        <span class="title">产仔数：</span>
                        <span class="content" style="font-size: 26px">{{0}}只</span>
                    </li>
                    <li class="li">
                        <span class="title">活仔数：</span>
                        <!-- 小于等于八只的标红 -->
                        <span class="content" style="font-size: 26px">{{0}}只</span>
                    </li>
                    <li class="li">
                        <span class="title">存活率：</span>
                        <!-- 小于等于80%的标红 -->
                        <span class="content" style="font-size: 26px">100%</span>
                    </li>
                    <li class="li">
                        <span class="title">猪仔日龄：</span>
                        <span class="content" style="font-size: 26px">{{0}}天</span>
                    </li>
                    <li class="li">
                        <span class="title">产床状态：</span>
                        <span class="content">空</span>
                    </li>
                    <li class="li">
                        <span class="title">出生日期：</span>
                        <span class="content"></span>
                    </li>
                    <li class="li">
                        <span class="title">预计断奶剩余天数：</span>
                        <span class="content"></span>
                    </li>
                </ul>
                <ul class="ul" v-else-if="roomType==2">
                    <li class="li">
                        <span class="title">产仔数：</span>
                        <span class="content" style="font-size: 26px">{{0}}只</span>
                    </li>
                    <li class="li">
                        <span class="title">活仔数：</span>
                        <!-- 小于等于八只的标红 -->
                        <span class="content" style="font-size: 26px">{{0}}只</span>
                    </li>
                    <li class="li">
                        <span class="title">存活率：</span>
                        <!-- 小于等于80%的标红 -->
                        <span class="content" style="font-size: 26px">100%</span>
                    </li>
                    <li class="li">
                        <span class="title">猪仔日龄：</span>
                        <span class="content" style="font-size: 26px">{{0}}天</span>
                    </li>
                    <li class="li">
                        <span class="title">产床状态：</span>
                        <span class="content">空</span>
                    </li>
                    <li class="li">
                        <span class="title">出生日期：</span>
                        <span class="content"></span>
                    </li>
                    <li class="li">
                        <span class="title">预计断奶剩余天数：</span>
                        <span class="content"></span>
                    </li>
                </ul>
                <ul class="ul" v-else-if="roomType==3">
                    <li class="li">
                        <span class="title">产仔数：</span>
                        <span class="content" style="font-size: 26px">{{0}}只</span>
                    </li>
                    <li class="li">
                        <span class="title">活仔数：</span>
                        <!-- 小于等于八只的标红 -->
                        <span class="content" style="font-size: 26px">{{0}}只</span>
                    </li>
                    <li class="li">
                        <span class="title">存活率：</span>
                        <!-- 小于等于80%的标红 -->
                        <span class="content" style="font-size: 26px">100%</span>
                    </li>
                    <li class="li">
                        <span class="title">猪仔日龄：</span>
                        <span class="content" style="font-size: 26px">{{0}}天</span>
                    </li>
                    <li class="li">
                        <span class="title">产床状态：</span>
                        <span class="content">空</span>
                    </li>
                    <li class="li">
                        <span class="title">出生日期：</span>
                        <span class="content"></span>
                    </li>
                    <li class="li">
                        <span class="title">预计断奶剩余天数：</span>
                        <span class="content"></span>
                    </li>
                </ul>
                <ul class="ul" v-else>
                    <li class="li">
                        <span class="title">产仔数：</span>
                        <span class="content" style="font-size: 26px">{{12}}只</span>
                    </li>
                    <li class="li">
                        <span class="title">活仔数：</span>
                        <!-- 小于等于八只的标红 -->
                        <span class="content" style="font-size: 26px">{{12}}只</span>
                    </li>
                    <li class="li">
                        <span class="title">存活率：</span>
                        <!-- 小于等于80%的标红 -->
                        <span class="content" style="font-size: 26px">100%</span>
                    </li>
                    <li class="li">
                        <span class="title">猪仔日龄：</span>
                        <span class="content" style="font-size: 26px">{{7}}天</span>
                    </li>
                    <li class="li">
                        <span class="title">产床状态：</span>
                        <span class="content">已产仔</span>
                    </li>
                    <li class="li">
                        <span class="title">出生日期：</span>
                        <span class="content">2020-07-23</span>
                    </li>
                    <li class="li">
                        <span class="title">预计断奶剩余天数：</span>
                        <span class="content">19天</span>
                    </li>
                </ul>
            </article>
        </section>

        <footer class="footer">
            <div class="h">
                <chart-a :dataArr="hoursD" :timeArr="hoursT"></chart-a>
            </div>
            <div class="d">
                <chart-b :dataArr="daysD" :timeArr="daysT"></chart-b>
            </div>
        </footer>
        <!-- :title="'共有 '+number.count[index] + ' 头小猪'" -->
        <el-dialog :visible.sync="show" center>
            <template #title>
                <span style="color: #444">
                    共有
                    <span style="font-size: 25px; font-weight:600">{{number.count[index]}}</span> 头小猪
                </span>
            </template>
            <img style="width: 100%" :src="number.a1[index]" alt />
        </el-dialog>
    </div>
</template>

<script>
import chart_a from "./charts/chart_a";
import chart_b from "./charts/chart_b";

import a1 from "../../../assets/img/1.jpg";
import a2 from "../../../assets/img/2.jpg";
import a3 from "../../../assets/img/3.jpg";
import a4 from "../../../assets/img/4.jpg";
import a5 from "../../../assets/img/5.jpg";

import aa1 from "../../../assets/img/a1.jpg";
import aa2 from "../../../assets/img/a2.jpg";
import aa3 from "../../../assets/img/a3.jpg";
import aa4 from "../../../assets/img/a4.jpg";
import aa5 from "../../../assets/img/a5.jpg";

import b1 from "../../../assets/img/1.jpg";
import b2 from "../../../assets/img/2.jpg";
import b3 from "../../../assets/img/3.jpg";
import b4 from "../../../assets/img/4.jpg";
import b5 from "../../../assets/img/5.jpg";

import ba1 from "../../../assets/img/a1.jpg";
import ba2 from "../../../assets/img/a2.jpg";
import ba3 from "../../../assets/img/a3.jpg";
import ba4 from "../../../assets/img/a4.jpg";
import ba5 from "../../../assets/img/a5.jpg";

import empty1 from "../../../assets/img/empty1.jpg";
import empty2 from "../../../assets/img/empty2.jpg";
import empty3 from "../../../assets/img/empty3.jpg";
import empty4 from "../../../assets/img/empty4.jpg";
import empty5 from "../../../assets/img/empty5.jpg";

import {
    reqDeliveryRoomInfo,
    reqUpload,
    reqImglist
} from "@/api/deliveryRoomManagement.js";

// 时间选择器配置
const pickerOptions = {
    // 禁用时间
    disabledDate(time) {
        return time.getTime() > Date.now();
    },
    shortcuts: [
        {
            text: "今天",
            onClick(picker) {
                picker.$emit("pick", new Date());
            }
        },
        {
            text: "昨天",
            onClick(picker) {
                const date = new Date();
                date.setTime(date.getTime() - 3600 * 1000 * 24);
                picker.$emit("pick", date);
            }
        },
        {
            text: "前天",
            onClick(picker) {
                const date = new Date();
                date.setTime(date.getTime() - 3600 * 1000 * 24 * 2);
                picker.$emit("pick", date);
            }
        }
    ]
};

export default {
    name: "Detail",
    components: {
        "chart-a": chart_a,
        "chart-b": chart_b
    },
    data() {
        return {
            date: "",
            pickerOptions,
            images: [],
            hoursD: [],
            hoursT: [],
            daysD: [],
            daysT: [],
            value: {},
            number: {
                a: [a1, a2, a3, a4, a5],
                a1: [aa1, aa2, aa3, aa4, aa5],
                count: [13, 10, 13, 14, 13]
            },
            numberB: {
                a: [b1, b2, b3, b4, b5],
                a1: [ba1, ba2, ba3, ba4, ba5],
                count: [13, 10, 13, 14, 13]
            },
            empty: {
                a: [empty1, empty2, empty3, empty4, empty5]
            },
            index: 0,
            show: false,
            roomType: -1,
            timer1: null
        };
    },
    created() {
        console.log(this.$route.query.type);
        this.roomType = this.$route.query.type;
        this.getDeliveryRoomInfo({ bedNo: "10086-1" });

        window.clearInterval(this.timer1)
        // this.getImglist()
        // this.timer1 = setInterval(() => {
        //     this.getImglist()
        //     console.log("1")
        // }, 10000)

    },
    beforeDestroy() {
        window.clearInterval(this.timer1)
    },
    methods: {
        // 请求厂房列表
        getDeliveryRoomInfo(data) {
            reqDeliveryRoomInfo(data)
                .then(res => {
                    this.images = res.value.images;
                    this.value = res.value;
                    this.hoursD = [];
                    this.hoursT = [];
                    this.daysD = [];
                    this.daysT = [];
                    res.value.thours.reverse().forEach(item => {
                        this.hoursD.push(item.temperature.toFixed(2));
                        this.hoursT.push(item.timestamp.substr(0, 14) + "时");
                    });
                    res.value.tdays.reverse().forEach(item => {
                        this.daysD.push(item.temperature.toFixed(2));
                        this.daysT.push(item.timestamp.substr(0, 10));
                    });
                })
                .catch(err => {
                    console.error(err);
                });
        },
        // 拿到图片数组
        getImglist() {
            reqImglist()
                .then(res => {
                    this.empty.a = res
                })
                .catch(err => {
                    console.error(err);
                });
        },
        pickerChange(value) {
            console.log(value);
            this.getDeliveryRoomInfo({ bedNo: "10086-1", date: value });
            // this.date = Math.floor(new Date(value[0]).getTime() / 1000)
            // this.getReportList()
        },
        toSowDetail(index) {
            console.log(index);
            this.index = index;
            this.show = true;
            // console.log(data.path[0].currentSrc);
            // console.log(data.path[0]);
            // console.log(data.path);
            // reqUpload({imageUrl: data.path[0].currentSrc}).then(res => {
            //     console.log(res)
            // })
        },
        goBack() {
            this.$router.go(-1);
        }
    }
};
</script>

<style lang="scss" scoped>
.Detail {
    .header {
        > .title {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0px 30% 10px 20px;
            margin: 0 0 10px 0;
            border-bottom: 2px solid #eee;
            > h4 {
                color: #777;
            }
            > .title {
                font-size: 20px;
                font-weight: 600;
                color: #444;
            }
        }
    }
    .section {
        display: flex;
        padding-bottom: 20px;
        margin: 0 70px;
        border-bottom: 3px solid #ccc;
        .left {
            width: 600px;
            // border: 2px solid rgb(63, 182, 69);
            .contianer {
                width: 600px;
                border-radius: 6px;
                overflow: hidden;
                img {
                    width: 100%;
                    // height: 300px;
                }
            }
        }
        .right {
            padding-left: 40px;
            .ul {
                .li {
                    margin: 5px 0 10px 10px;
                    .title {
                        font-size: 20px;
                        color: rgb(136, 115, 115);
                    }
                    .content {
                        font-size: 19px;
                        font-weight: 600;
                        color: rgb(139, 138, 138);
                    }
                }
            }
        }
    }
    .footer {
        margin-top: 20px;
        .h {
            border-bottom: 2px solid #eee;
        }
        .d {
            padding-top: 15px;
        }
    }
}

// border: 1px solid #00f;
</style>