<div class="list-template">
  <div class="list-template__content">
    <div *ngIf="currentUserAccount == 'dsadmin'" class="list-template__top">
    <!-- <div class="list-template__top"> -->
      <div nz-col nzXl="18" class="list-template__searchBox"></div>
      <div nz-col nzXl="6" class="list-template__btns">
        <button nz-button class="btn default" (click)="addModal()">新增</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="16%">院区/部门名称</th>
            <th nzWidth="16%">部门类型</th>
            <th nzWidth="16%">父院区</th>
            <th nzWidth="16%">父级部门</th>
            <th nzWidth="16%">院区编码</th>
            <th nzWidth="20%">操作</th>
          </tr>
        </thead>
        <tbody>
          <tr *ngFor="let data of listOfData">
            <td>{{ data.hosName || '无' }}</td>
            <td>{{ data.type ? data.type.name : '无' }}</td>
            <td>{{ data.parent ? data.parent.hosName : '无' }}</td>
            <td>{{ data.parentDeptDTO ? data.parentDeptDTO.hosName : '无' }}</td>
            <td>{{ data.hosNo || '无' }}</td>
            <td>
              <div class="coop">
                <span *ngIf="currentUserAccount == 'dsadmin'" (click)="copy(data)">复制</span>
                <span *ngIf="coopBtns.edit" (click)="edit(data)">编辑</span>
                <span *ngIf="coopBtns.del" (click)="showDelModal(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 class="save align-items_center display_flex justify-content_flex-center add" *ngIf="modal">
    <div class="modalBody">
      <div class="title">{{ add ? "新增" : "编辑" }}<i class="icon_transport transport-guanbi" (click)="hideAddModal()"></i>
      </div>
      <div class="content">
        <form
          nz-form
          [formGroup]="validateForm"
          class="addForm"
          (ngSubmit)="submitForm()"
        >
          <nz-form-item>
            <nz-form-label [nzSm]="6" [nzXs]="24" nzFor="parentHospital">父院区</nz-form-label>
            <nz-form-control nzErrorTip="请选择父院区!">
              <nz-select formControlName="parentHospital" [nzDropdownMatchSelectWidth]="false" nzPlaceHolder="请选择父院区" nzShowSearch nzAllowClear nzServerSearch (nzOnSearch)="changeInp($event, 'parent')"
              (nzOpenChange)="openHospitalSelect($event)" (ngModelChange)="changeHospitalSelect($event)">
                <ng-container *ngFor="let option of parentHospitals">
                  <nz-option *ngIf="!isLoading" [nzLabel]="option.hosName" [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-form-control>
          </nz-form-item>
          <nz-form-item>
            <nz-form-label [nzSm]="6" [nzXs]="24" nzFor="parentDeptId">父级部门</nz-form-label>
            <nz-form-control nzErrorTip="请选择父级部门!">
              <nz-select formControlName="parentDeptId" [nzDropdownMatchSelectWidth]="false" nzPlaceHolder="请选择父级部门" nzShowSearch nzAllowClear nzServerSearch (nzOnSearch)="changeInp($event, 'parentDept')"
              (nzOpenChange)="openParentDeptSelect($event)">
                <ng-container *ngFor="let option of parentDepts">
                  <nz-option *ngIf="!isLoading" [nzLabel]="option.hosName" [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-form-control>
          </nz-form-item>
          <nz-form-item>
            <nz-form-label
              [nzSm]="6"
              [nzXs]="24"
              nzRequired
              nzFor="hospitalName"
              >{{validateForm.value.parentHospital ? '部门' : '院区'}}名称</nz-form-label
            >
            <nz-form-control nzErrorTip="请输入院区名称!">
              <nz-input-group>
                <input
                  type="hospitalName"
                  nz-input
                  formControlName="hospitalName"
                  placeholder="请输入院区名称"
                />
              </nz-input-group>
            </nz-form-control>
          </nz-form-item>
          <nz-form-item [hidden]="!validateForm.value.parentHospital">
            <nz-form-label [nzSm]="6" [nzXs]="24" nzFor="hospitalType" [nzRequired]="validateForm.value.parentHospital">部门类型</nz-form-label>
            <nz-form-control nzErrorTip="请选择部门类型!">
              <nz-select formControlName="hospitalType" [nzDropdownMatchSelectWidth]="false" nzPlaceHolder="请选择部门类型" nzShowSearch nzAllowClear (nzOpenChange)="openHospitalTypeSelect($event)">
                <ng-container *ngFor="let option of hospitalTypes">
                  <nz-option *ngIf="!isHospitalTypeLoading" [nzLabel]="option.name" [nzValue]="option.id"></nz-option>
                </ng-container>
                <nz-option *ngIf="isHospitalTypeLoading" nzDisabled nzCustomContent>
                  <i nz-icon nzType="loading" class="loading-icon"></i>
                  搜索中...
                </nz-option>
              </nz-select>
            </nz-form-control>
          </nz-form-item>
          <nz-form-item>
            <nz-form-label [nzSm]="6" [nzXs]="24" nzRequired nzFor="hospitalNum"
              >院区编码</nz-form-label
            >
            <nz-form-control nzErrorTip="请输入院区编码!">
              <nz-input-group>
                <input
                  type="hospitalNum"
                  nz-input
                  formControlName="hospitalNum"
                  placeholder="请输入院区编码"
                />
              </nz-input-group>
            </nz-form-control>
          </nz-form-item>
        </form>
      </div>
      <div class="display_flex justify-content_flex-center">
        <button
          nzType="primary"
          [nzLoading]="btnLoading"
          nz-button
          (click)="submitForm()"
        >
          确认
        </button>
        <button
          class="btn cancel"
          nz-button
          nzType="default"
          (click)="hideAddModal()"
        >
          取消
        </button>
      </div>
    </div>
  </div>
  <!-- 复制模态框 -->
  <div
    class="save align-items_center display_flex justify-content_flex-center add"
    *ngIf="modalCopy"
  >
    <div class="modalBody">
      <div class="title">
        复制院区信息<i
          class="icon_transport transport-guanbi"
          (click)="hideAddModalCopy()"
        ></i>
      </div>
      <div class="content">
        <div class="red" style="margin-bottom: 16px">
          请选择您要复制的院区，如院区已经有任务类型则无法复制成功！
        </div>
        <form
          nz-form
          [formGroup]="validateFormCopy"
          class="addForm"
          (ngSubmit)="submitFormCopy()"
        >
          <nz-form-item>
            <nz-form-label
              style="line-height: 1"
              [nzSm]="6"
              [nzXs]="24"
              nzFor="copyHosId"
              >复制的院区</nz-form-label
            >
            <nz-form-control nzErrorTip="请选择复制的院区!">
              <nz-select
                nzAllowClear
                [nzDropdownMatchSelectWidth]="false"
                formControlName="copyHosId"
                nzPlaceHolder="请选择复制的院区"
              >
                <nz-option
                  *ngFor="let item of listOfData | filterSelf: coopId"
                  [nzLabel]="item.hosName"
                  [nzValue]="item.id"
                >
                </nz-option>
              </nz-select>
            </nz-form-control>
          </nz-form-item>
        </form>
      </div>
      <div class="display_flex justify-content_flex-center">
        <button
          nzType="primary"
          [nzLoading]="btnLoading"
          nz-button
          (click)="submitFormCopy()"
        >
          确认
        </button>
        <button
          class="btn cancel"
          nz-button
          nzType="default"
          (click)="hideAddModalCopy()"
        >
          取消
        </button>
      </div>
    </div>
  </div>
  <!-- 删除模态框 -->
  <app-dialog-delete
    [delModal]="delModal"
    (hideDelModalEvent)="hideDelModal()"
    [btnLoading]="btnLoading"
    (confirmDelEvent)="confirmDel()"
    content="您确认要删除此院区吗？"
  ></app-dialog-delete>
</div>
<!-- 操作成功/失败提示框 -->
<app-prompt-modal
  *ngIf="promptModalShow"
  [content]="promptContent"
  [success]="ifSuccess"
  [show]="promptModalShow"
  [info]="promptInfo"
></app-prompt-modal>
