<template>
  <div class="app-container">
    <div class="header_main">
      执法依据
      <div class="return_btn" @click="onClickLeftIndex"></div>
    </div>
    <div class="jg"></div>

    <div class="search_box">
      <van-popover
        v-model="showPopover"
        trigger="click"
        :actions="enforceNewsTypeOptions"
        placement="bottom-start"
        @select="popChange"
      >
        <template #reference>
          <div class="select_box">
            <p>{{popValue}}</p>
            <van-icon name="arrow-down" color="#1D6FE9" />
          </div>
        </template>
      </van-popover>
      <div class="search">
        <input type="text" v-model="searchInput" placeholder="请输入执法依据名称" />
        <img src="../../../../static/images/lawEnforcement/new/index_icon_04.png" @click="goSearch">
      </div>
    </div>

    <div class="main_box">
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="getList"
      >
        <div class="peopleList">
          <van-row v-for="(item,index) in list" :key="index" @click="$router.push({name:'lawEnforcementBasisDetail',query: {content:item}})" >
            <van-col :span="24">
              <img src="../../../../static/images/lawEnforcement/icon/record_icon_03.png"/>
              <p>{{item.title}}</p>
            </van-col>
          </van-row>
        </div>
      </van-list>
    </div>

  </div>
</template>

<script>
  import { getNewsList , enforceNewsType } from "@/api/lawEnforcement/index";
  export default {
    name: "programmeDetail",
    data() {
      return {
        showPopover: false,
        // 通过 actions 属性来定义菜单选项
        enforceNewsTypeOptions: [],
        loading: false,
        finished: false,
        searchInput:'',
        queryParams: {
          // 分页
          pageNum: 1,
          pageSize: 10,
          // 查询排序
          orderByColumn: "id",
          isAsc: "desc",
          number: "002",
          deptId: null,
          title:''
        },
        list:[],
        popValue:'执法依据'
      };
    },
    created() {
      enforceNewsType().then(response => {
        for (var i = 0; i < response.data.length; i++) {
          this.enforceNewsTypeOptions.push({text: response.data[i].dictLabel, value: response.data[i].dictValue});
        }
      });

      if (this.$route.query.searchInput){
        this.searchInput = this.$route.query.searchInput;
        this.goSearch();
      }
    },
    methods: {
      getList(){
        console.log('aaaa')
        var _this = this;
        getNewsList(_this.queryParams).then(response => {
          response.rows.map(res=>{
            // res.businessType = res.businessType == '' ? '' : this.selectDictLabel(this.businessTypeOptions, res.businessType);
            this.list.push(res);
          })
          if(this.list.length >= response.total){
            this.finished = true;
            return;
          }else{
            this.loading = false;
            this.queryParams.pageNum += 1 ;
          }
        });
      },
      popChange(action,index){
        console.log(action,index)
        this.popValue = action.text;
        this.queryParams.number = action.value;
        this.list = [];
        this.finished = true;
        this.loading = true;
        this.queryParams.pageNum = 1 ;
        this.queryParams.pageSize = '9999';
        this.getList();
      },
      goSearch(){
        if (this.searchInput == ''){
          location.reload()
        }
        if (this.searchInput == this.queryParams.title){
          return;
        }
        this.list = [];
        this.finished = false;
        this.loading = true;
        this.queryParams.title = this.searchInput;
        this.queryParams.pageNum = 1;
        this.getList();
      },
      onClickLeftIndex(){
        this.$router.push('/lawEnforcement/index_new')
      }
    },
  }
</script>

<style scoped lang="scss">
  .app-container {
    padding: 0 0 0.2rem;
  }
  .jg{
    height: 116px;
  }
  .search_box{
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 92%;
    margin: 10PX auto;
    .van-popover__wrapper{
      flex: 1;
      margin-right: 10PX;
    }
    .select_box{
      border: 1px solid #1D6FE9;
      border-radius: 50PX;
      padding: 0 12PX ;
      background: #ffffff;
      height: 30PX;
      line-height: 30PX;
      display: flex;
      justify-content: space-around;
      align-items: center;
      p{
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 1;
        word-break: break-all;
        overflow: hidden;
      }
    }
    .search{
      background: #ffffff;
      display: flex;
      justify-content: space-between;
      align-items: center;
      width: 70%;
      border: 1px solid #1D6FE9;
      padding: 1PX 1PX 1PX 12PX ;
      border-radius: 50PX;
      input{
        flex: 1;
        background: transparent;
      }
    }
  }
  .header_main{
    height: 116px;
    background: url('../../../../static/images/lawEnforcement/new/list_head.png') no-repeat;
    background-size: 100% 100%;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    font-size: 36px;
    line-height: 116px;
    text-align: center;
    color: #fff;
    z-index: 999;
    .return_btn{
      width: 24px;
      height: 43.2px;
      background: url('../../../assets/images/sunVillage_info/list_icon_5.png') center center no-repeat;
      background-size: 20px 36px;
      position: absolute;
      left: 38px;
      top: 36px;
    }
    .add_btn{
      width: 56.4px;
      height: 40.8px;
      background: url('../../../assets/images/sunVillage_info/list_icon_9.png') center center no-repeat;
      background-size: 47px 34px;
      position: absolute;
      right: 38px;
      top: 36px;
    }
  }
  .peopleList{
    padding: 0 3%;
    text-align: left;
    .van-row{
      border-bottom: 1px solid #dddddd;
      display: flex;
      align-items: center;
      &:last-child{
        border: none;
      }
      .van-col--24{
        display: flex;
        align-items: center;
        p{
          margin-left: 10PX;
        }
      }
      .van-col{
        text-align: left;
        font-size: 14PX;
        color: #333333;
        padding: 15PX 0;
        img{
          display: block;
        }
      }
    }
  }
  .main_box{
    width: 96%;
    margin: 0 auto;
    border-radius: 10PX;
    box-shadow: 0px 3px 6px 0px rgba(0,0,0,0.16);
    overflow: hidden;
    background-color: #FFF;
  }
</style>
