<template>
    <div>
        <el-form :inline="true" :model="query" class="query-form" size="mini">
            <el-form-item class="query-form-item">
                <el-input
                    v-model="query.name"
                    clearable
                    placeholder="仓库名称"
                    style="width: 400px"
                ></el-input>
            </el-form-item>
            <el-form-item class="query-form-item">
                <el-select v-model="query.advanceType" placeholder="请选择仓库类型" clearable>
                    <el-option label="全部" value=""></el-option>
                    <el-option label="寄售" value=true></el-option>
                    <el-option label="仓库" value=false></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-form>
        <el-table
            v-loading="loading"
            :data="list"
            style="width: 100%"
            @row-click="selectStorage"
        >
            <el-table-column
                prop="code"
                label="仓库编码"
            >
            </el-table-column>
            <el-table-column
                prop="name"
                label="仓库名称"
            >

            </el-table-column>
            <el-table-column
                prop="advanceType"
                label="仓库类型">
                <template slot-scope="scope">
                    <span>{{ enableMap[scope.row.advanceType] }}</span>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
import {
    filterAll,
} from "../../api/basic/invWarehouse";

export default {
    name: "DialogSelectInvStorage",
    data() {
        return {
            query: {key: "", page: 1, limit: 20},
            list: [],
            enableMap: {
                true: "寄售",
                false: "仓库",
            },
        }
    },
    methods: {
        onReset() {
            this.query = {
                key: "",
                page: 1,
                limit: 20
            }
            this.list = [];
        },
        getList() {
            this.loading = true;
            filterAll(this.query)
                .then((response) => {
                    this.loading = false;
                    this.list = response.data || [];
                })
                .catch(() => {
                    this.loading = false;
                });
        },
        selectStorage(row) {
            this.$emit("selectStorage", row);
        },
    },
}
</script>

<style scoped>

</style>
