<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" :value="item.statusName" :to="{name:'yinnongSupervisionDetail', query: {id:item.id}}" center >
            <template #icon>
              <van-icon name="../../../static/images/onlineHome/icon_zjd12.png" size="30" color="#539FFD" style="margin-right: 10px;" />
            </template>
            <template #label>
              <p>{{item.jglxName}}<i style="margin-right: 0.5rem;"></i>{{item.taskSourceName}}</p>
            </template>
          </van-cell>
          <template #right>
            <van-row>
              <van-col>
                <van-button v-if="item.status == '0'" color="#FFA63E" text="立案" :to="{name:'yinnongSupervisionWfxx', query: {id:item.id}}" type="info" class="delete-button" />
              </van-col>
              <van-col>
                <van-button v-if=" item.status == '1'" color="#7DDA4F" square text="结案" :to="{name:'yinnongSupervisionCloseCase', query: {id:item.id}}" type="danger" class="delete-button" />
              </van-col>
              <van-col>
                <van-button v-if="item.status == '0'" square text="修改" :to="{name:'yinnongSupervisionModify', query: {id:item.id}}" type="info" class="delete-button" />
              </van-col>
              <van-col>
                <van-button v-if="item.status == '0'" color="#FF4646" 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 , registerOn } from "@/api/onlineHome/homestead/supervision";
import { jgEdit } from "@/api/onlineHome/homestead/reporting";
export default {
  name: "supervisionList",
  data() {
    return {
      applicationList:[],
      houseApplyStatus:[],
      tcqllxStatus:[],
      tclxStatus:[],
      tcfsStatus:[],
      auditStatus:[],
      loading: false,
      finished: false,
      queryParams:{
        pageNum:1,
        pageSize:10,
        isAsc:'desc'
      }
    };
  },
  created() {
    this.houseGetDicts("regulatory_status").then((res) => {
      this.auditStatus = res.data;
    });
    //违法用地类型
    this.houseGetDicts("task_source").then((res) => {
      console.log(res.data)
      this.taskSourceDictionaries = res.data;
    });
    //违法用地类型
    this.houseGetDicts("jglx").then((res) => {
      this.jglxDictionaries = res.data;
    });
  },
  methods: {
    goAdd(){
      this.$router.push({name:'yinnongSupervisionAdd'})
    },
    getList(){
      setTimeout(() => {
        getList(this.queryParams).then(response => {
          console.log(response)
          for (var i = 0; i < response.rows.length; i++) {
            // response.rows[i].status = this.selectDictLabel(this.auditStatus, response.rows[i].status);
            // response.rows[i].jglx = this.selectDictLabel(this.jglxDictionaries, response.rows[i].jglx);
            this.$set(response.rows[i], "statusName", this.selectDictLabel(this.auditStatus, response.rows[i].status));
            this.$set(response.rows[i], "jglxName", this.selectDictLabel(this.jglxDictionaries, response.rows[i].jglx));
            this.$set(response.rows[i], "taskSourceName", this.selectDictLabel(this.taskSourceDictionaries, response.rows[i].taskSource));
            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
      });
    },
    onRegister(data){
      this.$set(data, "status", "1");
      jgEdit(data).then(res => {
        if(res.code = 200){
          this.$toast.success('立案成功');
          setTimeout(function(){
            window.location.reload()
          },1000)
        }
      });
    }
  },
}
</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>
