<div class="list-template">
  <div class="list-template__content">
    <div class="list-template__top" nz-row>
      <div nz-col nzXl='15' class="list-template__searchBox">
        <div class="list-template__searchItem">
          <span class="label label--big">轮巡计划名称：</span>
          <input nz-input class="formItem" placeholder="请输入关键字" [(ngModel)]="searchCriteria.name" />
        </div>
        <div class="list-template__searchItem">
          <span class="label">终点科室：</span>
          <nz-select [nzDropdownMatchSelectWidth]="false" class="formItem" nzServerSearch nzShowSearch nzAllowClear
            nzPlaceHolder="请选择终点科室" [(ngModel)]="searchCriteria.endDepartment" (nzOnSearch)="changeInp($event,'search')"
            (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>
      <div nz-col nzXl="9" class="list-template__btns">
        <button nz-button class="btn default" (click)='reset()'>重置</button>
        <button nz-button *ngIf="coopBtns.add" class="btn default ml8" (click)="addModal()">新增</button>
        <button nz-button class="btn default ml8" (click)='getList(1)'>搜索</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="5%">序号</th>
            <th nzWidth="10%">轮巡计划名称</th>
            <th nzWidth="10%">轮巡类型</th>
            <th nzWidth="15%">执行策略</th>
            <th nzWidth="15%">执行时间</th>
            <th nzWidth="20%">终点科室</th>
            <th nzWidth="25%">操作</th>
          </tr>
        </thead>
        <tbody>
          <tr *ngFor="let data of listOfData;let i = index">
            <td>{{ i+1 }}</td>
            <td>{{ data.title }}</td>
            <td>{{ data.taskType.taskName }}</td>
            <td [ngSwitch]="data.timeStep">
              <ng-container *ngSwitchCase="'day'">每日{{data.dayType == 0?'':'（'+dayType[data.dayType]+'）'}}
              </ng-container>
              <ng-container *ngSwitchCase="'week'">每周{{data.dayType == 0?'':'（'+dayType[data.dayType]+'）'}}
              </ng-container>
              <ng-container *ngSwitchCase="'month'">每月{{data.dayType == 0?'':'（'+dayType[data.dayType]+'）'}}
              </ng-container>
              <ng-container *ngSwitchCase="'year'">每年{{data.dayType == 0?'':'（'+dayType[data.dayType]+'）'}}
              </ng-container>
            </td>
            <td [ngSwitch]="data.timeStep">
              <ng-container *ngSwitchCase="'day'">{{ data.executeTime|date:'HH时mm分' }}</ng-container>
              <ng-container *ngSwitchCase="'week'">{{data.weekName}} {{ data.executeTime|date:'HH时mm分' }}</ng-container>
              <ng-container *ngSwitchCase="'month'">{{data.extra1}}日 {{ data.executeTime|date:'HH时mm分' }}</ng-container>
              <ng-container *ngSwitchCase="'year'">{{ data.executeTime|date:'MM月dd日HH时mm分' }}</ng-container>
            </td>
            <td>
              <div class="targetDept" nz-tooltip nzTooltipTitle="{{data.targetDeptShow}}">{{ data.targetDeptShow }}
              </div>
            </td>
            <td>
              <div class="coop">
                <span *ngIf="coopBtns.edit&&data.taskType.associationType.value=='other'&&!data.taskTypeDeptOrder"
                  (click)="batchOrdersHandler(data)">批量建单设置</span>
                <span *ngIf="coopBtns.look" (click)="detail(data.id)">查看</span>
                <span *ngIf="coopBtns.edit" (click)="edit(data)">修改</span>
                <span *ngIf="coopBtns.del" (click)="showDelModal(data.id,'您确认要删除此轮巡计划吗？','删除','del')">删除</span>
                <span *ngIf="coopBtns.isStartUp"
                  (click)="showDelModal(data.id,data.flag?'您确认要停用该计划吗？':'您确认要启用该计划吗？',data.flag?'停用':'启用','switch',data.flag)">{{data.flag?'停用':'启用'}}</span>
                <span *ngIf="coopBtns.executeNow" (click)="openExecModal(data)">立即执行</span>
              </div>
            </td>
          </tr>
        </tbody>
      </nz-table>
      <div class="list-template__pagination">
        <nz-pagination [(nzPageIndex)]="pageIndex" [(nzTotal)]="listLength" [(nzPageSize)]="pageSize"
          (nzPageIndexChange)="getList(0)" (nzPageSizeChange)="getList(0)">
        </nz-pagination>
      </div>
    </div>
  </div>

  <!-- 新增/编辑模态框 -->
  <div class="save display_flex justify-content_flex-center align-items_center add" *ngIf="modal">
    <div class="modalBody">
      <div class="title">{{add?"新增":"编辑"}}轮巡计划<i class="icon_transport transport-guanbi" (click)="hideAddModal()"></i>
      </div>
      <overlay-scrollbars #osComponentRef1 class="content">
        <p>创建人：{{createUser}}</p>
        <form nz-form [formGroup]="validateForm" class="addForm" (ngSubmit)="submitForm()">
          <nz-form-item>
            <nz-form-label [nzSm]="6" [nzXs]="24" nzRequired nzFor="roundRobinName">轮巡计划名称</nz-form-label>
            <nz-form-control nzErrorTip="请输入轮巡计划名称!">
              <nz-input-group>
                <input nz-input formControlName="roundRobinName" placeholder="请输入轮巡计划名称" />
              </nz-input-group>
            </nz-form-control>
          </nz-form-item>
          <nz-form-item>
            <nz-form-label [nzSm]="6" [nzXs]="24" nzRequired nzFor="roundRobinType">轮巡类型</nz-form-label>
            <nz-form-control nzErrorTip="请选择轮巡类型!">
              <nz-select [nzDropdownMatchSelectWidth]="false" formControlName="roundRobinType" nzShowSearch nzAllowClear
                nzPlaceHolder="请选择轮巡类型" nzServerSearch (nzOnSearch)="changeInpTasktype($event)"
                (nzOpenChange)="changeFormTasktype($event)" (ngModelChange)="selectedTasktypeHandler($event)">
                <ng-container *ngFor="let data of roundRobinTypes">
                  <nz-option *ngIf="!isLoading" [nzLabel]="data.taskName" [nzValue]="data.id"
                    [nzDisabled]="data.carryingCourses&&(!data.carryingCourses[0].departmentStrategy||!data.carryingCourses[1].departmentStrategy)">
                  </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]="24" [nzXs]="24" nzRequired nzFor="datesType">工作日或节假日</nz-form-label>
            <nz-form-control nzErrorTip="请选择工作日或节假日!" class="datesGroup">
              <nz-checkbox-group formControlName="datesType" [(ngModel)]="oneOption">
              </nz-checkbox-group>
            </nz-form-control>
          </nz-form-item>
          <nz-form-item>
            <nz-form-label [nzSm]="24" [nzXs]="24" nzRequired nzFor="timeStep">轮巡策略</nz-form-label>
            <nz-form-control nzErrorTip="请选择轮巡策略!">
              <nz-radio-group formControlName="timeStep" (ngModelChange)="timeStepChange($event)">
                <label nz-radio [nzValue]="data.key" *ngFor="let data of timeSteps">{{data.name}}</label>
              </nz-radio-group>
            </nz-form-control>
          </nz-form-item>
          <!-- <nz-form-item>
            <nz-form-label [nzSm]="6" [nzXs]="24" nzRequired nzFor="executionTime">执行时间</nz-form-label>
            <nz-form-control nzErrorTip="请选择执行时间!">
              <nz-select formControlName="executionTime" class="select-seimin" nzMode="multiple" nzPlaceHolder="请选择执行时间"
                [(ngModel)]="timeSelectedValue" (nzFocus)="timeSelectFocus()">
                <nz-option *ngFor="let option of defaultSelectTimesOption" [nzLabel]="option" [nzValue]="option" nzHide>
                </nz-option>
              </nz-select>
              <nz-time-picker formControlName="time" class="time-picker-seimin" [(ngModel)]="time"
                [nzDefaultOpenValue]="defaultTimePickerOpenValue" [nzAddOn]="timePickerAddOnTemplate"
                [nzOpen]="timePickerOpen" nzFormat="HH:mm" (nzOpenChange)="timePickerChange()" nzPlaceHolder="请选择执行时间">
              </nz-time-picker>
              <ng-template #timePickerAddOnTemplate>
                <button nz-button nzSize="small" nzType="primary" (click)="timePickerClick()">确定</button>
              </ng-template>
            </nz-form-control>
          </nz-form-item> -->
          <nz-form-item *ngIf="validateForm.value.timeStep == 'week'">
            <nz-form-label [nzSm]="24" [nzXs]="24" nzRequired nzFor="doWeek">计划执行周（每周）</nz-form-label>
            <nz-form-control nzErrorTip="请选择周!">
              <nz-select formControlName="doWeek" nzPlaceHolder="请选择周">
                <nz-option nzValue="1" nzLabel="周一"></nz-option>
                <nz-option nzValue="2" nzLabel="周二"></nz-option>
                <nz-option nzValue="3" nzLabel="周三"></nz-option>
                <nz-option nzValue="4" nzLabel="周四"></nz-option>
                <nz-option nzValue="5" nzLabel="周五"></nz-option>
                <nz-option nzValue="6" nzLabel="周六"></nz-option>
                <nz-option nzValue="7" nzLabel="周日"></nz-option>
              </nz-select>
            </nz-form-control>
          </nz-form-item>
          <nz-form-item *ngIf="validateForm.value.timeStep == 'month'">
            <nz-form-label [nzSm]="24" [nzXs]="24" nzRequired nzFor="doMonth">计划执行（每月）</nz-form-label>
            <nz-form-control nzErrorTip="请选择日!">
              <nz-select formControlName="doMonth" nzPlaceHolder="请选择日">
                <nz-option nzValue="{{item}}" nzLabel="{{item}}号" *ngFor="let item of months">
                </nz-option>
              </nz-select>
            </nz-form-control>
          </nz-form-item>
          <nz-form-item *ngIf="validateForm.value.timeStep == 'year'">
            <nz-form-label [nzSm]="24" [nzXs]="24" nzRequired nzFor="doYear">计划执行（每年）</nz-form-label>
            <nz-form-control nzErrorTip="请选择月日!">
              <nz-date-picker nzFormat="MM-dd" formControlName="doYear" nzPlaceHolder="请选择月日"></nz-date-picker>
            </nz-form-control>
          </nz-form-item>
          <nz-form-item>
            <nz-form-label [nzSm]="24" [nzXs]="24" nzRequired nzFor="executeTime">执行时间</nz-form-label>
            <nz-form-control nzErrorTip="请选择执行时间!">
              <nz-time-picker nzFormat="HH:mm" formControlName="executeTime" class="w100" nzPlaceHolder="请选择执行时间"
                [nzAllowEmpty]="false">
              </nz-time-picker>
            </nz-form-control>
          </nz-form-item>
          <ng-container *ngIf="selectedTasktype">
            <nz-form-item *ngIf="selectedTasktype.associationType.value=='specimenPlan' || selectedTasktype.associationType.value=='specimen'">
              <nz-form-label [nzSm]="6" [nzXs]="24"
                [nzRequired]="selectedTasktype.associationType.value=='specimenPlan' || selectedTasktype.associationType.value=='specimen'" nzFor="endDepartment">终点科室
              </nz-form-label>
              <nz-form-control nzErrorTip="请选择终点科室!">
                <nz-select [nzMode]="'multiple'" [nzDropdownMatchSelectWidth]="false" formControlName="endDepartment"
                  nzShowSearch nzAllowClear nzPlaceHolder="请选择终点科室" nzServerSearch
                  (nzOnSearch)="changeInp($event,'form')" (nzOpenChange)="changeForm($event)">
                  <ng-container *ngFor="let data of department">
                    <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>
              </nz-form-control>
            </nz-form-item>
            <nz-form-item
              *ngIf="selectedTasktype.associationType.value=='other'&&(selectedTasktype.carryingCourses[0].departmentStrategy.value==1||selectedTasktype.carryingCourses[1].departmentStrategy.value==1)">
              <nz-form-control>
                <label nz-checkbox formControlName="openDepartments">
                  <span>是否根据开通科室建单</span>
                </label>
              </nz-form-control>
              <div class="red openDepartmentsTips">(勾选后系统默认将开通科室，设置为发起科室)</div>
            </nz-form-item>
          </ng-container>
        </form>
        <ng-container *ngIf="selectedTasktype">
          <p *ngIf="selectedTasktype.associationType.value=='specimenPlan' || selectedTasktype.associationType.value=='specimen'" class="roundRobinTips">
            提示：起点科室即为标本开通科室；执行人即为科室绑定人员设定；前往设置开通科室、工作分配
          </p>
          <p *ngIf="selectedTasktype.associationType.value=='other'&&(selectedTasktype.carryingCourses[0].departmentStrategy.value==1||selectedTasktype.carryingCourses[1].departmentStrategy.value==1)"
            class="roundRobinTips">
            提示：您选择的任务类型，需要根据发起科室进行建单，您需要再批量建单中增加发起科室。</p>
          <p *ngIf="selectedTasktype.associationType.value=='other'&&selectedTasktype.carryingCourses[0].departmentStrategy.value!=1&&selectedTasktype.carryingCourses[1].departmentStrategy.value!=1"
            class="roundRobinTips">
            提示：您选择的任务类型，需要选择起点科室和终点科室，请在”批量建单“中进行设置。</p>
        </ng-container>
      </overlay-scrollbars>
      <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)="hideAddModal()">取消</button>
      </div>
    </div>
  </div>

  <!-- 删除模态框 -->
  <app-dialog-delete [delModal]="delModal" (hideDelModalEvent)="hideDelModal()" [btnLoading]="btnLoading"
    (confirmDelEvent)="confirmDel()" [content]="tipsMsg1"></app-dialog-delete>
</div>
<!-- 操作成功/失败提示框 -->
<app-prompt-modal *ngIf="promptModalShow" [content]="promptContent" [success]="ifSuccess" [show]="promptModalShow"
  [info]="promptInfo">
</app-prompt-modal>
<!-- 查看详情 -->
<router-outlet></router-outlet>
<!-- 立即执行 -->
<app-dialog-delete [delModal]="execModal" (hideDelModalEvent)="closeExecModal()" [btnLoading]="btnLoading"
  (confirmDelEvent)="confirmExec()" content="您确认要立即执行该轮巡计划吗？"></app-dialog-delete>
<!-- 遮罩 -->
<app-mask *ngIf="maskFlag"></app-mask>
<!-- 批量建单设置 -->
<app-batch-orders *ngIf="batchOrdersFlag" [selectedBatchOrder]="selectedBatchOrder" (close)="close($event)">
</app-batch-orders>
