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

    <div class="header_main">

      <el-dropdown trigger="click" placement="bottom-start">
        <div class="select_address el-dropdown-link">
          <span class="sanjiao-right"></span>
          <p>{{cityName}}</p>
        </div>
        <el-dropdown-menu slot="dropdown" style="width: 8vw;text-align: center;">
          <el-dropdown-item v-for="(item,index) in deptOptions" :command="item.orgCode">
            <div class="selected" @click="chooseCity(item.orgCode)">
              <p>{{item.deptName}}</p>
            </div>
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>

      <el-dropdown trigger="click" placement="bottom-start">
        <div class="select_address el-dropdown-link">
          <span class="sanjiao-right"></span>
          <p>{{townName}}</p>
        </div>
        <el-dropdown-menu slot="dropdown" style="width: 8vw;text-align: center;">
          <el-dropdown-item v-for="(item,index) in townList" :command="item.orgCode">
            <div class="selected" @click="chooseTown(item.orgCode)">
              <p>{{item.deptName}}</p>
            </div>
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>

      <p class="todo_num">镇处理进度：<span>15/50</span></p>
      <p class="todo_num3">镇审核进度：<span>5/50</span></p>
      <p class="todo_num1">合作社处理进度：<span>25/70</span></p>
      <p class="todo_num3">合作社审核进度：<span>10/70</span></p>
      <p class="todo_num2">任务异常数：<span>1</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%;" :default-sort = "{prop: 'date', order: 'descending'}">

              <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.isAudit">未审核</span>
                          <span v-if="task.agentStatus !== '1'" class="tab_green">已处理</span><span class="tab_green" v-if="task.isAudit">已审核</span>
                          <span class="tab_red">异常:1</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.allCount - task.voucherCount - task.contracCount}}</el-col>
                      <el-col :span="9" style="text-align: right"><el-button type="primary" size="mini">进入账套</el-button></el-col>
                    </el-row>
                  </div>
                </template>
              </el-table-column>

              <el-table-column prop="orgName" label="村" show-overflow-tooltip />
              <el-table-column prop="" 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 prop="value8" label="是否审批完成" show-overflow-tooltip >
                <template slot-scope="scope">
                  <p class="backButton">未完成</p>
                  <p class="backButton2">已完成</p>
                </template>
              </el-table-column>

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

      </div>

      <div class="right_main">
        <div class="title">
          <i></i>
          <p>任务日期</p>
        </div>

        <div class="time_main">
          <span class="sanjiao-top" @click="addDate"></span>
          <p @click = "selectionRange">{{year}}</p>
          <el-date-picker
            v-model="year"
            type="year"
            class="pickerTime"
            ref = "datePicker"
            value-format="yyyy"
            placeholder="选择年"
            @change="chooseMonth(1)"
          >
          </el-date-picker>
          <span class="sanjiao-bottom" @click="reduceDate"></span>
        </div>

        <div class="month_main">
          <p v-for="(item,index) in 12" @click="chooseMonth(index + 1)" :class="{'active': isCurrentMonth(index + 1)}">{{index+1}}月<i v-if="isCurrentMonth(index + 1)"></i></p>
        </div>

      </div>

    </div>


  </div>
</template>

<script>
import {cityTree, deptTree} from "@/api/misc/misc_dept";
import {ENV} from "@/utils/env";
import {date_format} from "@/utils/date";
import {taskList} from "@/api/agentcenter/task";

export default {
  name: "processing",
  data() {
    return {
      year: date_format('%Y'),
      cityCode: null,
      townCode: null,
      deptOptions: [],
      month: date_format('%m'),
      list: [],
      total: 0,
    }
  },
  created() {
    this.getDeptTree();
  },
  methods:{
    addDate(){
      this.year = Number(this.year) + 1 ;
      this.chooseMonth(1);
    },
    reduceDate(){
      this.year = Number(this.year) - 1 ;
      this.chooseMonth(1);
    },
    selectionRange(){
      this.$refs.datePicker.focus();
    },
    getDeptTree() {
      cityTree({rootId: ENV.UserDeptId()}).then((resp) => {
        this.deptOptions = resp.data;
        if(this.deptOptions.length)
          this.cityCode = this.deptOptions[0].orgCode;
      });
    },
    getTaskList() {
      if(!this.townCode || !this.year || !this.month)
        return;
      taskList({
        townCode: this.townCode,
        orderYear: this.year,
        orderMonth: this.month,
      }).then((resp) => {
        this.list = resp.rows;
        this.total = resp.total;
      })
    },
    chooseCity(cmd) {
      this.cityCode = cmd;
      this.townCode = null;
    },
    chooseTown(cmd) {
      this.townCode = cmd;
      this.getTaskList();
    },
    isCurrentMonth(m) {
      return parseInt(this.month) === m;
    },
    chooseMonth(month) {
      this.month = month >= 10 ? '' + month : ('0' + month);
      this.getTaskList();
    },
  },
  mounted(){

  },
  computed: {
    cityName() {
      if(!this.deptOptions.length)
        return '';
      let dept = this.deptOptions.find((x) => x.orgCode === this.cityCode);
      return dept ? dept.deptName : '';
    },
    townList() {
      if(!this.deptOptions.length)
        return [];
      let dept = this.deptOptions.find((x) => x.orgCode === this.cityCode);
      return dept ? dept.children || [] : [];
    },
    townName() {
      if(!this.townList.length)
        return '';
      let dept = this.townList.find((x) => x.orgCode === this.townCode);
      return dept ? dept.deptName : '';
    },
  },
}
</script>

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

  .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: 18px;
    }
  }

  ::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(100vh - 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(100vh - 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>
