<template>
  <div class="app-container">
    <van-nav-bar
      :title="title"
      fixed
      placeholder
      left-arrow
      @click-left="onClickLeft"
    />
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="getDeptId"
    >
      <van-cell-group class="listBox">
        <van-cell
          v-for="(item , index) in workList"
          :key="index"
          :title="pageType == 'scheme' ? item.schemeName : item.title"
          :value="pageType == 'scheme' ? item.applyTime : item.newsTime"
          :to="{name:pageType == 'scheme' ? 'schemeDetail':'workDetail',query:{id:item.id,type:pageType}}"
        />
      </van-cell-group>
    </van-list>
  </div>
</template>
<script>
import { getTopDeptId , newsList , schemeList  } from "@/api/lawEnforcement/index";
import law from "@/components/common/law_footer";
export default {
  name: "index",
  components: {
    law
  },
  data() {
    return {
      //是否显示加载
      loading: false,
      //是否滚动到底部
      finished: false,
      //查询参数
      queryParams: {
        number: '003',
        deptId: 100,
        pageNum: 1,
        pageSize: 20,
      },
      //新闻集合
      workList:[],
      //轮播图集合
      bannerList:'',
      pageType:'',
      title:'',
    };
  },
  created() {
    this.getDeptId();
  },
  methods: {
    getDeptId(){
      getTopDeptId().then(response => {
        this.queryParams.deptId = response.data ;
        this.getList();
      })
    },
    getList(){
      var type = this.$route.query.type ;
      this.pageType = this.$route.query.type;
      if (type == 'work'){
        this.queryParams.number = '003'
        this.title = '工作动态'
      }
      if (type == 'notice'){
        this.queryParams.number = '001'
        this.title = '通知公告'
      }
      if (type == 'enforcement'){
        this.queryParams.number = '002'
        this.title = '执法依据'
      }
      if (type == 'scheme'){
        this.title = '执法方案'
      }
      this.loading = true;
      if(this.$route.query.type == 'scheme'){
        schemeList(this.queryParams).then(response => {
          this.workList = response.rows;
          if(this.workList.length >= response.total){
            this.finished = true;
            return;
          }
          this.queryParams.pageNum += 1 ;
          this.loading = false;
        });
      }else{
        newsList(this.queryParams).then(response => {
          this.workList = response.rows;
          if(this.workList.length >= response.total){
            this.finished = true;
            return;
          }
          this.queryParams.pageNum += 1 ;
          this.loading = false;
        });
      }
    },
    getBanner(){
      this.loading = true;
      this.queryParams.number = 1 ;
      this.queryParams.pageSize = 5 ;
      newList(this.queryParams).then(response => {
        this.bannerList = response.rows;
        for (var i = 0; i < response.rows.length; i++) {
          var imgStrs = response.rows[i].content.match(/<IMG src=\"([^\"]*?)\">/gi)
          if (imgStrs != null && imgStrs != '') {
            this.bannerList[i].img = imgStrs[0].substr(10,(imgStrs[0].length-12));
          }
        }
        this.loading = false;
      });
    },
    goDetail(id){
      console.log(id)
      window.location = 'news/newDetail?id='+id;
    }
  },
};
</script>

<style scoped lang="scss">
@font-face {
  font-family: SourceHanSansCNBold;
  src: url("../../../assets/fonts/SourceHanSansCN-Bold.otf");
}
.van-cell__title{
  color: #666666;
  flex: 0.6;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
  word-break: break-all;
  overflow: hidden;
}
.van-cell__value{
  flex: 0.4;
}
.app-container {
  padding: 10PX ;
}
/deep/ .van-nav-bar--fixed{
  background: url("../../../../static/images/lawEnforcement/head_bg.png") 100%;
}
/deep/ .van-nav-bar .van-icon{
  color: #ffffff;
}
/deep/ .van-nav-bar__title{
  color: #ffffff;
}
.van-cell__title{
  color: #666666;
}
.listBox{
  border-radius: 8Px;
  overflow: hidden;
  box-shadow: 0PX 5PX 5PX #cccccc;
  .van-icon{
    vertical-align: middle;
  }
  .custom-title{
    font-size: 17PX;
    color: #333333;
    vertical-align: middle;
    line-height: 1;
    position: relative;
  }
  .tap{
    color: #1D6FE9;
  }
  .bgBlue{
    display: block;
    position: absolute;
    width: 17PX;
    height: 17PX;
    border-radius: 50%;
    background-color: rgba(29,111,233,0.26);
    top: -2PX;
    right: -8PX;
  }
}
/deep/ .van-nav-bar__title{
  display: flex;
  max-width: initial;
  p{
    line-height: 30Px;
    margin-left: 6Px;
    font-size: 21Px;
    color: #D60303;
    font-family: SourceHanSansCNBold;
  }
}
/deep/ .van-tabs__content{
  width: 96%;
  margin: 0 auto;
  box-shadow: 0px 5px 5px #ccc;
}
/deep/ van-tab__pane-wrapper{
  padding: 0 2%;
}
/deep/ .van-tab{
  border: none;
  color: #1D6FE9;
}
/deep/ .van-tab--active{
  border-radius: 30Px;
  box-shadow: 0px 5px 5px #ccc;
  background-color: #FE1313!important;
}
/deep/ .van-tabs--card>.van-tabs__wrap{
  height: 0.9rem;
  margin: 10Px 0;
}
/deep/ .van-tab__pane{
  background: #FFF;
  border-radius: 8Px;
  overflow: hidden;
}
/deep/ .van-tabs__nav--card{
  padding: 3Px 2%;
  border: none;
  border-radius: 1rem;
  height: 0.9rem;
}
.bannerTit{
  position: absolute;
  bottom: 10px;
  background: rgba(255,255,255,0.3);
  width: 100%;
  height: 0.8rem;
  line-height: 0.8rem;
  color: #fff;
  overflow: hidden;
  padding: 0 3%;
  font-size: 16Px;
}
.link{
  color: #000;
}
.my-swipe {
  border-radius: 8Px;
}
.my-swipe .van-swipe-item .van-image{
  width: 100%;
}
.van-grid-item p{
  margin-top: 10px;
}
.newTit{
  font-size: 0.45rem;
  margin: 0.4rem 0;
  font-family: Source Han Sans SC, Source Han Sans SC-Medium;
  font-weight: 500;
  text-align: left;
  color: #333333;
}
.newContent{
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  word-break: break-all;
  overflow: hidden;
}
.search-icon {
  line-height: inherit;
  margin-left: 10px;
}
</style>
