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

    <div class="header_main">

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

      <div class="header_btn1" @click="auditAll">
        <p>全部审核</p>
      </div>

      <div class="header_btn2" @click="audit">
        <p>确定提交</p>
      </div>

      <p class="header_tt">
        <i class="el-icon-warning"></i>已选中：{{selectedBooks}}
      </p>

      <p class="todo_num">待审核村庄：<span>{{summary.numVillage}}</span>个</p>
      <p class="todo_num2">待审核合作社：<span>{{summary.numBook}}</span>个</p>

    </div>

    <div class="main">

      <div class="left_main">
        <el-table :data="list" style="width: 100%;" v-if="list.length > 0">

          <el-table-column type="expand">
            <template slot-scope="props">
              <div class="openTable">
                <div class="openTable_block">
                  <el-button type="primary" size="mini" @click="auditVillage(props.row)">审核</el-button>
                  <p>已选中：百事合作社</p>
                </div>
                <el-table :data="props.row.taskList" style="width: 100%;background-color: transparent;">
                  <el-table-column prop="value9" label="操作">
                    <template slot-scope="scope">
                      <template v-if="!scope.row.audit">
                        <el-button type="primary" size="mini" @click="auditBook(scope.row)">审核</el-button>
                        <el-button type="primary" size="mini" plain>查看</el-button>
                      </template>
                      <template v-else>
                        <img src="../../assets/images/toBeAllocated_icon_delete.png" alt="" @click="cancelAuditBook(scope.row)">
                        <span class="name">已审核</span>
                      </template>
                    </template>
                  </el-table-column>
                  <el-table-column prop="bookName" label="组织名称" show-overflow-tooltip />
                  <el-table-column prop="voucherCount" label="记账笔数" show-overflow-tooltip >
                    <template slot-scope="scope">
                      {{scope.row.voucherCount}} <span class="num">7</span>
                    </template>
                  </el-table-column>
                  <el-table-column prop="contracCount" label="合同数量" show-overflow-tooltip />
                  <el-table-column prop="otherCount" label="其他" show-overflow-tooltip />
                  <el-table-column prop="allCount" label="任务总数" show-overflow-tooltip />
                </el-table>
              </div>
            </template>
          </el-table-column>

          <el-table-column prop="value1" label="操作" show-overflow-tooltip >
            <template slot-scope="scope">
              <el-button type="primary" size="mini" @click="auditVillage(scope.row)">审核</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="orgName" label="村" show-overflow-tooltip />
          <el-table-column prop="numBook" label="合作社数量" show-overflow-tooltip />
          <el-table-column prop="voucherCount" label="记账笔数" show-overflow-tooltip />
          <el-table-column prop="contracCount" label="合同数量" show-overflow-tooltip />
          <el-table-column prop="otherCount" 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="handleNick" label="负责人" show-overflow-tooltip />

        </el-table>

        <img src="../../assets/images/audit_icon_none.png" alt="" class="table_none" v-else>

      </div>

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

    </div>


  </div>
</template>

<script>
import {date_format} from "@/utils/date";
import TopDeptChooser from "@/components/framework/TopDeptChooser.vue";
import {ENV} from "@/utils/env";
import RightYearMonthSelector from "@/components/framework/RightYearMonthSelector.vue";
import {auditAllTask, auditTask, managerAuditingTaskList, managerAuditTaskSummary} from "@/api/agentcenter/task";

