<template>
  <div class="app-container">
    <van-nav-bar
      left-arrow
      fixed
      placeholder
      @click-left="$router.back(-1)"
      @click-right="goAdd"
    >
      <template #title>
        <p style="font-weight: bold;">无偿退出</p>
      </template>
      <template #right>
        <van-icon name="add" size="18" />
      </template>
    </van-nav-bar>
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="getList"
    >
      <van-swipe-cell v-for="(item,index) in applicationList" :key="index">
        <van-cell :title="item.zjddm" center :to="{name:'freeExitDetail', query: {id:item.id}}" >
          <template #icon>
            <van-icon name="../../../static/images/onlineHome/icon_zjd3.png" size="30" color="#539FFD" style="margin-right: 10px;" />
          </template>
          <template #label>
            <p><b style="color: #539FFD;">{{item.tcfs}}</b><i style="margin-right: 0.5rem;"></i><b style="color: #333333;">{{item.sqrxm}}</b><i style="margin-right: 0.5rem;"></i>{{item.tcmj}}㎡</p>
          </template>
        </van-cell>
        <template #right>
          <van-row>
            <van-col>
              <van-button square text="修改" :to="{name:'freeExitModify', query: {id:item.id}}" type="info" class="delete-button" />
            </van-col>
            <van-col>
              <van-button square text="删除" @click="deleteList(item.id,index)" type="danger" class="delete-button" />
            </van-col>
          </van-row>
        </template>
      </van-swipe-cell>
    </van-list>
  </div>
</template>

<script>
  import { getList , removeList, } from "@/api/onlineHome/homestead/paidExit";
  export default {
    name: "freeExitList",
    data() {
      return {
        applicationList:[],
        houseApplyStatus:[],
        tcqllxStatus:[],
        tclxStatus:[],
        tcfsStatus:[],
        loading: false,
        finished: false,
        queryParams:{
          pageNum:1,
          pageSize:10,
          orderByColumn:'createTime',
          isAsc:'desc',
          // 申请类型  1-宅基地退出
          sqlx: '1',
          // 退出类型  01-有偿退出   02-无偿退出
          tclx: '02',
        }
      };
    },
    created() {
      this.houseGetDicts("tcqllx").then((res) => {
        this.tcqllxStatus = res.data;
      });
      this.houseGetDicts("tclx").then((res) => {
        this.tclxStatus = res.data;
      });
      this.houseGetDicts("tcfs").then((res) => {
        this.tcfsStatus = res.data;
      });
    },
    methods: {
      goAdd(){
        window.location = 'freeExitAdd';
      },
      getList(){
        setTimeout(() => {
          getList(this.queryParams).then(response => {
            for (var i = 0; i < response.rows.length; i++) {
              response.rows[i].tcqllx = this.selectDictLabel(this.tcqllxStatus, response.rows[i].tcqllx)
              response.rows[i].tclx = this.selectDictLabel(this.tclxStatus, response.rows[i].tclx)
              response.rows[i].tcfs = this.selectDictLabel(this.tcfsStatus, response.rows[i].tcfs)
              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);
      },
      deleteList(id,index){
        this.$dialog.confirm({
          message: '您确认删除此退出申请？',
        })
          .then(() => {
            // on confirm
            this.applicationList.splice(index,1)
            removeList(id).then(res => {
              if(res.code = 200){
                this.$toast.success('删除成功');
              }
            });
          })
          .catch(() => {
            // on cancel
          });
      },
    },
  }
</script>

<style scoped lang="scss">
  .app-container {
    padding: 0.2rem 3%;
  }
  /deep/.van-cell__title{
    flex: 0.7;
  }
  /deep/.van-cell__title span{
    font-family: Arial;
    font-size: 0.4rem;
    font-weight: normal;
  }
  /deep/.van-cell__value{
    flex: 0.3;
    color: #1D6FE9;
    font-weight: bold;
  }
  /deep/.van-swipe-cell{
    margin-bottom: 0.2rem;
    border-radius: 0.2rem;
    overflow: hidden;
    box-shadow: 0px 3px 6px 0px rgba(0,0,0,0.16);
  }
  /deep/van-ellipsis{
    font-weight: bold;
  }
  .delete-button {
    height: 100%;
  }
  .van-row{
    height: 100%;
  }
  .van-col{
    height: 100%;
  }
</style>
