import { Component, OnInit, TemplateRef, ViewChild } from "@angular/core";
import { FormBuilder, Validators, FormGroup} from '@angular/forms';
import { CustomValidators } from 'ng2-validation';
import { BsModalService } from "ngx-bootstrap/modal";
import { FlexTableComponent } from "../../../../../shared/common/FlexTable.component";
import { AppComponent } from "../../../../../app.component";
import {FrameUploaderComponent} from '../../../../../core/uploader/uploader.component';
import { FrameRequest } from "../../../../../shared/frame/frame-request";
import { FramePagerComponent } from "../../../../../core/pager/pager.component";
import { FrameFunction } from "../../../../../shared/frame/frame_function";
import { ThemesService } from "../../../../../core/themes/themes.service";

@Component({
  selector: "app-pl-socialaudit",
  templateUrl: "./social-audit.component.html",
  styleUrls: ["./social-audit.component.scss"]
})
export class SocialAuditComponent extends FlexTableComponent implements OnInit {

  @ViewChild('uploader')
  uploader: FrameUploaderComponent;
  @ViewChild('framePager')
  framePager:FramePagerComponent;
  @ViewChild('oldCjPager')
  oldCjPager:FramePagerComponent;
  @ViewChild('ticketAssoPager')
  ticketAssoPager:FramePagerComponent;

  courseList=[];
  //TODO
  QUERY_URL = "by/byApply/page.htm";
  DELETE_URL = "by/byApply/delete.htm";
  GET_URL = "by/byApply/get.htm";
  ADD_URL = "by/byApply/add.htm";
  EDIT_URL = "by/byApply/edit.htm";

  ORG_LIST_URL = "cf/cfOrganization/list.htm";
  AUTH_DETAIL_URL = "by/byApply/getdetail.htm";
  AUTH_LIST_URL = "by/byApply/viewauth.htm";//审核记录
  OLD_CJ_URL = "hz/cjJigechengjiOld/page.htm";
  UPLOAD_URL = "pl/byApply/upload.htm";
  TICKET_ASSO_SCORE_URL = "kj/kjUnifiedScoreDetail/ticketassopage.htm";//准考证关联成绩查询
  STD_RESUME_URL = "std/stdResume/list.htm";
  UPDATE_STD_RESUME_URL = "std/stdResume/updateResume.htm";
  QUERY_BYSCORE_URL = "by/byApply/getscorelist.htm";
  

  orgList = [];
  authList = [];
  resumeList = [];
  xuexinList = [];
  isHaveXueXin = false;
  isShowMajorRemark = false;

  xuexinxjList = [];
  isHaveXueXinXj = false;

  isWeiJi = false;
  is_wj = null;

  weiJiList = [];
  filePath : String;
  radioSelect : any;
  scoreList = [];//考生的毕业成绩Map
  replScoreList = [];//用来顶替的成绩列表
  replCourseList = [];
  courseScoreList = [];
  assoScoreList = [];
  majorList = [];
  masterSchoolList = [];
  majorLevel = "";

  replSelected= [];
  replSelectedCourse= [];

  //毕业录入成绩
  inputScore = {
    use_type: "",
    by_apply_id: "",
    std_reg_id: "",
    major_id: "",
    major_code: "",

    course_code: "",//新录入的课程代码
    course_name: "",//新录入的课程名称
    final_score: "",
    origin_score: "",
    course_score: "",

    course_code2: "",//新录入的课程代码
    course_name2: "",//新录入的课程名称
    final_score2: "",
    origin_score2: "",
    course_score2: "",

    course_code3: "",//新录入的课程代码
    course_name3: "",//新录入的课程名称
    final_score3: "",
    origin_score3: "",
    course_score3: "",

    course_code4: "",//新录入的课程代码
    course_name4: "",//新录入的课程名称
    final_score4: "",
    origin_score4: "",
    course_score4: "",

    course_code5: "",//新录入的课程代码
    course_name5: "",//新录入的课程名称
    final_score5: "",
    origin_score5: "",
    course_score5: "",

    score_nature: "",
    score_source: "",
    score_id: "",
    old_course_id: "",//之前成绩对应的课程ID
    asso_ticket_no:"",
    score:"",
    score_type:""
  };

  inputModalWin: any;
  courseReplWin: any;
  idCardWin: any;
  uploadImgWin: any;
  scoreWin: any;
  assoWin: any;
  assoWin2: any;
  turnInAssocitWin : any;//转入关联
  ticketNoAssocitWin : any;//准考证关联
  oldCjWin: any;
  stdRefWin: any;

  turnInScoreList = [];//转入成绩
  turnInScore : any;//转入成绩对象

  repl_course_id : any;//待顶替课程id
  repl_score_id: any;//待顶替的成绩id
  public scoreFormModel: FormGroup;

  showTicketPage=false;//默认不显示
  certRetDesc : any;//学信网认证信息
  private applyStatus = {
    NEW_0: 0,
    TO_FIRST_AUDIT_1: 1,
    TO_FINAL_AUDIT_2: 2,
    TO_DISTRIBUTE_3: 3,
    ARCHIVED_4: 4
  };
  stdResumeArr : any ;
  start_time: any;
  std_reg_id: any;
  by_apply_id: any;

  scorelRadioItem: any;
  notSelectScoreRadioItem: any;
  by_score_id: any;

  order='';
  type='';

  file_access_url:any;
  bsModalWin2 = null;
  bsModalWin3 = null;
  file_path = null;
  curr_id = null;
  current = 0;

  public stdformModel: FormGroup

  constructor(
    public bsModalService: BsModalService,
    fb: FormBuilder
  ) {
    super();
    this.formModel = fb.group({
      id: [null],
      'std_name' : [null],
      'cert_no': [null],
      'ticket_no': [null],
      'std_sex': [null],
      'nation': [null],
      'std_birth': [null],
      'native_prov': [null],
      'native_city': [null],
      'political': [null],
      'pre_edu': [null],
      'work_unit': [null],
      'telephone': [null],
      'address': [null],
      'post_code': [null],
      'radioSelect' : [null, Validators.compose([Validators.required])],
      'remark' : [null, Validators.compose([Validators.required])],
    });
    this.scoreFormModel = fb.group({
      id: [null],
      'course_code' : [null, Validators.compose([Validators.required])],
      'course_name' : [null, Validators.compose([Validators.required])],
      'final_score' : [null, Validators.compose([Validators.required])],
      'course_score' : [null],

      'course_code2' : [null, Validators.compose([Validators.required])],
      'course_name2' : [null, Validators.compose([Validators.required])],
      'final_score2' : [null, Validators.compose([Validators.required])],
      'course_score2' : [null],

      'course_code3' : [null, Validators.compose([Validators.required])],
      'course_name3' : [null, Validators.compose([Validators.required])],
      'final_score3' : [null, Validators.compose([Validators.required])],
      'course_score3' : [null],

      'course_code4' : [null, Validators.compose([Validators.required])],
      'course_name4' : [null, Validators.compose([Validators.required])],
      'final_score4' : [null, Validators.compose([Validators.required])],
      'course_score4' : [null],

      'course_code5' : [null, Validators.compose([Validators.required])],
      'course_name5' : [null, Validators.compose([Validators.required])],
      'final_score5' : [null, Validators.compose([Validators.required])],
      'course_score5' : [null],
    });
  }

  ngOnInit() {
    this.query.status = "1";//默认为 待一级审核
     //课程
     //FrameRequest.requestArray("pl/plCourse/listCourseByType.htm", {course_exam_type:"",special_flag:""}, (arrary)=>{
     // this.courseList = arrary;
   // });

    FrameRequest.requestMap("by/byApply/initdata.htm", {}, async (map)=>{
      this.majorList  = map.majorList;//专业
      this.orgList = map.cityOrgList;//市考办
      this.masterSchoolList = map.schoolOrgList;//主考学校
      this.query.examTimeId = map.examTimeId;
      this.query.order_org_id = map.org_id;// 领取证书单位
      this.file_access_url = map.url;

      this.framePager.reload();
    });

    
  }