export default {
  name: "processed",
  components: {RightYearMonthSelector, TopDeptChooser},
  data() {
    return {
      list: [],
      total: 0,
      parms: {
        countyCode: null,
        townCode: null,
        orderYear: date_format('%Y'),
        orderMonth: date_format('%m'),
      },
      rootId: ENV.UserDeptId(),
      summary: {
        numVillage: 0,
        numBook: 0,
      },

    }
  },
  created() {

  },
  methods:{
    getTaskList() {
      if(!this.parms.countyCode || !this.parms.orderYear || !this.parms.orderMonth)
        return;
      managerAuditingTaskList(this.parms).then((resp) => {
        this.list = resp.rows;
        this.total = resp.total;
      })
    },
    getSummary() {
      if(!this.parms.countyCode || !this.parms.orderYear || !this.parms.orderMonth)
        return;
      managerAuditTaskSummary(this.parms).then((resp) => {
        this.summary = resp.data;
      })
    },
    chooseTown(cmd) {
      this.getTaskList();
      this.getSummary();
    },
    chooseMonth(year, month) {
      this.getTaskList();
      this.getSummary();
    },
    auditBook(row) {
      this.$set(row, 'audit', true);
    },
    cancelAuditBook(row) {
      this.$set(row, 'audit', false);
    },
    auditVillage(row) {
      for(let sv of row.taskList)
      {
        this.auditBook(sv);
      }
    },
    cancelAuditVillage(row) {
      for(let sv of row.taskList)
      {
        this.cancelAuditBook(sv);
      }
    },
    audit() {
      let arr = [];
      for(let v of this.list)
      {
        for(let sv of v.taskList)
        {
          if(sv.audit)
          {
            arr.push(sv.id);
          }
        }
      }
      if(!arr.length)
      {
        this.$message.error('请选择任务');
        return;
      }
      let data = {
        taskIds: arr,
      };
      auditTask(data).then((resp) => {
        this.$message.success('审核成功');
        this.getTaskList();
        this.getSummary();
      });
    },
    auditAll() {
      if(!this.parms.countyCode || !this.parms.orderYear || !this.parms.orderMonth)
        return;
      auditAllTask(this.parms).then((resp) => {
        this.$message.success('全部审核成功');
        this.getTaskList();
        this.getSummary();
      });
    },
  },
  mounted(){

  },
  computed: {
    selectedBooks() {
      let arr = [];
      for(let v of this.list)
      {
        let books = [];
        for(let sv of v.taskList)
        {
          if(sv.audit)
          {
            books.push(sv.bookName);
          }
        }
        if(books.length)
        {
          arr.push(`${v.orgName}（${books.join('、')}）`);
        }
      }
      return arr.join('、');
    },
  },
}
</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;
  }

  .header_tt{
    font-size: 14px;
    color: #7e7e7e;
  }
  .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;
    }
  }
  .table_none{
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
  }
  ::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{
    display: flex;
    align-items: center;
    background-color: #eef3fd;
    padding: 0 2.5vw 2vh;
    .openTable_block{
      width: 10%;
      display: flex;
      flex-direction: column;
      align-items: center;
      p{
        margin-top: 5px;
      }
    }
    ::v-deep .el-table__body{
      background-color: #ffffff;
      border-radius: 15px;
      overflow: hidden;
    }
    .num{
      color: #3976ff;
      display: inline-block;
      background-color: #e2ebff;
      width: 1.8vw;
      border-radius: 5px;
      margin-left: 5px;
    }
  }

  .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;
        }
      }
    }
    .header_btn1{
      display: flex;
      align-items: center;
      justify-content: center;
      margin-right: 2vw;
      background-color: #3976ff;
      padding: 0px 0px;
      border-radius: 8px;
      box-shadow: 0 0 10px #dedfe1;
      width: 8vw;
      height: 4vh;
      overflow: hidden;
      color: #ffffff;
      cursor: pointer;
    }
    .header_btn2{
      display: flex;
      align-items: center;
      justify-content: center;
      margin-right: 2vw;
      background-color: #209955;
      padding: 0px 0px;
      border-radius: 8px;
      box-shadow: 0 0 10px #dedfe1;
      width: 8vw;
      height: 4vh;
      overflow: hidden;
      color: #ffffff;
      cursor: pointer;
    }
    .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(3){
        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_num2{
      margin-left: 2vw;
      span{
        font-size: 24px;
        color: #ef0027;
      }
    }
  }

  .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);
      position: relative;
    }

    .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>
