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

@Component({
  selector: 'app-std-score-review',
  templateUrl: './std-score-review.component.html',
  styleUrls: ['./std-score-review.component.scss']
})
export class StdScoreReviewComponent extends FlexTableComponent implements OnInit {

  public query = {
    std_name: "",
    cert_no: "",
    ticket_no: "",
    year_code: "",
    status:"",
  };

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

  constructor(public bsModalService: BsModalService, fb: FormBuilder) {
    super();
    // CustomValidators.rangeLength([1, 6])
    this.formModel = fb.group({
      id: [null],
      result: [null, Validators.compose([Validators.required])],
     // status: [null, Validators.compose([Validators.required])],
    });
  }

  ngOnInit() {

  }

  courses = [];

  async preGoEditEvent(entity?): Promise<boolean> {
   if(entity) await FrameRequest.requestArray("/std/stdScoreReviewCourse/list.htm", {p_id: entity.id}, async (array) => {
      this.courses = array;
    })
    return super.preGoEditEvent(entity);
  }

  audit (){
      if(this.item.status!="待受理"){
        AppComponent.alert({title:"信息提示",text:"当前成绩复核申请单的审核状态不是待受理，不允许受理!"});
        return false;
    }

        if(this.item.fee_status!="已缴费"){
          AppComponent.alert({title:"信息提示",text:"当前成绩复核申请单未缴费，不允许受理!"});
          return false;
      }

      AppComponent.confirm("确定完成成绩复核受理吗?",()=>{
        super.save();
    });
  }

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

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

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

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

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

    param.std_name = this.query.std_name;
    param.cert_no = this.query.cert_no;
    param.ticket_no = this.query.ticket_no;
    param.year_code = this.query.year_code;
    param.status = this.query.status;
  }



  carouselContentFilter(str) {
    
    if(str){
        var carContent ='';
        if(str.length >= 30){
           
            carContent = str.substring(0,30) + '...';
        }
        else {
            carContent = str
        }
        return carContent;
    }else{
      return str;
    }
}

}