  public query = {
    query: "",
    cityOrgId: "",
    masterSchoolId: "",
    examTimeId: "",
    majorId: "",
    status: "",
    is_firstauth_pass:"",
    order_org_id:"",
    std_confirm:""
  };

  public oldCjQuery = {
    query: ""
  }
  public turnInQuery = {
    oldCourseId: "",
    stdName: "",
    ticketNo: "",
    courseCode: ""
  }
  public ticketAssoQuery = {
    ticketNo: "",
  }
  public stdRefQuery = {
    certNo: "",
    ticketNo: "",
    majorId: "", //待毕业专业
    masterSchoolId: ""
  }

  search(param) {
    param.query = this.query.query;
    param.std_source = 1;//只查社会考生
    if (!this.query.cityOrgId) {
      this.query.cityOrgId = "";
    }
    if (!this.query.majorId) {
      this.query.majorId = "";
    }
    if (!this.query.masterSchoolId) {
      this.query.masterSchoolId = "";
    }
    if (!this.query.examTimeId) {
      this.query.examTimeId = "";
    }
    if (!this.query.status) {
      this.query.status="";
    }
    if (!this.query.is_firstauth_pass) {
      this.query.is_firstauth_pass="";
    }

    if (!this.query.order_org_id) {
      this.query.order_org_id = "";
    }

    if (!this.query.std_confirm) {
      this.query.std_confirm="";
    }

   
    
    param.city_org_id = this.query.cityOrgId;
    param.major_id = this.query.majorId;
    param.school_id = this.query.masterSchoolId;
    param.exam_time_id = this.query.examTimeId;
    param.by_status = this.query.status;
    param.is_firstauth_pass = this.query.is_firstauth_pass;
    param.order_org_id = this.query.order_org_id;
    param.std_confirm = this.query.std_confirm;
    
  }

  replScoreSearch(param) {
      param.stdRegId=this.item.std_id;
      param.majorId=this.item.major_id;
      param.courseId=this.repl_course_id;
  }

  oldCjSearch(param) {
    param.query = this.oldCjQuery.query;
  }
  //准考证关联
  ticketAssoSearch(param) {
    param.ticketNo = this.ticketAssoQuery.ticketNo;
  }
  //转入
  turnInSearch(param) {
    param.std_name = this.turnInQuery.stdName;
    param.ticket_no = this.turnInQuery.ticketNo;
    param.course_code = this.turnInQuery.courseCode;
  }

  //弹出审核框
  showEditWin(obj) {
    if (!obj) {
      let checkedArray = this.framePager.getCheckedArray();
      if (checkedArray.length == 0) {
        AppComponent.alert({title:"信息提示",text:"请选择待审批记录!"});
        return;
      }
     
      obj = checkedArray[0];
    } 

    if (obj.status != this.applyStatus.TO_FIRST_AUDIT_1 && obj.status != 7&& obj.status != 8) {
      AppComponent.alert({title:"信息提示",text:"只能审批待审批记录!"});
      return;
  }

    this.editShowType="only";
    FrameRequest.requestMap(this.AUTH_DETAIL_URL, {id: obj.id}, (map) => {
      this.item = map.detail;
      this.authList = map.authList;
      this.resumeList = map.resumeList;
      this.xuexinList = map.xuexinList;
      this.isHaveXueXin = map.isHaveXueXin;
      this.xuexinxjList = map.xuexinxjList;
      this.isHaveXueXinXj = map.isHaveXueXinXj;
      
      this.weiJiList = map.weiJiList;
      this.isWeiJi = map.isWeiJi;
      this.is_wj = map.is_wj;
      this.scoreList = map.scoreMap;
      this.majorLevel = map.majorLevel;
      this.item.remark="";
      this.radioSelect = null;
      if (this.majorLevel == '本科') {
        if (!this.item.is_xuexin_pass || this.item.is_xuexin_pass == 0) {
          this.certRetDesc = "没有前置学历认证，请确认!";
        } else if (this.item.is_xuexin_pass == 1) {
          this.certRetDesc = "前置学历认证通过!";
        }
      }

      if(this.is_wj){
        AppComponent.alert({title:"信息提示",text:"考生在考试过程中涉嫌存在构成违规违纪行为，请审核时确认成绩是否可用。"});
      }
      
    });
  }

  //查看审核记录
  showAuthListWin(applyId) {
    this.editShowType="authQuery";
    //详情
    FrameRequest.requestMap(this.AUTH_DETAIL_URL, {id: applyId}, (map) => {
      this.item = map.detail;
      this.authList = map.authList;
      //this.resumeList = map.resumeList;
     // this.xuexinList = map.xuexinList;
     // this.isHaveXueXin = map.isHaveXueXin;
    //  this.weiJiList = map.weiJiList;
    //  this.isWeiJi = map.isWeiJi;
    });


    //详情界面的成绩
    /*FrameRequest.requestArray(this.QUERY_BYSCORE_URL, {id: applyId}, (arrary)=>{
      this.authList = arrary;
    });*/
    
  }

  //审核
  doAudit() {
    if (!FrameFunction.validForm(this.formModel)) {
      return;
    }
   
    
    let old_status = this.item.status;
    let old_is_auth_back = this.item.is_auth_back;

    //先做学历认证
    if (this.radioSelect == 0 && this.majorLevel == '本科' && (!this.item.is_xuexin_pass || this.item.is_xuexin_pass == 0)) {
      //AppComponent.alert({title:"信息提示",text:"该考生没有前置学历认证，请现场确认!"});
       AppComponent.confirm("该考生没有前置学历认证，确定审核通过吗？",()=>{
        this.item.auth_type = this.radioSelect;
        if (this.item.auth_type == 2) {//审核通过
          this.item.status = this.applyStatus.TO_FINAL_AUDIT_2;//待终审
          this.item.is_auth_back = 0;
        } else if (this.item.auth_type == 3) {
          this.item.status = this.applyStatus.NEW_0;
          this.item.is_auth_back = 1;//标识驳回
        }else if (this.item.auth_type == 11) {//转考生网上确认
          this.item.status = 7;
        }

        if(!this.item.is_auth_back){
          this.item.is_auth_back = "";
        }

        AppComponent.GobalComponent.setLoading(true);
        FrameRequest.request("by/byApply/audit.htm", this.item, (ret)=>{
          AppComponent.GobalComponent.setLoading(false);
         
          if (ret.errorCode == 1) {
            this.hideModal();
            this.framePager.reload();
            AppComponent.GobalComponent.successMsg("审核成功!");
          }else{
            this.item.status = old_status;
            this.item.is_auth_back = old_is_auth_back;
            AppComponent.GobalComponent.errorMsg(ret.errorMsg);
          }     

        });
      });

    }else{
      this.item.auth_type = this.radioSelect;
      if (this.item.auth_type == 2) {//审核通过
        this.item.status = this.applyStatus.TO_FINAL_AUDIT_2;//待终审
        this.item.is_auth_back = 0;
      } else if (this.item.auth_type == 3) {
        this.item.status = this.applyStatus.NEW_0;
        this.item.is_auth_back = 1;//标识驳回
      }else if (this.item.auth_type == 11) {//转考生网上确认
        this.item.status = 7;
       
      }

      if(!this.item.is_auth_back){
        this.item.is_auth_back = "";
      }
      
        AppComponent.GobalComponent.setLoading(true);
        FrameRequest.request("by/byApply/audit.htm", this.item, (ret)=>{
          AppComponent.GobalComponent.setLoading(false);
         
          if (ret.errorCode == 1) {
            this.hideModal();
            this.framePager.reload();
            AppComponent.GobalComponent.successMsg("审核成功!");
          }else{
            this.item.status = old_status;
            this.item.is_auth_back = old_is_auth_back;
            AppComponent.GobalComponent.errorMsg(ret.errorMsg);
          }     

        });

    }
    
  }

  
  callBackApply() {
    let checkedArray = this.framePager.getCheckedArray();
      if (checkedArray.length == 0 || checkedArray.length>1) {
        AppComponent.alert({title:"信息提示",text:"请选择一条记录!"});
        return;
      }
      if (checkedArray[0].status != this.applyStatus.TO_FINAL_AUDIT_2) {
          AppComponent.alert({title:"信息提示",text:"只能撤回状态是自治区招生考试院审核的记录!"});
          return;
      }
      
    
    AppComponent.confirm("确定撤回毕业申请单吗?",()=>{

    AppComponent.GobalComponent.setLoading(true);
    FrameRequest.request("by/byApply/callBack.htm", {id: checkedArray[0].id,std_source:checkedArray[0].std_source}, (ret)=>{
      AppComponent.GobalComponent.setLoading(false);
      this.hideModal();
      this.framePager.reload();
      if (ret.errorCode == 1) {
       
        AppComponent.GobalComponent.successMsg("撤回成功!");
      }else{
        
        AppComponent.GobalComponent.errorMsg(ret.errorMsg);
      }
    });
  });
  }


