<template>
  <el-dialog
    title="审核"
    :visible.sync="dataObj.detailDialog"
    width="800px"
    :close-on-click-modal="false"
    @close="closedialog"
  >
    <div class="content-box"  v-if="dataObj.auth">
      <div v-if="firstshow" class="content">
        <!-- 监测表审核 -->
        <el-descriptions class="margin-top" v-if="dataObj.key == 'monitor'" :column="1" :size="size" border>
          <el-descriptions-item v-for="(item,index) in dataObj.param" :key="index">
            <template slot="label">{{item.name}}</template>
            <div class="rejectresolve">
              <div class="oper" v-if="dataObj.auth.indexOf((index+1)+'') !== -1">
                <el-button v-if="dataObj.param[index].status == 1" type="danger" @click="rejecttownpop(index)" disabled ref="reject">驳回</el-button>
                <el-button v-else type="danger" @click="rejecttownpop(index)" ref="reject">驳回</el-button>
                <el-button v-if="dataObj.param[index].status == 1" type="primary" @click="qupass(index)" disabled ref="agree">已通过</el-button>
                <el-button v-else type="primary" @click="qupass(index)" ref="agree">通过</el-button>
              </div>
              <div class="oper" style="color:red;cursor:pointer;" v-if="dataObj.auth.indexOf((index+1)+'') == -1">
                <el-tag type="danger">无权限</el-tag>
              </div>
            </div>
          </el-descriptions-item>
        </el-descriptions>
        <el-descriptions class="margin-top" style="margin-top:20px;" :column="1" :size="size" border>
          <el-descriptions-item v-if="dataObj.key !== 'monitor'">
            <template slot="label">
              镇(街道)审核意见
            </template>
            <div>
              <div class="centerbtn" v-if="dataObj.paramInfo[0].status == 1">
                <el-button type="primary" disabled>已通过</el-button>
              </div>
              <div class="centerbtn" v-if="dataObj.auth.indexOf('9') !== -1 && dataObj.paramInfo[0].status !== 1">
                <el-button type="danger" @click="rejectpop(1)" :disabled = 'disabled' :style="display">驳回</el-button>
                <el-button type="primary" @click="passFn(1)" :disabled = 'disable'>{{agree1}}</el-button>
              </div>
              <div class="centerbtn" v-if="dataObj.auth.indexOf('9') == -1">
                <el-tag type="danger" style="margin-left:10px;">无权限</el-tag>
              </div>
            </div>
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              区供销总社意见
            </template>
            <div v-if="dataObj.key !== 'monitor'">
              <div class="centerbtn" v-if="dataObj.auth.indexOf('10') !== -1">
                <el-button type="danger" @click="rejectpop(2)">驳回</el-button>
                <el-button type="primary" @click="passFn(2)">通过</el-button>
              </div>
              <div class="centerbtn" v-if="dataObj.auth.indexOf('10') == -1">
                <el-tag type="danger" style="margin-left:10px;">无权限</el-tag>
              </div>
            </div>
            <div v-if="dataObj.key == 'monitor'">
              <div class="centerbtn" v-if="dataObj.auth.indexOf('10') !== -1">
                <el-button type="danger" @click="rejectpop(3)">驳回</el-button>
                <el-button type="primary" @click="passFn(3)">通过</el-button>
              </div>
              <div class="centerbtn" v-if="dataObj.auth.indexOf('10') == -1">
                <el-tag type="danger" style="margin-left:10px;">无权限</el-tag>
              </div>
            </div>
          </el-descriptions-item>
        </el-descriptions>
        <div class="last">
            <el-button @click="nextstepFn">返回</el-button>
        </div>
      </div>
    </div>
    <el-form v-if="rejectshow" :model="rejectData" :rules="rules" ref="ruleForm" label-width="100px" class="rejectcontainer">
        <div class="cause">驳回原因</div>
        <el-input type="textarea" v-model="rejectData.rejecttitle" :rows="5"></el-input>
        <el-form-item class="btn">
          <el-button @click="cancelFn">取消</el-button>
          <el-button type="primary" @click="rejectFn">确认</el-button>
        </el-form-item>
    </el-form>
    <el-form v-if="rejecttownshow" :model="rejectData" :rules="rules" ref="ruleForm" label-width="100px" class="rejectcontainer">
        <div class="cause">驳回原因</div>
        <el-input type="textarea" v-model="rejectData.townrejecttitle" :rows="5"></el-input>
        <el-form-item class="btn">
          <el-button @click="cancelFn">取消</el-button>
          <el-button type="primary" @click="qureject">确认</el-button>
        </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
