<div class="list-template">
  <div class="list-template__content">
    <div class="list-template__top" nz-row>
      <div nz-col nzXl="18" class="list-template__searchBox">
				<div class="list-template__searchItem">
				  <span class="label" style="width: 110px;">手术时间范围：</span>
				  <nz-range-picker [(ngModel)]="searchCriteria.dateRange" (ngModelChange)="changeDate($event)"></nz-range-picker>
				</div>
				
        <div class="list-template__searchItem">
          <span class="label">申请科室：</span>
          <nz-select
            [nzDropdownMatchSelectWidth]="false"
            class="formItem"
            nzServerSearch
            nzShowSearch
            nzAllowClear
            nzPlaceHolder="请选择申请科室"
            [(ngModel)]="searchCriteria.department"
            (nzOnSearch)="changeDeptInp($event)"
            (nzOpenChange)="changeSearch($event)"
          >
            <ng-container *ngFor="let data of departmentSearch">
              <nz-option
                *ngIf="!isLoading"
                nzLabel="{{ data.dept }}"
                nzValue="{{ data.id }}"
              ></nz-option>
            </ng-container>
            <nz-option *ngIf="isLoading" nzDisabled nzCustomContent>
              <i nz-icon nzType="loading" class="loading-icon"></i> 搜索中...
            </nz-option>
          </nz-select>
        </div>
				
				<div class="list-template__searchItem">
				  <span class="label">手术室：</span>
				  <nz-select
				    [nzDropdownMatchSelectWidth]="false"
				    class="formItem"
				    nzServerSearch
				    nzShowSearch
				    nzAllowClear
				    nzPlaceHolder="请选择手术室"
				    [(ngModel)]="searchCriteria.departmentRoom"
				    (nzOnSearch)="changeOperatingRoomInp($event, 'search')"
				    (nzOpenChange)="changeSearch2($event)"
				  >
				    <ng-container *ngFor="let data of operatingRoomDept">
				      <nz-option
				        *ngIf="!isLoading"
				        nzLabel="{{ data.dept }}"
				        nzValue="{{ data.id }}"
				      ></nz-option>
				    </ng-container>
				    <nz-option *ngIf="isLoading" nzDisabled nzCustomContent>
				      <i nz-icon nzType="loading" class="loading-icon"></i> 搜索中...
				    </nz-option>
				  </nz-select>
				</div>
				
        <div class="list-template__searchItem">
          <span class="label">状态：</span>
          <nz-select
            [nzDropdownMatchSelectWidth]="false"
            class="formItem"
            nzServerSearch
            nzShowSearch
            nzAllowClear
            nzPlaceHolder="请选择状态"
            [(ngModel)]="searchCriteria.speState"
            (nzOpenChange)="changeSearch1($event)"
          >
            <ng-container *ngFor="let data of types">
              <nz-option
                *ngIf="!isLoading1"
                nzLabel="{{ data.name }}"
                nzValue="{{ data.value }}"
              ></nz-option>
            </ng-container>
            <nz-option *ngIf="isLoading1" nzDisabled nzCustomContent>
              <i nz-icon nzType="loading" class="loading-icon"></i> 搜索中...
            </nz-option>
          </nz-select>
        </div>
				
				<div class="list-template__searchItem">
				  <span class="label">是否首台：</span>
					<label nz-checkbox [(ngModel)]="searchCriteria.firstOperation"></label>
				</div>
      </div>
      <div nz-col nzXl="6" class="list-template__btns">
				<button nz-button class="btn default" (click)="addMoadl()" *ngIf="coopBtns.add">新增</button>
				<button nz-button class="btn default ml8" (click)="getList(1)">
				  搜索
				</button>
        <button nz-button class="btn default ml8" (click)="reset()">
          重置
        </button>
      </div>
    </div>
    <div class="list-template__bottom">
      <nz-table
        class="list-template__nzTable"
        #headerTable
        [nzData]="listOfData"
        nzSize="middle"
        [nzShowPagination]="false"
        [nzLoading]="loading1"
      >
        <thead (nzSortChange)="sort($event)">
          <tr class="thead">
            <th>序号</th>
						<th>安排单号</th>
						<th>台次台序</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 data of listOfData; let i = index">
            <td>{{i+(pageIndex-1) * pageSize + 1}}</td>
            <td>{{ data.applyCode }}</td>
						<td>{{ data.total }}</td>
						<td>
							<div>{{data.patientDTO && data.patientDTO.residenceNo || ''}}</div>
							<div>
								{{ data.patientName}}<span *ngIf="data.patientDTO && data.patientDTO.bedNum">({{data.patientDTO.bedNum}})</span>
							</div>
						</td>
						<td>
							<div>{{ data.applyDate | date:"yyyy-MM-dd HH:mm:ss"  }}</div>
							<div>{{ data.printDate | date:"yyyy-MM-dd HH:mm:ss"  }}</div>
						</td>
						<td>
							<div>{{ data.surgeryDeptDTO ? data.surgeryDeptDTO.dept : '-'  }}</div>
							<div>{{ data.areaDeptDTO ? data.areaDeptDTO.dept : '-' }}</div>
						</td>
						<td>
							<div>{{ data.surgeryName || '-'  }}</div>
							<div>{{ data.diagnose || '-' }}</div>
						</td>
            <td>{{ data.doctorName }} 、{{data.assistantDoctorName}}</td>
            <td>
							<div>{{ data.nurseName }}</div>
							<div>{{ data.itinerantNurseName || ''}}</div>
						</td>
            <td>{{ data.state ? data.state.name : "-" }}</td>
            <td>{{ data.firstOperation==1 ? '是' : '否'}}</td>
						<td>
						  <div class="coop">
						    <span *ngIf="coopBtns.look" (click)="detail($event,data)">查看</span>
								<span *ngIf="coopBtns.edit" (click)="edit($event,data)">编辑</span>
								<span *ngIf="coopBtns.log && data.logs" (click)="viewLog($event,data)">查看日志</span>
							</div>
						</td>
          </tr>
        </tbody>
      </nz-table>
      <div class="list-template__pagination">
        <nz-pagination
          [(nzPageIndex)]="pageIndex"
          [(nzTotal)]="listLength"
          [(nzPageSize)]="pageSize"
          (nzPageIndexChange)="getList(0, sortCurrentKey, sortCurrentValue)"
          (nzPageSizeChange)="getList(0, sortCurrentKey, sortCurrentValue)"
        >
        </nz-pagination>
      </div>
    </div>
  </div>
