<template>
  <div class="app-container">

    <div class="header_main">

      <TopDeptChooser :county-code.sync="parms.countyCode" :town-code.sync="parms.townCode" :root-id="rootId" @countyChanged="chooseCity" @dataChanged="chooseDept"/>

      <p class="todo_num">镇处理进度：<span>{{ countySummary.numTownProcessedTask }}/{{ countySummary.numTown }}</span></p>
      <p class="todo_num3">镇审核进度：<span>{{ countySummary.numTownApprovalTask }}/{{ countySummary.numTown }}</span></p>
      <p class="todo_num1">合作社处理进度：<span>{{ countySummary.numBookProcessedTask }}/{{ countySummary.numBook }}</span></p>
      <p class="todo_num3">合作社审核进度：<span>{{ countySummary.numBookApprovalTask }}/{{ countySummary.numBook }}</span></p>
      <p class="todo_num2">任务异常数：<span>{{countySummary.abnormalCount}}</span>个</p>

    </div>

    <div class="main">

      <div class="left_main">
        <el-collapse accordion>
          <el-collapse-item v-for="(item,index) in list" :key="index">
            <template slot="title">
              <div class="left_main_tt">
                <p>{{item.townName}}</p>
                <div class="tt_label">
                  <p>异常：{{item.numExcept}}</p>
                  <p>村庄处理进度：{{item.numProcessFinish}}/{{item.num}}</p>
                  <p>村庄审核进度：{{item.numApprovalFinish}}/{{item.num}}</p>
                </div>
              </div>
            </template>
            <el-table :data="item.villageList" style="width: 100%;">

              <el-table-column type="expand">
                <template slot-scope="props">
                  <div class="openTable">
                    <el-row v-for="(task,index) in props.row.taskList" :key="index">
                      <el-col :span="9">
                        <div class="tab_main">
                          <span v-if="task.agentStatus === '1'">未处理</span><span v-if="task.agentStatus === '3'">未审核</span>
                          <span v-if="task.agentStatus !== '1'" class="tab_green">已处理</span><span class="tab_green" v-if="task.agentStatus === '4'">已审核</span>
                          <span class="tab_red" v-if="task.abnormalCount > 0">异常:{{task.abnormalCount}}</span>
                          {{task.bookName}}
                        </div>
                      </el-col>
                      <el-col :span="2">记账：{{task.voucherCount}}</el-col>
                      <el-col :span="2">合同：{{task.contracCount}}</el-col>
                      <el-col :span="2">其他：{{task.otherCount}}</el-col>
                      <el-col :span="9" style="text-align: right"><el-button type="primary" size="mini" @click="gotoRemoteSite(task)">进入账套</el-button></el-col>
                    </el-row>
                  </div>
                </template>
              </el-table-column>

              <el-table-column prop="orgName" label="村" show-overflow-tooltip />
              <el-table-column prop="num" label="合作社" show-overflow-tooltip />
              <el-table-column label="处理进度" show-overflow-tooltip >
                <template slot-scope="scope">
                  {{scope.row.numProcessFinish}}/{{scope.row.num}}
                </template>
              </el-table-column>
              <el-table-column prop="numExcept" label="异常任务" show-overflow-tooltip >
                <template slot-scope="scope">
                  {{scope.row.numExcept || '无'}}
                </template>
              </el-table-column>
              <el-table-column label="审核进度" show-overflow-tooltip >
                <template slot-scope="scope">
                  {{scope.row.numApprovalFinish}}/{{scope.row.num}}
                </template>
              </el-table-column>
              <el-table-column prop="handleNick" label="会计" show-overflow-tooltip />
              <el-table-column prop="distriDate" label="下发日期" show-overflow-tooltip />
              <el-table-column prop="endAt" label="截止日期" show-overflow-tooltip />
              <el-table-column prop="handleDate" label="记账完成日期" show-overflow-tooltip />
              <el-table-column label="是否审批完成" show-overflow-tooltip >
                <template slot-scope="scope">
                  <p class="backButton" v-if="!scope.row.approvalFinish">未完成</p>
                  <p class="backButton2" v-if="scope.row.approvalFinish">已完成</p>
                </template>
              </el-table-column>

            </el-table>
          </el-collapse-item>
        </el-collapse>

      </div>

      <RightYearMonthSelector class="right_main" :year.sync="parms.orderYear" :month.sync="parms.orderMonth" @dateChanged="chooseMonth"/>

    </div>


  </div>