  batchSubmitApply() {

    if (!this.query.order_org_id) {
      AppComponent.alert({title:"信息提示",text:"请选择领取证书单位!"});
      return;
    }
   
    AppComponent.confirm("确定将所有考生确认无误的毕业申请单提交到自治区招生考试院终审吗?",()=>{
    
    AppComponent.GobalComponent.setLoading(true);

    let param = {
      order_org_id:this.query.order_org_id,
      std_source : 1
    };

    FrameRequest.request("by/byApply/batchSubmitApply.htm", param, (ret)=>{
      AppComponent.GobalComponent.setLoading(false);
      this.hideModal();
      this.framePager.reload();
      if (ret.errorCode == 1) {
       
        AppComponent.GobalComponent.successMsg("一键报送成功!");
      }else{
        
        AppComponent.GobalComponent.errorMsg(ret.errorMsg);
      }
    });
  });
  }
  
  changeStdByPhoto(){
    AppComponent.confirm("确定将考生上传的照片作为毕业照片吗?",()=>{

      AppComponent.GobalComponent.setLoading(true);
      FrameRequest.request("by/byApply/changeStdByPhoto.htm", {id: this.item.id}, (ret)=>{
        AppComponent.GobalComponent.setLoading(false);
        
        if (ret.errorCode == 1) {
           this.resetByPhoto();
          AppComponent.GobalComponent.successMsg("操作成功!");
        }else{
          
          AppComponent.GobalComponent.errorMsg(ret.errorMsg);
        }
      });
    });
  }

  resetByPhoto(){
    FrameRequest.requestMap(this.AUTH_DETAIL_URL, {id: this.item.id}, (map) => {
      if(map.detail&& map.detail.by_photo_path){
        this.item.by_photo_path = map.detail.by_photo_path;
      }
     
    });
  
  }

  
  setStdByPhoto(){
    AppComponent.confirm("确定将考生照片调整至宽480*高640且大小20-40KB并设为毕业照片吗?",()=>{

      AppComponent.GobalComponent.setLoading(true);
      FrameRequest.request("by/byApply/setStdByPhoto.htm", {id: this.item.id}, (ret)=>{
        AppComponent.GobalComponent.setLoading(false);
        
        if (ret.errorCode == 1) {
           this.resetByPhoto();
          AppComponent.GobalComponent.successMsg("操作成功!");
        }else{
          
          AppComponent.GobalComponent.errorMsg(ret.errorMsg);
        }
      });
    });
  }

  //笔记卡审核
  doAuditWrite() {

  }

  formateFinalScore(item) {
    if (item.final_score == '888') {
      return '顶替';
    } else if (item.final_score == '999') {
      return '免考';
    }
    if (item.final_score == '-9') {
      return '缺考';
    } else if (item.final_score == '-3') {
      return '违纪';
    } else if (item.final_score == '-2') {
      return '免考';
    } else if (item.final_score == '-1') {
      return '舞弊';
    } else if (item.final_score == '200') {
      return '免考';
    } else if (item.final_score == '201') {
      return '及格';
    } else if (item.final_score == '202') {
      return '中等';
    } else if (item.final_score == '203') {
      return '良好';
    } else if (item.final_score == '204') {
      return '优秀';
    }
    if (Number(item.final_score) < 60) {
      return "";
    }
    return item.final_score;
  }

  //下载毕业登记表
  getRegisterPdf() {
    let checkedArray = this.framePager.getCheckedArray();
    if (checkedArray.length == 0) {
      AppComponent.alert({title:"信息提示",text:"请选择考生毕业申请!"});
      return;
    }
    AppComponent.GobalComponent.setLoading(true);
    FrameRequest.download("by/byApply/getregisterpdf.htm", {applyId: checkedArray[0].id}, ()=>{
      AppComponent.GobalComponent.setLoading(false);
      AppComponent.GobalComponent.successMsg("下载成功!");
    });
  }

  //下载毕业登记表
  getRegisterPdfForBatch() {
    
    let checkedArray = this.framePager.getCheckedArray((item)=>item.id);
    if (checkedArray.length == 0) {
      AppComponent.alert({title:"信息提示",text:"请选择考生毕业申请!"});
      return;
    }
   
    AppComponent.confirmForTitle("温馨提醒","毕业登记表优先选择网页打印，用软件打开打印必须选择实际大小再打印",()=>{
      AppComponent.GobalComponent.setLoading(true);
      FrameRequest.download("by/byApply/getByApplyRegisterPdfForBatch.htm",  {applyIds: checkedArray.join()}, ()=>{
          AppComponent.GobalComponent.setLoading(false);
          AppComponent.GobalComponent.successMsg("下载成功!");
      });
    });

    }

  //显示手工录入分数
  showInputDialog(templateModal) {
    if(this.item && this.item.status!=this.applyStatus.TO_FIRST_AUDIT_1&& this.item.status != 7&& this.item.status != 8){
      AppComponent.alert({title:"信息提示",text:"毕业申请单状态不是待现场确认，不允许操作!"});
      return;
    }

    if (!this.scorelRadioItem) {
      AppComponent.alert({title:"信息提示",text:"请选择待录入课程!"});
      return;
    }

    if(this.scorelRadioItem.is_passed=='1'){
      AppComponent.alert({title:"信息提示",text:"该门课程成绩已经合格，不允许手工录入!"});
      return;
    }

    this.inputScore.course_code="";
    this.inputScore.course_name="";
    this.inputScore.final_score="";
    this.inputScore.course_score="";

    this.inputScore.course_code2="";
    this.inputScore.course_name2="";
    this.inputScore.final_score2="";
    this.inputScore.course_score2="";

    this.inputScore.course_code3="";
    this.inputScore.course_name3="";
    this.inputScore.final_score3="";
    this.inputScore.course_score3="";

    this.inputScore.course_code4="";
    this.inputScore.course_name4="";
    this.inputScore.final_score4="";
    this.inputScore.course_score4="";

    this.inputScore.course_code5="";
    this.inputScore.course_name5="";
    this.inputScore.final_score5="";
    this.inputScore.course_score5="";

    this.inputScore.old_course_id = this.scorelRadioItem.course_id;
    this.inputModalWin = this.bsModalService.show(templateModal, { class: "modal-lg" });
  }

