<div>
	<div class="list-template">
		<div class="list-template__content">
			<div class="list-template__top" nz-row>
				<div nz-col nzLg='16' class="list-template__searchBox">
					<div class="list-template__searchItem">
						<span class="label">批次号：</span>
						<input nz-input class="formItem" [(ngModel)]="batchNumber" placeholder="请输入批次号" nzSize="default" />
					</div>
					<div class="list-template__searchItem">
						<span class="label">创建时间：</span>
						<nz-range-picker [(ngModel)]="dateRange" nzFormat="yyyy-MM-dd"
						(ngModelChange)="changeDate($event)"></nz-range-picker>
					</div>
				</div>
				<div nz-col nzLg='2' class="autoUpdate">{{ logTime }}秒</div>
				<div nz-col nzLg="6" class="list-template__btns">
					<button class="btn default" (click)='search()'>搜索</button>
					<button class="btn default ml8" (click)='reset()'>重置</button>
					<button *ngIf="coopBtns.add" class="btn default ml8" (click)='showModal()'>新增</button>
				</div>
			</div>
			<div class="list-template__bottom">
				<nz-table class="list-template__nzTable" [nzData]="listOfData" nzSize="middle" [nzShowPagination]="false"
					[nzLoading]="loading1">
					<thead>
						<tr class="thead">
							<th nzWidth="13%">批次号</th>
							<th nzWidth="13%">创建时间</th>
							<th nzWidth="13%">发药时间区间</th>
							<th nzWidth="7%">发药科室</th>
							<th nzWidth="7%">科室数</th>
							<th nzWidth="7%">发药量</th>
							<th nzWidth="7%">箱数</th>
							<th nzWidth="10%">药品总价</th>
							<th nzWidth="7%">状态</th>
							<th nzWidth="16%">操作</th>
						</tr>
					</thead>
					<tbody>
						<tr *ngFor="let data of listOfData">
							<td>{{ data.batchNo || '-' }}</td>
							<td>{{ data.createTime|date:'yyyy-MM-dd HH:mm' }}</td>
							<td>
								<div>{{ data.startTime|date:'yyyy-MM-dd HH:mm' }}至</div>
								<div>{{ data.endTime|date:'yyyy-MM-dd HH:mm' }}</div>
							</td>
							<td>{{ data.pharmacyDTO?data.pharmacyDTO.dept:'-' }}</td>
							<td>{{ data.deptNum || '0' }}</td>
							<td>{{ data.drugNum || '0'}}</td>
							<td>{{ data.cartonNum || '0' }}</td>
							<td>{{ data.totalPrice || '0' }}</td>
							<td>{{ data.batchState?data.batchState.name : '-' }}</td>
							<td>
								<div class="coop">
									<span *ngIf="coopBtns.edit && data.batchState.name=='未发药'" (click)="edit($event,data)">编辑</span>
									<span *ngIf="coopBtns.del && data.batchState.name=='未发药'" (click)="showDelModal($event,data.id)">删除</span>
									<span *ngIf="coopBtns.config && data.batchState.name=='未发药'" (click)="detail($event,data)">配置</span>
									<span *ngIf="coopBtns.dispensingGross && data.batchState.name=='已发药'" (click)="dispensingGross($event, data)">发药总量</span>
									<span *ngIf="coopBtns.dispensingInfo && data.batchState.name=='已发药'" (click)="dispensingInfo($event, data)">发药信息</span>
									<span *ngIf="coopBtns.export && data.batchState.name=='已发药'" (click)="exportPc($event, data)">导出</span>
									<span *ngIf="coopBtns.print && data.batchState.name=='已发药'" (click)="print($event,data, data.id)">打印</span>
									<span *ngIf="coopBtns.batchPrint && data.batchState.name=='未发药'" (click)="dispensingPrint($event, data, data.id)">发药并打印</span>
								</div>
							</td>
						</tr>
					</tbody>
				</nz-table>
				<div class="list-template__pagination">
					<nz-pagination [(nzPageIndex)]="pageIndex" [(nzTotal)]="listLength" nzShowSizeChanger [(nzPageSize)]="pageSize"
						(nzPageIndexChange)="getList()" (nzPageSizeChange)="getList()">
					</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 ? '新增' : '编辑'}}<i class="icon_transport transport-guanbi" (click)="hideModal()"></i>
      </div>
      <div class="content">
       <form nz-form [formGroup]="validateForm" class="addForm" (ngSubmit)="submitForm()">
       	<nz-form-item>
       	  <nz-form-label nzRequired nzFor="dispensingTime">发药时间区间</nz-form-label>
       	  <nz-form-control nzErrorTip="请选择发药时间区间!">
       	    <nz-input-group>
       				<nz-range-picker formControlName="dispensingTime" 
							[nzShowTime]="{ nzFormat: 'yyyy-MM-dd HH:mm:ss' }" nzFormat="yyyy-MM-dd HH:mm:ss"
							(ngModelChange)="formChangeDate($event)"></nz-range-picker>
       			</nz-input-group>
       	  </nz-form-control>
       	</nz-form-item>
       	<nz-form-item>
       	  <nz-form-label nzRequired nzFor="addDepartment">取药科室</nz-form-label>
       	  <nz-form-control nzErrorTip="请选择取药科室!">
       	    <nz-input-group>
       				<nz-select class="formItem" [nzDropdownMatchSelectWidth]="false" (nzOnSearch)="changeInp($event)" nzServerSearch nzShowSearch nzPlaceHolder="请选择申请科室" formControlName="addDepartment">
       				  <ng-container *ngFor="let option of addHospitals">
       				    <nz-option *ngIf="!isDeptLoading" [nzLabel]="option.dept" [nzValue]="option.id"></nz-option>
       				  </ng-container>
       				  <nz-option *ngIf="isDeptLoading" 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>加载所有消耗科室</nz-form-label>
					<nz-form-control>
						<label nz-checkbox formControlName="loadAllConsumeDept">
							<span>是否开启</span>
						</label>
					</nz-form-control>
				</nz-form-item>
       </form>
      </div>
      <div class="display_flex justify-content_flex-center">
        <button class="btn" nz-button nzType="primary" (click)="submitForm()" [nzLoading]="btnLoading">{{add ? '保存并配置' : '保存'}}</button>
				<button class="btn cancel" nz-button nzType="default" (click)="hideModal()">取消</button>
      </div>
    </div>
  </div>
  <!-- 删除模态框 -->
  <app-dialog-delete [delModal]="delModal" (hideDelModalEvent)="hideDelModal()" [btnLoading]="btnLoading"
    (confirmDelEvent)="confirmDel()" content="您确认要删除发药批次吗？"></app-dialog-delete>

  <!-- 编辑模态框 -->
  <app-dialog-delete [delModal]="editModal" (hideDelModalEvent)="hideDelModal1()" [btnLoading]="saveLoading"
    (confirmDelEvent)="confirmDel1()" [content]="'保存后会重置您的发药科室的药品信息，您确认吗？'"></app-dialog-delete>
	
	<!-- 发药总量 -->
	<div class="save add display_flex align-items_center justify-content_flex-center" *ngIf="grossModal">
	  <div class="modalBody modalBody-ga">
	    <div class="title">发药总量<i class="icon_transport transport-guanbi" (click)="hideGrossModal()"></i>
	    </div>
	    <overlay-scrollbars #osComponentRef1 class="content">
	      <div class="list-template__bottom">
	        <nz-table class="list-template__nzTable" [nzData]="viewData" nzSize="middle" [nzShowPagination]="false"
	          [nzLoading]="loading">
	          <thead>
	            <tr class="thead">
	              <th>药品名称</th>
	              <th>药品规格</th>
	              <th>包装规格</th>
	              <th>发药总量</th>
								<th>箱数合计</th>
	            </tr>
	          </thead>
	          <tbody>
	            <tr *ngFor="let data of viewData">
	              <td>{{ data.drugsInfoDTO.drugName}}</td>
	              <td>{{ data.drugsInfoDTO.specs}}</td>
	              <td>{{ data.drugsInfoDTO.packingSpecs}}</td>
								<td>{{ data.actualCount}}</td>
								<td>
									{{data.cartonNum}} 箱 &nbsp;
									<span *ngIf="data.afterInventory>0">
										{{data.afterInventory}} {{data.drugsInfoDTO.unit}}
									</span>
								</td>
	            </tr>
	          </tbody>
	        </nz-table>
	      </div>
	    </overlay-scrollbars>
	    <div class="display_flex justify-content_flex-center">
	      <button class="btn" nz-button nzType="primary" (click)="hideGrossModal()">知道了</button>
	    </div>
	  </div>
	</div>
	
	<!-- 发药信息 -->
	<div class="save add display_flex align-items_center justify-content_flex-center" *ngIf="infoModal">
	  <div class="modalBody modalBody-ga">
	    <div class="title">发药信息<i class="icon_transport transport-guanbi" (click)="hideInfoModal()"></i>
	    </div>
			<div class="list-template__top" nz-row>
			  <div nz-col nzLg='19' class="list-template__searchBox">
			    <div class="list-template__searchItem">
			      <span class="label">科室：</span>
			      <nz-select class="formItem" [nzDropdownMatchSelectWidth]="false" nzShowSearch nzPlaceHolder="请选择科室" [(ngModel)]="infoDepartment">
			        <ng-container *ngFor="let option of hospitals1">
			          <nz-option [nzLabel]="option.dept" [nzValue]="option.id"></nz-option>
			        </ng-container>
			      </nz-select>
			    </div>
			  </div>
			  <div nz-col nzLg="5" class="list-template__btns">
			    <button class="btn default" (click)='searchInfo()'>搜索</button>
					<button class="btn default" (click)='resetInfo()'>重置</button>
			  </div>
			</div>
	    <overlay-scrollbars #osComponentRef1 class="content">
	      <div class="list-template__bottom">
	        <nz-table class="list-template__nzTable" [nzData]="infoData" nzSize="middle" [nzShowPagination]="false"
	          [nzLoading]="infoLoading">
	          <thead>
	            <tr class="thead">
								<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 infoData">
	              <td>{{ data['0']}}</td>
								<td>{{ data['1']}}</td>
								<td>{{ data['2']}}</td>
								<td>{{ data['3']}}</td>
								<td>{{ data['4']}}</td>
	              <td>{{ data['5'] }}</td>
	              <td>{{ data['6'] }}</td>
								<td>{{ data['7'] }}</td>
								<td>{{ data['8'] }}</td>
								<td>{{ data['9'] }}</td>
	            </tr>
	          </tbody>
	        </nz-table>
	      </div>
	    </overlay-scrollbars>
	    <div class="display_flex justify-content_flex-center">
	      <button class="btn" nz-button nzType="primary" (click)="hideInfoModal()">知道了</button>
	    </div>
	  </div>
	</div>
	
  <!-- 打印 -->
  <div id="report" style="display: none">
		<div class="monad" *ngFor="let item of printData"
				style="padding: 10px;
				border: 1px solid #e7e7e7;
				border-radius: 5px;margin-bottom: 40px;">
			<div class="monad-title" 
				style="text-align: center;
				font-size: 18px;
				border-bottom: 1px solid #e7e7e7;
				padding-bottom: 10px;">
				大输液发药单-{{item.applyDeptDTO.dept}}
			</div>
			<div class="monad-sign" style="display: flex;line-height: 23px;font-size: 14px;">
				<div style="margin-right: 15px;">日期：{{item.createTime|date:'yyyy-MM-dd HH:mm'}}</div>
				<div style="margin-right: 15px;">批次号：{{item.batch.batchNo}}</div>
				<div style="margin-right: 15px;">单号：{{item.packingNo}}</div>
			</div>
			<div class="monad-sign" style="display: flex;line-height: 23px;font-size: 14px;">
				<div style="margin-right: 15px;">取药药房：{{item.pharmacyDTO?item.pharmacyDTO.dept:'-'}}</div>
			</div>
			<div style="border: 1px solid #e7e7e7;border-bottom: none;font-size: 14px;">
				<div class="thead" style="display: flex;">
					<div style="width: 40%;display: flex;font-size: 12px;
					align-items: center;
					justify-content: center;
					flex-wrap: wrap;
					border-right: 1px solid #e7e7e7;
					border-bottom: 1px solid #e7e7e7;">药品名称</div>
					
					<div style="width: 20%;display: flex;font-size: 12px;
					align-items: center;
					justify-content: center;
					flex-wrap: wrap;
					border-right: 1px solid #e7e7e7;
					border-bottom: 1px solid #e7e7e7;">规格</div>
					
					<div style="width: 10%;display: flex;font-size: 12px;
					align-items: center;
					justify-content: center;
					flex-wrap: wrap;
					border-right: 1px solid #e7e7e7;
					border-bottom: 1px solid #e7e7e7;">15日消耗</div>
					
					<div style="width: 8%;display: flex;font-size: 12px;
					align-items: center;
					justify-content: center;
					flex-wrap: wrap;
					border-right: 1px solid #e7e7e7;
					border-bottom: 1px solid #e7e7e7;">包规</div>
					
					<div style="width: 8%;display: flex;font-size: 12px;
					align-items: center;
					justify-content: center;
					flex-wrap: wrap;
					border-right: 1px solid #e7e7e7;
					border-bottom: 1px solid #e7e7e7;">实消</div>
					
					<div style="width: 10%;display: flex;font-size: 12px;
					align-items: center;
					justify-content: center;
					flex-wrap: wrap;
					border-right: 1px solid #e7e7e7;
					border-bottom: 1px solid #e7e7e7;">临时增发</div>
					
					<div style="width: 10%;display: flex;font-size: 12px;
					align-items: center;
					justify-content: center;
					flex-wrap: wrap;
					border-bottom: 1px solid #e7e7e7;">箱数</div>
					
				</div>
				<div *ngFor="let data of item.drugsConfigureDTOS" style="display: flex;">
					<div style="width: 40%;display: flex;font-size: 12px;
					align-items: center;
					justify-content: center;
					flex-wrap: wrap;
					border-right: 1px solid #e7e7e7;
					border-bottom: 1px solid #e7e7e7;">{{ data.drugsInfoDTO.drugName }}</div>
					
					<div style="width: 20%;display: flex;font-size: 12px;
					align-items: center;
					justify-content: center;
					flex-wrap: wrap;
					border-right: 1px solid #e7e7e7;
					border-bottom: 1px solid #e7e7e7;">{{ data.drugsInfoDTO.specs }}</div>
					
					<div style="width: 10%;display: flex;font-size: 12px;
					align-items: center;
					justify-content: center;
					flex-wrap: wrap;
					border-right: 1px solid #e7e7e7;
					border-bottom: 1px solid #e7e7e7;">{{data.fifteenExpendCount}}</div>
					
					<div style="width: 8%;display: flex;font-size: 12px;
					align-items: center;
					justify-content: center;
					flex-wrap: wrap;
					border-right: 1px solid #e7e7e7;
					border-bottom: 1px solid #e7e7e7;">{{ data.drugsInfoDTO.packingSpecs }}</div>
					
					<div style="width: 8%;display: flex;font-size: 12px;
					align-items: center;
					justify-content: center;
					flex-wrap: wrap;
					border-right: 1px solid #e7e7e7;
					border-bottom: 1px solid #e7e7e7;">{{ data.expendCount }}</div>
					
					<div style="width: 10%;display: flex;font-size: 12px;
					align-items: center;
					justify-content: center;
					flex-wrap: wrap;
					border-right: 1px solid #e7e7e7;
					border-bottom: 1px solid #e7e7e7;">{{ data.addSub || 0 }}</div>
					
					<div style="width: 10%;display: flex;font-size: 12px;
					align-items: center;
					justify-content: center;
					flex-wrap: wrap;
					border-bottom: 1px solid #e7e7e7;">
					<span *ngIf="data.drugsInfoDTO.drugName!='合计'">
						{{ data.giveOutType.value==1 ? data.actualCount :data.cartonNum }}
						{{data.giveOutType && data.giveOutType.value==1?
						data.drugsInfoDTO.unit:'箱'}}
					</span>
					<span *ngIf="data.drugsInfoDTO.drugName=='合计'">
						{{ data.cartonActual}}
					</span>
					</div>
					
				</div>
			</div>
		</div>
		
		<div class="monad" 
				style="padding: 10px;
				border: 1px solid #e7e7e7;
				border-radius: 5px;margin-bottom: 40px;">
			<div class="monad-title" 
				style="text-align: center;
				font-size: 18px;
				border-bottom: 1px solid #e7e7e7;
				padding-bottom: 10px;">
				大输液批次消耗汇总单
			</div>
			<div class="monad-sign" style="display: flex;line-height: 23px;font-size: 14px;">
				<div style="margin-right: 15px;" *ngIf="printData.length">日期：{{printData[0].createTime|date:'yyyy-MM-dd HH:mm'}}</div>
				<div style="margin-right: 15px;">批次号：{{batchNo}}</div>
			</div>
			<div style="border: 1px solid #e7e7e7;border-bottom: none;font-size: 14px;">
				<div class="thead" style="display: flex;">
					<div style="width: 40%;display: flex;font-size: 12px;
					align-items: center;
					justify-content: center;
					flex-wrap: wrap;
					border-right: 1px solid #e7e7e7;
					border-bottom: 1px solid #e7e7e7;">药品名称</div>
					
					<div style="width: 20%;display: flex;font-size: 12px;
					align-items: center;
					justify-content: center;
					flex-wrap: wrap;
					border-right: 1px solid #e7e7e7;
					border-bottom: 1px solid #e7e7e7;">药品规格</div>
					
					<div style="width: 13%;display: flex;font-size: 12px;
					align-items: center;
					justify-content: center;
					flex-wrap: wrap;
					border-right: 1px solid #e7e7e7;
					border-bottom: 1px solid #e7e7e7;">包装规格</div>
					
					<div style="width: 13%;display: flex;font-size: 12px;
					align-items: center;
					justify-content: center;
					flex-wrap: wrap;
					border-right: 1px solid #e7e7e7;
					border-bottom: 1px solid #e7e7e7;">发药总量</div>

					<div style="width: 14%;display: flex;font-size: 12px;
					align-items: center;
					justify-content: center;
					flex-wrap: wrap;
					border-bottom: 1px solid #e7e7e7;">箱数合计</div>
					
				</div>
				<div *ngFor="let data of summaryDataList" style="display: flex;">
					<div style="width: 40%;display: flex;font-size: 12px;
					align-items: center;
					justify-content: center;
					flex-wrap: wrap;
					border-right: 1px solid #e7e7e7;
					border-bottom: 1px solid #e7e7e7;">{{data.drugsInfoDTO.drugName}}</div>
					
					<div style="width: 20%;display: flex;font-size: 12px;
					align-items: center;
					justify-content: center;
					flex-wrap: wrap;
					border-right: 1px solid #e7e7e7;
					border-bottom: 1px solid #e7e7e7;">{{data.drugsInfoDTO.specs}}</div>
					
					<div style="width: 13%;display: flex;font-size: 12px;
					align-items: center;
					justify-content: center;
					flex-wrap: wrap;
					border-right: 1px solid #e7e7e7;
					border-bottom: 1px solid #e7e7e7;">{{ data.drugsInfoDTO.packingSpecs }}</div>
					
					<div style="width: 13%;display: flex;font-size: 12px;
					align-items: center;
					justify-content: center;
					flex-wrap: wrap;
					border-right: 1px solid #e7e7e7;
					border-bottom: 1px solid #e7e7e7;">{{data.actualCount}}</div>
					
					<div style="width: 14%;display: flex;font-size: 12px;
					align-items: center;
					justify-content: center;
					flex-wrap: wrap;
					border-bottom: 1px solid #e7e7e7;">
					{{data.cartonNum}} 箱 &nbsp;
					<span *ngIf="data.afterInventory>0">
						{{data.afterInventory}} {{data.drugsInfoDTO.unit}}
					</span>
					</div>
					
				</div>
			</div>
		</div>
  </div>

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

 <!-- 模态框 -->
<app-dialog-delete [delModal]="printModal" (hideDelModalEvent)="hidePrintModal()" [btnLoading]="btnLoading"
  (confirmDelEvent)="confirmPrintDel()" [content]="'您确认发药并打印吗？打印同时会更新云库存并建立配送工单？'"></app-dialog-delete>