</template>

<script>
import {cityTree, deptTree} from "@/api/misc/misc_dept";
import {ENV} from "@/utils/env";
import {date_format} from "@/utils/date";
import {managerAllTaskList, managerCountyTaskSummary,} from "@/api/agentcenter/task";
import RightYearMonthSelector from "@/components/framework/RightYearMonthSelector.vue";
import TopDeptChooser from "@/components/framework/TopDeptChooser.vue";

export default {
  name: "processing",
  components: {TopDeptChooser, RightYearMonthSelector},
  data() {
    return {
      list: [],
      total: 0,
      parms: {
        countyCode: null,
        townCode: null,
        orderYear: date_format('%Y'),
        orderMonth: date_format('%m'),
      },
      countySummary: {
        numTown: 0,
        numBook: 0,
        abnormalCount: 0,
        numTownProcessedTask: 0,
        numTownApprovalTask: 0,
        numBookProcessedTask: 0,
        numBookApprovalTask: 0,
      },
      rootId: ENV.UserDeptId(),
    }
  },
  created() {
  },
  methods:{
    getTaskList() {
      if(!this.parms.countyCode || !this.parms.orderYear || !this.parms.orderMonth)
        return;
      managerAllTaskList(this.parms).then((resp) => {
        this.list = resp.rows;
        this.total = resp.total;
      })
    },
    chooseDept(countyCode, townCode, what) {
      this.getTaskList();
    },
    chooseCity(countyCode, townCode) {
      this.getSummary();
    },
    chooseMonth(year, month) {
      this.getSummary();
      this.getTaskList();
    },
    gotoRemoteSite(task) {
      window.open(`/api/open/book/${task.orgCode}/${task.bookId}`, '_blank');
    },
    getSummary() {
      if(!this.parms.countyCode || !this.parms.orderYear || !this.parms.orderMonth)
        return;
      managerCountyTaskSummary(this.parms).then((resp) => {
        this.countySummary = resp.data;
      })
    }
  },
  mounted(){

  },
  computed: {
  },
}
</script>

