<template>
    <div class="container">
        <!-- <div class="tabs">
            <div class="headerText">
                <div class="searchP">统计分析</div>
            </div>
            <div>
                <MapCars leafletitle="药品" echartstitle="药品" @arealist="arealist" ref="mapcars" v-if="MapCarsshow" />
            </div>
        </div> -->
        <div class="tabs">
            <div class="headerText">
                <div class="searchP">查询条件</div>
            </div>
            <el-form ref="form1" :model="form1">
                <div style="margin-top: 10px">
                    <!-- <el-row>
              <el-col :span="21">
                <el-form-item label="查询条件">
                  <el-input v-model="form1.name" placeholder="支持模糊查询"></el-input>
                </el-form-item>
              </el-col>
            </el-row> -->
                </div>

                <el-row>
                    <el-col :span="8">
                        <el-form-item label="产品名称">
                            <el-input v-model="form1.pzName" placeholder="支持模糊查询" clearable @clear="isclear"></el-input>
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="产品来源">
                            <el-input v-model="form1.cpSource" placeholder="支持模糊查询" clearable
                                @clear="isclear"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="登记号">
                            <el-input v-model="form1.djh" placeholder="支持模糊查询" clearable @clear="isclear"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>

                    <el-col :span="8">
                        <el-form-item label="企业名称">
                            <el-input v-model="form1.qymc" placeholder="支持模糊查询" clearable @clear="isclear"></el-input>
                        </el-form-item></el-col>
                    <el-col :span="8">
                        <el-form-item label="生产许可证">
                            <el-input v-model="form1.scxkz" placeholder="支持模糊查询" clearable @clear="isclear"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="批准文号">
                            <el-input v-model="form1.bz" placeholder="支持模糊查询" clearable @clear="isclear"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <cpbq :form1="form1" @isclear="isclear" mytype="2"></cpbq>

                </el-row>
                <div class="footBox" v-show="bthshow">
                    <el-button icon="el-icon-refresh-left" @click="reset">重置</el-button>
                    <el-button type="primary" icon="el-icon-search" @click="searchList">查询</el-button>
                    <!-- <el-button type="success" icon="el-icon-circle-plus-outline" @click="collapsechange(0)">展开</el-button> -->
                </div>
                <div v-if="false">
                    <el-row>
                        <div class="title-box">产品抽检信息查询：</div>
                        <el-col :span="8">
                            <el-form-item label="检验项目">
                                <el-input v-model="form1.cjxm" placeholder="支持模糊查询" clearable
                                    @clear="isclear"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="检验受理编号">
                                <el-input v-model="form1.jyslbh" placeholder="支持模糊查询" clearable
                                    @clear="isclear"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="抽样编号">
                                <el-input v-model="form1.cybh" placeholder="支持模糊查询" clearable
                                    @clear="isclear"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-form-item label="抽样级别">
                                <el-input v-model="form1.cyjb" placeholder="支持模糊查询" clearable
                                    @clear="isclear"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="抽样日期" placeholder="支持模糊查询">
                                <el-input v-model="form1.cyrq" placeholder="支持模糊查询" clearable
                                    @clear="isclear"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <div class="title-box">不良反应信息查询：</div>
                        <el-col :span="8">
                            <el-form-item label="发生年份">
                                <el-input v-model="form1.fsnf" placeholder="支持模糊查询发生年份" clearable
                                    @clear="isclear"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <div class="logformitem">
                                <el-form-item label="不良反应报告编号">
                                    <el-input v-model="form1.blfybgbh" placeholder="支持模糊查询不良反应报告编号" clearable
                                        @clear="isclear"></el-input>
                                </el-form-item>
                            </div>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="不良反应类型">
                                <el-input v-model="form1.blfylx" placeholder="支持模糊查询不良反应类型" clearable
                                    @clear="isclear"></el-input>
                            </el-form-item>
                        </el-col>

                    </el-row>
                    <div class="footBox " v-show="!bthshow">
                        <el-button icon="el-icon-refresh-left" @click="reset">重置</el-button>
                        <el-button type="primary" icon="el-icon-search" @click="searchList">查询</el-button>
                        <el-button type="success" icon="el-icon-remove-outline"
                            @click="collapsechange(1)">收起</el-button>
                    </div>
                </div>
            </el-form>

        </div>
        <div class="tabsBottom">
            <div class="foot-main">
                <div class="headerText">
                    <div class="searchP">药品列表</div>
                </div>
                <div class="exportBtn">
                    <el-button type="primary" icon="el-icon-edit-outline" @click="exportList()">导出excel</el-button>
                </div>
                <section class="table-box">
                    <div class="table-item">
                        <el-table v-loading="loading" :data="tableData" border height="500" style="width: 100%">
                            <el-table-column type="index" label="序号" width="80" align="center" />
                            <el-table-column label="品种名称" min-width="130" align="center">
                                <template slot-scope="scope">
                                    {{ scope.row.pzName }}
                                </template>
                            </el-table-column>
                            <el-table-column label="批准文号" min-width="180" align="center">
                                <template slot-scope="scope">
                                    {{ scope.row.bz }}
                                </template>
                            </el-table-column>
                            <el-table-column label="企业名称" min-width="200" align="center">
                                <template slot-scope="scope">
                                    {{ scope.row.qymc }}
                                </template>
                            </el-table-column>
                            <el-table-column label="登记号" min-width="170" align="center">
                                <template slot-scope="scope">
                                    {{ scope.row.djh }}
                                </template>
                            </el-table-column>
                            <el-table-column label="产品来源" min-width="120" align="center">
                                <template slot-scope="scope">
                                    {{ scope.row.cpSource }}
                                </template>
                            </el-table-column>
                            <!-- <el-table-column label="规格" min-width="100" align="center">
                                <template slot-scope="scope">
                                    {{ scope.row.gg }}
                                </template>
                            </el-table-column> -->
                            <el-table-column label="包装规格" min-width="180" align="center">
                                <template slot-scope="scope">
                                    {{ scope.row.bzgg }}
                                </template>
                            </el-table-column>
                            <el-table-column label="统一社会信用代码" min-width="200" align="center">
                                <template slot-scope="scope">
                                    <div class="norepet">{{ scope.row.uniscid }}</div>
                                </template>
                            </el-table-column>
                            <el-table-column label="生产许可证" min-width="150" align="center">
                                <template slot-scope="scope">
                                    {{ scope.row.scxkz }}
                                </template>
                            </el-table-column>
                            <el-table-column label="生产许可证状态" min-width="170" align="center">
                                <template slot-scope="scope">
                                    {{ dataArr[scope.row.scxkzStatus] || "--" }}
                                </template>
                            </el-table-column>


                            <el-table-column label="操作" width="100" fixed="right" align="center">
                                <template slot-scope="scope">
                                    <el-button type="primary" @click="toDetail(scope.row)">详情</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                    </div>
                </section>
                <pagination :total="total" :page="form.current" :limit="form.size" @pagination="getPagination"
                    :current-page.sync="form.current" :page-sizes="[5, 10, 20]"></pagination>
            </div>
        </div>
        <el-dialog title="提示" :visible.sync="showCK" width="30%">
            <span>{{ src }}</span>
            <span slot="footer" class="dialog-footer">
                <el-button @click="closeDC()">取 消</el-button>
                <el-button type="primary" @click="openDC()">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import { download, vRdgYpwhGxwzexportYly } from "../../../api/archives/updata";