   //课程顶替界面
  showReplDialog(templateModal) {
    if(this.item && this.item.status!=this.applyStatus.TO_FIRST_AUDIT_1&& this.item.status != 7&& this.item.status != 8){
      AppComponent.alert({title:"信息提示",text:"毕业申请单状态不是待现场确认，不允许操作!"});
      return;
    }

    if (!this.scorelRadioItem) {
      AppComponent.alert({title:"信息提示",text:"请选择待顶替课程!"});
      return;
    }

    if(this.scorelRadioItem.is_passed=='1'){
      AppComponent.alert({title:"信息提示",text:"该门课程成绩已经合格，不允许顶替!"});
      return;
    }

    this.repl_score_id = this.scorelRadioItem.id;
    this.repl_course_id = this.scorelRadioItem.course_id;
    this.courseReplWin = this.bsModalService.show(templateModal, { class: "modal-lg" });
    //查询
    let params = {
      stdRegId: this.item.std_id,
      majorId: this.item.major_id,
      courseId: this.scorelRadioItem.course_id
    }
    FrameRequest.requestArray("kj/byCourseReplRecord/byReplscoreList.htm", params, (arrary)=>{
      this.replScoreList = arrary;
    });

    FrameRequest.requestArray("by/byCourseReplRecord/byReplOldCourseList.htm", params, (arrary)=>{
      this.replCourseList  = arrary;
    });

    

    this.replSelected = [];
    this.replSelectedCourse = [];
  }

 
  showScoreDialog(templateModal, id_arg, courseId_arg) {
    this.notSelectScoreRadioItem = null;
    this.by_score_id = id_arg;

    if(!courseId_arg){
      courseId_arg = "";
    }
    
    this.scoreWin = this.bsModalService.show(templateModal, { class: "modal-lg" });
    //查询
    let params = {
      stdRegId: this.item.std_id,
     
      courseId: courseId_arg
    }
    FrameRequest.requestArray("kj/kjUnifiedScoreDetail/pageCourseScore.htm", params, (arrary)=>{
      this.courseScoreList = arrary;
    });
  }

  setByScore(){
    if (!this.notSelectScoreRadioItem) {
      AppComponent.alert({title:"信息提示",text:"请选择一门课程成绩!"});
      return;
    }

    if (this.notSelectScoreRadioItem && this.notSelectScoreRadioItem.is_passed !='1') {
      AppComponent.alert({title:"信息提示",text:"不允许选择不合格的成绩作为毕业成绩!"});
      return;
    }

    if (!this.by_score_id) {
      AppComponent.alert({title:"信息提示",text:"请选择一门毕业课程!"});
      return;
    }
    
    AppComponent.confirm("确定将选中的成绩作为毕业成绩吗?",()=>{
      let param = {
        by_apply_id: this.item.id,
        score_id:this.by_score_id,
        detail_id:this.notSelectScoreRadioItem.id,
        
      };
      
      AppComponent.GobalComponent.setLoading(true);
      FrameRequest.requestEntity("by/byScore/setByScore.htm", param, async () => {
        AppComponent.GobalComponent.setLoading(false);
        this.scoreWin.hide();
        AppComponent.GobalComponent.successMsg('操作成功!');
        
        //刷新成绩显示
        FrameRequest.requestArray(this.QUERY_BYSCORE_URL, {id: this.item.id}, (arrary) => {
          this.scoreList = arrary;
          this.scorelRadioItem = undefined;
        });
      });
   });
  }

  //转入成绩关联
  showTurnInDialog(templateModal) {
    if(this.item && this.item.status!=this.applyStatus.TO_FIRST_AUDIT_1&& this.item.status != 7&& this.item.status != 8){
      AppComponent.alert({title:"信息提示",text:"毕业申请单状态不是待现场确认，不允许操作!"});
      return;
    }

    if (!this.scorelRadioItem) {
      AppComponent.alert({title:"信息提示",text:"请选择待转入关联课程!"});
      return;
    }

    if(this.scorelRadioItem.is_passed=='1'){
      AppComponent.alert({title:"信息提示",text:"该门课程成绩已经合格，不允许转入关联!"});
      return;
    }

    this.turnInQuery.stdName = "";//清空
    this.turnInQuery.ticketNo = "";//清空
    this.turnInScoreList = [];//清空
    this.turnInQuery.oldCourseId = this.scorelRadioItem.course_id;
    this.inputScore.old_course_id = this.scorelRadioItem.course_id;
    this.turnInAssocitWin = this.bsModalService.show(templateModal, { class: "modal-lg" });
  }

  //老生成绩
  showOldCjDialog(templateModal) {
    this.oldCjWin = this.bsModalService.show(templateModal, { class: "modal-lg" });
  }

  //关联准考证
  showTicketAssocitDialog(templateModal) {
    if(this.item && this.item.status!=this.applyStatus.TO_FIRST_AUDIT_1&& this.item.status != 7&& this.item.status != 8){
      AppComponent.alert({title:"信息提示",text:"毕业申请单状态不是待现场确认，不允许操作!"});
      return;
    }
    this.ticketNoAssocitWin = this.bsModalService.show(templateModal, { class: "modal-lg" });
    this.stdTicketRefList = [];
    this.ticketAssoQuery.ticketNo = "";
    this.ticketRadioItem = {};
    this.assoStdSelected = undefined;
    
    FrameRequest.requestArray("by/stdRegInfo/showassolist.htm", {by_apply_id: this.item.id}, (arr) => {
      if (arr.length > 0) {
        this.stdTicketRefList = arr;
        
      }
    });
  }

  //手工录入分数
  saveMannualInput() {
    //第一行必输入
    if (!this.inputScore.course_code || !this.inputScore.course_name || !this.inputScore.final_score) {
      AppComponent.alert({title:"信息提示",text:"第1行课程代码、课程名称、成绩必须录入!"});
      return;
    }
    if ((this.inputScore.course_code2 && (!this.inputScore.course_name2 || !this.inputScore.final_score2))
        || (this.inputScore.course_name2 && (!this.inputScore.course_code2 || !this.inputScore.final_score2))
        || (this.inputScore.final_score2 && (!this.inputScore.course_name2 || !this.inputScore.final_score2))) {
      AppComponent.alert({title:"信息提示",text:"第2行课程代码、课程名称、成绩录入不完整!"});
      return;
    }
    if ((this.inputScore.course_code3 && (!this.inputScore.course_name3 || !this.inputScore.final_score3))
        || (this.inputScore.course_name3 && (!this.inputScore.course_code3 || !this.inputScore.final_score3))
        || (this.inputScore.final_score3 && (!this.inputScore.course_name3 || !this.inputScore.final_score3))) {
      AppComponent.alert({title:"信息提示",text:"第3行课程代码、课程名称、成绩录入不完整!"});
      return;
    }
    if ((this.inputScore.course_code4 && (!this.inputScore.course_name4 || !this.inputScore.final_score4))
        || (this.inputScore.course_name4 && (!this.inputScore.course_code4 || !this.inputScore.final_score4))
        || (this.inputScore.final_score4 && (!this.inputScore.course_name4 || !this.inputScore.final_score4))) {
      AppComponent.alert({title:"信息提示",text:"第4行课程代码、课程名称、成绩录入不完整!"});
      return;
    }
    if ((this.inputScore.course_code5 && (!this.inputScore.course_name5 || !this.inputScore.final_score5))
        || (this.inputScore.course_name5 && (!this.inputScore.course_code5 || !this.inputScore.final_score5))
        || (this.inputScore.final_score5 && (!this.inputScore.course_name5 || !this.inputScore.final_score5))) {
      AppComponent.alert({title:"信息提示",text:"第5行课程代码、课程名称、成绩录入不完整!"});
      return;
    }    
    if (this.inputScore.final_score && Number(this.inputScore.final_score) < 60) {
      AppComponent.alert({title:"信息提示",text:"第1行录入成绩不能小于60!"});
      return;
    }
    if (this.inputScore.final_score2 && Number(this.inputScore.final_score2) < 60) {
      AppComponent.alert({title:"信息提示",text:"第2行录入成绩不能小于60!"});
      return;
    }
    if (this.inputScore.final_score3 && Number(this.inputScore.final_score3) < 60) {
      AppComponent.alert({title:"信息提示",text:"第3行录入成绩不能小于60!"});
      return;
    }
    if (this.inputScore.final_score4 && Number(this.inputScore.final_score4) < 60) {
      AppComponent.alert({title:"信息提示",text:"第4行录入成绩不能小于60!"});
      return;
    }
    if (this.inputScore.final_score5 && Number(this.inputScore.final_score5) < 60) {
      AppComponent.alert({title:"信息提示",text:"第5行录入成绩不能小于60!"});
      return;
    } 
    this.inputScore.by_apply_id = this.item.id;
    this.inputScore.std_reg_id = this.item.std_id;
    this.inputScore.major_id = this.item.major_id;
    this.inputScore.score_source = "4";//手工录入
    this.inputScore.score_type = "7";//手工录入
    //保存
    
    let addUrl = "by/byScore/add.htm";
    FrameRequest.requestEntity(addUrl, this.inputScore, async () => {
      AppComponent.GobalComponent.successMsg('信息保存成功!');
      this.inputModalWin.hide();
      this.scorelRadioItem = undefined;
      //刷新成绩显示
      FrameRequest.requestArray(this.QUERY_BYSCORE_URL, {id: this.item.id}, (arrary) => {
        this.scoreList = arrary;
      });
    });
  }
  
//上传毕业照片
uploadByPhoto(applyId) {
  let param = {
    byApplyId: applyId,
    RequestLoading: true
  };
  this.uploader.choooseFileAndUpload(param, ((ret) => {
    if (ret.errorCode > 0) {
      AppComponent.alert({title:"信息提示", text: ret.errorMsg});
    } else if (ret.errorCode == -1) {
      AppComponent.GobalComponent.successMsg("上传失败!");
    } else if (ret.errorCode == 0) {
      AppComponent.GobalComponent.successMsg("上传成功!");
      this.item.by_photo = ret.map.file_path;
      this.item.by_photo_path = ret.map.by_photo_path;
      this.uploadImgWin.hide();
    }
  }));
}

