<template>
  <div>
    <van-nav-bar
      title="已办事项"
    />
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white" style="width: 96%;margin: 2%;height:150px;border-radius: 6px;">
      <van-swipe-item v-for="(image,index) in images" :key="index">
        <img :src="image" style="width:100%;height: 150px"/>
      </van-swipe-item>
    </van-swipe>

    <paged-list
      ref="pagedList"
      :page-num.sync="queryParams.pageNum"
      :page-size.sync="queryParams.pageSize"
      :total.sync="total"
      :getListFunc="getListReq"
      @reload="taskList = []"
      get-when-created
      :finished.sync="finished"
      :loading.sync="loading">

    <van-cell-group @click="goDetail(item)" v-for="(item,index) in taskList" :key="index" style="width: 96%;margin:2%;border-radius: 6px;overflow: hidden;padding-top: 10px;box-shadow: 0px 3px 6px 0px rgba(0,0,0,0.16);">
      <van-cell style="padding: 0 0">
        <template #title>
          <van-row style="">
            <van-col span="23" :offset="1">

              <p style="display: inline-block;line-height: 30px;margin-left: 6px;width: 100%;overflow: hidden;">
                <van-image
                  height="20"
                  width="20"
                  style="vertical-align: middle;margin-right: 10px"
                  src="../../../../static/images/onlineHome/done.png"></van-image>{{item.auditName}}</p>
            </van-col>
          </van-row>
        </template>
      </van-cell>
      <van-cell>
        <template #title>
          <van-row>
            <van-col span="6" :offset="1">
              <p style="color: #878787">{{item.auditTime.substring(0,10)}}</p>
            </van-col>
            <van-col span="10" :offset="1">
              <p style="color: #878787">{{item.businessType}}</p>
            </van-col>
            <van-col span="5" :offset="1">
              <p v-if="item.auditStatus == '2'" style="font-size: 14px;font-weight:bold;text-align: right;color: red">驳回</p>
              <p v-if="item.auditStatus == '3'" style="font-size: 14px;font-weight:bold;text-align: right;color: #1D6FE9">通过</p>
            </van-col>
          </van-row>
        </template>
      </van-cell>
    </van-cell-group>
    </paged-list>
      <van-empty v-if="taskList.length<1" description="暂无事项" />
    <yinnongIndex></yinnongIndex>
  </div>
</template>

