<template>
    <div class="app-container">
      <div class="header_main-placeholder">
        <div class="header_main">
          行级填报
          <div class="return_btn" @click="$router.back()"></div>
        </div>
      </div>

      <van-pull-refresh v-model="refreshing" @refresh="getList()">
        <van-list
          class="list_main"
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="getList('+1')"
      >

          <van-swipe-cell class="item"  v-for="(item,index) in list" :key="index">
            <div class="item_box" @click="view(item)">
              <div class="head_block">
                <i class="icon"></i>
                <div class="title">{{item.reportName}}</div>
              </div>

              <div class="order_block">
                <div class="flex_block">
                  <i class="icon icon_1"></i>
                  <div class="text">最近填报: {{item.params.lastOperatorDate}}</div>
                </div>
                <div class="flex_block">
                  <i class="icon icon_2"></i>
                  <div class="text">总填报数: {{item.params.numReport}}</div>
                </div>
              </div>
            </div>
            <template #right>
              <van-row class="full-height toolbar">
                <van-col class="full-height">
                  <van-button square text="填报" type="primary" :to="{name:'entityReportLineView', query: {templateId:item.id, intent: 'add'}}" class="full-height" />
                </van-col>
              </van-row>
            </template>
          </van-swipe-cell>
      </van-list>
      </van-pull-refresh>
    </div>
</template>

<script>
import {delReport, listLineReporttitle} from "@/api/sunVillage_info/entity/report.js";
export default {
  name: "ReportLineList",
  data() {
    return {
      list:[],
      loading: false,
      finished: false,
      refreshing: false,
      total: 0,
      queryParams:{
        pageNum:1,
        pageSize:10,
        orderByColumn:'createTime',
        isAsc:'desc',
        type: '2',
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    view(row){
      this.$router.push({
        name: 'entityReportLineSummary',
        query: {
          intent: 'view',
          templateId: row.id,
        }
      });
    },
    getList(target){
      let type = typeof (target);
      //console.log(type, target);
      if(target && this.finished)
        return;
      if (target === 0) {
        this.refreshing = true;
        this.finished = true;
        this.total = 0;
        this.queryParams.pageNum = 1;
        this.list = [];
      }
      else if (type === 'number')
        this.queryParams.pageNum = target;
      else if (type === 'string') {
        this.queryParams.pageNum = eval(this.queryParams.pageNum + target)
      }
      else
      {
        this.refreshing = true;
        this.finished = true;
        this.total = 0;
        this.queryParams.pageNum = 1;
        this.list = []
      }
      listLineReporttitle(this.queryParams).then(response => {
        if (response.rows.length === 0) {
          this.finished = true;
          return;
        }
        this.list.push(...response.rows);
        this.total += response.rows.length;
        this.finished = this.total >= response.total;
      }).finally(() => {
        this.loading = false;
        this.refreshing = false;
      });
    },
    remove(row, index){
      this.$dialog.confirm({
        message: '您确认删除综合填报？',
      })
      .then(() => {
        delReport(row.id).then(res => {
          this.$toast.success('删除成功');
          this.list.splice(index,1);
        });
      })
      .catch(() => {
      });
    },
    refresh() {
      this.getList(); return;
      this.list = [];
      this.queryParams.pageNum = 1;
      this.refreshing = true;
      this.finished = false;
    },
  },
}
</script>

<style scoped lang="scss">
  .app-container {
    //padding: 0.2rem 3%;
    width: 100vw;
    height: 100vh;
  }
  .full-height {
    height: 100%;
  }
  .header_main-placeholder {
    height: 116px;
  }
  .header_main {
    height: 116px;
    background: url('../../../assets/images/sunVillage_info/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;
    }
  }

  .list_main{
    padding:26px 22px 0;
    .item{
      height: 162px;
      border-radius: 30px;
      background: #fff;
      box-shadow: 4px 6px 5px rgba(63, 68, 75, 0.1);
      margin-bottom: 20px;
      .item_box{
        padding:25px 32px;
      }
      .head_block{
        height: 62px;
        display: flex;
        align-items: center;
        width: 100%;
        .icon{
          width: 34px;
          height: 30px;
          background: url('../../../assets/images/sunVillage_info/fixedAssets_icon_4.png') no-repeat;
          background-size: 100% 100%;
          display: block;
          margin-right: 12px;
        }
        .title{
          flex:1;
          font-size: 32px;
          color: #252525;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          padding-right: 20px;

        }
      }
      .order_block{
        display: flex;
        height: 52px;
        padding-top: 12px;
        font-size: 24px;
        color: #858585;
        align-items: center;
        padding-bottom: 10px;
        .flex_block{
          display: flex;
          align-items: center;
          justify-content: center;
          margin-right: 28px;
          height: 42px;
          .icon{
            width: 25px;
            height: 25px;
            margin-top: 3px;
            margin-right: 8px;
            &.icon_1{
              background:  url('../../../assets/images/sunVillage_info/fixedAssets_icon_3.png') no-repeat;
              background-size: 100% 100%;
            }
            &.icon_2{
              background:  url('../../../assets/images/sunVillage_info/fixedAssets_icon_5.png') no-repeat;
              background-size: 100% 100%;
            }
          }
        }
      }
    }
  }

  .toolbar {
    margin-left: 2px;
  }
</style>