  replRadioItem: any;

  replRadioCheckFun(it) {
    this.replRadioItem = it;
  }

  updateSelection($event,it) {
    
    var checkbox = $event.target; 
    var action = (checkbox.checked?'add':'remove'); 

    if(action == 'add'){ 
      this.replSelected.push(it.id); 
      this.replSelectedCourse.push(it.course_id); 
      
    } 

    if(action == 'add' && this.replSelected.indexOf(it.id) == -1){ 
      this.replSelected.push(it.id); 
    } 
    if(action == 'add' && this.replSelectedCourse.indexOf(it.course_id) == -1){ 
      this.replSelectedCourse.push(it.course_id); 
    } 

    if(action == 'remove' && this.replSelected.indexOf(it.id)!=-1){ 
      var idx = this.replSelected.indexOf(it.id); 
      this.replSelected.splice(idx,1); 
    } 

    if(action == 'remove' && this.replSelectedCourse.indexOf(it.course_id)!=-1){ 
      var idx = this.replSelectedCourse.indexOf(it.course_id); 
      this.replSelectedCourse.splice(idx,1); 
    } 

  }
  

  //保存顶替
  replSave() {
    if (!this.replSelected || this.replSelected.length == 0) {
      AppComponent.alert({title:"信息提示",text:"请选择顶替成绩!"});
      return;
    }
    let parm = {
      by_apply_id: this.item.id,      //毕业Id
      std_id: this.item.std_id,
      major_id: this.item.major_id,
      score_ids:this.replSelected.join(),
      old_course_ids:this.replSelectedCourse.join(),
      new_course_id:this.repl_course_id
    }
    
    AppComponent.confirm("确定课程顶替吗?",()=>{
      FrameRequest.request("by/byCourseReplRecord/repl.htm", parm, (ret)=>{
        if (ret.errorCode == 0) {
          this.courseReplWin.hide();
  
          this.repl_score_id = "";//清空
          this.repl_course_id = "";
          this.replSelected =[];
          this.replSelectedCourse =[];
  
          //刷新成绩显示
          FrameRequest.requestArray(this.QUERY_BYSCORE_URL, {id: this.item.id}, (arrary) => {
            this.scoreList = arrary;
          });
          AppComponent.GobalComponent.successMsg("课程顶替成功!");
        }
      });
    });

    
  }

  //保存顶替
  replSavebak() {
    if (!this.replRadioItem) {
      AppComponent.alert({title:"信息提示",text:"请选择顶替成绩!"});
      return;
    }
    let parm = {
      by_apply_id: this.item.id,      //毕业Id
      std_reg_id: this.item.std_id,
      major_id: this.item.major_id,
      repl_score_ids: this.repl_score_id,       //未通过的成绩ID
      repl_course_ids: this.repl_course_id,    //未考或不及格课程----待顶替
      new_score_ids: this.replRadioItem.id,    //新成绩IDs
      detail_id: this.replRadioItem.detail_id,  //规则详情ID
      cj_from: this.replRadioItem.cjfrom      //成绩来自统考1 还是 校考0
    }
    FrameRequest.request("by/byCourseReplRecord/repl.htm", parm, (ret)=>{
      if (ret.errorCode == 0) {
        this.courseReplWin.hide();

        this.repl_score_id = "";//清空
        this.repl_course_id = "";
        this.replRadioItem = undefined;
        

        //刷新成绩显示
        FrameRequest.requestArray(this.QUERY_BYSCORE_URL, {id: this.item.id}, (arrary) => {
          this.scoreList = arrary;
          this.scorelRadioItem = undefined;
        });
        AppComponent.GobalComponent.successMsg("顶替成功!");
      }
    });
  }

  //老生成绩选择
  selectOldCj() {
    let checkedArray = this.oldCjPager.getCheckedArray();
    if (checkedArray.length == 0) {
      AppComponent.alert({title:"信息提示",text:"请选择老成绩!"});
      return;
    }
    if (checkedArray.length > 1) {
      AppComponent.alert({title:"信息提示",text:"只能选择一条老成绩!"});
      return;
    }
    let scoreShow = {};
    scoreShow["course_code"] = checkedArray[0].kechengdaihao;
    scoreShow["course_name"] = "";
    scoreShow["score_source"] = "老成绩引入";
    //scoreShow["score_nature"] = "老课程成绩";
    scoreShow["origin_score"] = checkedArray[0].chengji;
    scoreShow["final_score"] = checkedArray[0].chengji;
    scoreShow["is_passed"] = Number.parseInt(checkedArray[0].chengji) >= 60 ? "1" : "0";
    this.scoreList.push(scoreShow);
    //保存到库
    this.inputScore.by_apply_id = this.item.id;
    this.inputScore.std_reg_id = this.item.std_id;
    this.inputScore.major_id = this.item.major_id;
    this.inputScore.course_code = checkedArray[0].kechengdaihao;
    this.inputScore.major_code = checkedArray[0].zhuanyedaihao;
    this.inputScore.origin_score = checkedArray[0].chengji;
    this.inputScore.final_score = checkedArray[0].chengji;
    this.inputScore.score_source = "14";//老成绩引入
    let addUrl = "kj/kjByInputScore/add.htm";
    FrameRequest.requestEntity(addUrl, this.inputScore, async () => {
      AppComponent.GobalComponent.successMsg('选择成功!');
      this.oldCjWin.hide();
      this.radioItem = {};//清空radio选择
    });
  }

  //删除毕业申请验证----只能删除0、1状态的
  deleteApply(item){
    if (item.status > 1) {
      AppComponent.alert({title:"信息提示",text:"只能删除新建状态申请!"});
      return;
    }

    AppComponent.confirm("确定删除吗?",()=>{
      FrameRequest.requestMap(this.DELETE_URL, {ids:item.id}, () => {
        AppComponent.GobalComponent.successMsg('删除成功!');
         this.framePager.reload();
      });
  });

    
  }