import { Notification, MessageBox, Message, Loading, TabPane } from "element-ui";
// import MapCars from "@/views/components/MapCars.vue";
import cpbq from "@/views/components/AdvancedSearch/cpbq.vue";

export default {
    components: {
        // MapCars,
        cpbq
    },
    data() {
        return {
            MapCarsshow: true,
            bthshow: true,

            //===========
            loading: false,
            tableData: [],
            total: 0,
            form1: {
                qymc: "",
                pzName: "", //产品名称
                jx: "", //剂型
                cpSource: "", //批准文号
                djh: "",//生产单位
                ypfl: "", //药品分类
                name: "",
                scxkz: "", // 持有人
                ypbm: "", //药品编码
                sfyblfy: "",  //是否有不良反应
                // 统一查询
                cjxm: "", // 检验项目
                jyslbh: "", //检验受理编号
                cybh: "", //抽样编号
                cyjb: "", // 抽样级别
                cyrq: "", // 抽样日期
                blfybgbh: "", // 不良反应报告编号
                blfylx: "", // 不良反应类型
                fsnf: "", // 发生年份
                bz: "",
                cpbq: "",//标签

                area: this.$store.getters.usersort,

            },
            dataArr: {
                1: '有效',
                2: '撤销',
                4: '过期',
                7: '注销',
            },

            form: {
                size: 20,
                current: 1,
                area: this.$store.getters.usersort,
            },
            //药品分类
            ypType: ["中药", "生物制品", "化学药品"],
            //剂型
            jxType: [
                "散剂",
                "片剂",
                "颗粒剂",
                "胶囊剂",
                "溶液剂",
                "乳剂",
                "混悬剂",
                "注射剂",
                "喷雾剂",
                "气雾剂",
                "原料药"
            ],
            shif: ["是", "否"],
            jieliuShow: true,

            loadA: null,
            showCK: false,
            src: "",
        };
    },
    mounted() {
        this.form1.name = this.$route.query.value || "";
        if (this.form1.name) {
            this.searchList();
        } else {
            this.chinaCosmetics(1);
        }
    },
    created() {

    },
    methods: {
        // 点击input上的x号
        isclear() {
            this.searchList()
        },
        // 展开收起按钮
        collapsechange(e) {
            if (e == 0) {
                this.bthshow = false
            } else {
                this.bthshow = true
            }
        },
        // echarts lefet 回调函数
        arealist(area) {
            this.form.area = area
            this.form1.area = area
            this.chinaCosmetics()
        },
        // 确定导出
        openDC() {
            this.showCK = false;
            this.loadA = Loading.service({
                text: "正在下载数据，请稍候",
                spinner: "el-icon-loading",
                background: "rgba(0, 0, 0, 0.7)",
            });
            vRdgYpwhGxwzexportYly(this.form1).then((res) => {
                const blob = new Blob([res], { type: res.type });
                const link = document.createElement("a");
                link.href = window.URL.createObjectURL(blob);
                link.style.display = "none";
                link.download = "原料药品种" + ".xlsx";
                link.click();
                this.loadA.close();
                this.$message({
                    type: "success",
                    message: "导出成功",
                }).catch((err) => {
                    this.$message({
                        type: "info",
                        message: "导出失败",
                    });
                });
            });
        },
        // 取消导出
        closeDC() {
            this.showCK = false;
            this.$message({
                type: "info",
                message: "已取消导出",
            });
        },
        // 导出按钮
        exportList() {
            this.src = `确定导出${this.form1.pzName ? `产品名称为${this.form1.pzName}、` : ""
                }${this.form1.ypfl ? `产品来源为${this.form1.cpSource}、` : ""}${this.form1.cpSource ? `登记号为${this.form1.djh}、` : ""
                }${this.form1.djh ? `企业名称${this.form1.qymc}、` : ""}${this.form1.jx ? `生产许可证
${this.form1.scxkz}、` : ""
                }数据吗?`;
            this.showCK = true;
        },
        // 查询按钮
        jieliuFunc() {
            if (this.jieliuShow) {
                this.chinaCosmetics();
                this.jieliuShow = false;
                setTimeout(() => {
                    this.jieliuShow = true;
                }, 500);
            } else {
                this.$message("点击过快");
            }
        },
        //去内嵌页面
        toDetail(e) {
            setTimeout(() => {
                this.$router.push({
                    path: `/cosmeticsDetail`,
                    query: { type: "5", data: e.xh, bah: e.bz },
                });
            }, 1000);
        },
        //搜索
        searchList() {
            this.form.current = 1;
            for (let i in this.form1) {
                this.form[i] = this.form1[i];
            }
            this.jieliuFunc();
        },
        // 分页
        getPagination(e) {
            this.form.current = e.page;
            this.form.size = e.limit;
            this.chinaCosmetics(1);
        },
        //重置
        reset(type) {
            this.form1 = {

                qymc: "",
                //产品名称
                pzName: "",
                //剂型
                jx: "",
                //批准文号
                cpSource: "",
                //生产单位
                djh: "",
                //药品分类
                ypfl: "",
                // 统一查询
                name: "",
                // 是否抽检
                scxkz: "",
                ypbm: "",
                //是否有不良反应
                sfyblfy: "",
                // 统一查询
                cjxm: "",
                jyslbh: "",
                cybh: "",
                cyjb: "",
                cyrq: "",
                blfybgbh: "",
                blfylx: "",
                fsnf: "",
                bz: "",
                cpbq: "",//标签

                area: this.$store.getters.usersort,
            };
            this.form = {
                size: 20,
                current: 1,
                area: this.$store.getters.usersort,
            };
            this.jieliuFunc();
        },
        // 药品
        async chinaCosmetics() {
            this.loading = true;
            let msg1 = await this.$api.cosmetics.vRdgYpwhGxwzylList(this.form);
            this.tableData = msg1.data.records;
            this.total = msg1.data.total;
            this.form.size = msg1.data.size;
            this.form.current = msg1.data.current;
            this.loading = false;
        },
    },
    beforeRouteLeave(to, from, next) {
        if (to.path != '/cosmeticsDetail') {
            this.reset(1)
            this.MapCarsshow = false
        }
        next()
    },
    activated(to, from, next) {
        this.MapCarsshow = true

    }

};
</script>

