import { FlexTableComponent } from "./../../../../shared/common/FlexTable.component";
import { Component, OnInit } from "@angular/core";
import { FormBuilder, Validators } from "@angular/forms";
import { CustomValidators } from "ng2-validation";
import { BsModalService } from "ngx-bootstrap/modal";
import { AppComponent } from "../../../..";
import { FrameRequest } from "../../../../shared/frame/frame-request";
import * as _ from 'lodash';

@Component({
    selector: "app-std-info-modify-loc",
    templateUrl: "./std-info-modify.loc.component.html",
    styleUrls: ["./std-info-modify.loc.component.scss"]
})
export class StdInfoModifyLocComponent extends FlexTableComponent implements OnInit {

    ngOnInit() {
       // this.query.is_his = "0";
        this.query.status="1";
      }

    isActive=0;
    status=0;

    query = {
        "std_name": "",
        "cert_no": "",
        "ticket_no": "",
        //"is_his":"1",
        "status":""
    };

    QUERY_URL = "std/stdInfoModifyApply/page.htm";
    DELETE_URL = "std/stdInfoModifyApply/delete.htm";
    GET_URL = "std/stdInfoModifyApply/get.htm";
    ADD_URL = "std/stdInfoModifyApply/add.htm";
    EDIT_URL = "std/stdInfoModifyApply/edit.htm";

    constructor(public bsModalService: BsModalService, fb: FormBuilder) {
        super();
        this.formModel = fb.group({
            id: [null],
            'std_name': [null],
            'cert_no': [null],
            'ticket_no': [null],
            'modify_content': [null],
            'status': [null],
            'apply_time': [null],
            'modify_remark': [null],
            'verify_person1': [null],
            'verify_time1': [null],
            'verify_remark2': [null],
            'verify_person2': [null],
            'verify_time2': [null],
            'verify_remark1': [null],
        });
    }

    transModifyContent(val) {
        if (val == 1) {
            return "姓名";
        } else if (val == 2) {
            return "身份证号";
        } else if (val == 3) {
            return "照片";
        } else if (val == 4) {
            return "身份证号，照片";
        } else if (val == 5) {
            return "身份证号，姓名";
        }else if (val == 6) {
            return "姓名，照片";
        }
    }

    search(param) {
        
        let searchCondition = this.query;
        _.assignIn(param,searchCondition);
      //  param.status = 1;
        
        //if(param.is_his == 0){
           
        //    if(!this.query.cert_no.trim() && !this.query.std_name.trim() && !this.query.ticket_no.trim()){
        //        AppComponent.alert({title:"信息提示",text:"请输入考生查询条件"});
        //        param['rtn'] = true;
                
        //    }else{
         //       param['rtn'] = false;
        //    }
      //  }else{
      //      param['rtn'] = false;
      //  }

    }

    searchData(){
        if(this.query.status == "1"){
            if(!this.query.cert_no.trim() && !this.query.std_name.trim() && !this.query.ticket_no.trim()){
                AppComponent.alert({title:"信息提示",text:"请输入查询条件"});
                return;  
            }
        }
        

        this.framePager.reload();
    }

    doreset() {
        
        this.query.cert_no='';
        this.query.std_name='';
        this.query.ticket_no='';
       // this.query.is_his='1';

        

    }
    
    goVerify(tpl, item?) {
        if(!item){
            let items = this.framePager.getCheckedArray();
            if(items.length == 0){
                AppComponent.alert({title:"信息提示",text:"请选择操作数据!"});
                return;
            }

            if(items.length > 1){
                AppComponent.alert({title:"信息提示",text:"只运行选择单条数据!"});
                return;
            }
        }
        AppComponent.GobalComponent.setLoading(true);
        this.status = item.status;
        FrameRequest.requestMap("std/stdInfoModifyApply/toVerify.htm", {apply_id:item.id}, (map) => {
            let url = map.url;
            let apply = map.apply;
            let std = map.std;
            let http_url = map.http_url;

            apply.old_std_name = apply.old_std_name || "";
            apply.old_cert_no = apply.old_cert_no || "";
            if( apply.face_file_path){
                apply.face_file_path_full = url + apply.face_file_path;
               }

            if(apply.old_photo_path){
            apply.old_face_file_path_full = http_url + apply.old_photo_path;
            }
            apply.cert_file_path_full = url + apply.cert_file_path;

            this.item = apply;
            this.bsModalWin = this.bsModalService.show(tpl, { class: "modal-lg" });
            AppComponent.GobalComponent.setLoading(false);
        });
    }

    //现场审批
    saveVerify(){
        if(!String(this.item.status)){
            AppComponent.alert({title:"信息提示",text:"请填写审批状态!"});
            return
        }
        if(String(this.item.status) == "0" && (!this.item.verify_remark1 || this.item.verify_remark1.lengh == 0)){
            AppComponent.alert({title:"信息提示",text:"拒绝请填写审批意见!"});
            return
        }

        if(!this.item.verify_remark1 || this.item.verify_remark1.lengh == 0){
            AppComponent.alert({title:"信息提示",text:"请填写审批意见!"});
            return;
        }
        let verify_url;
        switch (this.item.status) {
            case "0":
                verify_url = "std/stdInfoModifyApply/refuse.htm";
                break;
            case "1":
                verify_url = "std/stdInfoModifyApply/verifyPass.htm";
                break;
            default:
                break;
        }
        FrameRequest.requestMap(verify_url, 
            { apply_id: this.item.id,verify_remark1:this.item.verify_remark1}, (map) => {
                AppComponent.alert({title:"信息提示",text:"审批提交成功!"});
                this.hideModal();
               this.framePager.reload();
         });
    }

    downWord(){
        let checkArray = this.framePager.getCheckedArray((item) => item.id);

        if(checkArray.length == 0){
          AppComponent.alert({title:"信息提示",text:"请单选考生信息变更申请单!"});
          return;
        }

        AppComponent.confirm("请不要忘记审核上报考生信息变更申请单",()=>{
            FrameRequest.download("std/stdInfoModifyApply/downloadApply.htm",{ids:checkArray.join()}, ()=>{
                AppComponent.GobalComponent.setLoading(false);
                AppComponent.GobalComponent.successMsg("下载成功");
            });
        });   

        
    }


    changeRemark(remark){
        this.item.verify_remark1=remark;
    }


    
    
  changeLi(event,index,status){
    //点击时，将索引值赋值给变量isActive可以实现点击切换样式
    this.isActive = index;
    
    this.query.status = status;
    this.framePager.reload();

  }
}