  //******************************************新建毕业申请*********************************************** */
  stdRefList = [];//引用考生列表
  stdTicketRefList = [];//准考证引用考生列表
  radioItem = {};
  ticketRadioItem = {};
  byMajorList = [];//毕业带选择专业
  selectOldMajorList = [];//新专业对应的老专业
  showStdRefDialog(templateModal) {
    this.selectOldMajorList = [];
    this.stdRefQuery.certNo="";
    this.stdRefQuery.ticketNo="";
    this.stdRefQuery.majorId="";
    this.stdRefQuery.masterSchoolId="";
    this.stdRefWin = this.bsModalService.show(templateModal, { class: "modal-lg" });
  }
  //引用考生-查询
  findStdRefList() {
    if (!this.stdRefQuery.certNo && !this.stdRefQuery.ticketNo) {
      AppComponent.alert({title:"信息提示",text:"请输入过滤条件!"});
      return;
    }
    //刷新考生
    let param = {
      cert_no: this.stdRefQuery.certNo, 
      ticket_no: this.stdRefQuery.ticketNo,
      std_source: "" 
    };
    AppComponent.GobalComponent.setLoading(true);
    FrameRequest.requestArray("std/stdRegInfo/list.htm", param, (arrary) => {
        AppComponent.GobalComponent.setLoading(false);
        if (arrary.length > 0 && arrary[0].std_source != 1) {
          AppComponent.alert({title:"信息提示",text:"助学班考生请到主考学校申请!"});
          return;
        } else {
          this.stdRefList = arrary;
        }
    });
  }

  //选择的考生 查询待毕业专业
  stdRefRadioCheckFun(item) {
    this.stdRefQuery.masterSchoolId = item.school_id;
  }

  //新申请
  selectStdRef() {
    if (!this.stdRefList.length || !this.radioItem['id']) {
      AppComponent.alert({title:"信息提示",text:"请选择考生!"});
      return;
    }
    if (!this.stdRefQuery.majorId) {
      AppComponent.alert({title:"信息提示",text:"请选择专业!"});
      return;
    }
    if (!this.stdRefQuery.masterSchoolId) {
      AppComponent.alert({title:"信息提示",text:"请选择学校!"});
      return;
    }
    let param = {
      std_reg_id: this.radioItem['id'], 
      major_id: this.stdRefQuery.majorId,
      school_id: this.stdRefQuery.masterSchoolId
    };
    FrameRequest.requestEntity("by/byApply/createbymgm.htm", param, async () => {
      AppComponent.GobalComponent.successMsg('选择成功!');
      this.framePager.reload();
      this.stdRefWin.hide();
    });
  }

  freshSchoolInfo(majorId) {
   
    this.freshOldMajor(majorId);//刷新对应老专业显示
  }
  
  freshOldMajor(majorId) {
    let param = {
      new_major_id: majorId
    }
    FrameRequest.requestArray("pl/plMajorOldNew/getOldMajorList.htm", param, (array)=>{
      this.selectOldMajorList = array;
    });

    FrameRequest.requestEntity("pl/plMajor/findMajorSchool.htm", { id: majorId }, (entity) => {
      if(null != entity){
        this.stdRefQuery.masterSchoolId = entity.org_id;
      }

    });

  }

//******************************关联准考证选择************************** */
assoStdSelected : any;
findStdTicketRefList() {
  if (!this.ticketAssoQuery.ticketNo) {
    AppComponent.alert({title:"信息提示",text:"请输入过滤条件!"});
    return;
  }
  //刷新成绩显示
  let param = {
    ticket_no: this.ticketAssoQuery.ticketNo,
    by_apply_id: this.item.id
  };


  FrameRequest.requestArray("std/stdRegInfo/listbyticket.htm", param, (arrary) => {
   
    this.stdTicketRefList = arrary;
    this.ticketRadioItem = {};
    this.assoStdSelected = undefined;

   // FrameRequest.requestArray("by/stdRegInfo/showassolist.htm", {by_apply_id: this.item.id}, (arr) => {
      
  //    for (let std of this.stdTicketRefList) {
  //      std.assoStatus="";
  //    }
  //    if (arr.length > 0) {
  //      for (let std of arr) {
  //        std.assoStatus="已关联";
  //        this.stdTicketRefList.push(arr);
  //      }
  //    }
  //  });
  });
  
}

//关联准考证--选择的考生 查询指定准考证成绩
stdTicketCheckFun(item) {
  this.showTicketPage = true;
  this.ticketAssoQuery.ticketNo = item.ticket_no;
  this.assoStdSelected = item;
  this.ticketAssoPager.reload();
}
//关联准考证操作
selectTicketNoAssocit() {
  if (!this.assoStdSelected || !this.ticketRadioItem) {
    AppComponent.alert({title:"信息提示",text:"请选择!"});
    return;
  }
  if (this.assoStdSelected.asso_status == '已关联') {
    AppComponent.alert({title:"信息提示",text:"不能重复关联!"});
    return;
  }
  AppComponent.confirm("确定关联准考证成绩?",()=>{
      //加到列表显示
      let param = {
        stdRegId: this.item.std_id,
        byApplyId: this.item.id,
        refTicketNo: this.assoStdSelected.ticket_no
      };
      let addUrl = "kj/kjByInputScore/refticketscore.htm";
      FrameRequest.requestEntity(addUrl, param, async () => {
        AppComponent.GobalComponent.successMsg('关联成功!');
        this.closeAssoTicketWin();
        //刷新成绩显示
        FrameRequest.requestArray(this.QUERY_BYSCORE_URL, {id: this.item.id}, (arrary) => {
          this.scoreList = arrary;
          this.scorelRadioItem = undefined;
        });
      });
  });
}
//取消关联
unSelectTicketNoAssocit() {
  
  if (!this.assoStdSelected) {
    AppComponent.alert({title:"信息提示",text:"请选择!"});
    return;
  }
  if (!this.assoStdSelected.asso_status) {
    AppComponent.alert({title:"信息提示",text:"只能取消已关联的准考证!"});
    return;
  }
  AppComponent.confirm("确定取消关联准考证成绩?",()=>{
    let param = {
      byApplyId: this.item.id,
      refTicketNo: this.assoStdSelected.ticket_no
    };
    let addUrl = "kj/kjByInputScore/delticketscore.htm";
    FrameRequest.requestEntity(addUrl, param, async () => {
      AppComponent.GobalComponent.successMsg('取消成功!');
      this.closeAssoTicketWin();
      //刷新成绩显示
      FrameRequest.requestArray(this.QUERY_BYSCORE_URL, {id: this.item.id}, (arrary) => {
        this.scoreList = arrary;
        this.scorelRadioItem = undefined;
      });
    });
  });
}
//关闭关联准考证界面
closeAssoTicketWin() {
  this.ticketNoAssocitWin.hide();
  this.showTicketPage = false;
  this.stdTicketRefList=[];
  this.assoStdSelected = undefined;
}

//****************************************外省转入成绩****************************************************** */
  turnInQueryRequest() {
    if (!this.turnInQuery.stdName && !this.turnInQuery.ticketNo) {
      AppComponent.alert({title:"信息提示",text:"请输入过考生姓名或准考证号!"});
      return;
    }
    //刷新成绩显示
    let param = {
      std_name : this.turnInQuery.stdName,
      ticket_no : this.turnInQuery.ticketNo,
      course_code : this.turnInQuery.courseCode
    }
    FrameRequest.requestArray("by/byApply/getturninscorelist.htm", param, (arrary) => {
      this.turnInScoreList = arrary;
    });
    this.radioItem = {};//清空radio选择
  }

  //转入选择
  turnInSelect(it) {
    this.turnInScore = it;
  }

