<template>
    <div class="app-container">
      <van-nav-bar
        left-arrow
        fixed
        placeholder
        @click-left="$router.back(-1)"
      >
        <template #title>
          <p style="font-weight: bold;">公示信息</p>
        </template>
      </van-nav-bar>
      <van-search v-model="value" placeholder="请输入姓名" class="searchInput" @search="onSearch" show-action>
        <template #action>
          <div @click="onSearch" style="color:#B4B0B0 ">搜索</div>
        </template>
      </van-search>
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="getList"
      >
        <van-swipe-cell v-for="(item,index) in informationList" :key="index">
          <van-cell :title="item.projectName" :value="item.announceStatus" center :to="{name:'informationDetail', query: {id:item.applyProposerId}}">
            <template #icon>
              <van-icon name="../../../static/images/onlineHome/icon_zjd8.png" size="30" color="#539FFD" style="margin-right: 10px;" />
            </template>
            <template #label>
              <p>{{item.announceType}}<i style="margin-right: 0.2rem;"></i>{{item.startDate}}至{{item.endDate}}</p>
            </template>
          </van-cell>
        </van-swipe-cell>
      </van-list>
    </div>
</template>

<script>
  import { getList } from "@/api/onlineHome/homestead/information";
  export default {
  name: "informationList",
  data() {
    return {
      value:'',
      loading: false,
      finished: false,
      queryParams:{
        pageNum:1,
        pageSize:10,
        orderByColumn:'createTime',
        isAsc:'desc',
        announceStatus:2,
        memberName:''
      },
      informationList:[],
      announceStatus:[],
      announceTypeStatus:[]
    };
  },
  created() {
    this.houseGetDicts("announce_status").then((response) => {
      this.announceStatus = response.data;
    });
    this.houseGetDicts("announce_type").then((response) => {
      this.announceTypeStatus = response.data;
    });
  },
  methods: {
    getList(){
      setTimeout(() => {
        getList(this.queryParams).then(response => {
          console.log(response)
          for (var i = 0; i < response.rows.length; i++) {
            var announceStatus = this.selectDictLabel(this.announceStatus, response.rows[i].announceStatus);
            var announceType = this.selectDictLabel(this.announceTypeStatus, response.rows[i].announceType);
            response.rows[i].announceStatus = announceStatus;
            response.rows[i].announceType = announceType;
            this.informationList.push(response.rows[i]);
          }
          console.log(this.informationList.length >= response.total)
          if(this.informationList.length >= response.total){
            this.finished = true;
            return;
          }else{
            this.loading = false;
            this.queryParams.pageNum += 1 ;
          }
        });
      }, 1000);
    },
    onSearch(){
      this.queryParams.memberName = this.value;
      this.informationList = [];
      this.getList();
    }
  },
}
</script>

<style scoped>
  .app-container {
    padding: 0.2rem 3%;
  }
  /deep/.van-cell__title{
    flex: 0.85;
  }
  /deep/.van-cell__title span{
    font-family: Arial;
    font-size: 0.4rem;
    font-weight: normal;
  }
  /deep/.van-cell__value{
    flex: 0.15;
    color: #1D6FE9;
    font-weight: bold;
  }
  /deep/.van-swipe-cell{
    margin-bottom: 0.2rem;
    border-radius: 0.2rem;
    overflow: hidden;
    box-shadow: 0px 3px 6px 0px rgba(0,0,0,0.16);
  }
  /deep/van-ellipsis{
    font-weight: bold;
  }
  .delete-button {
    height: 100%;
  }
  /deep/.van-search__content{
    background-color: transparent;
  }
  /deep/.van-search__action{
    padding-right: 0.5rem;
  }
  .searchInput{
    background: #ffffff;
    border: 1px solid #c9c9c9;
    border-radius: 50px;
    padding:0 ;
    margin-bottom: 0.2rem;
  }
</style>
