import { Component, OnInit, TemplateRef, ViewChild } from "@angular/core";
import { FormBuilder, Validators } 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 { isNumber } from "util";

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

  public query = {
    query:"",
    is_net_exam: "",
    is_live_enrol: ""
  };

  public setObj = {
    id:"",
    is_net_exam: "",
    is_live_enrol: ""
  }


  @ViewChild('framePager')
  framePager:FramePagerComponent;

  QUERY_URL = "pl/plMajor/page.htm";
  EDITE_URL = "pl/plMajor/edit.htm";

  constructor(public bsModalService: BsModalService, fb: FormBuilder) {
    super();
  }

  ngOnInit() {

  }

  search(param) {
    if (!this.query.is_net_exam) {
      this.query.is_net_exam="";
    }
    if (!this.query.is_live_enrol) {
      this.query.is_live_enrol="";
    }
    param.is_net_exam=this.query.is_net_exam;
    param.is_live_enrol=this.query.is_live_enrol;
    param.query=this.query.query;
  }


  //设置网考
  netExamSetFunc() {
    let url = "pl/plMajor/updateNetExam.htm";
   // let checkedArray = this.framePager.getCheckedArray();
   // if (checkedArray.length == 0) {
   //   AppComponent.alert({title:"信息提示",text:"选择要设置的专业!"});
   //   return false;
   // }

    if (!this.setObj.is_net_exam) {
      AppComponent.alert({title:"信息提示",text:"选择选择网络报名!"});
      return false;
    }

    //if (!this.setObj.is_net_exam) {
   //   AppComponent.alert({title:"信息提示",text:"选择选择是否网考!"});
   //   return false;
   // }
   // let idArr = checkedArray.map((obj) => obj.id);

    FrameRequest.request(url, {ids:  this.setObj.id, yesOrNo: this.setObj.is_net_exam}, (ret)=>{
      if (ret.errorCode == 0) {
        this.framePager.reload();
        AppComponent.GobalComponent.successMsg('设置成功!');
        this.hideModal();
      }
    });
  }

  //现场报考
  liveEnrolSetFunc() {
    let url = "pl/plMajor/updateLiveEnrol.htm";
    let checkedArray = this.framePager.getCheckedArray();
    let arr = this.framePager.getCheckedArray();
    if (arr.length == 0) {
      AppComponent.alert({title:"信息提示",text:"选择要设置的专业!"});
      return false;
    }
    if (!this.setObj.is_live_enrol) {
      AppComponent.alert({title:"信息提示",text:"选择选择是否现场报考!"});
      return false;
    }
    let idArr = checkedArray.map((obj) => obj.id);
    FrameRequest.request(url, {ids: idArr, yesOrNo: this.setObj.is_live_enrol}, (ret)=>{
      if (ret.errorCode == 0) {
        this.framePager.reload();
        AppComponent.GobalComponent.successMsg('设置成功!');
        this.hideModal();
      }
    });
  }
}