import { Component, OnInit } from '@angular/core';
import {FormBuilder} from '@angular/forms';
import {BsModalRef} from 'ngx-bootstrap/modal';
import { FrameDetailComponent } from '../../../frame/core/detail/frame.detail';
import { MsgService } from '../../../../core/service/msg.service';
import {ModalService} from '../../../../core/service/modal.service';

@Component({
  selector: 'app-cf-material-feedback',
  templateUrl: './material-feedback.component.html',
  styleUrls: ['./material-feedback.component.scss']
})
export class CfMaterialFeedBackComponent extends FrameDetailComponent implements OnInit {


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

  step = 'page';

  ngOnInit() {


  }

  goAdd() {
    this.step = 'add';
    this.currentEntity.feedback_msg=null;
    this.currentEntity.feed_id=null;
  }

  goPage() {
    this.step = 'page';
  }

  save() {
    if (!this.currentEntity.feedback_msg) {
      MsgService.errorAlert('请输入材料反馈内容');
      return;
    }
    const _this = this;
    this.currentEntity.material_def_id = this.ResponseEntity.material_def_id;
    this.AjaxService.request('cf/material/feedback/add.htm', this.currentEntity, (ret) => {
      _this.step = 'page';
      _this.pager.reload();
    });
  }

  goEdit(param:any) {
    this.currentEntity=param;
    this.step = 'edit';
  }

  update() {
    if (!this.currentEntity.feedback_msg) {
      MsgService.errorAlert('请输入材料反馈内容');
      return;
    }
    const _this = this;
    this.AjaxService.request('cf/material/feedback/edit.htm', this.currentEntity, (ret) => {
      _this.step = 'page';
      _this.pager.reload();
    });
  }

  doUploadFile() {
    // 线程参数 和 业务参数
    const reqParam = {
      thread_name: '初始导入线程',
      error_flag: 'InActive',
      callback_type: 'Swal',
      material_def_id: this.ResponseEntity.material_def_id
    };
    // 上传参数
    const uploadParam = {
      uploadTitle: '数据导入',
      templateFile: 'ImpFeedback.xlsx',
      uploadCallback: this.uploadWithThreadCallback.bind(this),
      autoClose: true
    };
    ModalService.showUploadWindow(this.framePageComponent.bsService, './cf/material/feedback/upload.htm', reqParam, uploadParam);
  }

  uploadWithThreadCallback(ajax) {
   // MsgService.successToastr('导入成功!');
    this.pager.reload();
  }
}
