import { Component, OnInit } from '@angular/core';
import { BsModalService } from 'ngx-bootstrap/modal';
import { ModalService } from 'src/app/core/service/modal.service';
import { MsgService } from 'src/app/core/service/msg.service';
import { FramePageComponent } from '../../../../frame/core/page/frame.page';



@Component({
  selector: 'app-std-tracks-page',
  templateUrl: './std-tracks-page.component.html',
  styleUrls: ['./std-tracks-page.component.scss']
})
export class StdTracksPageComponent extends FramePageComponent implements OnInit {

    schoolArray = [];
    batchArr = [];
    layout_status = "";
    query = {
      school_id : '',
      batch_id : ''
    };

  constructor(private modalService: BsModalService) {
    super(modalService);
    //this.modalComponent = MaterialVideoPageComponent;
  }

  ngOnInit(): void {
    this.AjaxService.requestArray('./cf/school/list.htm', {}, (array) => {
      this.schoolArray = array;
    });
  }

  changeSchool() {
    this.AjaxService.requestArray("./cf/batch/list.htm", {school_id : this.query.school_id}, (array)=>{
      debugger;
      this.batchArr = array;
    });    
  }

  requestData() {
    this.pager.reload({school_id : this.query.school_id, batch_id : this.query.batch_id});
  }

  showMaterials(v, target) {
   //this.showComponentModal(MaterialVideoPageComponent, { 'ResponseEntity': v });
  }

  //导入
  uploaStdTracks() {
    debugger;
    //线程参数 和 业务参数
    let reqParam = {
      thread_name: "导入曲目线程",
      error_flag: "InActive", 
      school_id : this.query.school_id,
      batch_id : this.query.batch_id,
      callback_type: "Swal"
    };
    //上传参数
    let uploadParam = {
      uploadTitle:'曲目材料导入',
      templateFile:'ExStdTracks.xls',
      uploadCallback: this.uploadWithThreadCallback.bind(this),
      autoClose:true
    };
    ModalService.showUploadWindow(this.bsService,'./ex/std/tracks/upload.htm', reqParam, uploadParam);    
  }

  uploadWithThreadCallback(ajax) {
    debugger;
    console.log("upload callback --->" + ajax.errorCode + " , " + ajax.url);
    if (ajax.errorCode != 0 && ajax.url) {
      MsgService.errorToastr("导入报错!");
    } else {
      MsgService.successToastr("导入成功!");
    }
    this.pager.reload();
  }

  //删除
  deleteStdTracks() {
    debugger;
    if (!this.query.school_id) {
      MsgService.errorToastr('请选择学校！');
      return;
    }
    if (!this.query.batch_id) {
      MsgService.errorToastr('请选择批次！');
      return;
    }
    MsgService.confirmAlert("确定删除该批次下导入数据吗?", () => {
      this.AjaxService.request("ex/std/tracks/delete.htm", {school_id: this.query.school_id, batch_id: this.query.batch_id}, (ret)=>{
        MsgService.successAlert('删除成功！');
        this.pager.reload();
      });
    });    
  }



}
