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

<script>
  import list from '../components/list'
  import awsuiAxios from "../awsuiAxios";
  export default {
    name: 'myfavorite',
    components: {list},
    data () {
      return {
		  initLoad:true,
		  hstyle:"",
		  isLoadingData:false,//防止重复加载数据
		  loading:false,
		  finished:true,
		  curPage:0,
		  keyWord:"",
		profileId:"",
		count:0,
        lists: [
        ]
      }
    },
    methods: {
      refreshList () {
        console.log('myfavorite:refreshList')
      },
		downLoadMore(){

		},
	  getData(){
			let that = this;
			// 获取知识列表数据
			awsuiAxios.post({
				url: "jd",
				async:false,
				data: {
					cmd: "com.actionsoft.apps.favorite_load_category_names"
				},
			}).then(function (r) {
				that.loading = false;
				if (r.result == "error") {
					console.log(r.msg);
				} else {
					let data = r.data.categoryNames;
					for(let i in data){
						if(data[i]['categoryName']=='KMS'){
							that.profileId=data[i]['id'];
							that.count = (data[i]['amount'] == undefined) ? 0 : data[i]['amount'];
							break;
						}
					}
				}
				that.$emit("func",that.count,"favorite");
				that.loadData("");
			});

	  },
	  loadData(key){
			// 获取知识列表数据
		  if(this.isLoadingData){
		  	return;
		  }
		  this.isLoadingData = true;
		   let that = this;
			awsuiAxios.post({
				url: "jd",
				data: {
					cmd: "com.actionsoft.apps.favorite_load_data",
					profileId:this.profileId,
					searchValue: key
				},
			}).then(function (r) {
				that.initLoad = false;
				that.isLoadingData = false;
				that.loading = false;
				if (r.result == "error") {
					alert(r.msg);
				} else {
					that.lists = r.data.list;
				}
			});
	  }
    },
	  mounted(){
		  // this.hstyle ="height:"+ (window.innerHeight-44-54-51)+"px";
    	this.getData();
	  }
  }
</script>

<style scoped>

</style>
