<template>
    <div class="deliveryRoom">
        <h2 style="margin-bottom: 20px;padding-bottom:7px;border-bottom:2px solid #ddd">厂房信息</h2>
        <header style="margin-bottom:20px">
            <el-row type="flex" :gutter="20" align="middle">
                <el-col :span="3">
                    <el-input v-model="S_form.area" placeholder="请输入产床号"></el-input>
                </el-col>
                <el-col :span="3">
                    <el-select v-model="S_form.area" placeholder="请选择栋舍">
                        <el-option label="选项一" :value="1"></el-option>
                        <el-option label="选项二" :value="1"></el-option>
                    </el-select>
                </el-col>
                <el-col :span="3">
                    <el-select v-model="S_form.area" placeholder="请选择产房">
                        <el-option label="选项一" :value="1"></el-option>
                        <el-option label="选项二" :value="1"></el-option>
                    </el-select>
                </el-col>
                <el-col :span="2">
                    <el-button type="primary" @click="getBasicsInfoList">查找</el-button>
                </el-col>
                <el-col :span="2">
                    <el-button type="primary" @click="add">新增</el-button>
                </el-col>
            </el-row>
        </header>
        <section class="section">
            <ul class="ul">
                <li
                    @click="toDetail(item.type, '产房00'+(index+1))"
                    class="li"
                    v-for="(item, index) in list"
                    :key="index"
                >
                    <h5>产床00{{ index+1 }}</h5>
                    <img class="img" :src="typeImgUrl[item.type - 1]" />
                    <p v-if="item.type == 1" class="info fontC">空床时间{{ 4 }}天</p>
                    <div class="info" v-if="item.type == 2">
                        <p class="p">
                            <span class="title">母猪耳标：</span>
                            <span class="content">{{ item.id }}</span>
                        </p>
                        <p class="p">
                            <span class="title">入床时间：</span>
                            <span class="content">2020-07-25</span>
                        </p>
                        <p class="p">
                            <span class="title">预计产仔：</span>
                            <span class="content">2020-08-1</span>
                        </p>
                    </div>
                    <div class="info" v-else-if="item.type == 3">
                        <p class="p">
                            <span class="title">母猪耳标：</span>
                            <span class="content">{{ item.id }}</span>
                        </p>
                        <p class="p">
                            <span class="title">产子时间：</span>
                            <span class="content">2020-07-20</span>
                        </p>
                        <p class="p">
                            <span class="title">仔猪日龄：</span>
                            <span class="content">10天</span>
                        </p>
                        <p class="p">
                            <span class="title">产仔数：</span>
                            <span class="content">9</span>
                        </p>
                    </div>
                    <div class="info" v-else-if="item.type == 4">
                        <p class="p">
                            <span class="title">母猪耳标：</span>
                            <span class="content">{{ item.id }}</span>
                        </p>
                        <p class="p">
                            <span class="title">断奶时间：</span>
                            <span class="content">2020-07-20</span>
                        </p>
                        <p class="p">
                            <span class="title">断奶活仔数：</span>
                            <span class="content">8</span>
                        </p>
                        <p class="p">
                            <span class="title">断奶活仔率：</span>
                            <span class="content">98%</span>
                        </p>
                    </div>
                </li>
            </ul>
            <el-row type="flex" justify="center" style="margin-top: 20px;">
                <el-col :span="6" class="pagination">
                    <el-pagination
                        @current-change="pageChange"
                        background
                        layout="prev, pager, next"
                        :page-count="500"
                    ></el-pagination>
                </el-col>
            </el-row>
        </section>

        <el-dialog title="新增" :visible.sync="isShow" width="40%">
            <el-row type="flex">
                <el-col :span="20">
                    <el-form
                        ref="addDeliveryRoom"
                        :model="formData"
                        :rules="rules"
                        label-width="140px"
                    >
                        <el-form-item label="名称">
                            <el-input v-model="formData.name"></el-input>
                        </el-form-item>
                        <el-form-item label="有效期/单位">
                            <el-row type="flex" :gutter="20">
                                <el-col :span="10">
                                    <el-input v-model.number="formData.periodOfValidity"></el-input>
                                </el-col>
                                <el-col :span="6">
                                    <el-select v-model="formData.unit" placeholder="请选择">
                                        <el-option
                                            v-for="item in $store.state['periodOfValidityUnit']"
                                            :key="item.value"
                                            :label="item.label"
                                            :value="item.value"
                                        ></el-option>
                                    </el-select>
                                </el-col>
                            </el-row>
                        </el-form-item>
                        <el-form-item label="库存/规格">
                            <el-row type="flex" :gutter="20">
                                <el-col :span="10">
                                    <el-input v-model.number="formData.safeThreshold"></el-input>
                                </el-col>
                                <el-col :span="6">
                                    <el-input v-model="formData.specifications"></el-input>
                                </el-col>
                            </el-row>
                        </el-form-item>
                        <el-form-item label="厂家">
                            <el-input v-model="formData.factory"></el-input>
                        </el-form-item>
                        <el-form-item label="用法">
                            <el-input type="textarea" autosize v-model="formData.usageIntro"></el-input>
                        </el-form-item>
                        <el-form-item label="注意事项">
                            <el-input type="textarea" autosize v-model="formData.note"></el-input>
                        </el-form-item>
                        <el-form-item label="状态">
                            <el-radio-group v-model="formData.status">
                                <el-radio
                                    v-for="item in $store.state['drugStatus']"
                                    :key="item.value"
                                    :label="item.value"
                                >{{ item.label }}</el-radio>
                            </el-radio-group>
                        </el-form-item>
                        <el-form-item>
                            <el-button @click="isShow=false">取 消</el-button>
                            <el-button type="primary" @click="submitForm('addDeliveryRoom')">保 存</el-button>
                        </el-form-item>
                    </el-form>
                </el-col>
            </el-row>
        </el-dialog>
    </div>
