<template>


    <div>

        <el-card style="margin-top: -20px">

            <div style="float: right;margin-bottom: 10px;margin-right: 25px">
                <el-button type="primary" size="small" @click="selectSet()">选入</el-button>
            </div>

            <el-table v-loading="loading" :data="list" style="width: 100%"   border highlight-current-row @selection-change="handleCheckedChange">
                <el-table-column type="selection" width="55"></el-table-column>
                <el-table-column type="index" label="序号" width="50"></el-table-column>
                <el-table-column label="证书名称" prop="name"></el-table-column>
                <el-table-column label="是否必传" prop="require" v-if="certType == 1">
                    <template slot-scope="scope">
                        <span>{{ enableMap[scope.row.need] }}</span>
                    </template>
                </el-table-column>

                <el-table-column label="产地" prop="foreign" v-if="certType == 2">
                    <template slot-scope="scope">
                        <span>{{ foreignMap[scope.row.foreign] }}</span>
                    </template>
                </el-table-column>


                <el-table-column label="产地" prop="imports" v-if="certType == 3">
                    <template slot-scope="scope">
                        <span>{{ foreignMap[scope.row.imports] }}</span>
                    </template>
                </el-table-column>

                <el-table-column label="器械类别" prop="cplx" v-if="certType == 3">
                </el-table-column>
                <el-table-column label="产品类别" prop="hchzsb" v-if="certType == 3">
                </el-table-column>

                <el-table-column label="分类编码" prop="flbm" v-if="certType == 3">
                </el-table-column>


                <el-table-column label="说明" prop="remark"></el-table-column>
            </el-table>

          <pagination
            v-show="total>0"
            :total="total"
            :page.sync="query.page"
            :limit.sync="query.limit"
            @pagination="handleCurrentChange"

          ></pagination>
        </el-card>

    </div>

</template>

<script>

import {filterCertSet, selectAllCert} from "@/api/purchase/supCertSet";

export default {
    name: "supCertSetDialog",

    props: {
        closeDialog: {
            type: Function,
            required: true,
        },
        certType: {                 //类型：（1.供应商，2.生产企业，3，产品)
            type: Object,
            required: true,
        },
        manufacturerId: {
            type: Object,
            required: true,
        },
        productId: {
            type: Object,
            required: true,
        },
        customerId:{
            type: Object,
            required: true,
        },


    },

    data() {
        return {
            query: {
                manufacturerIdFk: null,
                type: 1,
                page: 1,
                limit: 20
            },
            multipleSelection: [],
            enableMap: {
                true: "是",
                false: "否",
            },
            list: [],
            total: 0,
            loading: false,
            foreignMap: {
                "1": "全部",
                "2": "国外",
                "3": "国内",

            },
        };
    },
    methods: {
        handleCheckedChange(val) {
            this.multipleSelection = val;
        },
        handleCurrentChange(val) {
            this.query.page = val.page;
            this.getList();
        },

        getList() {
            this.loading = true;
            this.query.type = this.certType;
            filterCertSet(this.query)
                .then(response => {
                    this.loading = false;
                    this.list = response.data.list || [];
                    this.total = response.data.total || 0;
                })
                .catch(() => {
                    this.loading = false;
                    this.list = [];
                    this.total = 0;
                });
        },


        selectSet() {
            let postQuery = {
                certType: this.certType,
                manufacturerIdFk: this.manufacturerId,
                productIdFk: this.productId,
                supCertSetEntities: this.multipleSelection,
                customerId:this.customerId,
            };
            selectAllCert(postQuery)
                .then(response => {
                    if (response.code === 20000) {
                        this.closeDialog();
                    } else {
                        this.$message.error(response.message);
                    }
                })
                .catch(() => {
                    this.$message.error(response.message);
                });
        },
    },

    filters: {},
    mounted() {
        document.body.ondrop = function (event) {
            event.preventDefault();
            event.stopPropagation();
        };
    },
    created() {
        this.getList();
    },
}
</script>

<style scoped>

</style>