<script>
    import onlineHomeIndex from "../../onlineHomeIndex";
    import yinnongIndex from "../../yinnongIndex";
    import {A_myDoneList, A_myTodoList} from "../../../api/audit/aauditpipeline";
    import PagedList from "@/components/common/PagedList.vue";
    import {selectDictLabel} from "@/utils/utils";

    export default {
      components: {
        PagedList,
        onlineHomeIndex,
        yinnongIndex
      },
        name: "done",
      data(){
        return{
          loading:false,
          finished:false,
          taskList:[],
          transferTypeOptions:[],
          activeName:this.$route.query.activeName?this.$route.query.activeName:'2',
          total:0,
          queryParams: {
            pageNum: 1,
            pageSize: 20,
            systemType: null,
            deptId: null,
            translate_dict:'1'
          },
          activityBusinessTypeOptions:[],
          images:['../../../../static/images/yinnong/banner_02.jpg'],
        }
      },
      created() {
        this.getDicts("transfer_type").then(response => {
          this.transferTypeOptions = response.data;
        });
        this.getDicts("activity_business_type").then((response) => {
          this.activityBusinessTypeOptions = response.data;
          if(this.$route.query.activeName){
            this.activeName = this.$route.query.activeName
          }
        });
        //console.log(this.$route.query.fr)
        if(this.$route.query.fr){
          this.$cookies.set("from",this.$route.query.fr,"0")
        }

      },
      methods: {
        goOnlineHomeIndex(){
          if(this.$cookies.get("from")=="my"){
            this.$router.push({name:"yinnongMy"})
          }else{
            this.$router.push({name:"yinnongWorkbench"})
          }
        },
        getListReq(pageInfo) {
          //console.log(pageInfo, this.queryParams.pageNum, this.queryParams.pageSize)
          this.$set(this.queryParams, "deptId", this.$store.state.user.deptId);
          return new Promise((resolve, reject) => {

            A_myDoneList(this.queryParams).then((response) => {
              //console.info(_this.taskList.length)
              response.rows.forEach(res => {
                // if(res.tableName?res.tableName.indexOf('t_homeapply')>0:""){
                //   res.tableName = '来自农村宅基地管理系统'
                // }else if(res.tableName?res.tableName.indexOf('sys_seal')>0:""){
                //   res.tableName = '来自银农直联审批管理系统'
                // }else if(res.tableName?res.tableName.indexOf('yinnong')>0:""){
                //   res.tableName = '来自银农直联审批管理系统'
                // }
                res.businessType = this.selectDictLabel(this.activityBusinessTypeOptions, res.businessType);
                this.taskList.push(res)
              });
              resolve(response);
            });
          });
        },
        getList() {
          if(this.$refs.pagedList)
          {
            this.$refs.pagedList.getList(target);
            return;
          }

          //this.$set(this.queryParams, "systemType", '4');
          this.$set(this.queryParams, "deptId", this.$store.state.user.deptId);
          A_myDoneList(this.queryParams).then((response) => {
            response.rows.map(res => {
              // if(res.tableName?res.tableName.indexOf('t_homeapply')>0:""){
              //   res.tableName = '来自农村宅基地管理系统'
              // }else if(res.tableName?res.tableName.indexOf('sys_seal')>0:""){
              //   res.tableName = '来自银农直联审批管理系统'
              // }else if(res.tableName?res.tableName.indexOf('yinnong')>0:""){
              //   res.tableName = '来自银农直联审批管理系统'
              // }
              if(this.activityBusinessTypeOptions){
                this.activityBusinessTypeOptions.map(t => {
                  if(t.dictValue == res.businessType){
                    res.businessType = t.dictLabel
                    this.taskList.push(res)
                  }
                });
              }
            })

            if(this.taskList.length >= response.total){
              this.finished = true;
              return;
            }else{
              this.loading = false;
              this.queryParams.pageNum += 1 ;
            }

          })
        },
        goDetail(item){
          //console.log(item)
          let type = item.tableName;
          switch (type) {
            case 't_homeuse_zyyctc':
              this.$router.push({name:'sunVillageInfoPaidExitDetailNew',query: {id:item.data.id,taskId:item.id,auditbatchNo:item.auditbatchNo,type:"done",electronicSignature:this.electronicSignature,nickName:this.nickName}})
              break;
            case 't_homeapply_ydjfys':
            case 't_homeapply_ydjfkg':
              this.$router.push({name:'sunVillageInfoProposerLiteNew',query: {id:item.data.ydjfsqId,taskId:item.id,auditbatchNo:item.auditbatchNo,type:"done"}})
              break;
            case 't_homeapply_ydjfsq':
              this.$router.push({name:'sunVillageInfoProposerLiteNew',query: {id:item.data.id,taskId:item.id,auditbatchNo:item.auditbatchNo,type:"done"}})
              break;
            case 'baseApply':
            case 'landscope':
            case 'accepting':
              this.$router.push({name:'approvalForm',query: {id:item.formData.id,taskId:item.taskId,instanceId:item.formData.instanceId,type:item.type}})
              break;
            case 'toReviewTransferProcess':
            case 't_yinnong_transfer':
              if(item.data.transferType == '10'){
                this.$router.push({name:'approvalApproval10',query: {id:item.data.id,taskId:item.id,auditbatchNo:item.auditbatchNo,type:"done"}})
                break;
              }
              if(item.data.transferType == '11'){
                this.$router.push({name:'approvalApproval11',query: {id:item.data.id,taskId:item.id,auditbatchNo:item.auditbatchNo,type:"done"}})
                break;
              }
              if(item.data.transferType == '12'){
                this.$router.push({name:'approvalApproval12',query: {id:item.data.id,taskId:item.id,auditbatchNo:item.auditbatchNo,type:"done"}})
                break;
              }
              if(item.data.transferType != '10'&&item.data.transferType != '11'&&item.data.transferType != '12'){
                this.$router.push({name:'approvalApproval',query: {id:item.data.id,taskId:item.id,auditbatchNo:item.auditbatchNo,type:"done"}})
                break;
              }
            case 'yinnong_majorevent':
            case 't_yinnong_majorevent':
              this.$router.push({name:'approvalApproval13',query: {id:item.data.id,taskId:item.id, auditbatchNo: item.auditbatchNo, type:"done"}})
              break;
            case 't_yinnong_cashexpense':
              this.$router.push({
                path: '/yinnong/cashExpenseApproval',
                query: { id: item.data.id, taskId: item.id, auditbatchNo: item.auditbatchNo, type: "done" }
              });
              break;
            case 't_sys_seal':
              this.$router.push({name:'sealApproval',query: {id:item.data.id,taskId:item.id, auditbatchNo: item.auditbatchNo, type:"done"}})
              break;
            case 't_sys_asset':
              this.$router.push({name:'assetApproval',query: {id:item.data.id,taskId:item.id, auditbatchNo: item.auditbatchNo, type:"done"}})
              break;
            case 't_sys_contraction':
              this.$router.push({name:'contractionApproval',query: {id:item.data.id,taskId:item.id, auditbatchNo: item.auditbatchNo, type:"done"}})
              break;
            case 't_cashier_funds':
              this.$router.push({name:'approvalApprovalFuns',query: {id:item.data.id, taskId:item.id, type:"done"}})
              break;
          }
        }
      },
    }
</script>

<style scoped>
  >>>.my-swipe .van-swipe-item {
    color: #fff;
    font-size: 20px;
    line-height: 144px;
    text-align: center;
  }
</style>
