<template>
    <div class="Detail">
        <header class="header">
            <el-page-header @back="goBack" content="产床信息" />
            <div class="title">
                <h4></h4>
                <span class="title">产床002</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 class="contianer">
                    <el-carousel height="300px" indicator-position="none" :interval="3000">
                        <el-carousel-item v-for="item in images" :key="item">
                            <img @click="toSowDetail" :src="'http://119.3.84.55:31288/' + item" />
                        </el-carousel-item>
                    </el-carousel>
                </div>
            </article>

            <article class="right">
                <ul class="ul">
                    <li class="li">
                        <span class="title">产仔数：</span>
                        <span class="content" style="font-size: 26px">9只</span>
                    </li>
                    <li class="li">
                        <span class="title">活仔数：</span>
                        <!-- 小于等于八只的标红 -->
                        <span class="content" style="font-size: 26px">9只</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">12天</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-04-25</span>
                    </li>
                    <li class="li">
                        <span class="title">预计断奶剩余天数：</span>
                        <span class="content">16天</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>
    </div>
</template>

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

import { reqDeliveryRoomInfo } 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: []
        };
    },
    created() {
        this.getDeliveryRoomInfo({ bedNo: "10086-1" });
    },
    methods: {
        // 请求厂房列表
        getDeliveryRoomInfo(data) {
            reqDeliveryRoomInfo(data)
                .then(res => {
                    this.images = res.value.images;
                    res.value.thours.forEach(item => {
                        this.hoursD.push(item.temperature.toFixed(2));
                        this.hoursT.push(item.timestamp.substr(0, 14));
                    });
                    res.value.tdays.forEach(item => {
                        this.daysD.push(item.temperature.toFixed(2));
                        this.daysT.push(item.timestamp.substr(0, 10));
                    });
                })
                .catch(err => {
                    console.error(err);
                });
        },
        pickerChange(value) {
            console.log(value);
            // this.date = Math.floor(new Date(value[0]).getTime() / 1000)
            // this.getReportList()
        },
        toSowDetail() {
            console.log(555);
            this.$message.warning("母猪详细信息正在开发中！！");
        },
        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>