  //选择转入成绩替换
  selectTurnInScore() {
    if (!this.turnInScore) {
      AppComponent.alert({title:"信息提示",text:"请选择转入成绩!"});
      return;
    }
    //保存到手工处理成绩表
    //保存到库
    this.inputScore.by_apply_id = this.item.id;
    this.inputScore.std_reg_id = this.item.std_id;
    this.inputScore.major_id = this.item.major_id;
    this.inputScore.course_code = this.turnInScore.course_code;
    this.inputScore.course_name = this.turnInScore.course_name;
    this.inputScore.score = this.turnInScore.final_score;
    this.inputScore.asso_ticket_no =this.turnInScore.ticket_no;
    this.inputScore.score_source = "6";//手工---转考转入成绩
    this.inputScore.score_type = "6";//手工---转考转入成绩
    

    let addUrl = "by/byScore/add.htm";
    FrameRequest.requestEntity(addUrl, this.inputScore, async () => {
      this.turnInScore = undefined;
      AppComponent.GobalComponent.successMsg('转入成功!');
      this.turnInAssocitWin.hide();
      this.radioItem = {};//清空radio选择
      this.scorelRadioItem = undefined;
      //刷新成绩显示
      FrameRequest.requestArray(this.QUERY_BYSCORE_URL, {id: this.item.id}, (arrary) => {
        this.scoreList = arrary;
      });
    });
  }

  //保存基本信息
  saveBaseInfo() {
    AppComponent.GobalComponent.setLoading(true);
    FrameRequest.requestEntity("by/byApply/edit.htm", this.item, (entity)=>{
      AppComponent.GobalComponent.setLoading(false);
      AppComponent.GobalComponent.successMsg('保存成功!');
    });
  }

  //学历认证
  reqCertify() {
    AppComponent.GobalComponent.setLoading(true);
    FrameRequest.requestEntity("by/byApply/educertified.htm", {id: this.item.id}, (entity)=>{
      AppComponent.GobalComponent.setLoading(false);
      if (entity == 1) {
        this.item.is_xuexin_pass=1;//认证通过
        this.certRetDesc = "前置学历认证通过!";

        // 更新学历认证列表
        FrameRequest.requestMap(this.AUTH_DETAIL_URL, {id: this.item.id}, (map) => {
          this.xuexinList = map.xuexinList;
          this.isHaveXueXin = map.isHaveXueXin;
        });
        
        AppComponent.alert({title:"信息提示",text:"认证通过!"});
      } else {
        this.certRetDesc = "前置学历认证不通过，请确认!";
        AppComponent.alert({title:"信息提示",text:"前置学历认证不通过，请确认!"});
      }
    },(error)=>{
      AppComponent.GobalComponent.setLoading(false);
      //AppComponent.alert({title:"信息提示",text:"调用学信网学历认证接口失败!"});
    });
  }

  //标识初审是否通过
  setFirstAuthPass(is_firstauth_pass) {
   

    AppComponent.GobalComponent.setLoading(true);
    FrameRequest.requestEntity("by/byApply/setFirstAuthPass.htm", {id: this.item.id,is_firstauth_pass:is_firstauth_pass}, (entity)=>{
      AppComponent.GobalComponent.setLoading(false);
      if(1==is_firstauth_pass){
        AppComponent.GobalComponent.successMsg('标识初审是否通过成功!');
      }else{
        AppComponent.GobalComponent.successMsg('取消标识初审是否通过成功!');
      }
      
    });
  }


  showAudit() {
    let checkedArray = this.framePager.getCheckedArray();
    if(checkedArray.length === 0 || checkedArray.length > 1){
      AppComponent.alert({title:"信息提示",text:"请选择一个考生!"})
      return;
    }

    this.showAuthListWin(checkedArray[0].id) ;
    
    
  }


  //个人简历修改
  showStdResume() {
    let checkedArray = this.framePager.getCheckedArray();
    if(checkedArray.length === 0 || checkedArray.length > 1){
      AppComponent.alert({title:"信息提示",text:"请选择一个考生!"})
      return;
    }
    this.by_apply_id = checkedArray[0].id;
    this.std_reg_id = checkedArray[0].std_id;
    FrameRequest.requestArray(this.STD_RESUME_URL, {std_reg_id: checkedArray[0].std_id, by_apply_id: checkedArray[0].id}, (array) => {
      this.stdResumeArr = array;
      this.editShowType = "stdResume";
      // if(array && array.length >0) {
      //   this.by_apply_id = array[0].by_apply_id;
      // }
    });
    
  }

  //更新考生简历
  updateStdResume() {
    if(!this.stdResumeArr || this.stdResumeArr.length<1) {
      AppComponent.alert({title:"信息提示",text:"至少需要填写1条个人经历!"});
      return;
    }

    let work_exp_tempArr = [];
    let position_tempArr = [];
    let work_exp = "";
    let position = "";
    for(let j=0;j<this.stdResumeArr.length;j++) {
      work_exp = this.stdResumeArr[j].work_exp;
      position = this.stdResumeArr[j].position;
      if(work_exp.indexOf("+") != -1){
        work_exp = work_exp.replace(/\+/g,"%2B");
      }

      if(position.indexOf("+") != -1){
        position = position.replace(/\+/g,"%2B");

      }

      work_exp_tempArr.push(work_exp);
      position_tempArr.push(position);

    }

    // AppComponent.GobalComponent.setLoading(true);
    FrameRequest.request(this.UPDATE_STD_RESUME_URL, {
      std_reg_id : this.std_reg_id,
      by_apply_id : this.by_apply_id === undefined ? "" : this.by_apply_id,
      start_date : this.stdResumeArr.map(item => item.start_date),
      end_date : this.stdResumeArr.map(item => item.end_date),
      work_exp : work_exp_tempArr.join(),
      position : position_tempArr.join()
    }, () => {
      // AppComponent.GobalComponent.setLoading(false);
      AppComponent.GobalComponent.successMsg("修改成功!");
      this.hideModal();
    });
  }

  addResume() {
    this.stdResumeArr.push(
      {
        "start_date": "",
        "end_date":  "",
        "work_exp": "",
        "position": ""
      }
    );
  }

 
  removeResume(i? :any) {
    AppComponent.confirm("确定删除",()=>{
      let tempArr = [];
    for(let j=0;j<this.stdResumeArr.length;j++) {
      if(i !== j) {
        tempArr.push(this.stdResumeArr[j]);
      }
    }
    this.stdResumeArr = tempArr;
    });

    
  }

  downApplyXls() {
    let param = {
      exam_time_id: this.query.examTimeId,
      by_status: this.query.status,
      major_id: this.query.majorId,
      is_firstauth_pass: this.query.is_firstauth_pass,
      order_org_id:this.query.order_org_id,
      std_confirm: this.query.std_confirm,
      std_source : 1
  };
  AppComponent.GobalComponent.setLoading(true);
  FrameRequest.download("by/byApply/downapplyxls.htm", param, ()=>{
      AppComponent.GobalComponent.setLoading(false);
      AppComponent.GobalComponent.successMsg("导出成功!");
  });
  }

  resetdata(){
    this.query.query="";
    this.query.majorId="";
    this.query.status="1";
    this.query.is_firstauth_pass = "";
    this.query.examTimeId="";
    this.query.order_org_id = "";
    this.query.std_confirm = "";
    this.order='';
    this.type='';
  }

  resetByScore(){
    if(this.item && this.item.status!=this.applyStatus.TO_FIRST_AUDIT_1&& this.item.status != 7&& this.item.status != 8){
      AppComponent.alert({title:"信息提示",text:"毕业申请单状态不是待现场确认，不允许操作!"});
      return;
    }

    AppComponent.confirm("确定重置毕业成绩，重新将统考和校考成绩录入到毕业成绩表吗?",()=>{
      let param = {
        by_apply_id: this.item.id  
      };
      
      AppComponent.GobalComponent.setLoading(true);
      FrameRequest.requestEntity("by/byScore/resetByScore.htm", param, async () => {
        AppComponent.GobalComponent.setLoading(false);
        AppComponent.GobalComponent.successMsg('毕业成绩重置成功!');
        
        //刷新成绩显示
        FrameRequest.requestArray(this.QUERY_BYSCORE_URL, {id: this.item.id}, (arrary) => {
          this.scoreList = arrary;
          this.scorelRadioItem = undefined;
        });
      });
   });
  }

