<template>
  <div class="tv-container">
      
        <div class="container-box">
             <div>
                <div class="el-label"><i class="el-icon-collection-tag"></i>基本信息</div>
                <div class="el-line"></div>
                <baseTable v-if="woNo" :woNo="woNo" step="9"  @callBack="callBack"/>
                <div class="el-line"></div>
                <div class="el-label"><i class="el-icon-collection-tag"></i>室主任初审</div>
                <div class="el-line"></div>

                <div>
                  <el-row>
                    <el-col :span="6">&nbsp;</el-col>
                    <el-col :span="12">
                        <el-form ref="form" :model="form" label-width="80px">
                           <el-form-item label="审核结果">
                              <el-radio v-model="audit5" label="Y">通过</el-radio>
                              <el-radio v-model="audit5" label="N">未通过</el-radio>
                          </el-form-item>

                          <el-form-item label="备注信息">
                            <el-input type="textarea" v-model="form.note"></el-input>
                          </el-form-item>
                        </el-form>
                    </el-col>
                    <el-col :span="6">&nbsp;</el-col>
                  </el-row>

                </div>

                <div class="el-line"></div>
                <div class="el-label"></div>
                <div class="el-line"></div>
                <div style="text-align:right">
                  <el-button type="primary" @click="handleAudit">确定</el-button>
                </div>
             </div>
        </div>
        <!--<fullscreen :fullscreen.sync="fullscreen" class="container"></fullscreen>-->
              <el-dialog
                title="请选择"
                :visible.sync="userDlgVisual"
                width="30%"
                :modal-append-to-body="false"
                :close-on-click-modal="false"
                :before-close="handleClose">
              <div>
                  <el-radio  v-for="user in userList " v-model="assigneeNo" :key="user.loginNoStr" :label="user.loginNoStr">{{user.loginNameStr}}</el-radio>
              </div>
              <span slot="footer" class="dialog-footer">
                  <el-button @click="userDlgVisual = false">取 消</el-button>
                  <el-button type="primary" @click="checkSelectUser">确 定</el-button>
              </span>
            </el-dialog>
  </div>
</template>

<script>
import baseTable from "./basePeerReview"
export default {
  components:{ baseTable },
  data(){
    return{
      woNo:'',
      itemId:'',
      fullscreen:true,
      form:{note:""},
      audit5:"Y",
      assigneeNo:'',
      assigneeName:'',
      bpmInfo:{},
      userDlgVisual:false,
      userList:[]
    }
  },
  methods:{
    callBack(itemId){
      this.itemId = itemId
    },
    completeTask(){
        if(this.assigneeNo===""){
           this.$message({ showClose: true, message:"数据异常",type: 'error'});
          return 
        }
        //拼装参数
        let info={}
        info.params={
          "note":this.form.note,
          "itemId":this.itemId,
          "woNo":this.woNo, 
          "assigneeNo":this.assigneeNo,
          "assigneeName":this.assigneeName,
          "audit5":this.audit5
        },
        info.taskId = this.bpmInfo.taskId
        info.woNo = this.bpmInfo.woNo 
        info.stepId = this.bpmInfo.stepId
        info.procId = this.bpmInfo.procId
        info.procVersion = this.bpmInfo.procVersion
        //POST请求
        this.$http({
        url: "/bpm/api/submitTask",
        method: "post",
        headers: {"Content-Type": "application/json"},
        data:info
        }).then((res) => {
         if(res.data.result==0){
            this.$router.push({	path: '/tvIntroduction'});
         }else{
            this.$message({ showClose: true, message: res.data.desc,type: 'error'});
         }
        });
    },

    handleAudit(){
      //部门领导审批
      if(this.audit5==='Y'){
          let userInfo = window.sessionStorage.userInfo;
          if(null === userInfo){
                this.$message({ showClose: true, message: "数据异常",type: 'error'});
                return 
          }
          userInfo = JSON.parse(userInfo);
          let loginNoStr = userInfo.loginNoStr;
          this.$http({
            url: "/market/api/user/info/leader2",
            method: "post",
            headers: {"Content-Type": "application/json"},
            data:{"loginNoStr":loginNoStr,"level":"2","type":"1"}//部门领导复审
          }).then((res) => {
            if(res.data.result==0){
              let user = res.data.body
              if(null==user || user.length==0){
                  this.$message({ showClose: true, message: "数据异常",type: 'error'});
              }else{
                if(user.length==1){
                    this.assigneeNo = user[0].loginNoStr
                    this.assigneeName = user[0].loginNameStr
                    this.completeTask()
                }else{
                    this.userList = user;
                    this.userDlgVisual = true;
                }
              }
            }else{
              this.$message({ showClose: true, message: res.data.desc,type: 'error'});
            }
          });
      }else if(this.audit5==='N'){
      //发起人 会议结果录入
          this.$http({
              url: "/market/tvImport/basicInfo",
              method: "post",
              headers: {"Content-Type": "application/json"},
              data:{"itemId":this.itemId,"woNo":this.woNo}
            }).then((res) => {
              if(res.data.result==0){
                let user = res.data.body.imp
                if(null==user){
                    this.$message({ showClose: true, message: "数据异常",type: 'error'});
                }else{
                      this.assigneeNo = user.createLogin
                      this.assigneeName = user.createLoginName
                      this.completeTask()
                }
              }else{
                this.$message({ showClose: true, message: res.data.desc,type: 'error'});
              }
            });
      }else{
        this.$message({ showClose: true, message:'数据异常',type: 'error'});
      }
    },
    checkSelectUser(){
      if(this.assigneeNo===''){
          this.$message.error('请选择下一步处理人');
          return
      }
      //
      this.userList.forEach((e)=>{
          if(e.loginNoStr === this.assigneeNo){
              this.assigneeName = e.loginNameStr
          }
      });
      //
      this.userDlgVisual = false
      
      this.completeTask()
    },
    handleClose(){
      this.userDlgVisual = true
    },
  },
  mounted(){
    this.woNo = this.$route.query.woNo
    this.bpmInfo.taskId = this.$route.query.taskId
    this.bpmInfo.woNo = this.woNo
    this.bpmInfo.stepId = this.$route.query.stepId
    this.bpmInfo.procId = this.$route.query.procId
    this.bpmInfo.procVersion = this.$route.query.procVersion
  }
}
</script>
<style lang="scss" scoped>
.tv-container{
  background-color: white;
  margin:15px 15px 15px 15px;
  padding:20px ;

}
.el-label{
  /*border-left:5px solid #0b82ff;*/
  /*padding-left:5px;*/
  color: #606266;
  border-bottom:1px dotted #bfc1c5;
  padding-bottom:5px;
}
.el-line{
  margin: 0px 0px 20px 0px;
}
</style>