// 申报表，监测表审核
import { 
  // 申请表审核
  putApply,
  // 监测表审核
  putCheck,
  } from "../../../apis/modules/coopapproval.js";
export default {
  props: ["dataObj"],
  data() {
    return {
      // 镇审核的禁用
      disable:false,
      disabled:false,
      display:{display:"block"},
      agree1:'通过',
      // 镇通过
      flag: false,
      size:'',
      // 表单数据显示
      rejectData: {
          rejecttitle: '',
          townrejecttitle: ''
      },
      // 弹框显示
      rejectshow: false,
      rejecttownshow: false,
      // 第一次显示
      firstshow: true,
      // 第三次显示
      threeshow: false,
      rules: {
          rejecttitle: [
            { required: true, message: '请填写驳回内容', trigger: 'blur' }
          ]
      },
      applyfiles:[
          '1.专业合作社主要情况说明','2.专业合作社营业执照复印件','3.专业合作社章程','4.成员名册及出资表',
          '5.成员账户','6.上年度资产负债表、盈余及盈余分配表、成员权益变动表','7.产品和基地认证证书复印件','8.注册商标证书复印件或授权使用合同复印件','9.农产品生产记录和农业投入使用记录'],
      monitorfiles:[
        '1.自查总结','2.上年度资产负债表和收益分配表','3.新获得各种认证、奖励证书复印件','4.台作社相关信息变更材料'
      ]
      };
  },
  // 监控恢复已通过->通过
  watch:{
    'dataObj.detailDialog':function(v) {
        if (v == true) {
          setTimeout(()=>{
            for(let i=0;i<8;i++){
              if (this.dataObj.param[i].status != 1) {
                this.$refs.reject[i].$el.style.display = "block"
                this.$refs.agree[i].$el.innerText = "通过"
              }else{
                this.$refs.reject[i].$el.style.display = "none"
                this.$refs.agree[i].$el.innerText = "已通过"
              }
            }
          },0)
          this.agree1 = "通过"
          this.disabled = false
          this.disable = false
          this.display.display = "block"
          this.flag = false
        }
    }
  },
  methods:{
      // 申报表下载
      fileapplydownload(sort){
        let _this = this
        this.dataObj.fileParam.forEach((item,index) => {
          if (item.sort == (sort+1)) {
            _this.downLoad(item.fileUrl,item.fileName);
          }
        });
        this.$refs.text[sort].innerText = '已下载'
      },
      downLoad(content, fileName) {
        var aEle = document.createElement("a"); // 创建a标签
        aEle.download = fileName; // 设置下载文件的文件名
        aEle.href = content; // content为后台返回的下载地址
        aEle.click(); // 设置点击事件
      },
      // 监测表下载
      filemonitordownload(sort){
        let _this = this
        this.dataObj.fileParam.forEach((item,index) => {
          if (item.sort == (sort+1)) {
            _this.downLoad(item.fileUrl,item.fileName);
          }
        });
        this.$refs.textcheck[sort].innerText = '已下载'
      },
      //弹出层 
      // 总社
      rejectpop(rejectnum){
        this.rejectnum = rejectnum
        this.rejectshow = true
      },
      // 区审核
      rejecttownpop(rejecttownnum){
        this.rejectData.townrejecttitle=''
        this.rejecttownnum = rejecttownnum
        this.rejecttownshow = true
      },
      //8个区驳回审核 
      qureject(){
        let num = this.rejecttownnum
        let reviewId = this.dataObj.auth
        let data = {
          desc:'描述',
          formId: this.dataObj.formParam.formId,
          operate:this.dataObj.param[num].key,
          rejectInfo:this.rejectData.townrejecttitle,
          reviewId,
          status:'reject'
        }
        putCheck(data).then((res)=>{
          if (res.status == 0) {
            this.$message({
              message: '驳回成功',
              type: 'success'
            });
            this.rejecttownshow = false
            this.dataObj.detailDialog = false
            this.dataObj.fn()
            this.dataObj.totalfn()
          }
        })
      },
      //8个区通过审核
      qupass(num){
        let reviewId = this.dataObj.auth
        let data = {
          desc:'描述',
          formId: this.dataObj.formParam.formId,
          operate:this.dataObj.param[num].key,
          reviewId,
          status:'agree'
        }
        // let data = {}
        putCheck(data).then((res)=>{
          if (res.status == 0) {
            this.$message({
              message: '已通过',
              type: 'success'
            });
          }
          // 处理驳回、通过按钮的变化
          this.$refs.agree[num].$el.innerText = '已通过'
          this.$refs.reject[num].$el.style.display = "none"
          this.$refs.agree[num].disabled = true
          this.$refs.reject[num].disabled = true
          this.dataObj.totalfn()
        })
      },      
      // 取消按钮
      closeFn(){
        this.dataObj.detailDialog=false
        this.threeshow = false
        this.firstshow = true
        this.dataObj.fn()
      },
      // 关闭弹框
      closedialog(){
        this.dataObj.fn()
      },
      // //////////第一次
      // 第一次下一步按钮
      nextstepFn(){
        this.dataObj.detailDialog=false
        this.threeshow = false
        this.firstshow = true
        this.dataObj.fn()
      },
      // //////////第三次
      beforethreestepFn(){
        this.threeshow = false
        this.firstshow = true
      },
      // 申报表、监测表通过
      passFn(num){
        if (num == 1) {
          let reviewId = this.dataObj.auth
          let data = {
            desc:'描述',
            formId: this.dataObj.formParam.formId,
            operate:this.dataObj.paramInfo[0].key,
            reviewId,
            status:'agree'
          }
          putApply(data).then((res)=>{
            if (res.status == 0) {
              this.$message({
                message: '已通过',
                type: 'success'
              });
              this.disabled = true
              this.disable = true
              this.display.display = "none"
              this.agree1 = "已通过"
              this.dataObj.fn()
              this.dataObj.totalfn()
            }
            this.flag = true
          })
        }else if (num == 2){
          if (this.flag == false && this.dataObj.paramInfo[0].status !== 1) {
            this.$message({
              message: '请先进行镇审核',
              type: 'error'
            });
            return
          }
          let reviewId = this.dataObj.auth
          let data = {
            desc:'描述',
            formId: this.dataObj.formParam.formId,
            operate:this.dataObj.paramInfo[1].key,
            reviewId,
            status:'agree'
          }
          putApply(data).then((res)=>{
            if (res.status == 0) {
              this.$message({
                message: '已通过',
                type: 'success'
              });
              this.dataObj.fn()
              this.dataObj.totalfn()
            }
            this.dataObj.detailDialog = false
            this.flag = false
          })
        }else{
          let reviewId = this.dataObj.auth
          let data = {
            desc:'描述',
            formId: this.dataObj.formParam.formId,
            operate:this.dataObj.paramInfo[1].key,
            reviewId,
            status:'agree'
          }
          putCheck(data).then((res)=>{
            if (res.status == 0) {
              this.$message({
                message: '已通过',
                type: 'success'
              });
              this.dataObj.fn()
              this.dataObj.totalfn()
            }
          })
          this.dataObj.detailDialog = false
        }
      },
      // 申报表、监测表驳回
      rejectFn(){
        if (this.rejectnum == 1) {
          let reviewId = this.dataObj.auth
          let data = {
            desc:'描述',
            formId: this.dataObj.formParam.formId,
            operate:this.dataObj.paramInfo[0].key,
            rejectInfo:this.rejectData.rejecttitle,
            reviewId,
            status:'reject'
          }
          putApply(data).then((res)=>{
            if (res.status == 0) {
              this.$message({
                message: '驳回成功',
                type: 'success'
              });
              this.rejectData.rejecttitle = ''
              this.dataObj.fn()
              this.dataObj.totalfn()
            }
            this.flag = true
          })
        }else if (this.rejectnum == 2){
          let reviewId = this.dataObj.auth
          let data = {
            desc:'描述',
            formId: this.dataObj.formParam.formId,
            operate:this.dataObj.paramInfo[1].key,
            rejectInfo:this.rejectData.rejecttitle,
            reviewId,
            status:'reject'
          }
          if (this.flag == false && this.dataObj.paramInfo[1].status !== 2) {
            this.$message({
              message: '请先进行镇审核',
              type: 'error'
            });
            return
          }
          putApply(data).then((res)=>{
            if (res.status == 0) {
              this.$message({
                message: '驳回成功',
                type: 'success'
              });
              this.dataObj.fn()
              this.dataObj.totalfn()
              this.rejectData.rejecttitle = ''
              this.flag = false
            }
          })
        }else{
          let reviewId = this.dataObj.auth
          let data = {
            desc:'描述',
            formId: this.dataObj.formParam.formId,
            operate:this.dataObj.paramInfo[1].key,
            rejectInfo:this.rejectData.rejecttitle,
            reviewId,
            status:'reject'
          }
          putCheck(data).then((res)=>{
            if (res.status == 0) {
              this.$message({
                message: '驳回成功',
                type: 'success'
              });
              this.rejectData.rejecttitle = ''
              this.dataObj.fn()
              this.dataObj.totalfn()
              this.flag = false
            }
          })
        }
        this.dataObj.detailDialog = false
        this.rejectshow = false
      },
      // 驳回取消
      cancelFn(){
        this.rejectshow = false
        this.rejecttownshow = false
      }
  },
};
</script>

