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

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

  constructor(bsModalRef: BsModalRef, fb: FormBuilder) {
    super(bsModalRef);
    this.detailForm = fb.group({
      'page_width': [null, Validators.compose([Validators.required, Validators.min(50), Validators.max(1000)])],
      'page_height': [null, Validators.compose([Validators.required, Validators.min(50), Validators.max(1000)])],
      'page_margin': [null, Validators.compose([Validators.required])],
      'page_rows': [null, Validators.compose([Validators.required, Validators.min(1), Validators.max(50)])],
      'page_columns': [null, Validators.compose([Validators.required, Validators.min(1), Validators.max(20)])],
      'row_margin': [null, Validators.compose([Validators.required, Validators.min(1), Validators.max(200)])],

      'page_horizontal': [null, Validators.compose([Validators.required])],

      // 门贴
      'room_name_flag': [null, Validators.compose([Validators.required])],
      'room_name_font': [null],
      'room_addr_flag': [null, Validators.compose([Validators.required])],
      'room_addr_font': [null],
      // 是否显示准考证
      'ticket_flag': [null],
      'ticket_aspect_num': [null],
      'ticket_font': [null, Validators.compose([Validators.required])],
      // 科目名称
      'subject_name_flag': [null],
      'group_name_flag': [null],
      'subject_name_font': [null],
      // 是否显示准考证
      'school_name_flag': [null],
      'school_name_text': [null],
      'school_name_font': [null],
      // 桌贴：
      'std_margin_left': [null],
      'std_margin_top': [null],
      // 是否显示身份证号
      'cert_id_flag': [null],
      'cert_id_font': [null],
      // 是否显示考生姓名
      'std_name_flag': [null],
      'std_name_font': [null],
      // 是否显示考生性别
      'std_sex_flag': [null],
      'std_sex_font': [null],
      // 是否显示座位号
      'room_seq_flag': [null],
      'room_seq_font': [null],
      // 是否显示座位号
      'std_image_width': [null],
      'std_image_height': [null],
      // 切刀模式
      'cutter_flag': [null],
      // 卷袋颜色
      'bag_font_color': [null],


    });
  }

  goDownload(params) {
    debugger;
    if (this['thread_flag'] === undefined || params.preview_flag === 'Active') {
      this.FuncService.ajaxDownload(this['download_url'], Object.assign({}, this.currentEntity, params));
    } else {
      // 线程模式
      AjaxService.requestEntity(this['download_url'], Object.assign({}, this.currentEntity, params), (entity) => {
        ModalService.showThreadWindow(this.framePageComponent.bsService, entity, {threadTitle: '正在整理数据，请稍候'});
        this.closeWindow();
      });
    }
  }


  initDefautEntity() {
    this.currentEntity.ag_subject_id = this['ag_subject_id'];
    this.currentEntity.ly_group_id = this['ly_group_id'];
    this.currentEntity.material_name = this['material_name'];
    this.currentEntity.download_url = this['download_url'];
    this.currentEntity.subject_id = this['subject_id'];
    // 是否是预览
    this.currentEntity.preview_flag = 'InActive';
    // 纸张宽度
    this.currentEntity.page_width = 210;
    // 纸张高度
    this.currentEntity.page_height = 297;
    // 页边距
    this.currentEntity.page_margin = '10px 10px 10px 10px';
    // 每页行数
    this.currentEntity.page_rows = 4;
    // 每页列数
    this.currentEntity.page_columns = 5;
    // 每页列数
    this.currentEntity.row_margin = 10;
    // 页面横排
    this.currentEntity.page_horizontal = 'InActive';
    // 是否显示第几考场
    this.currentEntity.room_name_flag = 'Active';
    // 第几场字体大小
    this.currentEntity.room_name_font = 14;
    // 是否显示考场地址
    this.currentEntity.room_addr_flag = 'Active';
    // 考场地址字体大小
    this.currentEntity.room_addr_font = 14;
    // 是否显示准考证证号
    this.currentEntity.ticket_flag = 'Active';
    // 准考证号类型，Active 表示专业考号，InActive表示准考证号
    this.currentEntity.ticket_aspect_num = FrameService.getParamValue('LayoutTicketAspectNum', 'Active');
    // 准考证字体大小
    this.currentEntity.ticket_font = 14;

    // 是否要显示科目名称
    this.currentEntity.subject_name_flag = 'Active';
    // 用分组名称代替科目名称
    this.currentEntity.group_name_flag = 'Active';
    // 科目名称字体大小
    this.currentEntity.subject_name_font = 14;

    // 是否显示学校名称
    this.currentEntity.school_name_flag = 'Active';
    // 学校名称
    this.currentEntity.school_name_text = FrameService.getParamValue('SchoolName');
    // 学校名称字体大小
    this.currentEntity.school_name_font = 14;

    // 是否显示考场名称
    this.currentEntity.room_name_flag = 'Active';
    // 考场名称字体大小
    this.currentEntity.room_name_font = 14;
    // 是否显示考场地址
    this.currentEntity.room_addr_flag = 'Active';
    // 考场地址字体大小
    this.currentEntity.room_addr_font = 14;

    this.currentEntity.cutter_flag = 'InActive';
    this.currentEntity.bag_font_color = '#e61515';


    if (this['material_name'] === '门贴') {
      // 纸张宽度
      this.currentEntity.page_width = 297;
      // 纸张高度
      this.currentEntity.page_height = 210;
      // 每页行数
      this.currentEntity.page_rows = 1;
      // 每页列数
      this.currentEntity.page_columns = 1;
      // 每页列数
      this.currentEntity.row_margin = 20;
      // 科目名称字体大小
      this.currentEntity.subject_name_font = 40;
      // 学校名称字体大小
      this.currentEntity.school_name_font = 40;
      // 科目名称字体大小
      this.currentEntity.room_name_font = 30;
      // 学校名称字体大小
      this.currentEntity.room_addr_font = 24;
      // 准考证字体大小
      this.currentEntity.ticket_font = 30;

      // 页边距
      this.currentEntity.page_margin = '80px 10px 10px 10px';

    }
    if (this['material_name'] === '桌贴') {
      // 纸张宽度
      this.currentEntity.page_width = 297;
      // 纸张高度
      this.currentEntity.page_height = 210;
      // 每页列数
      this.currentEntity.row_margin = -5;
      // 每页行数
      this.currentEntity.page_rows = 4;
      // 每页列数
      this.currentEntity.page_columns = 3;
      // 是否显示考场名称
      this.currentEntity.room_name_flag = 'InActive';
      this.currentEntity.page_margin = '10px 10px 10px 10px';
      this.currentEntity.std_margin_left = 20;
      this.currentEntity.std_margin_top = 25;
      // 默认不显示学校名称
      this.currentEntity.school_name_flag = 'InActive';

      // 是否显示身份证号
      this.currentEntity.cert_id_flag = 'Active';
      this.currentEntity.cert_id_font = 12;
      // 是否显示考生姓名
      this.currentEntity.std_name_flag = 'Active';
      this.currentEntity.std_name_font = 14;
      // 是否显示考生性别
      this.currentEntity.std_sex_flag = 'InActive';
      this.currentEntity.std_sex_font = 14;
      // 座位号
      this.currentEntity.room_seq_flag = 'Active';
      this.currentEntity.room_seq_font = 16;

      this.currentEntity.ticket_font = 18;
    }

    if (this['material_name'] === '桌贴(带照片)') {
      // 纸张宽度
      this.currentEntity.page_width = 297;
      // 纸张高度
      this.currentEntity.page_height = 210;
      // 每页列数
      this.currentEntity.row_margin = 0;
      // 每页行数
      this.currentEntity.page_rows = 4;
      // 每页列数
      this.currentEntity.page_columns = 4;
      // 是否显示考场名称
      this.currentEntity.room_name_flag = 'InActive';
      this.currentEntity.page_margin = '10px 10px 10px 10px';
      this.currentEntity.std_margin_left = 20;
      this.currentEntity.std_margin_top = 25;
      // 默认不显示学校名称
      this.currentEntity.school_name_flag = 'InActive';

      // 是否显示身份证号
      this.currentEntity.cert_id_flag = 'Active';
      this.currentEntity.cert_id_font = 11.5;
      // 是否显示考生姓名
      this.currentEntity.std_name_flag = 'Active';
      this.currentEntity.std_name_font = 16;
      // 是否显示考生性别
      this.currentEntity.std_sex_flag = 'InActive';
      this.currentEntity.std_sex_font = 14;
      // 座位号
      this.currentEntity.room_seq_flag = 'Active';
      this.currentEntity.room_seq_font = 16;

      this.currentEntity.ticket_font = 20;
      this.currentEntity.std_image_width = 60;
      this.currentEntity.std_image_height = 72;

      if (this['group_name'].length>8) {
        this.currentEntity.subject_name_font = 14;
        this.currentEntity.std_image_width = 128;
        this.currentEntity.std_image_height = 128;
      }
    }

    if (this['material_name'] === '卷袋') {
      // 纸张宽度
      this.currentEntity.page_width = 297;
      // 纸张高度
      this.currentEntity.page_height = 210;
      this.currentEntity.bag_font_color = '#e61515';
      // 每页列数
      this.currentEntity.row_margin = 10;
      // 每页行数
      this.currentEntity.page_rows = 3;
      // 每页列数
      if(this.ResponseArray.length == 1) {
        this.currentEntity.page_columns = 1;
      } else {
        this.currentEntity.page_columns = 2;
      }
      // 每页列数
      this.currentEntity.std_margin_left = 10;
      this.currentEntity.subject_name_font = 24;
      this.currentEntity.std_image_width = 128;
      this.currentEntity.std_image_height = 128;
      this.currentEntity.std_margin_left = 20;
      this.currentEntity.std_margin_top = 25;
      this.currentEntity.room_name_font = 18;
      this.currentEntity.ticket_font = 18;
    }

    if (this['material_name'] === '签字单') {
      // 纸张宽度
      this.currentEntity.page_width = 297;
      // 纸张高度
      this.currentEntity.page_height = 210;
      // 每页列数
      this.currentEntity.row_margin = 0;
      // 每页行数
      this.currentEntity.page_rows = 4;
      // 每页列数
      this.currentEntity.page_columns = 4;
      // 是否显示考场名称
      this.currentEntity.page_margin = '10px 10px 10px 10px';
      this.currentEntity.std_margin_left = 20;
      this.currentEntity.std_margin_top = 25;
      // 默认不显示学校名称
      this.currentEntity.school_name_flag = 'InActive';

      // 是否显示身份证号
      this.currentEntity.cert_id_flag = 'InActive';
      this.currentEntity.cert_id_font = 18;
      // 是否显示考生姓名
      this.currentEntity.std_name_flag = 'Active';
      this.currentEntity.std_name_font = 16;
      // 座位号
      this.currentEntity.room_seq_flag = 'Active';
      this.currentEntity.room_seq_font = 16;

      this.currentEntity.ticket_font = 20;
      this.currentEntity.std_image_width = 60;
      this.currentEntity.std_image_height = 72;
      this.currentEntity.subject_name_font = 22;
      this.currentEntity.room_name_flag = 'Active';
      this.currentEntity.room_addr_font = 14;
      this.currentEntity.school_name_font = 12;
    }

  }



  ngOnInit() {
  }

}
