<div class="container">
  <div class="row">
    <div class="content-block">
      <ngx-loading [show]="loading" [config]="{fullScreenBackdrop: true}"></ngx-loading>
      <h2 class="title">使用者管理</h2>
      <button type="button" class="btn btn-sm btn-primary" routerLink="/sys/sys002-create-user" routerLinkActive="active">新增使用者</button>
      <div class="right">
        <input type="search" class="form-group" [(ngModel)]="this.tableQueryData.Term" placeholder="查詢使用者帳號/名稱">
        <button type="submit" class="btn btn-sm btn-outline-primary" (click)="doSearch()">
          <i class="fa fa-search" aria-hidden="true"></i>
        </button>
        <button type="submit" class="btn btn-sm btn-outline-danger" (click)="clearSearch()">
          <i class="fa fa-times" aria-hidden="true"></i>
        </button>
      </div>
      <div class="table-responsive">
        <table class="table table-hover">
          <thead>
            <tr>
              <th (click)="order('Account')">
                <i [ngClass]="{'asc icon-arrow-up-circle': IsAsc, 'desc icon-arrow-down-circle': !IsAsc}" *ngIf="this.item === 'Account'"></i>
                帳號</th>
              <th (click)="order('UserName')">
                <i [ngClass]="{'asc icon-arrow-up-circle': IsAsc, 'desc icon-arrow-down-circle': !IsAsc}" *ngIf="this.item === 'UserName'"></i>
                使用者名稱</th>
              <th (click)="order('GroupCodeId')">
                <i [ngClass]="{'asc icon-arrow-up-circle': IsAsc, 'desc icon-arrow-down-circle': !IsAsc}" *ngIf="this.item === 'GroupCodeId'"></i>
                所屬分局</th>
              <th (click)="order('RoleCodeId')">
                <i [ngClass]="{'asc icon-arrow-up-circle': IsAsc, 'desc icon-arrow-down-circle': !IsAsc}" *ngIf="this.item === 'RoleCodeId'"></i>
                角色權限</th>
                <th (click)="order('Status')">
                  <i [ngClass]="{'asc icon-arrow-up-circle': IsAsc, 'desc icon-arrow-down-circle': !IsAsc}" *ngIf="this.item === 'Status'"></i>
                  狀態</th>
              <th>執行動作</th>
            </tr>
          </thead>
          <tbody>
            <tr *ngFor="let user of userDataList">
              <td>{{user.Account}}</td>
              <td>{{user.UserName}}</td>
              <td>{{getGroupCodeText(user.GroupCode_Id)}}</td>
              <td>{{getRoleCodeText(user.RoleCode_Id)}}</td>
              <td *ngIf="user.Status === 1">啟用</td>
              <td *ngIf="user.Status === 0">停用</td>
              <td>
                <button type="button" class="btn btn-sm btn-outline-info" (click)="goUserDetail(user)">
                  <i class="fa fa-eye"></i> 詳情
                </button>
                <button type="button" class="btn btn-sm btn-outline-warning" (click)="goEditUser(user)">
                  <i class="fa fa-pencil"></i> 編輯
                </button>
                <button type="button" *ngIf="user.RoleCode_Id != setRole" class="btn btn-sm btn-outline-danger" (click)="deleteUserData(user.Id)">
                  <i class="fa fa-trash"></i> 刪除
                </button>
                <button type="button" class="btn btn-sm btn-outline-info" *ngIf="user.Status === 1" (click)="setUserStatus(user, 0)">
                  <i class="fa fa-eye"></i> 停用
                </button>
                <button type="button" class="btn btn-sm btn-outline-info" *ngIf="user.Status === 0" (click)="setUserStatus(user, 1)">
                  <i class="fa fa-eye"></i> 啟用
                </button>
                <button type="button" class="btn btn-sm btn-outline-info" (click)="setUserPassword(user)">
                  <i class="fa fa-eye"></i> 初始密碼
                </button>
                <button type="button" *ngIf="user.RoleCode_Id == setRole" class="btn btn-sm btn-outline-danger" [disabled]="user.RoleCode_Id == setRole">
                  禁止刪除
                </button>
              </td>
            </tr>
          </tbody>
        </table>
      </div>
      <div class="noData" *ngIf="userDataList.length == 0">
        暫無資料
      </div>
      <div *ngIf="userDataList.length > 0" class="pagination_center">
        <div class="pagination">
          <span *ngFor="let page of pageLinks;">
            <a *ngIf="page.pageNo!==this.tableQueryData.CurrentPage" (click)="onPageChange($event,page.pageNo)">{{page.text}}</a>
            <a *ngIf="page.pageNo===this.tableQueryData.CurrentPage" class="active">{{page.text}}</a>
          </span>
        </div>
      </div>
    </div>
  </div>
</div>