<style lang="scss" scoped>
/* 弹框滚动条 */
/deep/ .el-dialog__body {
  max-height: 62vh;
  overflow: auto;
}
.content-box {
  .content{
    height: 100%;
    display: flex;
    flex-direction: column;
  }
  .from{
    flex: 1;
  }
}
.rejectcontainer{
  background-color: #fff;
  .cause{
    width: 100%;
    font-size: 18px;
    text-align: center;
    line-height: 40px;
    background:#2ab999;
    color:#fff;
    margin-bottom: 20px;
  }
  .el-textarea{
    margin-left: 5%;
    width: 90%;
  }
  border: 1px solid #cccccc;
  position: absolute;
  width: 50%;
  height: 250px;
  left: 0;top: 0;bottom: 0;right: 0;margin: auto;
/deep/ .el-form-item__content{
    display: flex;
    justify-content: flex-end;
    padding: 20px;
  }
  .el-form-item{
    padding-top: 0;
  }
}
/deep/ .el-dialog__header {
  background: #2ab999;
  .el-dialog__title {
    color: white;
  }
}
/deep/ .el-icon-close:before {
  color: white;
}
/* 表项 */
.file{
  display: flex;
  justify-content: space-between;
  padding-top: 10px;
  span{
    line-height: 30px;
  }
  i{
    font-size:30px;
    color:#67C23A;
  }
}
.rejectresolve{
  display: flex;
  justify-content: space-around;
  .resolve{
    box-sizing: border-box;
    text-align: center;
    width: 50%;
    border-right: 1px solid #ebeef5;
  }
}
/* 描述样式 */
/deep/ .el-descriptions-item__label{
  width: 550px;
}
.resolve{
  width: 100px;
}
.oper{
  width: 100px;
  display: flex;
  justify-content: center;
  align-items: center;
  .op{
    cursor: pointer;
    color:#16a952;
    margin-right: 10px;
  }
}
/* 按钮右下角 */
.last{
  display: flex;
  justify-content: flex-end;
  margin-top: 20px;
}
.centerbtn{
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>
