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';


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

  constructor(bsModalRef: BsModalRef, fb: FormBuilder) {
    super(bsModalRef);
  }

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

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

  handleImageEvent(event) {

  }

  //明细通过
  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};
    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();
    });
  }
}
