
import { FormBuilder, Validators } from '@angular/forms';
import { CustomValidators } from 'ng2-validation';
import { BsModalService } from "ngx-bootstrap/modal";

import * as _ from 'lodash';
import { FlexTableComponent } from '../../../../shared/common/FlexTable.component';
import { OnInit, Component } from '@angular/core';

import { FrameRequest } from '../../../../shared/frame/frame-request';
import { AppComponent } from '../../../..';

//审批状态
const APPLY_STATUS = {
    NEW: 0,//草稿
    LOCAL_VERIFY: 1,//待现场验证
    PROV_VERIFY:2,//待省级验证
    ARCHIVE:3//归档
};

@Component({
    selector: 'pre_edu_apply_Local',
    templateUrl: './pre_edu_apply.componentLocal.html',
    styleUrls: ['./pre_edu_apply.componentLocal.scss']
})
export class PreEduApplyComponentLocal extends FlexTableComponent implements OnInit {

    public query = {
        "std_name": "",
        "std_cert_no": "",
        "cert_type_id": "",
        "cert_no": "",
    };

    QUERY_URL = "mk/mkPreEduApply/page.htm?status=1";
    DELETE_URL = "mk/mkPreEduApply/delete.htm";
    GET_URL = "mk/mkPreEduApply/get.htm";
    ADD_URL = "mk/mkPreEduApply/add.htm";
    EDIT_URL = "mk/mkPreEduApply/edit.htm";
    GO_VERIFT_URL = "mk/mkPreEduApply/goVerify.htm";



    APPLY_VERIFY_URL = "mk/mkPreEduApply/verify.htm";
    CERT_TYPE_List_URL= "mk/mkCertType/listAll.htm";

    bsModalWin_verify : any;
    certTypeList = [];

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

        FrameRequest.requestArray(this.CERT_TYPE_List_URL, {type: 1}, (array) => {
            this.certTypeList = array;
          });
    
    }

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

        FrameRequest.requestEntity(this.GET_URL, {id: checkedArray[0].id}, (entity) => {
            this.item = entity;
            this.editShowType = 'only';
            // this.shouModalWin_verify(tpl);
            
         });
    }

    async shouModalWin_verify(editFormTemplateModal, modalcss?) {
        if(!this.item) this.item = {};
        let css = modalcss ? modalcss : "modal-lg";//big_modal modal-lg
        this.bsModalWin= this.bsModalService.show(editFormTemplateModal, { class: css });
    }

    //现场审批
    saveVerify(){
        if(!(this.item.status+"")){
            AppComponent.alert({title:"信息提示",text:"请填写审批状态!"});
            return
        }
        if(!this.item.verify1_remark || this.item.verify1_remark.lengh == 0){
            AppComponent.alert({title:"信息提示",text:"请填写审批意见!"});
            return
        }
        let verfiyStatus;
        switch (this.item.status) {
            case "0":
                verfiyStatus = APPLY_STATUS.NEW
                break;
            case "1":
                verfiyStatus = APPLY_STATUS.PROV_VERIFY
                break;
            default:
                break;
        }
        FrameRequest.requestMap(this.APPLY_VERIFY_URL, 
            { apply_id: this.item.id, status: verfiyStatus,verify1_remark:this.item.verify1_remark}, (map) => {
                AppComponent.alert({title:"信息提示",text:"审批提交成功!"});
                this.hideModal();
               this.framePager.reload();
         });
    }
    
  

}