</template>


<script>
import typeImgUrl_1 from "@/assets/deliveryRoom_1.jpg";
import typeImgUrl_2 from "@/assets/deliveryRoom_2.jpg";
import typeImgUrl_3 from "@/assets/deliveryRoom_3.jpg";
import typeImgUrl_4 from "@/assets/deliveryRoom_4.jpg";

// import { reqDeliveryRoomList } from "@/api/deliveryRoomManagement.js"tuodan

// 每页数据条数
const pageSize = 10;
const rules = {};

let list = [
    {
        type: 1,
        id: 16532
    },
    {
        type: 2,
        id: 16546
    },
    {
        type: 3,
        id: 16548
    },
    {
        type: 4,
        id: 16566
    },
    {
        type: 2,
        id: 16596
    },
    {
        type: 3,
        id: 16540
    },
    {
        type: 3,
        id: 16551
    }
];

export default {
    name: "deliveryRoom",
    data() {
        return {
            list,
            isShow: false,
            rules,
            pageSize,
            page: 1,
            S_form: {},
            formData: {
                name: ""
            },
            typeImgUrl: [typeImgUrl_1, typeImgUrl_2, typeImgUrl_3, typeImgUrl_4]
        };
    },
    created() {},
    methods: {
        submitForm(formName) {
            this.$refs[formName].validate(valid => {
                if (valid) {
                    // reqAddMOutStore(this.formData)
                    //     .then(res => {
                    //         // 物料出库列表
                    //         this.getMOutStoreList();
                    //         if (res.errCode) {
                    //             this.$message.error(res.errMsg);
                    //         } else {
                    //             this.$message.success("成功");
                    //         }
                    //         // this.isShow = false
                    //     })
                    //     .catch(err => {
                    //         console.log(err);
                    //         this.$message.error("失败！");
                    //     });
                } else {
                    return false;
                }
            });
        },
        toDetail(type, roomNum) {
            // if(type == 1) {
            //     this.$message.warning("产床为空！")
            //     return
            // }
            this.$router.push({ path: "Detail", query: { type, roomNum } });
        },
        getBasicsInfoList() {},
        add() {
            this.isShow = true;
        },
        pageChange(p) {
            console.log(p);
            this.page = p;
            // this.getDeviceList();
        }
    }
};
</script>

<style lang="scss" scoped>
.deliveryRoom {
    .section {
        background-color: #eee;
        padding: 10px 10px 20px 10px;
        border-radius: 10px;
        .ul {
            display: flex;
            flex-direction: row;
            flex-wrap: wrap;

            .li {
                background-color: #fff;
                border: 2px solid #fff;
                border-radius: 8px;
                padding: 6px;
                margin: 6px;
                display: flex;
                flex-direction: column;
                width: 200px;
                height: 430px;

                h5 {
                    text-align: center;
                    font-size: 30px;
                    color: #424242;
                    background-color: #d2e4f0;
                }
                .img {
                    width: 100%;
                }
                .info {
                    flex: 1;
                    display: flex;
                    padding-left: 20px;
                    flex-direction: column;
                    justify-content: space-around;
                    .p {
                        .title {
                            font-size: 14px;
                            font-weight: 600;
                            color: rgb(136, 127, 127);
                        }
                        .content {
                            color: #777;
                        }
                    }
                }
                .fontC {
                    align-items: center;
                    padding-left: 0px;
                    color: rgb(80, 183, 231);
                    font-size: 20px;
                    font-weight: 600;
                }
            }
            .li:hover {
                border: 2px solid #32adf4;
            }
        }
    }
}

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