<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>
      <div nz-col nzLg="6" class="list-template__btns">
        <button nz-button *ngIf="coopBtns.add" 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="12%">表单名称</th>
            <th nzWidth="12%">是否允许生成维修单</th>
            <th nzWidth="12%">是否自动生成维修单</th>
            <th nzWidth="12%">报修科室</th>
            <th nzWidth="12%">故障现象</th>
            <th nzWidth="12%">优先级</th>
            <th nzWidth="12%">状态</th>
            <th nzWidth="16%">操作</th>
          </tr>
        </thead>
        <tbody>
          <tr *ngFor="let data of listOfData;let i = index">
            <td>{{data.name}}</td>
            <td>{{data.showOrder ? '是' : '否'}}</td>
            <td>{{data.createOrder ? '是' : '否'}}</td>
            <td>{{data.repairDeptDTO?.dept}}</td>
            <td>{{data.categoryDTO?.mutiCategory}}</td>
            <td>{{data.priorityDTO?.name}}</td>
            <td>{{data.status.name}}</td>
            <td>
              <div class="coop">
                <span *ngIf="coopBtns.edit" (click)="edit(data)">编辑</span>
                <span *ngIf="coopBtns.publish && data.status.value === '0'" (click)="showDelModal(data,'您确认要发布吗？','发布','publish')">发布</span>
                <span *ngIf="coopBtns.config" (click)="toItem(data)">配置巡检项</span>
                <span *ngIf="coopBtns.del" (click)="showDelModal(data,'删除后您将无法引用此表单，现有关联的计划可继续使用','删除','del')">删除</span>
              </div>
            </td>
          </tr>
        </tbody>
      </nz-table>
      <div class="list-template__pagination">
        <nz-pagination [(nzPageIndex)]="pageIndex" [(nzTotal)]="listLength" [(nzPageSize)]="pageSize" nzShowSizeChanger
          (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">{{modelName}}巡检单<i class="icon_transport transport-guanbi" (click)="hideAddModal()"></i></div>
      <div class="content">
        <form nz-form [formGroup]="validateForm" class="addForm">
          <nz-form-item>
            <nz-form-label class="line_height_normal" [nzSpan]="5" nzRequired nzFor="name">表单名称</nz-form-label>
            <nz-form-control [nzSpan]="19" nzErrorTip="请输入表单名称!">
              <nz-input-group>
                <textarea formControlName="name" nz-input
                  placeholder="请输入表单名称"></textarea>
              </nz-input-group>
            </nz-form-control>
          </nz-form-item>
          <nz-form-item>
            <nz-form-label [nzSpan]="9" nzRequired nzFor="showOrder">是否允许生成维修单</nz-form-label>
            <nz-form-control [nzSpan]="15" nzErrorTip="请选择是否允许生成维修单!">
              <nz-radio-group formControlName="showOrder" (ngModelChange)="changeShowOrder($event)">
                <label nz-radio [nzValue]="1">是</label>
                <label nz-radio [nzValue]="0">否</label>
              </nz-radio-group>
            </nz-form-control>
          </nz-form-item>
          <nz-form-item *ngIf="validateForm.value.showOrder == 1">
            <nz-form-label [nzSpan]="9" nzRequired nzFor="createOrder">是否自动生成维修单</nz-form-label>
            <nz-form-control [nzSpan]="15" nzErrorTip="请选择是否自动生成维修单!">
              <nz-radio-group formControlName="createOrder" (ngModelChange)="changeCreateOrder($event)">
                <label nz-radio [nzValue]="1">是</label>
                <label nz-radio [nzValue]="0">否</label>
              </nz-radio-group>
            </nz-form-control>
          </nz-form-item>
          <nz-form-item *ngIf="validateForm.value.showOrder == 1">
            <nz-form-label [nzSpan]="5" [nzRequired]="validateForm.value.createOrder == 1" nzFor="repairDeptId">报修科室</nz-form-label>
            <nz-form-control [nzSpan]="19" nzErrorTip="请选择报修科室!">
              <nz-select (nzOnSearch)="changeInp('repairDept', $event)" [nzDropdownMatchSelectWidth]="false" nzServerSearch nzShowSearch nzAllowClear formControlName="repairDeptId" nzPlaceHolder="请选择报修科室" (nzOpenChange)="changeInp('repairDept', '')">
                <ng-container *ngFor="let option of repairDeptList">
                  <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-form-control>
          </nz-form-item>
          <nz-form-item *ngIf="validateForm.value.showOrder == 1">
            <nz-form-label [nzSpan]="5" [nzRequired]="validateForm.value.createOrder == 1" nzFor="categoryId">故障现象</nz-form-label>
            <nz-form-control [nzSpan]="19" nzErrorTip="请选择故障现象!">
              <nz-select (nzOnSearch)="changeInp('category', $event)" [nzDropdownMatchSelectWidth]="false" nzServerSearch nzShowSearch nzAllowClear formControlName="categoryId" nzPlaceHolder="请选择故障现象" (nzOpenChange)="changeInp('category', '')">
                <ng-container *ngFor="let option of categoryList">
                  <nz-option *ngIf="!isLoading" [nzLabel]="option.mutiCategory" [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 *ngIf="validateForm.value.showOrder == 1">
            <nz-form-label [nzSpan]="5" nzFor="priorityId">优&nbsp;&nbsp;先&nbsp;&nbsp;级</nz-form-label>
            <nz-form-control [nzSpan]="19" nzErrorTip="请选择优先级!">
              <nz-select [nzDropdownMatchSelectWidth]="false" nzAllowClear formControlName="priorityId" nzPlaceHolder="请选择优先级" (nzOpenChange)="changeInp('priority', '')">
                <ng-container *ngFor="let option of priorityList">
                  <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-form-control>
          </nz-form-item>
          <nz-form-item *ngIf="validateForm.value.createOrder == 1">
            <nz-form-label [nzSpan]="5" nzRequired nzFor="userGroup">自动派单</nz-form-label>
            <nz-form-control [nzSpan]="19" nzErrorTip="请选择自动派单!">
              <nz-radio-group formControlName="userGroup" (ngModelChange)="changeUserGroup($event)">
                <label nz-radio [nzValue]="1">当前人</label>
                <label nz-radio [nzValue]="2">派单给组</label>
                <label nz-radio [nzValue]="3">派单给人</label>
              </nz-radio-group>
            </nz-form-control>
          </nz-form-item>
          <nz-form-item *ngIf="validateForm.value.userGroup == 1 || validateForm.value.userGroup == 2 || validateForm.value.userGroup == 3">
            <nz-form-label [nzSpan]="5" nzRequired nzFor="groupId">维&nbsp;&nbsp;修&nbsp;&nbsp;组</nz-form-label>
            <nz-form-control [nzSpan]="19" nzErrorTip="请选择维修组!">
              <nz-select (nzOnSearch)="changeInp('group', $event)" [nzDropdownMatchSelectWidth]="false" nzServerSearch nzShowSearch nzAllowClear formControlName="groupId" nzPlaceHolder="请选择维修组" (nzOpenChange)="changeInp('group', '')">
                <ng-container *ngFor="let option of groupList">
                  <nz-option *ngIf="!isLoading" [nzLabel]="option.groupName" [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 *ngIf="validateForm.value.userGroup == 3">
            <nz-form-label [nzSpan]="5" nzRequired nzFor="userId">维&nbsp;&nbsp;修&nbsp;&nbsp;人</nz-form-label>
            <nz-form-control [nzSpan]="19" nzErrorTip="请选择维修人!">
              <nz-select (nzOnSearch)="changeInp('user', $event)" [nzDropdownMatchSelectWidth]="false" nzServerSearch nzShowSearch nzAllowClear formControlName="userId" nzPlaceHolder="请选择维修人" (nzOpenChange)="changeInp('user', '')">
                <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-form-control>
          </nz-form-item>
        </form>
      </div>
      <div class=" display_flex justify-content_flex-center">
        <button nzType="primary" nz-button (click)="submitForm()" [nzLoading]="btnLoading">{{add ? '保存并配置' : '保存'}}</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>
