<template>
    <div>
        <el-form :inline="true" :model="query" class="query-form" size="mini">
            <el-row>
                <el-form-item class="query-form-item">
                    <el-input v-model="filterQuery.udiCode" placeholder="UDI码"></el-input>
                </el-form-item>
                <el-form-item class="query-form-item">
                    <el-input v-model="filterQuery.batchNo" placeholder="批次号"></el-input>
                </el-form-item>
                <el-form-item class="query-form-item">
                    <el-input v-model="filterQuery.inventoryCode" placeholder="存货编码"></el-input>
                </el-form-item>
                <el-form-item class="query-form-item">
                    <el-input v-model="filterQuery.warehouseCode" placeholder="仓库编码"></el-input>
                </el-form-item>
                <el-form-item class="query-form-item">
                    <el-select v-model="thirdSysFk" placeholder="请选择第三方系统">
                        <el-option
                            v-for="item in thirdSys"
                            :key="item.value"
                            :label="item.thirdName"
                            :value="item.thirdId">
                            <span style="float: left">{{ item.thirdName }}</span>
                            <span style="float: right; color: #8492a6; font-size: 13px">{{ item.thirdId }}</span>
                        </el-option>
                    </el-select>
                </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-group>
                </el-form-item>
            </el-row>
        </el-form>

        <el-table
            v-loading="loading"
            :data="list"
            style="width: 100%"
            @selection-change="handleSelectionChange"
        >
            <el-table-column label="序号" type="index"></el-table-column>
            <el-table-column
                label="存货编码"
                prop="code"
                show-overflow-tooltip
            ></el-table-column>
            <el-table-column
                label="存货名称"
                prop="name"
                show-overflow-tooltip
            ></el-table-column>
            <el-table-column
                label="批次号"
                prop="batchNo"
                show-overflow-tooltip
            ></el-table-column>
            <el-table-column
                label="仓库名称"
                prop="warehouseCode"
                show-overflow-tooltip
            ></el-table-column>
            <el-table-column
                label="仓库名称"
                prop="warehouseName"
                show-overflow-tooltip
            ></el-table-column>
            <el-table-column
                label="规格型号"
                prop="spec"
                show-overflow-tooltip
            ></el-table-column>
            <el-table-column
                label="结存数量"
                prop="count"
                show-overflow-tooltip
            ></el-table-column>
        </el-table>
    </div>
</template>

<script>
    import {getOnhands} from "../../api/inventory/onHand.js";
    import {getBasicThirdSys} from "../../api/basic/basicThirdSys";
    import selectUdi from "../basic/UdiInfoRelevance";
    import selectErp from "../basic/UdiInfoselectErpUdi.vue";

    export default {
        data() {
            return {
                filterQuery: {
                    udiCode: null,
                    nameCode: null,
                    batchNo: "",
                    inventoryCode: "",
                    warehouseCode: "",
                    page: 1,
                    limit: 20,
                    thirdSys: null,
                },

                editQuery: null,
                relevanceEdit: {
                    id: null,
                    thirdId: "",
                    isUseDy: false,
                },
                checked: false,
                list: [],
                detailList: [],
                total: 0,
                thirdNo: "",
                uuid: "111",
                relId: "",
                multipleSelection: [],
                editDialogVisible: false,
                selectUdiDialogVisible: false,
                selectErpDialogVisible: false,
                thirdSys: [],
                thirdSysFk: null,
            };
        },

        methods: {
            onReset() {
                this.$router.push({
                    path: "",
                });
                this.filterQuery = {
                    batchNo: "",
                    warehouseCode: "",
                    nameCode: "",
                    page: 1,
                    limit: 20,
                    inventoryCode: null,
                    udiCode: null
                };
                this.getList();
            },
            getList() {
                this.loading = true;
                this.filterQuery.thirdSys = this.thirdSysFk;
                getOnhands(this.filterQuery)
                    .then((response) => {
                        if (response.code == 20000) {
                            this.loading = false;
                            this.list = response.data.list || [];
                            this.total = response.data.total || 0;
                        } else {
                            this.$message.error(response.message);
                            this.list = [];
                            this.total = 0;
                        }
                    })
                    .catch(() => {
                        this.loading = false;
                        this.list = [];
                        this.total = 0;
                    });
            },

            exportTxt() {
            },

            intentDetail() {
                // this.$router.push({ path: "../product/udirevance" });
                this.selectUdiDialogVisible = true;
                //  this.$router.push({name:'home',query: {id:'1'}})
            },

            handleSelectionChange(val) {
                console.log("----" + val);
                this.multipleSelection = val;
            },

            cancelDialog() {
                this.editDialogVisible = false;
            },
            getBasicThirdSys() {
                let query = {
                    enabled: true,
                };
                getBasicThirdSys(query)
                    .then((response) => {
                        this.thirdSys = response.data.list || [];
                        this.thirdSysFk = this.thirdSys[0].thirdId;
                    })
                    .catch(() => {
                        this.loading = false;
                        this.list = [];
                    });
            },
        },
        mounted() {
        },
        components: {
            selectUdi,
            selectErp,
        },
        created() {
            // this.getList();
            this.getBasicThirdSys();
        },
    };
</script>
