<template>
    <lj-win-common title="存放位置-选择">
        <lj-searchbar slot="header_sub" hint="输入存放位置进行查找" @search="handleSearchbar" v-model="keyword" />
        <div slot="body">
            <div style="margin-top:10px">
                <lj-grid :table-data="columns" :columns="columnProperties" :editing="true"
                         @cell-click="handleGridCellClick"/>
            </div>
        </div>
        <template slot="footer">
            <mu-button large color="primary" @click="chooseCommit" style="width:100%">选择</mu-button>
        </template>
    </lj-win-common>
</template>

<script>
    import ljWinCommon from 'components/lj-win-common';
    import LjSearchbar from "components/lj-searchbar";
    import LjGrid from "components/lj-grid";

    export default {
        components: {
            ljWinCommon,
            LjSearchbar,
            LjGrid,
        },
        data() {
            return {
                columns: [],
                columnProperties: [
                    {
                        property: "checked",
                        width: screen.width * 0.1,
                        type: "selection",
                        editable: true,
                        headerType: "selection"
                    },
                    {property: "location", label: "存放位置", width: screen.width * 0.9,},
                ],
                locationSelect: [],
                keyword: "",
                item: {},
                ifshowall: false,
            }
        },
        created() {
            this.GetL1WorkgroupSelection()
        },
        methods: {
            handleSearchbar() {
                this.GetL1WorkgroupSelection();
            },
            GetL1WorkgroupSelection() {
                let self = this;
                this.columns = [];
                $lj.postLJRequest("GetLocationList", {
                    token: $lj.getStorage("token"),
                    keyword: this.keyword,
                }, function (ret) {
                    self.columns = ret.locationList;
                })
            },
            handleGridCellClick({column, row, index}) {
                if (!column) {
                    return;
                }
                let self = this;
                if (column.property === "checked") {
                    for (let i = 0; i < self.columns.length; i++) {
                        if (i === index) {
                            self.$set(self.columns[i], column.property, true);
                            self.locationSelect = self.columns[i];
                        }else{
                            self.$set(self.columns[i], column.property, false);
                        }
                    }
                }
            },
            chooseCommit() {
                if (this.locationSelect.length <= 0) {
                    $lj.toast('请选择库位');
                    return;
                }
                $lj.sendEvent("location_select", this.locationSelect);
                $lj.closeWin();
            }
        }
    }
</script>

<style>

</style>