</div>

<!-- 新增/编辑模态框 -->
<div class="save add display_flex align-items_center justify-content_flex-center" *ngIf="modal">
  <div class="modalBody">
    <div class="title">{{add?"新增":view?"查看":"编辑"}}<i class="icon_transport transport-guanbi" (click)="hideModal()"></i>
    </div>
    <div class="content">
      <form nz-form [formGroup]="validateForm" class="addForm" (ngSubmit)="submitForm()">
				<div class="df"> 
					<nz-form-item>
					  <nz-form-label [nzSm]="6" [nzXs]="24" nzRequired nzFor="patientName">患者</nz-form-label>
					  <nz-form-control nzErrorTip="请选择患者!">
					    <nz-input-group>
								<nz-select class="formItem" [nzDisabled]="view" [nzDropdownMatchSelectWidth]="false" nzServerSearch nzShowSearch
								  (nzOnSearch)="changePatient($event)" (ngModelChange)="onPatientChange($event)" nzAllowClear nzPlaceHolder="请选择患者" formControlName="patientName">
									<ng-container *ngFor="let option of patientList">
									  <nz-option *ngIf="!isLoading" [nzLabel]="option.patientName" [nzValue]="option.id"></nz-option>
									</ng-container>
									<nz-option *ngIf="isLoading" nzDisabled nzCustomContent>
									  <i nz-icon nzType="loading" class="loading-icon"></i> 搜索中...
									</nz-option>
								</nz-select>
					    </nz-input-group>
					  </nz-form-control>
					</nz-form-item>
					
					<nz-form-item>
					  <nz-form-label [nzSm]="7" [nzXs]="24" nzFor="patientPhone">患者电话</nz-form-label>
					  <nz-form-control nzErrorTip="请选择患者电话!">
					    <nz-input-group>
								<input nz-input [disabled]="view" class="formItem" formControlName="patientPhone" placeholder="请输入患者电话" nzSize="default" />
					    </nz-input-group>
					  </nz-form-control>
					</nz-form-item>
					
					<nz-form-item>
					  <nz-form-label [nzSm]="6" [nzXs]="24" nzFor="patientFamilyPhone">患者家属电话</nz-form-label>
					  <nz-form-control nzErrorTip="请选择患者家属电话!">
					    <nz-input-group>
								<input nz-input [disabled]="view" class="formItem" formControlName="patientFamilyPhone" placeholder="请输入患者家属电话" nzSize="default" />
					    </nz-input-group>
					  </nz-form-control>
					</nz-form-item>
				</div>
				
      	<div class="df">
					<nz-form-item>
					  <nz-form-label [nzSm]="8" [nzXs]="24" nzRequired nzFor="applyDate">申请日期</nz-form-label>
					  <nz-form-control nzErrorTip="请选择申请日期!">
					    <nz-input-group>
					      <nz-date-picker
									[nzDisabled]="view"
									nzShowTime
									nzFormat="yyyy-MM-dd HH:mm"
									nzPlaceHolder="请选择申请日期"
									formControlName="applyDate"
									(ngModelChange)="onApplyChange($event)"
								></nz-date-picker>
					    </nz-input-group>
					  </nz-form-control>
					</nz-form-item>
					
					<nz-form-item>
					  <nz-form-label [nzSm]="8" [nzXs]="24" nzRequired nzFor="printDate">手术时间</nz-form-label>
					  <nz-form-control nzErrorTip="请选择手术时间!">
					    <nz-input-group>
					      <nz-date-picker
									[nzDisabled]="view"
									nzShowTime
									nzFormat="yyyy-MM-dd HH:mm"
									nzPlaceHolder="请选择手术时间"
									formControlName="printDate"
									(ngModelChange)="onOperationChange($event)"
								></nz-date-picker>
					    </nz-input-group>
					  </nz-form-control>
					</nz-form-item>
					
					<nz-form-item>
					  <nz-form-label [nzSm]="6" nzRequired [nzXs]="24" nzFor="firstOperation">是否首台</nz-form-label>
					  <nz-form-control nzErrorTip="请选择是否首台!">
					    <nz-input-group>
								<nz-radio-group [nzDisabled]="view" [disabled]="view" formControlName="firstOperation">
									<label nz-radio nzValue="1">是</label>
									<label nz-radio nzValue="0">否</label>
								</nz-radio-group>
							</nz-input-group>
					  </nz-form-control>
					</nz-form-item>
				</div>
				
				<div class="df">
					<nz-form-item>
						<nz-form-label [nzSm]="6" [nzXs]="24" nzRequired nzFor="areaDept">申请科室</nz-form-label>
						<nz-form-control nzErrorTip="请选择申请科室!">
							<nz-input-group>
								<nz-select [nzDisabled]="view" class="formItem" [nzDropdownMatchSelectWidth]="false" nzServerSearch nzShowSearch
									(nzOnSearch)="changeDeptInp($event,2)" (nzOpenChange)="changeSearch($event)" nzAllowClear nzPlaceHolder="请选择申请科室" formControlName="areaDept">
									<ng-container *ngFor="let option of departmentSearch">
										<nz-option *ngIf="!isLoading" [nzLabel]="option.dept" [nzValue]="option.id"></nz-option>
									</ng-container>
									<nz-option *ngIf="isLoading" nzDisabled nzCustomContent>
										<i nz-icon nzType="loading" class="loading-icon"></i> 搜索中...
									</nz-option>
								</nz-select>
							</nz-input-group>
						</nz-form-control>
					</nz-form-item>
					
					<nz-form-item>
						<nz-form-label [nzSm]="6" [nzXs]="24" nzRequired nzFor="surgeryDept">手术室</nz-form-label>
						<nz-form-control nzErrorTip="请选择手术室!">
							<nz-input-group>
								<nz-select [nzDisabled]="view" class="formItem" [nzDropdownMatchSelectWidth]="false" nzServerSearch nzShowSearch
									(nzOnSearch)="changeOperatingRoomInp($event, 'search')" (nzOpenChange)="changeSearch2($event)" nzAllowClear nzPlaceHolder="请选择手术室" formControlName="surgeryDept">
									<ng-container *ngFor="let option of operatingRoomDept">
										<nz-option *ngIf="!isLoading" [nzLabel]="option.dept" [nzValue]="option.id"></nz-option>
									</ng-container>
									<nz-option *ngIf="isLoading" nzDisabled nzCustomContent>
										<i nz-icon nzType="loading" class="loading-icon"></i> 搜索中...
									</nz-option>
								</nz-select>
							</nz-input-group>
						</nz-form-control>
					</nz-form-item>
					
	<!--      	<nz-form-item>
						<nz-form-label [nzSm]="6" [nzXs]="24" nzRequired nzFor="surgeryName">手术名称</nz-form-label>
						<nz-form-control nzErrorTip="请选择手术名称!">
							<nz-input-group>
								<textarea [disabled]="view" formControlName="surgeryName" nz-input rows="3" placeholder="请输入手术名称"></textarea>
							</nz-input-group>
						</nz-form-control>
					</nz-form-item> -->
					
					<nz-form-item>
						<nz-form-label [nzSm]="6" [nzXs]="24" nzFor="doctorId">主刀医生</nz-form-label>
						<nz-form-control nzErrorTip="请选择主刀医生!">
							<nz-input-group>
								<nz-select [nzDisabled]="view" class="formItem" [nzDropdownMatchSelectWidth]="false" nzServerSearch nzShowSearch
									(nzOnSearch)="changeUser($event)" nzAllowClear nzPlaceHolder="请选择主刀医生" formControlName="doctorId">
									<ng-container *ngFor="let option of userList">
										<nz-option *ngIf="!isLoading" [nzLabel]="option.name" [nzValue]="option.id"></nz-option>
									</ng-container>
									<nz-option *ngIf="isLoading" nzDisabled nzCustomContent>
										<i nz-icon nzType="loading" class="loading-icon"></i> 搜索中...
									</nz-option>
								</nz-select>
							</nz-input-group>
						</nz-form-control>
					</nz-form-item>
				</div>
				
				<div class="df">
					<nz-form-item>
					  <nz-form-label [nzSm]="6" [nzXs]="24" nzFor="docAssistantInfos">助理医生</nz-form-label>
					  <nz-form-control nzErrorTip="请选择助理医生!">
					    <nz-input-group>
								<nz-select [nzDisabled]="view" class="formItem" nzMode="multiple" [nzDropdownMatchSelectWidth]="false" nzServerSearch nzShowSearch
								  (nzOnSearch)="changeUser($event)" nzAllowClear nzPlaceHolder="请选择助理医生" formControlName="docAssistantInfos">
									<ng-container *ngFor="let option of userList">
									  <nz-option *ngIf="!isLoading" [nzLabel]="option.name" [nzValue]="option.id"></nz-option>
									</ng-container>
									<nz-option *ngIf="isLoading" nzDisabled nzCustomContent>
									  <i nz-icon nzType="loading" class="loading-icon"></i> 搜索中...
									</nz-option>
								</nz-select>
					    </nz-input-group>
					  </nz-form-control>
					</nz-form-item>
					
					<nz-form-item>
					  <nz-form-label [nzSm]="6" [nzXs]="24" nzFor="itinerantNurseId">巡回护士</nz-form-label>
					  <nz-form-control nzErrorTip="请选择巡回护士!">
					    <nz-input-group>
								<nz-select [nzDisabled]="view" class="formItem" [nzDropdownMatchSelectWidth]="false" nzServerSearch nzShowSearch
								  (nzOnSearch)="changeUser($event)" nzAllowClear nzPlaceHolder="请选择巡回护士" formControlName="itinerantNurseId">
									<ng-container *ngFor="let option of userList">
									  <nz-option *ngIf="!isLoading" [nzLabel]="option.name" [nzValue]="option.id"></nz-option>
									</ng-container>
									<nz-option *ngIf="isLoading" nzDisabled nzCustomContent>
									  <i nz-icon nzType="loading" class="loading-icon"></i> 搜索中...
									</nz-option>
								</nz-select>
					    </nz-input-group>
					  </nz-form-control>
					</nz-form-item>
					
					<nz-form-item>
					  <nz-form-label [nzSm]="6" [nzXs]="24" nzFor="nurseId">洗手护士</nz-form-label>
					  <nz-form-control nzErrorTip="请选择洗手护士!">
					    <nz-input-group>
								<nz-select [nzDisabled]="view" class="formItem" [nzDropdownMatchSelectWidth]="false" nzServerSearch nzShowSearch
								  (nzOnSearch)="changeUser($event)" nzAllowClear nzPlaceHolder="请选择洗手护士" formControlName="nurseId">
									<ng-container *ngFor="let option of userList">
									  <nz-option *ngIf="!isLoading" [nzLabel]="option.name" [nzValue]="option.id"></nz-option>
									</ng-container>
									<nz-option *ngIf="isLoading" nzDisabled nzCustomContent>
									  <i nz-icon nzType="loading" class="loading-icon"></i> 搜索中...
									</nz-option>
								</nz-select>
					    </nz-input-group>
					  </nz-form-control>
					</nz-form-item>
				</div>
				
				<div class="df">
					<nz-form-item>
					  <nz-form-label [nzSm]="6" [nzXs]="24" nzRequired nzFor="state">状态</nz-form-label>
					  <nz-form-control nzErrorTip="请选择状态!">
					    <nz-input-group>
								<nz-select [nzDisabled]="view" class="formItem" [nzDropdownMatchSelectWidth]="false" 
								nzShowSearch nzAllowClear nzPlaceHolder="请选择状态" 
								formControlName="state">
								  <ng-container *ngFor="let option of types">
								    <nz-option [nzLabel]="option.name" [nzValue]="option.id"></nz-option>
								  </ng-container>
								</nz-select>
					    </nz-input-group>
					  </nz-form-control>
					</nz-form-item>
					
					<nz-form-item>
					  <nz-form-label [nzSm]="6" [nzXs]="24" nzRequired nzFor="type">手术类型</nz-form-label>
					  <nz-form-control nzErrorTip="请选择手术类型!">
					    <nz-input-group>
								<nz-select [nzDisabled]="view" class="formItem" [nzDropdownMatchSelectWidth]="false" 
								nzShowSearch nzAllowClear nzPlaceHolder="请选择手术类型" 
								formControlName="type">
								  <ng-container *ngFor="let option of operationType">
								    <nz-option [nzLabel]="option.name" [nzValue]="option.id"></nz-option>
								  </ng-container>
								</nz-select>
					    </nz-input-group>
					  </nz-form-control>
					</nz-form-item>
				</div>
      </form>
    </div>
    <div class="display_flex justify-content_flex-center">
      <button nzType="primary" nz-button (click)="submitForm()" [nzLoading]="btnLoading">确认</button>
      <button class="btn cancel" nz-button nzType="default" (click)="hideModal()">取消</button>
    </div>
  </div>