<style lang="scss" scoped>
  p{margin: 0;line-height: 1;}
  .app-container{
    background-color: #f5f6f8;
    width: 100%;
    height: 91vh;
  }

  .selected{
    display: flex;
    height: 4vh;
    p{
      width: 8vw;
      line-height: 4vh;
      text-align: center;
    }
  }
  .pickerTime{
    opacity: 0;
    position: absolute;
    left: 0px;
    top: 30px;
    width: 5px;
    height: 5px;
    z-index: -1;
  }
  .el-dropdown-link {
    cursor: pointer;
  }

  .title{
    display: flex;
    align-items: center;
    i{
      display: inline-block;
      width: 5px;
      height: 20px;
      background: #4d7cfe;
      border-radius: 5px;
      margin-right: 10px;
    }
    p{
      font-size: 16px;
    }
  }

  ::v-deep .el-collapse {
    border: none;
  }

  ::v-deep .el-collapse-item__header {
    border: none;
  }

  ::v-deep .el-collapse-item__content {
    background-color: #e2ebff;
  }

  ::v-deep .el-table__expanded-cell {
    background-color: #e2ebff;
  }

  ::v-deep .el-table {
    background-color: transparent;
  }

  ::v-deep .el-table .cell{
    text-align: center;
  }

  ::v-deep .el-table .el-table__cell{
    border: none!important;
  }
  ::v-deep .el-table::before{
    display: none;
  }
  ::v-deep .el-table .el-table__header-wrapper th{
    background-color: transparent;
  }
  ::v-deep .el-table tr{
    background-color: transparent;
  }

  .openTable{
    padding: 1vh 2vw;
    background-color: #ffffff;
    border-radius: 15px;
    overflow: hidden;
    width: calc(100% - 40px);
    margin: 0 auto;
    .tab_main{
      display: flex;
      span{
        color: #ffffff;
        background-color: #acabab;
        padding: 2px 0px;
        width: 4vw;
        display: inline-block;
        border-radius: 7px;
        margin-right: 1vw;
        text-align: center;
      }
      .tab_green{
        background-color: #209955;
      }
      .tab_red{
        background-color: #ef0027;
      }
    }

    .num{
      color: #3976ff;
      display: inline-block;
      background-color: #e2ebff;
      width: 1.8vw;
      border-radius: 5px;
      margin-left: 5px;
    }
    .el-col{
      padding: 10px 0;
    }
  }

  .header_main{
    display: flex;
    align-items: center;
    position: relative;
    .selected{
      width: 16vw;
      background-color: #ffffff;
      position: absolute;
      top: 4vh;
      left: 10vw;
      z-index: 9;
      border-radius: 8px;
      box-shadow: 0 10px 10px #dedfe1;
      padding: 1vh 0;
      div{
        display: flex;
        height: 4vh;
        p{
          width: 8vw;
          line-height: 4vh;
          text-align: center;
        }
      }
    }
    .select_address{
      display: flex;
      align-items: center;
      justify-content: center;
      margin-right: 2vw;
      background-color: #ffffff;
      padding: 0px 0px;
      border-radius: 8px;
      box-shadow: 0 0 10px #dedfe1;
      width: 8vw;
      height: 4vh;
      overflow: hidden;
      &:nth-child(2){
        margin-right: 0vw;
      }
      &:nth-child(3){
        margin-right: 0vw;
        border-top-left-radius: initial;
        border-bottom-left-radius: initial;
      }
      .sanjiao-right {
        display: inline-block;
        border-left: 8px solid #000;
        border-left-color: initial;
        border-top: 5px solid transparent;
        border-bottom: 5px solid transparent;
        margin-right: 5px;
      }
      .select_time{
        text-align: center;
        width: 100%;
        height: 4vh;
        line-height: 4vh;
        background-color: #3976ff;
        color: #ffffff;
      }
    }
    .todo_num{
      margin-left: auto;
      span{
        font-size: 24px;
        color: #3976ff;
      }
    }
    .todo_num1{
      margin-left: 2vw;
      span{
        font-size: 24px;
        color: #3976ff;
      }
    }
    .todo_num2{
      margin-left: 2vw;
      span{
        font-size: 24px;
        color: #ef0027;
      }
    }
    .todo_num3{
      margin-left: 2vw;
      span{
        font-size: 24px;
        color: #209955;
      }
    }
  }

  .main{
    display: flex;
    .left_main{
      width: 92%;
      margin-right: 0.57%;
      margin-top: 15px;
      border-radius: 8px;
      box-shadow: 4px 0px 10px rgba(0, 0, 0, 0.13);
      background: #fff;
      padding: 15px 20px;
      height: calc(91vh - 91px);
      .backButton{
        color: #3976ff;
        display: inline-block;
      }
      .backButton2{
        color: #209955;
        display: inline-block;
      }
      .left_main_tt{
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: space-between;
        .tt_label{
          display: flex;
          align-items: center;
          p{
            margin-right: 2vw;
            &:nth-child(1){
              color: #ef0027;
            }
          }
        }
      }
    }

    .right_main{
      width: 7.43%;
      margin-top: 15px;
      border-radius: 8px;
      box-shadow: 4px 0px 10px rgba(0, 0, 0, 0.13);
      background: #fff;
      padding: 15px 20px;
      height: calc(91vh - 91px);
    }

  }

  .sanjiao-top {
    display: inline-block;
    border-bottom: 8px solid #414141;
    border-bottom-color: initial;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
  }

  .sanjiao-bottom {
    display: inline-block;
    border-top: 8px solid #414141;
    border-top-color: initial;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
  }

  .time_main{
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: #f5f6f8;
    color: #414141;
    width: 75%;
    margin: 0 auto;
    margin-top: 15px;
    padding: 15px 0;
    border-radius: 8px;
    position: relative;
    cursor: pointer;
    p{
      margin: 10px 0;
    }
  }

  .month_main{
    display: flex;
    flex-direction: column;
    align-items: center;
    color: #414141;
    p{
      margin-top: 3vh;
      position: relative;
      &.active{
        color: #3976ff;
      }
      &:hover{
        color: #3976ff;
        cursor: pointer;
      }
      i{
        display: block;
        width: 5px;
        height: 5px;
        background-color: #fc5659;
        position: absolute;
        top: -5px;
        right: -5px;
        border-radius: 100%;
      }
    }

  }

</style>
