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

@Component({
  selector: 'app-std-reg-custom-export',
  templateUrl: './std-reg-custom-export.component.html',
  styleUrls: ['./std-reg-custom-export.component.scss']
})
export class StdRegCustomExportComponent extends FrameDetailComponent implements OnInit {

  fields = [
    { field_name: '证件类型', field_value: 'cert_type', checked: false },
    { field_name: '证件号码', field_value: 'cert_id', checked: false },
    { field_name: '考生姓名', field_value: 'std_name', checked: false },
    { field_name: '考生号', field_value: 'exam_id', checked: false },
    { field_name: '应往届', field_value: 'std_type', checked: false },
    { field_name: '生源地', field_value: 'std_province', checked: false },
    { field_name: '是否本省考生', field_value: 'province_flag', checked: false },
    { field_name: '注册时间', field_value: 'reg_time', checked: false },
    { field_name: '考生性别', field_value: 'std_sex', checked: false },
    { field_name: '考生电话', field_value: 'std_mobile', checked: false },
    { field_name: '备用电话', field_value: 'link_mobile', checked: false },
    { field_name: '毕业高中', field_value: 'std_school', checked: false },
    { field_name: '邮政编码', field_value: 'link_postal', checked: false },
    { field_name: '联系地址', field_value: 'link_addr', checked: false },
    { field_name: '联系人', field_value: 'link_man', checked: false },
    { field_name: '考生民族', field_value: 'std_nation', checked: false },
    { field_name: '证件地址', field_value: 'cert_addr', checked: false },
    { field_name: '考试确认', field_value: 'std_admit_flag', checked: false },
    { field_name: '大头照地址', field_value: 'std_image', checked: false }
  ]


  constructor(bsModalRef: BsModalRef) {
    super(bsModalRef);
  }

  ngOnInit() {
  }


  selectAll(b) {
    for (const v of this.fields) {
      v.checked = b;
    }
  }

  export() {
    let array = [];
    let fieldArr = [];
    let titleArr = [];
    for(const arr of this.fields ) {
      if(arr.checked) {
        array.push(arr);
        titleArr.push(arr.field_name);
        fieldArr.push(arr.field_value);
      }
    }
    if(array.length < 1) {
      MsgService.errorToastr('请至少选择一个导出字段！');
      return ;
    }
    AjaxService.requestEntity('std/reg/export/custom.htm', {
      fields: fieldArr,
      titles: titleArr
    }, (entity) => {
      ModalService.showThreadWindow(this.framePageComponent.bsService, entity, {threadTitle: '正在整理数据，请稍候'});
    });
  }


}
