<template>
  <div class="mypublish" :style="hstyle">
	 <van-loading v-if="initLoad" size="24" style="text-align: center;height: 300px;line-height: 300px;"/>
    <list v-else @refreshCount="refreshCount" :myPublicCount="myPublicCount" @downLoadMore="downLoadMore" :pageSetting="{'loading':loading,'finished':finished}" type="publish" :list="lists"></list>
  </div>
</template>

<script>
  import list from '../components/list'
  import awsuiAxios from "../awsuiAxios";
  export default {
    name: 'mypublish',
    components: {list},
	  props:{
		  myPublicCount:Number
	  },
    data () {
      return {
		  initLoad:true,
		  hstyle:"",
		  isLoadingData:false,
		  loading:false,
		  finished:false,
		  curPage:0,
		  keyWord:"",
        lists: [
        ]
      }
    },
    methods: {
		downLoadMore(){
			this.searchMobileList("");
		},
		refreshCount(count){
			this.$emit("func",count,"publish");
		},
      refreshList () {
        console.log('mypublish:refreshList')
      },
		searchMobileList(key,type){
			if(this.isLoadingData){
				return;
			}
			this.isLoadingData = true;
			let that = this;
			if(type=='search'){
				this.keyWord = key;
				this.curPage =0;
				this.finished = false;
			}
			// 获取知识列表数据
			awsuiAxios.post({
				url: "jd",
				data: {
					cmd: "com.actionsoft.apps.kms_knwl_center_publish_card_list_json",
		 			sortIndx:"publishTime",
					sortDir: "down",
					rowsPerPage:0,
					curPage:this.curPage<=0?1:this.curPage+1,
					filter: encodeURIComponent(this.keyWord)
				},
			}).then(function (r) {
				that.initLoad = false;
				that.isLoadingData = false;
				that.loading = false;
				if (r.result == "error") {
					alert(r.msg);
				} else {
					let rowsPerPage = r.data.rowsPerPage;
					if(that.curPage==0){
						that.lists = r.data.data;
					}else{
						that.lists =that.lists.concat( r.data.data);
					}
					that.loading = false;
					that.curPage = r.data.curPage;
					let totalRecords = r.data.totalRecords;
					if(that.curPage*rowsPerPage>=totalRecords){
						that.finished = true;
					}
					if(!that.finished&&that.curPage>=2&&that.lists.length<6){
						that.searchMobileList("");
					}

				}
			});
		}
    },
	  mounted(){
    	// this.hstyle ="height:"+ (window.innerHeight-44-54-51)+"px";
    	this.searchMobileList("");
	  }
  }
</script>

<style scoped>

</style>



