<template>
  <div class="visitCheck">
    <NavBar />
    <div class="page-container">
      <van-search v-model="query.reasons" class="van-hairline--bottom" placeholder="请输入来访事由"  @change="refreshData"/>
      <div class="search-flex">
        <select-cell
          style="border-right: 1px solid #f5f5f5;"
          title="出入类型"
          :isAll="true"
          :border="false"
          v-model="query.type"
          :data-list="getDictItem('out_in_type')"
          @change="refreshData"/>
        <select-cell
          style="border-right: 1px solid #f5f5f5;"
          title="审批状态"
          :isAll="true"
          :border="false"
          v-model="query.approveStatus"
          :data-list="getDictItem('out_in_approve_status')"
          @change="refreshData"/>
      </div>
      <div class="card-list">
        <Scroll
          ref="Scroll"
          @refresh="refreshData"
          @loadMore="getDataList"
          :pullup="pullup">
          <empty  v-if="!dataList || dataList.length === 0" />
          <card v-else v-for="(v,i) in dataList" :key="v.id">
            <van-cell
              :title-style="{color:v.type == 3?'#D7000F':''}"
              :title="getDictLabel(v.type,'out_in_type')"
              @click="clickItem(v.id)">
              <template #extra>
                  <span :style="{color:getState(getDictLabel(v.approveStatus,'out_in_approve_status'))}">
                    {{getDictLabel(v.approveStatus,'out_in_approve_status') }}
                  </span>
              </template>
              <template #label>
                <div class="info-box">
                  <div v-if="v.type == 2" class="info-item">
                    <div class="item-label">介绍信编号：</div>
                    <div class="item-value"> {{v.letterNo}}</div>
                  </div>
                  <div class="info-item">
                    <div class="item-label">有效期：</div>
                    <div class="item-value">{{v.startTime}}~{{v.endTime}}</div>
                  </div>
                  <div class="info-item">
                    <div class="item-label">来访事由：</div>
                    <div class="item-value">
                      {{v.reasons}}
                    </div>
                  </div>
                </div>
              </template>
            </van-cell>
          </card>
        </Scroll>
      </div>
    </div>
  </div>
</template>
<script>
import NavBar from '@/components/NavBar'
import OrgTree from '@/components/orgTree'
import Scroll from '@/components/scroll/scroll'
import Card from '@/components/card'
import dateCell from '@/components/dateCell'
import selectCell from '@/components/selectCell'
import {dataList} from './api'
import {mapGetters} from "vuex";
import {formatDate} from "@/filters/filter";
export default {
  components: {
    NavBar,
    OrgTree,
    Scroll,
    Card,
    dateCell,
    selectCell,
  },
  data() {
    return {
      query:{
        reasons:'',
        approveStatus:null,
        type:null,
        pageSize:10,
        pageNum:1,
      },
      dataList:[],
      pullup:false,
      dicts:['out_in_approve_status','out_in_type']
    }
  },
  mounted() {
    this.initData();
  },
  computed:{
    ...mapGetters(['orgId','id','dictionary']),
  },
  methods: {
    getState(state){
      switch (state){
        case '待审批':
          return '#008cd6';
        case '不同意':
          return '#bc9f71';
        case '同意':
          return '#009240';
        case '已逾期':
          return '#D7000F';
      }
    },
    clickAdd(){
      this.$router.push({
        path:'/introAdd',
        query:{type:'add'}
      });
    },
    refreshData(){
      this.pullup = true;
      this.query.pageNum = 1;
      this.total = 0;
      this.dataList = [];
      this.getDataList();
    },
    //初始化数据
    initData(){
      this.getDataList();
    },
    //获取数据列表
    getDataList(){
      if( this.dataList.length !== 0 && this.dataList.length >= this.total) {
        this.pullup = false;
        this.$toast('已加载完毕');
        return;
      }
      let data = {
        ...this.query,
        orgId:this.orgId,
      }
      dataList(data).then(res=>{
        if(res.total === '0'){
          this.pullup = false;
          this.$toast('已加载完毕');
          return
        }
        this.total = res.total;
        if(this.dataList.length < res.total) {
          this.dataList = [...this.dataList,...res.rows] ;
          this.pullup = true;
          this.query.pageNum++;
          this.$refs.Scroll.refresh();
        }
      })
    },
    clickItem(id){
      this.$router.push({
        path:'/visitCheckDetail',
        query:{id}
      });
    }
  }
}
</script>
<style lang="scss">
.visitCheck{
  .card {
    >.van-cell{
      padding: 0;
    }
  }
  .van-cell-group{
    margin-bottom: 20px;
  }
  .van-cell-group:last-child{
    margin-bottom: 0;
  }
  .vue-table-root{
    tr,td,th{
      font-size: 25px!important;
      color:#666!important;
    }
  }
}
</style>
<style lang="scss" scoped>
.problem-item{

}
.app-container{

}
.card-list{
  padding:0 20px 20px 20px;
  height: calc(100vh - 426px);
  overflow:  auto;
}
.card-num{
  display: flex;
  align-items: center;
  font-size: 28px;
  color: #009dff;
}
.search-flex{
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #f5f5f5;
  >div{
    width: 50%;
  }
}
.btn-box{
  width: 100%;
  height: 100%;
  padding: 30px;
  background-color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}
.info-box{
  color:#555;
}
.info-desc{
  padding-top: 10px;
  min-height: 50px;
  line-height: 36px;
  max-height: 250px;
  display: -webkit-box;
  -webkit-line-clamp: 3; /* 限制显示为3行 */
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  >span{
    color:#999;
  }
}
.info-item{
  display: flex;
  justify-content: space-between;
  font-size: 26px;
  .item-label{
    flex:.25;
    text-align: left;
    color:#333;
  }
  .item-value{
    flex:.75;
    color:#666;
    min-height: 50px;
    line-height: 36px;
    max-height: 250px;
    display: -webkit-box;
    -webkit-line-clamp: 3; /* 限制显示为3行 */
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}
</style>
