<template>
    <div>
        <lj-win-index-common :title="title" api-name="GetScWkps"
                             :data-reset-callback="handleDataReset"
                             :data-loaded-callback="handleDataLoaded"
                             ref="baseWin"
                             :addable="!isSelectMode"
                             @add-click="addcus"
                             :query-hard-parms="queryHardParms"
                             :query-fields="queryFields"
                             :binding-parms="bindingParms"
                             @query-field-click="handleQueryFieldClick">
            <!-- <lj-searchbar slot="header_sub" hint="输入车间名称进行查找" v-model="bindingParms.keyword" @search="handleSearchbar" style="width: 100%"/> -->
            <div slot="body_list">
                <mu-list class="lj-group">
                    <template v-for="item in allData">
                        <wkp-item :item="item" @click.native="handleCellClick(item)"></wkp-item>
                    </template>
                </mu-list>
            </div>
        </lj-win-index-common>
    </div>
</template>

<script>
    import LjWinIndexCommon from "components/lj-win-index-common";
    import LjSearchbar from "components/lj-searchbar";
    import wkpItem from './wkp-item';

    export default {
        components: {
            LjSearchbar,
            LjWinIndexCommon,
            wkpItem
        },
        data() {
            return {
                bindingParms: {keyword: ""},
                winMode: "",
                allData: [],
                queryHardParms: {},
                queryFields: [
                ]
            }
        },
        created() {
            let pageParam = $lj.getPageParam();
            if (pageParam) {
                this.winMode = pageParam.winMode;
            }
        },
        methods: {
            handleDataReset(response) {
                this.allData.length = 0;
                this.addList(response.wkps);
            },
            handleDataLoaded(response) {
                // let moreItems = response.workgroupList;
                // if (moreItems.length > 0) {
                //     this.addList(moreItems);
                //     return true;
                // }
                return false;
            },
            addList(list) {
                this.allData = this.allData.concat(list);
            },
            handleSearchbar(text) {
                this.$refs.baseWin.refresh({keyword: text});
            },
            handleCellClick(mainObject) {
                if (this.isSelectMode) {
                    $lj.sendEvent("wkp_select", mainObject);
                    $lj.closeWin();
                } else {
                    //$lj.openWin("workgroup-detail", {mainObject: mainObject});
                }
            },
            addcus() {
                //$lj.openWin("workgroup-detail");
            },
            handleQueryFieldClick({property}) {
                // if (property === 'cusareaid') {
                //     this.$refs.areaChooseDialog.open();
                // }
            },
        },
        computed: {
            isSelectMode() {
                return this.winMode === "single-select";
            },
            title() {
                if (this.winMode === 'single-select') {
                    return "车间选择";
                } else {
                    return "车间管理";
                }
            }
        }
    }
</script>