<ng-container *ngIf="agent">
  <div class="content-heading  justify-content-between">
    <div>笔试编排 - {{agent?.ly_agent_name}}</div>
    <div class="float-right">
      <div class="row">
        <div>
          <input class="form-control mt-1" type="text" [(ngModel)]="searchText" placeholder="输入关键字进行搜索"/>
        </div>
        <div *ngIf="FrameService.getParamValue('ExamBatchs' , '1') > '1'" class="ml-3">
          <select class="form-control mt-1" [(ngModel)]="exam_batch">
            <option [value]="v.dict_value" *ngFor="let v of batchNameArray">{{v.dict_text}}</option>
          </select>
        </div>

        <div class="btn-group mb-1 mr-1 ml-3" dropdown>
          <button class="btn dropdown-toggle btn-secondary btn-lg" type="button" dropdownToggle>笔试编排功能
            <span class="caret"></span>
          </button>
          <div *dropdownMenu class="dropdown-menu modal-lg" role="menu">
            <a class="dropdown-item text-success" href="#"
               (click)="ajax.optrRecord('layout/agent/refresh.htm',{ly_agent_id: agent.ly_agent_id},{ successMsg:'编排数据已刷新！', showMsg: true}, {RequestWithLoading: true})">刷新数据</a>
            <div class="dropdown-divider"></div>
            <a class="dropdown-item" href="#" (click)="FuncService.ajaxDownload('frame/template/download.htm', {file_name: '模版-笔试考场.xls'})">下载考场模版</a>
          </div>
        </div>
      </div>
    </div>
  </div>

  <div class="card card-default" *ngIf="ajax && ajax.getMap() && ajax.getMap()['SingleArray']">
    <div class="row card-header justify-content-between">
      <div>
    <span class="table-button"
          (click)="showSingleGroup = (showSingleGroup === undefined || showSingleGroup)? false : true">
       <em class="fa-2x fas ml-2"
           [ngClass]="{'fa-angle-double-down': !showSingleGroup,'fa-angle-double-up':(showSingleGroup === undefined || showSingleGroup)}"></em> 未分组科目（{{ajax.getMap()['SingleArray'].length}}）
    </span>
      </div>
      <div class="float-right mr-5" [hidden]="showSingleGroup === false">
        <button class="btn btn-info" type="button" (click)="makeGroup()"> 科目分组</button>
      </div>
    </div>
    <table class="table table-striped table-hover table-bordered" [hidden]="showSingleGroup === false">
      <thead>
      <tr>
        <th class=""></th>
        <th>分组名称</th>
        <th>顺序</th>
        <th>考生数</th>
        <th>状态</th>
        <th>考试时间</th>
        <th>考场数</th>
        <th>桌贴类型</th>
        <th>预约</th>
        <th></th>
      </tr>
      </thead>
      <tbody>
      <tr
        *ngFor="let v of ajax.getMap()['SingleArray'] | arrayFilter:  searchText | attrFilter :{exam_batch: exam_batch}; let i = index">
        <td>
          <div class="form-check">
            <div class="checkbox c-checkbox">
              <label>
                <input type="checkbox" [(ngModel)]="v.checked"/>
                <span class="fa fa-check"></span>{{i + 1}}</label>
            </div>
          </div>
        </td>
        <td><span class="table-button"
                  [ngClass]="{'text-primary':(v.ly_status==='Complete' && v.room_total === undefined),'text-info':(v.ly_status==='Complete' && v.room_total >0),'text-success':(v.ly_status==='Publish')}"
                  (click)="showModal({'ResponseEntity':v, 'ResponseArray':ajax.getMap()['SubjectArray_' + v.ly_group_id]})"><span
          *ngIf="v.dept_name">{{v.dept_name}} - </span>{{v.group_name}}({{v.subject_id}})</span>
        </td>
        <td>{{v.ly_order}}</td>
        <td><span [tooltip]="'省内：' + v.province_std_total + '；省外：' + v.outside_std_total">{{v.group_std_total}}</span>
        </td>
        <td [innerHTML]="v.ly_status | frameDict:'LayoutGroupStatus'"
            [ngClass]="{'text-primary':v.ly_status==='Complete', 'text-success':v.ly_status === 'Publish'}"></td>
        <td> <span *ngIf="v.exam_start_time">
          {{FuncService.dateToShortString(v.exam_start_time)}} {{FuncService.dateToMinuteString(v.exam_start_time)}}-{{FuncService.dateToMinuteString(v.exam_end_time)}}</span>
        </td>
        <td>{{v.room_total}}</td>
        <td [innerHTML]="v.aspect_num_flag | frameStatusCustom:['专业考号','准考证号','text-danger', 'text-black']"></td>
        <td [innerHTML]="v.appointment_type | frameStatusCustom:['开放预约','不可预约','text-danger', 'text-black']"></td>

        <td>
          <div class="btn-group btn-group-sm" dropdown style="margin-top:-2px">
            <button class="btn dropdown-toggle btn-secondary btn-sm" type="button" dropdownToggle>分组操作
              <span class="caret"></span>
            </button>
            <div *dropdownMenu class="dropdown-menu" role="menu">
              <a class="dropdown-item" href="#" *ngIf="v.ly_status==='Init'"
                 (click)="showModal({'ResponseEntity':v, 'ResponseArray':ajax.getMap()['SubjectArray_' + v.ly_group_id]})">笔试编排</a>
              <a class="dropdown-item text-primary" href="#" *ngIf="v.ly_status==='Complete'"
                 (click)="showModal({'ResponseEntity':v, 'ResponseArray':ajax.getMap()['SubjectArray_' + v.ly_group_id]})">编排后编辑</a>
              <a class="dropdown-item text-primary" href="#" *ngIf="v.ly_status==='Publish'"
                 (click)="showModal({'ResponseEntity':v, 'ResponseArray':ajax.getMap()['SubjectArray_' + v.ly_group_id]})">发布后查看</a>

              <div class="dropdown-divider" *ngIf="v.ly_status!== 'Ready' "></div>
              <!-- <a class="dropdown-item" href="#"
                 *ngIf="v.ly_status === 'Ready' " (click)="uploader.uploadFiles( {ly_group_id: v.ly_group_id})">上传考场</a> -->

              <a class="dropdown-item" href="#"  *ngIf="v.ly_status === 'Ready' " (click)="ModalService.showUploadWindow(bsService,'layout/group/written/room/upload.htm',
              {ly_group_id: v.ly_group_id},{
                uploadTitle:'上传考场',
                templateFile:'模版-笔试考场.xls',
                uploadCallback:uploadCallback.bind(this),
                autoClose:true
              })">上传考场</a>   

              <div class="dropdown-divider" *ngIf="v.room_total > 0 && v.ly_status !== 'Publish'"></div>

              <!-- <a class="dropdown-item text-warning" href="#" *ngIf="v.room_total > 0  && v.ly_status !== 'Publish'"
                 (click)="uploader.uploadFiles( {ly_group_id: v.ly_group_id})">重传考场</a> -->
              <a class="dropdown-item" href="#" *ngIf="v.room_total > 0  && v.ly_status !== 'Publish'" (click)="ModalService.showUploadWindow(bsService,'layout/group/written/room/upload.htm',
              {ly_group_id: v.ly_group_id},{
                uploadTitle:'重传考场',
                templateFile:'模版-笔试考场.xls',
                uploadCallback:uploadCallback.bind(this),
                autoClose:true
              })">重传考场</a>

              <div class="dropdown-divider"
                   *ngIf="v.ly_status=== 'Ready' && v.focus_flag === 'Active'"></div>
              <a class="dropdown-item" href="#" *ngIf="v.ly_status === 'Ready'  && v.focus_flag === 'Active'"
                 (click)="confirmNoRoom(v)">确认无考场</a>

              <div class="dropdown-divider" *ngIf="v.ly_status=== 'Publish' && (v.room_total === undefined || v.room_total < 1)"></div>
              <a class="dropdown-item" href="#" *ngIf="v.ly_status=== 'Publish' && (v.room_total === undefined || v.room_total < 1)" (click)="uploadRoom(v)">发布后上传</a>


              <div class="dropdown-divider" *ngIf="v.room_total > 0"></div>
              <a class="dropdown-item" href="#" *ngIf="v.room_total > 0"
                 (click)="FuncService.ajaxDownload('rpt/layout/written/room/download.htm', {ly_group_id: v.ly_group_id})">导出考场</a>

              <div class="dropdown-divider" *ngIf="v.ly_status === 'Complete'"></div>
              <a class="dropdown-item" href="#" *ngIf="v.ly_status === 'Complete'" (click)="publishWritten(v)">发布编排</a>

              <div class="dropdown-divider" *ngIf="v.ly_status === 'Publish'"></div>
              <a class="dropdown-item text-danger" href="#" *ngIf="v.ly_status === 'Publish'"
               (click)="resetData(v)">重置编排</a>


            </div>
          </div>
        </td>
      </tr>
      </tbody>
    </table>
  </div>

  <div class="card card-default">
    <table class="table table-striped table-hover table-bordered">
      <thead>
      <tr>
        <th class="th-index">#</th>
        <th>科目名称</th>
        <th class="wd-sm">考试人数</th>
        <th class="wd-md">考试时间</th>
        <th class="wd-sm">笔试时长(分钟)</th>
      </tr>
      </thead>
    </table>
  </div>
  <div class="card card-default"
       *ngFor="let group of ajax.getMap()['MoreArray'] | arrayFilter:  searchText | attrFilter :{exam_batch: exam_batch}">
    <div class="row card-header justify-content-between bg-gray">
      <div class="row ml-2 text-1-2">
        <span
          [ngClass]="{'text-success':group.ly_status==='Publish','text-warning':(group.ly_status==='Complete' && group.room_total === undefined),'text-info':(group.ly_status==='Complete' && group.room_total >0)}">【{{group.group_name}}({{group.group_std_total}})】</span>
        <span *ngIf="group.ly_status!=='Init' && group.room_total > 0 "
              class="text-success">【{{group.room_total}}个考场】</span>
        <span *ngIf="group.ly_status!=='Init' && (group.room_total=== undefined ||  group.room_total ===0) "
              class="text-warning">【未上传考场】</span>【<span
        [innerHTML]="group.aspect_num_flag | frameStatusCustom:['专业考号','准考证号','text-danger', 'text-black']"></span>】【<span
        [innerHTML]="group.once_flag | frameStatusCustom:['进场一次','多次进场', 'text-danger', 'text-black']"></span>】【<span
        [innerHTML]="group.appointment_type | frameStatusCustom:['开放预约','不可预约','text-danger', 'text-black']"></span>】
        <span *ngIf="group.province_flag === 'Active'" class="text-warning">【分省内外考场】</span>
      </div>
      <div class="float-right mr-5">
        <div class="btn-group btn-group-sm mb-1 mr-1 ml-3" dropdown>
          <button class="btn dropdown-toggle btn-secondary btn-lg" type="button" dropdownToggle>分组操作
            <span class="caret"></span>
          </button>
          <div *dropdownMenu class="dropdown-menu modal-lg" role="menu">
            <a class="dropdown-item" href="#" *ngIf="group.ly_status==='Init'"
               (click)="showModal({'ResponseEntity':group, 'ResponseArray':ajax.getMap()['SubjectArray_' + group.ly_group_id]})">笔试编排</a>
            <a class="dropdown-item text-primary" href="#" *ngIf="group.ly_status==='Complete'"
               (click)="showModal({'ResponseEntity':group, 'ResponseArray':ajax.getMap()['SubjectArray_' + group.ly_group_id]})">编排后编辑</a>
            <a class="dropdown-item text-primary" href="#" *ngIf="group.ly_status==='Publish'"
               (click)="showModal({'ResponseEntity':group, 'ResponseArray':ajax.getMap()['SubjectArray_' + group.ly_group_id]})">发布后查看</a>

            <div class="dropdown-divider"
                 *ngIf="group.ly_status=== 'Ready'"></div>
            <!-- <a class="dropdown-item" href="#" *ngIf="group.ly_status === 'Ready'"
               (click)="uploader.uploadFiles( {ly_group_id: group.ly_group_id})">上传考场</a> -->
               <a class="dropdown-item" href="#" *ngIf="group.ly_status === 'Ready'" (click)="ModalService.showUploadWindow(bsService,'layout/group/written/room/upload.htm',
        {ly_group_id: group.ly_group_id},{
          uploadTitle:'上传考场',
          templateFile:'模版-笔试考场.xls',
          uploadCallback:uploadCallback.bind(this),
          autoClose:true
        })">上传考场</a>

            <div class="dropdown-divider" *ngIf="group.room_total > 0 && group.ly_status !== 'Publish'"></div>
            <!-- <a class="dropdown-item text-warning" href="#"
               *ngIf="group.room_total > 0  && group.ly_status !== 'Publish'"
               (click)="uploader.uploadFiles( {ly_group_id: group.ly_group_id})">重传考场</a> -->
               
          <a class="dropdown-item" href="#" *ngIf="group.room_total > 0  && group.ly_status !== 'Publish'" (click)="ModalService.showUploadWindow(bsService,'layout/group/written/room/upload.htm',
          {ly_group_id: group.ly_group_id},{
            uploadTitle:'重传考场',
            templateFile:'模版-笔试考场.xls',
            uploadCallback:uploadCallback.bind(this),
            autoClose:true
          })">重传考场</a>   


            <div class="dropdown-divider" *ngIf="group.ly_status=== 'Ready' && group.focus_flag === 'Active'"></div>
            <a class="dropdown-item" href="#" *ngIf="group.ly_status === 'Ready'  && group.focus_flag === 'Active'"
               (click)="confirmNoRoom(group)">确认无考场</a>

            <div class="dropdown-divider" *ngIf="group.ly_status=== 'Publish' && (group.room_total === undefined || group.room_total < 1)"></div>
            <a class="dropdown-item" href="#" *ngIf="group.ly_status=== 'Publish' && (group.room_total === undefined || group.room_total < 1)" (click)="uploadRoom(group)">发布后上传</a>

            <div class="dropdown-divider" *ngIf="group.room_total > 0"></div>
            <a class="dropdown-item" href="#" *ngIf="group.room_total > 0"
               (click)="FuncService.ajaxDownload('rpt/layout/written/room/download.htm', {ly_group_id: group.ly_group_id})">导出考场</a>

            <div class="dropdown-divider" *ngIf="group.ly_status === 'Complete'"></div>
            <a class="dropdown-item" href="#" *ngIf="group.ly_status === 'Complete'" (click)="publishWritten(group)">发布编排</a>


            <div class="dropdown-divider" *ngIf="group.ly_status === 'Complete' || group.ly_status === 'Publish' "></div>
            <!-- ajax.optrRecord('layout/group/written/reset.htm', {ly_group_id: group.ly_group_id}, {'confirmMsg': '确定要重置分组【'+group.group_name+'】的编排吗？', 'successMsgType': 'Swal', successMsg:'分组【'+group.group_name+'】编排信息已重置，请重新对该分组进行编排！', showMsg:true}, {RequestWithLoading: true}) -->
            <a class="dropdown-item text-danger" href="#" *ngIf="group.ly_status === 'Complete' || group.ly_status === 'Publish' "
               (click)="resetData(group)">重置编排</a>

            <div class="dropdown-divider" *ngIf="group.ly_status === 'Init' || group.ly_status === 'Ready'"></div>
            <a class="dropdown-item text-warning" href="#"
               *ngIf="group.ly_status === 'Init'  || group.ly_status === 'Ready'"
               (click)="ajax.optrRecord('layout/group/union/delete.htm', {ly_group_id: group.ly_group_id}, {'confirmMsg': '确定要解散分组【'+group.group_name+'】吗？', 'successMsgType': 'Swal', successMsg:'分组【'+group.group_name+'】已打散，每个科目作为单独科目编排！', showMsg:true}, {RequestWithLoading: true})">解散分组</a>
          </div>
        </div>
      </div>
    </div>
    <table class="table table-striped table-hover table-bordered">
      <tbody>
      <tr *ngFor="let sb of ajax.getMap()['SubjectArray_' + group.ly_group_id] ; let i = index">
        <td class="th-index">{{sb.group_order}}</td>
        <td>{{sb.subject_name}}({{sb.subject_id}})</td>
        <td class="wd-sm"><span
          [tooltip]="'省内：' + sb.province_std_total + '；省外：' + sb.outside_std_total">{{sb.subject_std_total}}</span></td>
        <td class="wd-md">
          <span *ngIf="sb.exam_start_time">
          {{FuncService.dateToShortString(sb.exam_start_time)}} {{FuncService.dateToMinuteString(sb.exam_start_time)}}-{{FuncService.dateToMinuteString(sb.exam_end_time)}}</span>
        </td>
        <td class="wd-sm">{{sb.exam_minutes}}</td>
      </tr>
      </tbody>
    </table>
  </div>
  <frame-ajax [url]="'layout/group/list.htm'" [requestData]="{group_type:'Written',ly_agent_id: agent.ly_agent_id}"
              [autoRequest]="false"
              [requestParam]="{RequestDataType:'map', RequestWithLoading:true}" #ajax></frame-ajax>
</ng-container>

<!-- <frame-uploader [uploadUrl]="'layout/group/written/room/upload.htm'" [allowedFileType]="['xls']"
                [successMsg]="'考场信息已上传，容量可以满足编排要求！'"
                [templateFile]="'模版-笔试考场.xls'" [confirmMsg]="'确定要上传考场信息吗？'" (allUpload)="ajax.reload()"
                #uploader></frame-uploader> -->