</div>

<!-- 操作成功/失败提示框 -->
<app-prompt-modal
  *ngIf="promptModalShow"
  [content]="promptContent"
  [success]="ifSuccess"
  [show]="promptModalShow"
  [info]="promptInfo"
>
</app-prompt-modal>

	<!-- 日志查看模态框 -->
	<div class="save add display_flex align-items_center justify-content_flex-center" *ngIf="logModal">
	  <div class="modalBody modalLogBody">
	    <div class="title">日志查看<i class="icon_transport transport-guanbi" (click)="hideLogModal()"></i>
	    </div>
	    <div class="content">
	      <div class="list-template__bottom">
	        <nz-table class="list-template__nzTable" [nzData]="itemData.logs" nzSize="middle" [nzShowPagination]="false"
	          [nzLoading]="loading2">
	          <thead>
	            <tr class="thead">
								<th>动作</th>
	              <th>操作时间</th>
	              <th>操作人</th>
	            </tr>
	          </thead>
	          <tbody>
	            <tr *ngFor="let data of itemData.logs">
								<td>{{ data.operationType ? data.operationType.name : '-' }}</td>
	              <td>{{ data.operationTime|date:'yyyy-MM-dd HH:mm'}}</td>
	              <td>{{ data.username }}</td>
	            </tr>
	          </tbody>
	        </nz-table>
	      </div>
	    </div>
	    <div class="display_flex justify-content_flex-center">
	      <button class="btn" nz-button nzType="primary" (click)="hideLogModal()">知道了</button>
	    </div>
	  </div>
	</div>