<style lang="scss" scoped>
::v-deep .el-dialog:not(.is-fullscreen) {
    margin-top: 30vh !important;
}

::v-deep .el-dialog__body {
    padding: 15px;
}

::v-deep .el-select {
    width: 100% !important;
}

.container {
    height: 100%;
    // overflow: auto;
    background: #f2f2f2;

    .headerText {
        width: 100%;
        padding: 10px 20px;
        border-bottom: 1px solid #f2f3f5;
        color: #323233;
        font-size: 20px;
        font-weight: bold;

        .searchP {
            position: relative;
            cursor: pointer;

            &::before {
                content: "";
                width: 78px;
                height: 3px;
                background: #1349c5;
                position: absolute;
                bottom: -10px;
            }
        }
    }

    .tabs {
        width: 100%;
        background: #fff;
        margin-bottom: 10px;


    }
}

//===================
::v-deep .el-button--medium {
    padding: 8px;
}

.footBox {
    width: 97.5%;
    text-align: center;
    padding-bottom: 10px;
}

.tabsBottom {
    // height: 70%;

    .foot-main {
        height: 100%;
        // min-height: 600px;
        width: 100%;
        background: white;
    }
}

.exportBtn {
    padding: 10px 20px;
}

.table-box {
    overflow-y: auto;
    padding: 0 20px;

    .table-item {}
}

.pagination {
    display: flex;
    justify-content: space-between;
    padding: 15px 20px;
}



::v-deep .el-table {
    overflow: auto;
}

::v-deep .logformitem {
    .el-form-item__label {
        line-height: 20px;
    }
}

.title-box {
    position: relative;
    padding-left: 30px;
    font-size: 16px;
    font-weight: 600;
    margin: 10px 0;
    color: #1349c5;
}
</style>