<template>
  <div class="app-container">
    <van-nav-bar
      title="新闻资讯"
      left-arrow
      fixed
      placeholder
      @click-left="onClickLeft"
    />
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="getList()"
    >
      <!--        @load="newList"-->
      <van-cell v-for="item in newList" :key="item.id" :title="item.title" :label="item.newsTime" :to="{name:'newDetail', query: {id:item.id}}">
        <!-- 使用 right-icon 插槽来自定义右侧图标 -->
        <template #right-icon>
          <van-image :src="item.img" class="search-icon" width="30%" style="margin-left: 10px;" v-if="item.img" />
          <van-image src="../../static/images/zwtpxw.jpg" class="search-icon" width="30%" v-else/>
        </template>
      </van-cell>
    </van-list>
  </div>
</template>

<script>
import { newList } from "@/api/index";
export default {
  name: "news",
  data() {
    return {
      //是否显示加载
      loading: false,
      //是否滚动到底部
      finished: false,
      //新闻集合
      newList:[],
      //查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 5,
        deptId:100,
        number:2
      },
    };
  },
  created() {},
  methods: {
    getList(){
      this.loading = true;
      newList(this.queryParams).then(response => {
        console.log(response);
        for (var i = 0; i < response.rows.length; i++) {
          this.newList.push(response.rows[i]);
          var imgStrs = response.rows[i].content.match(/<IMG src=\"([^\"]*?)\">/gi)
          if (imgStrs != null && imgStrs != '') {
            console.log(imgStrs[0].length-2)
            console.log(imgStrs[0])
            this.newList[i].img = imgStrs[0].substr(10,(imgStrs[0].length-12));
          }
        }
        console.log(this.newList)
        if(this.newList.length >= response.total){
          this.finished = true;
          return;
        }
        this.queryParams.pageNum += 1 ;
        this.loading = false;
      });
    },
  },
};
</script>

<style scoped lang="scss">
.app-container {
}
</style>
