<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-tabs v-model="active" @change="onStatusChanged">
        <van-tab title="全部" name=""></van-tab>
        <van-tab title="已上报" name="1"></van-tab>
        <van-tab title="未上报" name="2"></van-tab>
      </van-tabs>
      <van-pull-refresh v-model="refreshing" @refresh="getList()">
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="getList"
      >
        <van-swipe-cell v-for="(item,index) in list" :key="index">
          <van-cell :value="formatDict(options.task_status, item.taskStatus)" center>
            <template #title>
              <p class="van-ellipsis">{{item.title}}</p>
            </template>
            <template #icon>
              <van-icon name="../../../static/images/onlineHome/icon_zjd10.png" size="30" color="#539FFD" style="margin-right: 10px;" />
            </template>
            <template #label>
              <p>{{item.reportDeadline}}</p>
            </template>
          </van-cell>
          <template #right>
            <van-row>
              <van-col>
                <van-button square text="上报" :to="{name:'taskCloseCaseAdd', query: {id:item.id}}" type="info" class="delete-button" v-if="allowCUD"/>
              </van-col>
              <van-col>
                <van-button color="#FFA63E" square :to="{name:'taskDetailedList', query: {id:item.id}}" type="info" class="delete-button" >
                    上报<br/>情况
                </van-button>
              </van-col>
            </van-row>
          </template>
        </van-swipe-cell>
      </van-list>
      </van-pull-refresh>
    </div>
</template>

<script>
import { getList } from "@/api/onlineHome/homestead/reporting";
import { getTaskListByDeptId } from "@/api/onlineHome/homestead/supervision";
export default {
  name: "paidExit",
  data() {
    return {
      list:[],
      refreshing: false,
      loading: false,
      finished: false,
      total: 0,
      queryParams:{
        pageNum:1,
        pageSize:10,
        orderByColumn:'createTime',
        isAsc:'desc',
        taskStatus: null,
        taskSubjectStatus: '2'
      },
      active: '',
      options: {
        task_subject_status: [],
        task_status: [],
      },
    };
  },
  created() {
    this.initOptions();
    this.getList();
  },
  computed: {
    allowCUD: function () {
      return this.$store.getters.businessLevel == '2'
    },
  },
  methods: {
    initOptions() {
      for(let k in this.options)
      {
        this.houseGetDicts(k).then((res) => {
          this.options[k] = res.data;
        });
      }
    },
    getList(target) {
      let type = typeof (target);
      console.log(type, target);
      if (target === 0) {
        this.refreshing = true;
        this.finished = true;
        this.total = 0;
        this.queryParams.pageNum = 1;
        this.list = [];
        this.filterVisible = false;
      }
      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 = []
      }
      getTaskListByDeptId(this.queryParams).then((response) => {
        console.log(response)
        if (response.rows.length === 0) {
          this.finished = true;
          return;
        }
        response.rows.forEach((e) => {
          e.title = e.title.replace(/<[^>]+>/g,"").replace(/&nbsp;/ig,"");//截取html标签
          this.list.push(e);
        });
        this.total += response.rows.length;
        this.finished = this.total >= response.total;
      }).finally(() => {
        this.loading = false;
        this.refreshing = false;
      });
    },
    formatDict(dict, value) {
      return this.selectDictLabel(dict, value);
    },
    onStatusChanged(name, title) {
      this.queryParams.taskStatus = name;
      this.getList();
    },
  },
}
</script>

<style scoped lang="scss">
  .app-container {
    padding: 0.2rem 3%;
  }
  /deep/.van-cell__title{
    flex: 0.7;
    width: 50%!important;
  }
  /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>