  distinctByScore(){
    if(this.item && this.item.status!=this.applyStatus.TO_FIRST_AUDIT_1&& this.item.status != 7&& this.item.status != 8){
      AppComponent.alert({title:"信息提示",text:"毕业申请单状态不是待现场确认，不允许操作!"});
      return;
    }

    AppComponent.confirm("确定去重毕业成绩吗?",()=>{
      let param = {
        by_apply_id: this.item.id  
      };
      
      AppComponent.GobalComponent.setLoading(true);
      FrameRequest.requestEntity("by/byScore/distinctByScore.htm", param, async () => {
        AppComponent.GobalComponent.setLoading(false);
        AppComponent.GobalComponent.successMsg('毕业成绩去重成功!');
        
        //刷新成绩显示
        FrameRequest.requestArray(this.QUERY_BYSCORE_URL, {id: this.item.id}, (arrary) => {
          this.scoreList = arrary;
          this.scorelRadioItem = undefined;
        });
      });
   });
  }

  
  scoreRadioCheckFun(it) {
    this.scorelRadioItem = it;
  }

  notSelectScoreRadioCheckFun(it) {
    this.notSelectScoreRadioItem = it;
  }

  deleteByScore(it){
    if(!it.byscore_id) {
      AppComponent.alert({title:"信息提示",text:"该门课程没有毕业成绩，无法删除！"});
      return;
    }

      let parm = {
        by_apply_id: this.item.id,
        id: it.byscore_id    
      };

      AppComponent.confirm("确定删除课程成绩吗?",()=>{
        FrameRequest.request("by/byScore/deleteByScore.htm", parm, async ()=>{
            //刷新成绩显示
            FrameRequest.requestArray(this.QUERY_BYSCORE_URL, {id: this.item.id}, (arrary) => {
              this.scoreList = arrary;
              this.scorelRadioItem = undefined;
              this.turnInScore = undefined;
              this.replRadioItem = undefined;
              this.clearInputScore();
            });
            AppComponent.GobalComponent.successMsg("删除课程成绩成功!");
        
        });
    });
  }

  deleteByCourse(){
    if(this.item && this.item.status!=this.applyStatus.TO_FIRST_AUDIT_1&& this.item.status != 7&& this.item.status != 8){
      AppComponent.alert({title:"信息提示",text:"毕业申请单状态不是待现场确认，不允许操作!"});
      return;
    }
    
    if (!this.scorelRadioItem) {
      AppComponent.alert({title:"信息提示",text:"请选择一门课程!"});
      return;
    }

      let parm = {
        id: this.scorelRadioItem.byscore_id    
      };

      AppComponent.confirm("确定删除毕业课程吗?",()=>{
        FrameRequest.request("by/byScore/deleteByCourse.htm", parm, async ()=>{
            //刷新成绩显示
            FrameRequest.requestArray(this.QUERY_BYSCORE_URL, {id: this.item.id}, (arrary) => {
              this.scoreList = arrary;
              this.scorelRadioItem = undefined;
              this.turnInScore = undefined;
              this.replRadioItem = undefined;
              this.clearInputScore();
            });
            AppComponent.GobalComponent.successMsg("删除毕业课程成功!");
        
        });
    });
  }

  // 毕业合格校验
  checkBy() {
    AppComponent.GobalComponent.setLoading(true);
    FrameRequest.requestEntity("by/byApply/checkBy.htm", {id: this.item.id}, (entity)=>{
      AppComponent.GobalComponent.setLoading(false);
      if (entity == "success") {
        AppComponent.alert({title:"信息提示(仅供参考)",text:"考生符合毕业条件!"});
      } else {
        AppComponent.alert({title:"信息提示(仅供参考)",text:entity});
      }
    });
  }

  clearInputScore (){
    this.inputScore.course_code="";
    this.inputScore.course_name="";
    this.inputScore.final_score="";
    this.inputScore.course_score="";

    this.inputScore.course_code2="";
    this.inputScore.course_name2="";
    this.inputScore.final_score2="";
    this.inputScore.course_score2="";

    this.inputScore.course_code3="";
    this.inputScore.course_name3="";
    this.inputScore.final_score3="";
    this.inputScore.course_score3="";

    this.inputScore.course_code4="";
    this.inputScore.course_name4="";
    this.inputScore.final_score4="";
    this.inputScore.course_score4="";

    this.inputScore.course_code5="";
    this.inputScore.course_name5="";
    this.inputScore.final_score5="";
    this.inputScore.course_score5="";
  }



  

  showAssoDialog(templateModal, asso_ticket_no,course_code) {
    
    this.assoWin = this.bsModalService.show(templateModal, { class: "modal-lg" });
    //查询
    let params = {
      ticket_no: asso_ticket_no,
     
      course_code: course_code
    }
    FrameRequest.requestArray("kj/kjUnifiedScoreDetail/queryZhuankaozhuanruByTicketno.htm", params, (arrary)=>{
      this.assoScoreList = arrary;
    });
  }

  showAssoDialog2(templateModal, asso_ticket_no,course_code) {
    
    this.assoWin2 = this.bsModalService.show(templateModal, { class: "modal-lg" });
    //查询
    let params = {
      ticket_no: asso_ticket_no,
     
      course_code: course_code
    }
    FrameRequest.requestArray("kj/kjUnifiedScoreDetail/pageCourseScoreByAsso.htm", params, (arrary)=>{
      this.assoScoreList = arrary;
    });
  }

  downByFile(by_file){
    window.open(by_file);
  }


  // 身份证照片界面
  showIdCardDialog(templateModal) {
    
    this.idCardWin = this.bsModalService.show(templateModal, { class: "modal-lg" });
    
  }

  showUploadImgDialog(templateModal) {
    
    this.uploadImgWin = this.bsModalService.show(templateModal, { class: "modal-lg" });
    
  }

  downloadIdCardPhoto(){
    
    let mess = "";
    if(this.item.idcard_photo_path){
      mess = "身份证照片已经存在，确定重新更新身份证照片吗？";
    }else{
      mess = "确定更新身份证照片吗？";
    }

    AppComponent.confirm(mess,()=>{
      FrameRequest.request('std/stdRegInfo/downloadIdCardPhoto.htm',{std_id:this.item.std_id}, (resp) => {
        if(resp.success){
          if(resp.errorMsg){
            AppComponent.GobalComponent.errorMsg(resp.errorMsg);
        
          }else{
            this.item.idcard_photo_path = resp.entity.idcard_photo_path;
            AppComponent.GobalComponent.successMsg('下载身份证照片成功!');
          }
        }else{
          AppComponent.GobalComponent.errorMsg(resp.errorMsg);
         
        }
       }
     )

    });

    
  }


  showImg(editFormTemplateModal,path) {
    this.file_path = path;
    this.curr_id = path;
    this.current =0;
   
    let css = "modal-lg";
    this.bsModalWin2 = this.bsModalService.show(editFormTemplateModal, { class: css });
  
  }
  
  rotate(i){
  
    var imge = document.getElementById(this.curr_id);
    if(i ==0){
      this.current = (this.current-90)%360
    }else if(i ==1){
      this.current = (this.current+90)%360
    }
  
    
  
  imge.style.transform='rotate('+this.current+'deg)';
  
  if(imge.offsetWidth>imge.offsetHeight){
    imge.style.marginTop = (imge.offsetWidth-imge.offsetHeight)/2+"px";
  
  }
    
  }


  showImgTable(editFormTemplateModal) {
    let css = "modal-lg";
    this.bsModalWin3 = this.bsModalService.show(editFormTemplateModal, { class: css });
  
  }

}