<template>
    <div class="ImmuneLog">
        <h2 style="margin-bottom: 20px;padding-bottom:7px;border-bottom:2px solid #ddd">免疫记录</h2>
        <header id="header">
            <el-row type="flex" :gutter="20">
                <el-col :span="4">
                    <el-input v-model="search" placeholder="请选择"></el-input>
                </el-col>
                <el-col :span="10">
                    <el-button type="primary" @click="getImmuneLogList">查找</el-button>
                </el-col>
                <el-col :span="4">
                    <el-select v-model="formData.vaccineStyle" @change="S_change" placeholder="请选择">
                        <el-option
                            v-for="item in $store.state['vaccineStyle']"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        ></el-option>
                    </el-select>
                </el-col>
                <el-col :span="4">
                    <el-button-group>
                        <el-button
                            v-for="item in $store.state['sheepType']"
                            :key="item.value"
                            :type="target==item.value?'primary':''"
                            @click="onTargetType(item.value)"
                        >{{ item.label }}</el-button>
                    </el-button-group>
                </el-col>
            </el-row>
        </header>
        <section>
            <article class="table">
                <el-table
                    :data="tableData"
                    tooltip-effect="dark"
                    style="width: 100%"
                >
                    <el-table-column prop="id" label="序号" width="80"></el-table-column>
                    <el-table-column label="免疫日期" width="180">
                        <template v-slot="scope">
                            <span>{{ scope.row['vaccineDate'].substr(0,10) }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="batch" label="批次号"></el-table-column>
                    <el-table-column prop="medicineName" label="疫苗名称"></el-table-column>
                    <el-table-column prop="medicineFactory" label="生产厂家"></el-table-column>
                    <el-table-column prop="sheepDay" label="免疫羊只日龄"></el-table-column>
                    <el-table-column label="免疫类型">
                        <template v-slot="scope">
                            <div v-for="item in $store.state['vaccineStyle']" :key="item.value">
                                <span
                                    v-if="item.value == scope.row['vaccineStyle']"
                                >{{ item.label }}</span>
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column prop="number" label="免疫数量"></el-table-column>
                    <el-table-column prop="method" label="免疫方法"></el-table-column>
                    <el-table-column label="操作人">
                        <template v-slot="scope">
                            <div v-for="item in $store.state['workerList']" :key="item.value">
                                <span v-if="item.id == scope.row['opeUser']">{{ `${item.name}(${item.position})` }}</span>
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column prop="remark" label="备注"></el-table-column>
                </el-table>

                <el-row type="flex" justify="end">
                    <el-col :span="8" class="pagination">
                        <el-pagination
                            @current-change="pageChange"
                            background
                            layout="prev, pager, next"
                            :page-count="Number(totalPages)"
                        ></el-pagination>
                    </el-col>
                </el-row>
            </article>
        </section>

    </div>
</template>

<script>
import { reqImmuneLogList } from "@/api/antiepidemic.js";

const pageSize = 10;
const rules = {};

export default {
    name: "ImmuneLog",
    data() {
        return {
            search: "",
            pageNum: 1,
            tableData: [],
            totalPages: 0,
            target: this.$store.state["sheepType"][0].value,  // 按钮绑定的
            sheepTypeArr: [this.$store.state["sheepType"][0].value],
            formData: {
                vaccineStyle: this.$store.state["vaccineStyle"][0].value
            },
            rules
        };
    },
    created() {
        // 免疫程序列表
        this.getImmuneLogList();
    },
    methods: {
        // 点击按钮组
        onTargetType(target) {
            this.target = target;
            this.sheepTypeArr = [target];
            this.getImmuneLogList();
        },
        // 下拉选择框改变
        S_change() {
            this.getImmuneLogList();
        },
        // 免疫程序列表
        getImmuneLogList() {
            reqImmuneLogList({
                searchStr: this.search,
                pageSize,
                pageNum: this.pageNum,
                vaccineStyle: this.formData.vaccineStyle,
                target: this.target
            })
                .then(res => {
                    this.tableData = res.content;
                    this.totalPages = res.totalPages;
                })
                .catch(err => {
                    console.log(err);
                });
        },
        pageChange(p) {
            console.log(p);
            this.pageNum = p;
            // 免疫程序列表
            this.getImmuneLogList();
        }
    }
};
</script>

<style lang="scss" scoped>
#header {
    margin-bottom: 15px;
}
.table {
    .pagination {
        margin-top: 20px;
    }
}
</style>