<template>
    <div>
        <lj-win-index-common :title="title" api-name="GetL1APPSysPost" :data-reset-callback="handleDataReset"
            :data-loaded-callback="handleDataLoaded" ref="baseWin" :addable="false">
            <mu-button icon slot="header_right" @click="addPost">
                <svg class="icon" aria-hidden="true">
                    <use xlink:href="#icon-edit1"></use>
                </svg>
            </mu-button>
            <lj-searchbar slot="header_sub" hint="输入公告内容进行查找" @search="handleSearchbar" style="width: 100%" />
            <div slot="body_list">
                <mu-list class="lj-group">
                    <template v-for="item in allData">
                        <gonggao-item :item="item" @click.native="handleCellClick(item)"></gonggao-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 gonggaoItem from './gonggao-item';

    export default {
        components: {
            LjSearchbar,
            LjWinIndexCommon,
            gonggaoItem
        },
        data() {
            return {
                winMode: "",
                allData: [],
                queryHardParms: {},
                queryFields: []
            }
        },
        created() {
            let self = this;
            $lj.addEventListener("gonggao_edit", function (ret, err) {
                self.$refs.baseWin.refresh({});
            });
        },
        methods: {
            handleDataReset(response) {
                this.allData.length = 0;
                this.addList(response.postList);
            },
            handleDataLoaded(response) {
                let moreItems = response.postList;
                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) {
                
            },
            addPost(){
                if (!$lj.checkPower(5741)) {
                    alert("您没有发公告权限，请检查");
                    return;
                }
                $lj.openWin("gonggao-edit");
            }
        },
        computed: {
            title() {
                return "公告"
            }
        }
    }
</script>