<div class="panel panel-default">
  <div>
    <!--标题-->
    <div class="panel-title">
      <nav aria-label="breadcrumb">
        <ol class="breadcrumb">
          <li class="breadcrumb-item">特殊报考</li>
          <li class="breadcrumb-item active" aria-current="page">考场场次管理</li>
        </ol>
      </nav>
    </div>
  </div>

  <div class="panel-body ml-sm " [hidden]="editShowType=='only'">
    <!--查询条件-->
    <div class="row mb-3 ml-1" [hidden]="editShowType=='only'">
      <div class="col-lg-12">
        <form (ngSubmit)="framePager.goSearch()" class="form-inline">
          <!-- 支持排序 -->
          <div class="input-group mr-1 input-group-sm">
            <label>关键字：</label>
            <input name="query" [(ngModel)]="query.query" class="input-sm form-control" type="text" value="" maxlength="64"
              placeholder="请输入查询关键字">
          </div>
          <div class="input-group mr-1 input-group-sm">
            <label>考试日期：</label>
            <select name="exam_time_id" [(ngModel)]="query.exam_time_id" class="form-control">
              <option value="">请选择</option>
              <option *ngFor="let item of examtimeList" [value]="item.id">{{item.exam_year_month}}</option>
            </select>
            <button class="btn btn-primary btn-rounded btn-outline btn-sm  mr-1" (click)="framePager.goSearch()">
              <i class="fa fa-search"></i> 查询</button>
          </div>
        </form>
      </div>
    </div>

    <!-- 工具栏 -->
    <div class="row mb-2" [hidden]="editShowType=='only' ">
      <div class="col-lg-12">
        <div class="pull-left">
          <button class="btn mr-1 btn-sm bg-danger" (click)="delete()" data-toggle="tooltip" data-placement="left"
            title="删除">
            <i class="fa fa-trash"> 删除</i>
          </button>
        </div>

      </div>
    </div>

    <!--表格-->
    <div class="row" [hidden]="editShowType=='only'">
      <div class="col-sm-12 ml-0">
        <table class="table table-sm table-striped table-hover table-bordered bg-white">
          <thead>
            <tr>
              <th>
                <div class="checkbox c-checkbox">
                  <label>
                    <input type="checkbox" (change)="framePager.checkedMasterToggle($event)" />
                    <span class="fa fa-check"></span>
                  </label>
                </div>
              </th>
              <th>年度码</th>
              <th>批次代码</th>
              <th>考点名称</th>
              <th>场次</th>
              <th>场次容量(人)</th>
              <th>开考时间</th>
              <th>结束时间</th>
              <th>考试课程</th>
              <th>备注</th>
              <th style="width: 80px;" align="center">操作</th>
            </tr>
          </thead>
          <tbody>
            <tr *ngFor="let item of framePager.getRecords(); let i = index">
              <td>
                <div class="checkbox c-checkbox input-group-sm">
                  <label>
                    <input type="checkbox" [value]="item.id" [(checked)]="item.isChecked" [(ngModel)]="item.isChecked" />
                    <span class="fa fa-check"></span>
                  </label>
                </div>
              </td>
              <td>{{item.year_month}}</td>
              <td>{{item.batch_code}}</td>
              <td>{{item.batch_name}}</td>
              <td>第{{item.room_num}}场</td>
              <td>{{item.room_capacity}}</td>
              <td>{{item.start_time}}</td>
              <td>{{item.end_time}}</td>
              <td>{{item.course_full_name}}</td>
              <td>{{item.remark}}</td>
              <td align="center">
                <a href="#" *ngIf="item.id>0" frameRole res="major_manage" (click)="goEdit(editTemplateModal,'only','modal-lg',item)"
                  title="编辑"><em class="fa-lg fas fa-edit mr-1"></em></a>
                <a href="#" *ngIf="item.id>0" frameRole res="major_manage" (click)="delete(item)" title="删除"><em class="fa-lg fas fa-trash mr-1"
                    style="color:#F56D6D"></em></a>
              </td>
            </tr>
          </tbody>
        </table>
        <frame-pager [url]="QUERY_URL" hideSearch="true" hasCheck="true" #framePager (preReqEvent)="search($event)"></frame-pager>
      </div>
      <!-- 编辑页面 -->
      <div class="col-lg-12" *ngIf="item && editShowType != null &&editShowType=='show'">
        <ng-container *ngTemplateOutlet="editTemplateModal">
        </ng-container>
      </div>

    </div>
  </div>
  <!-- only编辑页面-->
  <div class="col-lg-12" *ngIf="item && editShowType != null &&editShowType =='only'">
    <ng-container *ngTemplateOutlet="editTemplateModal">
    </ng-container>
  </div>

