import { Component, OnInit } from '@angular/core';
import {FormBuilder, Validators} from '@angular/forms';
import {BsModalRef} from 'ngx-bootstrap/modal';
import { FrameDetailComponent } from '../../../frame/core/detail/frame.detail';
import { AjaxService } from '../../../../core/service/ajax.service';
import { FuncService } from '../../../../core/service/func.service';
import { MsgService } from '../../../../core/service/msg.service';
import { pdfDefaultOptions } from 'ngx-extended-pdf-viewer';

@Component({
  selector: 'app-cf-initial-review-pdf',
  templateUrl: './initial-review-pdf.component.html',
  styleUrls: ['./initial-review-pdf.component.scss']
})
export class InitialReviewPdfComponent extends FrameDetailComponent implements OnInit {
  pdfSrc = "";
  cMapsUrl = "";
  initial_remark = "";
  currReviewMsg = "";//常用审核
  reviewMsgArray = [];

  constructor(bsModalRef: BsModalRef, fb: FormBuilder) {
    super(bsModalRef);
    //(<any>window).pdfWorkerSrc = '/m/assets/plugins/pdfjs/pdf.worker.min.js';
  }

  ngOnInit() {
    //this.pdfSrc = "https://vadimdez.github.io/ng2-pdf-viewer/assets/pdf-test.pdf";
    this.pdfSrc = this.ResponseEntity.file_path;

    AjaxService.requestArray("cf/material/def/msg/list.htm", {material_def_id: this.ResponseEntity.material_def_id}, (array)=>{
      this.reviewMsgArray = array;
    });
  }

  changeReviewMsg() {
    this.initial_remark = this.initial_remark + this.currReviewMsg;
  }

  
  fileLoadCompeleted() {
  }

  onError() {
  }

  handleImageEvent() {

  }

//明细通过
doApproveDetail() {
  // if (this.initial_remark && this.initial_remark.trim().length > 0) {
  //   MsgService.errorAlert("审核意见不为空，不能通过");
  //   return;
  // }
  let _this = this;
  let param = {detail_ids: [this.ResponseEntity.detail_id], remark: this.initial_remark};
  MsgService.showLoading();
  AjaxService.request('review/initial/detail/approve.htm', param, (entity) => {
    MsgService.hideLoading();
    MsgService.successToastr("初审通过!");
    _this.closeWindow();
  });
}
//明细退回
doRejectDetail() {
  if (!this.initial_remark || this.initial_remark.trim().length == 0) {
    MsgService.errorAlert("请输入审核意见");
    return;
  }
  let _this = this;
  let param = {detail_ids: [this.ResponseEntity.detail_id], remark: this.initial_remark};
  MsgService.showLoading();
  AjaxService.request('review/initial/detail/reject.htm', param, (entity) => {
    MsgService.hideLoading();
    MsgService.successToastr("已退回!");
    _this.closeWindow();
  });
}
}
