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-textattr',
  templateUrl: './material-textattr.component.html',
  styleUrls: ['./material-textattr.component.scss']
})
export class CfMaterialTextAttrComponent extends FrameDetailComponent implements OnInit {


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

  step = "page";

  ngOnInit() {


  }

  goAdd() {
    this.step = "add";
    this.currentEntity.attr_name='';
    this.currentEntity.attr_requrid='';
    this.currentEntity.attr_formart='';
  }

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

  save() {
    if (!this.currentEntity.attr_name) {
      MsgService.errorAlert("请输入补充项目");
      return;
    }
    if (!this.currentEntity.attr_requrid) {
      MsgService.errorAlert("请选择是否必填");
      return;
    }
    if (!this.currentEntity.attr_formart) {
      MsgService.errorAlert("请选择格式");
      return;
    }
    let _this = this;
    this.currentEntity.material_def_id = this.ResponseEntity.material_def_id;
    this.AjaxService.request("cf/material/textattr/add.htm", this.currentEntity, (ret) => {
      debugger;
      _this.step = "page";
      _this.pager.reload();
    });
  }

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

  update() {
    if (!this.currentEntity.attr_name) {
      MsgService.errorAlert("请输入补充项目");
      return;
    }
    if (!this.currentEntity.attr_requrid) {
      MsgService.errorAlert("请选择是否必填");
      return;
    }
    if (!this.currentEntity.attr_formart) {
      MsgService.errorAlert("请选择格式");
      return;
    }

    let _this = this;
    this.AjaxService.request("cf/material/textattr/edit.htm", this.currentEntity, (ret) => {
      debugger;
      _this.step = "page";
      _this.pager.reload();
    });
  }

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

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