</div>


<!-- 编辑页面 -->
<ng-template #editTemplateModal>
  <div class="modal-content">
    <div class="modal-header info-success-qm">
      <div class="pull-left">
        <em class="fa-lg fas fa-edit "></em> <span *ngIf="item?.id">编辑</span> <span *ngIf="!item?.id">新增</span> 批次
      </div>

      <button type="button" class="close" (click)="hideModal()">×</button>
    </div>

    <div class="modal-body">
      <div [ngTemplateOutlet]="editFormTemplate"></div>

    </div>
    <div class="modal-footer">
      <button class="btn btn-info" (click)="save()">
        <i class="fa fa-info-circle"> </i> 保存
      </button>
      <button class="btn btn-default" (click)="hideModal()">
        <i class="icon-close"> </i> 取消
      </button>
    </div>
  </div>
</ng-template>

<ng-template #editFormTemplate>
  <form [formGroup]="formModel" *ngIf="item" (ngSubmit)="save()" class="form-validate form-horizontal" novalidate>
    <input type="hidden" formControlName="id" [formControl]="formModel.controls['id']" />
    <div class="row mt-3">
      <label class="col-lg-2 col-form-label text-lg-right">场次容量</label>
      <div class="col-lg-4">
        <div class="input-group">
          <input class="form-control" type="number" formControlName="room_capacity" [formControl]="formModel.controls['room_capacity']"
            [(ngModel)]="item.room_capacity" />
          <div class="input-group-append">
            <div class="input-group-text">人</div>
          </div>
        </div>
        <span class="text-danger" *ngIf="formModel.get('room_capacity').hasError('required') && (formModel.get('room_capacity').dirty || formModel.get('room_capacity').touched)">请填写场次容量</span>
      </div>
      <label class="col-lg-2 col-form-label text-lg-right">考试课程</label>
      <div class="col-lg-4">
        <flex-select [allowClear]="true" [url]="SPECIAL_COURSE_URL" respDataPath="array" optionValueField="id"
          optionTextField="code_course_name" [(ngModel)]="item.course_id" placeholder="请选择" noResultsFound="无数据"
          formControlName="course_id" [formControl]="formModel.controls['course_id']" width="200">
        </flex-select>
        <span class="text-danger" *ngIf="formModel.get('course_id').hasError('required') && (formModel.get('course_id').dirty || formModel.get('course_id').touched)">请选择考试课程</span>
      </div>
    </div>

    <div class="row mt-3">
      <label class="col-lg-2 col-form-label text-lg-right">考试开始时间</label>
      <div class="col-lg-4">
        <div class="input-group">
          <input class="form-control" type="text" formControlName="start_time" [formControl]="formModel.controls['start_time']"
            [(ngModel)]="item.start_time" readonly DateTimePicker [dpType]="'time'" [dpValue]="'item.start_time'" />
          <div class="input-group-append">
            <div class="input-group-text"><i class="icon-calendar"></i></div>
          </div>
        </div>
        <span class="text-danger" *ngIf="formModel.get('start_time').hasError('required') && (formModel.get('start_time').dirty || formModel.get('start_time').touched)">请填写考试开始时间</span>
      </div>

      <label class="col-lg-2 col-form-label text-lg-right">考试结束时间</label>
      <div class="col-lg-4">
        <div class="input-group">
          <input class="form-control" type="text" formControlName="end_time" [formControl]="formModel.controls['end_time']"
            [(ngModel)]="item.end_time" readonly DateTimePicker [dpType]="'time'" [dpValue]="'item.end_time'" />
          <div class="input-group-append">
            <div class="input-group-text"><i class="icon-calendar"></i></div>
          </div>
        </div>
        <span class="text-danger" *ngIf="formModel.get('end_time').hasError('required') && (formModel.get('end_time').dirty || formModel.get('end_time').touched)">请填写考试结束时间</span>
      </div>
    </div>

    <div class="row mt-3">
      <label class="col-lg-2 col-form-label text-lg-right">备注</label>
      <div class="col-lg-10">
        <textarea class="form-control" [(ngModel)]="item.remark" rows="5" formControlName="remark" [formControl]="formModel.controls['remark']"></textarea>
      </div>
    </div>


  </form>
</ng-template>