<template>
    <div>
        <el-form :inline="true" :model="filterQuery"  size="mini">
            <el-row>
                <el-form-item class="query-form-item">
                    <el-input v-model="filterQuery.cpmctymc" placeholder="产品通用名"></el-input>
                </el-form-item>
                <el-form-item class="query-form-item">
                    <el-input v-model="filterQuery.ylqxzcrbarmc" placeholder="生产企业"></el-input>
                </el-form-item>
                <!--<el-form-item class="query-form-item">-->
                    <!--<el-input-->
                        <!--v-model="filterQuery.nameCode"-->
                        <!--placeholder="最小销售产品标识"-->
                    <!--&gt;</el-input>-->
                <!--</el-form-item>-->
                <!--<el-form-item class="query-form-item">-->
                    <!--<el-input v-model="filterQuery.thirdId" placeholder="ERP产品ID"></el-input>-->
                <!--</el-form-item>-->

                <el-form-item>
                    <el-button-group>
                        <el-button type="primary" icon="el-icon-refresh" @click="onReset"></el-button>
                        <el-button type="primary" icon="search" @click="getList">查询</el-button>
                        <el-button type="primary" icon="search" @click="genIncode"
                        >生成内部码
                        </el-button>
                        <el-button type="primary" icon="search" @click="genAllIncode"
                        >一键全部生成
                        </el-button>
                    </el-button-group>
                </el-form-item>
            </el-row>
        </el-form>
        <el-table
            v-loading="loading"
            :data="list"
            style="width: 100%"
            @selection-change="handleSelectionChange"
        >
            <el-table-column type="selection" width="55"></el-table-column>
            <el-table-column label="序号" type="index"></el-table-column>
            <el-table-column
                label="最小销售产品标识"
                prop="nameCode"
                width="140"
                show-overflow-tooltip
            ></el-table-column>
            <el-table-column
                label="生产企业"
                prop="ylqxzcrbarmc"
                show-overflow-tooltip
            ></el-table-column>
            <el-table-column
                label="产品通用名"
                prop="cpmctymc"
                show-overflow-tooltip
            ></el-table-column>
            <el-table-column
                label="规格型号"
                prop="ggxh"
                show-overflow-tooltip
            ></el-table-column>
            <el-table-column
                label="产品类型"
                prop="cplb"
                show-overflow-tooltip
            ></el-table-column>

            <el-table-column
                label="分类编码"
                prop="flbm"
                show-overflow-tooltip
            ></el-table-column>
            <el-table-column
                label="器械类别"
                prop="qxlb"
                show-overflow-tooltip
            ></el-table-column>

        </el-table>
        <el-pagination
            :page-size="filterQuery.limit"
            @current-change="handleCurrentChange"
            layout="prev, pager, next"
            :total="total"
        ></el-pagination>
    </div>
</template>

<script>
    import {postByUdiInfo} from "../../api/inventory/inCodelog.js";
    import {updateStockPrint} from "../../api/inventory/stockPrint.js";
    import {getUdiInfos} from "../../api/basic/udiRelevance";

    export default {
        name: "selectUdiInfo",
        props: {
            closeDialog: {
                type: Function,
                required: true,
            },
            thirdSys: {
                type: Object,
                required: true,
            },

        },
        data() {
            return {
                filterQuery: {
                    ylqxzcrbarmc: "",
                    cpmctymc: "",
                    nameCode: "",
                    page: 1,
                    limit: 20,
                    addType: 1,
                },
                list: [],
                total: 0,
                multipleSelection: [],
            };
        },
        methods: {
            onReset() {
                this.$router.push({
                    path: "",
                });
                this.filterQuery = {
                    ylqxzcrbarmc: "",
                    cpmctymc: "",
                    nameCode: "",
                    page: 1,
                    limit: 20,
                    addType: 1,
                };
                this.getList();
            },
            getList() {
                this.loading = true;
                getUdiInfos(this.filterQuery)
                    .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;
                    });
            },
            genIncode() {
                let selectData = this.multipleSelection;
                var ids = [];
                selectData.forEach((obj) => {
                    ids.push(obj.id);
                });
                let query = {
                    ids: ids,
                    thirdSys: this.thirdSys
                }

                postByUdiInfo(query)
                    .then((response) => {
                        if (response.code == 20000) {
                            this.closeDialog();
                            this.$message.success(response.data);
                        } else {
                            this.$message.error(response.message);
                        }
                    })
                    .catch(() => {
                    });
            },
            genAllIncode() {
                this.loading = true;
                let query = {
                    thirdSysFk: this.thirdSys
                };
                updateStockPrint(query)
                    .then((response) => {
                        this.loading = false;
                        if (response.code == 20000) {
                            this.closeDialog();
                            this.$message.success(response.data);
                        } else {
                            this.$message.error(response.message);
                        }
                    })
                    .catch(() => {
                        this.loading = false;
                    });
            },
            handleSelectionChange(val) {
                console.log("----" + val);
                this.multipleSelection = val;
            },
            handleCurrentChange(val) {
                this.filterQuery.page = val;
                this.getList();
            },
        }
    }

</script>

<style scoped>

</style>
