<template>
    <div class="app-container">
      <van-nav-bar
        left-arrow
        fixed
        placeholder
        @click-left="$router.back(-1)"
      >
        <template #title>
          <p style="font-weight: bold;">结案</p>
        </template>
      </van-nav-bar>
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="getList"
      >
        <div class="main_box" v-for="(item,index) in applicationList" :key="index">
          <van-field readonly label="ID" input-align="right" v-model="item.id" label-width="auto" />
          <van-field readonly label="宅基地代码" input-align="right" v-model="item.zjddm" label-width="auto" />
          <van-field readonly label="监管类型" input-align="right" v-model="item.jglx" label-width="auto" />
          <van-field readonly label="立案时间" input-align="right" v-model="item.lasj" label-width="auto" />
          <van-field readonly label="违法用地类型" input-align="right" v-model="item.wfydlx" label-width="auto" />
          <van-field readonly label="违法用地面积" input-align="right" v-model="item.wfydmj+'㎡'" label-width="auto"/>
          <van-cell title="操作" >
            <template #default>
              <van-button :to="{name:'taskReportingDetail', query: {id:item.id}}" color="#FFA63E" round type="default" size="mini" style="padding: 0 15px">查看</van-button>
              <van-button v-if="allowCUD && item.status != 2" :to="{name:'taskReportingAdd', query: {id:item.id}}" color="#1D6FE9" round type="default" size="mini" style="padding: 0 15px">结案</van-button>
            </template>
          </van-cell>
        </div>
      </van-list>
    </div>
</template>

<script>
import { getTaskList } from "@/api/onlineHome/homestead/reporting";
import { listByTaskId } from "@/api/onlineHome/homestead/task";
export default {
  name: "taskDetailedList",
  data() {
    return {
      applicationList:[],
      houseApplyStatus:[],
      jglxStatus:[],
      wfydlxStatus:[],
      loading: false,
      finished: false,
      queryParams:{
        taskId:'',
      }

    };
  },
  created() {
    this.queryParams.taskId = this.$route.query.id;
    this.houseGetDicts("jglx").then((res) => {
      this.jglxStatus = res.data;
    });
    this.houseGetDicts("villations_type").then((res) => {
      this.wfydlxStatus = res.data;
    });
  },
  computed: {
    allowCUD: function () {
      return this.$store.getters.businessLevel == '2'
    },
  },
  methods: {
    getList(){
      setTimeout(() => {
        listByTaskId(this.queryParams).then(response => {
          for (var i = 0; i < response.rows.length; i++) {
            response.rows[i].jglx = this.selectDictLabel(this.jglxStatus, response.rows[i].jglx)
            response.rows[i].wfydlx = this.selectDictLabel(this.wfydlxStatus, response.rows[i].wfydlx)
            this.applicationList.push(response.rows[i]);
          }
          if(this.applicationList.length >= response.total){
            this.finished = true;
            return;
          }else{
            this.loading = false;
            this.queryParams.pageNum += 1 ;
          }
        });
      }, 1000);
    },
  },
}
</script>

<style scoped lang="scss">
  .app-container {
    padding: 2% 0;
  }
  .main_title{
    font-size: 0.4rem;
    color: #1D6FE9;
    margin: 0.2rem 6%;
    position: relative;
  }
  .main_box{
    width: 96%;
    margin: 0 auto;
    border-radius: 6px;
    box-shadow: 0px 3px 6px 0px rgba(0,0,0,0.16);
    overflow: hidden;
    background-color: #FFF;
    margin-bottom: 2%;
  }
  .submitButton{
    width: 80%;
    margin: 0 auto;
    background-color: #1D6FE9;
  }
</style>
