<!-- start 面包屑 -->
<app-breadcrumb></app-breadcrumb>
<!-- end 面包屑 -->
<!--条件搜索-->

<nz-spin [nzSpinning]="loadingObject.spinning" nzTip="{{loadingObject.msg}}">
    <div class="inner-content">
        <form nz-form [formGroup]="searchForm" (ngSubmit)="search(searchForm.value)">
            <div nz-row>
                <div nz-col nzSpan="8" *ngIf="roleType == 5 && adminFlag == 1">
                    <nz-form-item>
                        <nz-form-label [nzSpan]="8">所属部门</nz-form-label>
                        <nz-form-control [nzSpan]="14">
                            <nz-select nzAllowClear formControlName="orgId">
                                <nz-option *ngFor="let item of orgArray" nzLabel="{{item.name}}" nzValue="{{item.id}}"></nz-option>
                            </nz-select>
                        </nz-form-control>
                    </nz-form-item>
                </div>

                <div nz-col nzSpan="8">
                    <nz-form-item>
                        <nz-form-label [nzSpan]="8">卡号</nz-form-label>
                        <nz-form-control [nzSpan]="14">
                            <input nz-input formControlName="cardNo" />
                        </nz-form-control>
                    </nz-form-item>
                </div>

                <div nz-col nzSpan="8">
                    <nz-form-item>
                        <nz-form-label [nzSpan]="8">联系人</nz-form-label>
                        <nz-form-control [nzSpan]="14">
                            <input nz-input formControlName="contactName" />
                        </nz-form-control>
                    </nz-form-item>
                </div>

                <div nz-col nzSpan="8">
                    <nz-form-item>
                        <nz-form-label [nzSpan]="8">联系电话</nz-form-label>
                        <nz-form-control [nzSpan]="14">
                            <input nz-input formControlName="contactPhone" />
                        </nz-form-control>
                    </nz-form-item>
                </div>

                <div nz-col nzSpan="8">
                    <nz-form-item>
                        <nz-form-label [nzSpan]="8">油卡状态</nz-form-label>
                        <nz-form-control [nzSpan]="14">
                            <nz-select nzAllowClear formControlName="status">
                                <nz-option nzValue="1" nzLabel="正常"></nz-option>
                                <nz-option nzValue="2" nzLabel="禁用"></nz-option>
                            </nz-select>
                        </nz-form-control>
                    </nz-form-item>
                </div>

                <div nz-col nzSpan="8">
                    <nz-form-item>
                        <nz-form-label [nzSpan]="8">联系人设置</nz-form-label>
                        <nz-form-control [nzSpan]="14">
                            <nz-select nzAllowClear formControlName="isConfigContact">
                                <nz-option nzValue="false" nzLabel="未设置"></nz-option>
                                <nz-option nzValue="true" nzLabel="已设置"></nz-option>
                            </nz-select>
                        </nz-form-control>
                    </nz-form-item>
                </div>

                <div nz-col nzSpan="8">
                    <nz-form-item>
                        <nz-form-label [nzSpan]="8">绑定状态</nz-form-label>
                        <nz-form-control [nzSpan]="14">
                            <nz-select nzAllowClear formControlName="bindStatus">
                                <nz-option nzValue="0" nzLabel="未绑定"></nz-option>
                                <nz-option nzValue="1" nzLabel="已绑定"></nz-option>
                            </nz-select>
                        </nz-form-control>
                    </nz-form-item>
                </div>

                <div nz-col nzSpan="8">
                    <nz-form-item>
                        <nz-form-label [nzSpan]="8">绑定时间</nz-form-label>
                        <nz-form-control [nzSpan]="14">
                            <nz-range-picker
                                    formControlName="bindTime"
                                    [nzShowTime]="{ nzHideDisabledOptions: true}"
                                    nzFormat="yyyy-MM-dd HH:mm:ss"
                            ></nz-range-picker>
                        </nz-form-control>
                    </nz-form-item>
                </div>

                <div nz-col nzSpan="8">
                    <nz-form-item>
                        <nz-form-label [nzSpan]="8">生成时间</nz-form-label>
                        <nz-form-control [nzSpan]="14">
                            <nz-range-picker
                                    formControlName="createTime"
                                    [nzShowTime]="{ nzHideDisabledOptions: true}"
                                    nzFormat="yyyy-MM-dd HH:mm:ss"
                            ></nz-range-picker>
                        </nz-form-control>
                    </nz-form-item>
                </div>

            </div>

            <div nz-row>
                <div nz-col nzSpan="24" class="search-button">
                    <button nz-button nzType="primary"><i nz-icon nzType="search" nzTheme="outline"></i>搜索</button>
                    <button nz-button nzType="default" (click)="resetForm()"><i nz-icon nzType="reload" nzTheme="outline"></i>重置</button>
                </div>
            </div>
        </form>
    </div>

    <div class="inner-content">
        <div *ngIf="roleType == 5 && adminFlag == 0" style="width: 100%;text-align: center;">
            <nz-row [nzGutter]="16">
                <nz-col [nzSpan]="24">
                    <nz-statistic [nzValue]="'￥' + accountObject['amounts']" [nzTitle]="'账户余额'"></nz-statistic>
                </nz-col>
            </nz-row>
        </div>
        <span>共计 {{dataObject.total?dataObject.total:0}} 条数据</span>
        <div class="operating-button">
            <button nz-button nzType="primary" class="right-btn" (click)="showGenerateCardModal()" ><i nz-icon nzType="plus" nzTheme="outline"></i>生成油卡</button>
            <button nz-button nzType="primary" class="right-btn" (click)="excelCard()" ><i nz-icon nzType="import" nzTheme="outline"></i>导出油卡</button>
        </div>

        <!--数组表格 -->
        <nz-table #basicTable
                  [nzData]="dataObject.list"
                  [nzTotal]="dataObject.total"
                  [nzFrontPagination]="false"
                  [nzLoading]="tableLoading"
                  [nzPageIndex]="whereObject.pageNum"
                  (nzPageIndexChange)="requestData($event)"
                  [nzScroll]="{ x: '1100px'}">
            <thead>
            <tr>
                <th nzWidth="60px">序号</th>
                <th nzWidth="120px" *ngIf="roleType == 5 && adminFlag == 1">所属部门</th>
                <th nzWidth="160px">卡号</th>
                <th nzWidth="110px">余额</th>
                <th nzWidth="110px">消费金额</th>
                <th nzWidth="100px">联系人</th>
                <th nzWidth="120px">联系电话</th>
                <th nzWidth="100px">油卡状态</th>
                <th nzWidth="100px">绑定状态</th>
                <th nzWidth="160px">绑定时间</th>
                <th nzWidth="80px">操作人</th>
                <th nzWidth="160px">生成时间</th>
                <th nzWidth="160px" nzRight="0px">操作</th>
            </tr>
            </thead>
            <tbody>
            <tr *ngFor="let data of basicTable.data;let i = index">
                <td>{{i+1}}</td>
                <td *ngIf="roleType == 5 && adminFlag == 1">{{data.orgName}}</td>
                <td>{{data.cardNo}}</td>
                <td>￥{{data.amount}}</td>
                <td>￥{{data.amountConsume}}</td>
                <td>{{data.contactName?data.contactName:'未设置'}}</td>
                <td>{{data.contactPhone?data.contactPhone:'未设置'}}</td>
                <td>{{data.status | oilCardStatus}}</td>
                <td>{{data.bindStatus | oilCardBindStatus}}</td>
                <td>
                    <span *ngIf="data.bindTime != null">{{data.bindTime | date : 'yyyy-MM-dd HH:mm:ss'}}</span>
                    <span *ngIf="data.bindTime == null">未绑定</span>
                <td>{{data.opUserName}}</td>
                <td>{{data.createTime | date : 'yyyy-MM-dd HH:mm:ss'}}</td>
                <td nzRight="0px" class="table-td-operation">
                    <a (click)="showRechargeModal(data.cardNo)"> 充值 </a>
                    <a nz-dropdown [nzDropdownMenu]="menu"> 操作列表 <i nz-icon nzType="down"></i> </a>
                    <nz-dropdown-menu #menu="nzDropdownMenu">
                        <ul nz-menu nzSelectable>
                            <li nz-menu-item *ngIf="!data.contactPhone" (click)="showEditContactModal(data)"><a >设置联系人</a></li>
                            <li nz-menu-item *ngIf="data.contactPhone" (click)="showEditContactModal(data)"><a >更换联系人</a></li>
                            <li nz-menu-item *ngIf="data.status == 1" (click)="showDisabledConfirm(data.cardNo)"><a>禁用</a></li>
                            <li nz-menu-item *ngIf="data.status == 2" (click)="showEnableConfirm(data.cardNo)"><a>启用</a></li>
                            <li nz-menu-item [routerLink]="['/admin/oil-card/record-op-list']" [queryParams]="{ cardNo: data.cardNo}"><a>变更记录</a></li>
                            <li nz-menu-item [routerLink]="['/admin/oil-card/record-list']" [queryParams]="{ cardNo: data.cardNo}"><a>油卡账单</a></li>
                            <li nz-menu-item [routerLink]="['/admin/oil-card/order']" [queryParams]="{ cardNo: data.cardNo}"><a>消费订单</a></li>
                            <li nz-menu-item (click)="showRecycleAmountModal(data)"><a>回收余额</a></li>
                        </ul>
                    </nz-dropdown-menu>
                </td>
            </tr>
            </tbody>
        </nz-table>
    </div>
</nz-spin>

<nz-modal [(nzVisible)]="generateCardModal" nzTitle="生成油卡" (nzOnCancel)="closeGenerateCardModal()" nzWidth="500px" [nzFooter]="null">
    <form nz-form [formGroup]="generateCardForm">
        <nz-form-item>
            <nz-form-label [nzSpan]="6" nzRequired >生成数量</nz-form-label>
            <nz-form-control [nzSpan]="14">
                <nz-input-number style="width: 100%" formControlName="generateNum" [nzMin]="1" [nzMax]="1000" [nzStep]="1"></nz-input-number>
            </nz-form-control>
        </nz-form-item>
        <div style="text-align: center;">
            <button nz-button nzType="primary" style="width: 150px;" (click)="submitGenerateCard()">确定</button>
        </div>
    </form>
</nz-modal>

<nz-modal [(nzVisible)]="editContactModal" nzTitle="设置联系人" (nzOnCancel)="closeEditContactModal()" nzWidth="500px" [nzFooter]="null">
    <form nz-form [formGroup]="editContactForm">
        <nz-form-item>
            <nz-form-label [nzSpan]="6" nzRequired >联系人</nz-form-label>
            <nz-form-control [nzSpan]="14">
                <input nz-input formControlName="contactName" placeholder="请输入联系姓名" />
            </nz-form-control>
        </nz-form-item>
        <nz-form-item>
            <nz-form-label [nzSpan]="6" nzRequired >联系电话</nz-form-label>
            <nz-form-control [nzSpan]="14">
                <input nz-input formControlName="contactPhone" placeholder="请输入联系电话" />
            </nz-form-control>
        </nz-form-item>
        <div style="text-align: center;">
            <button nz-button nzType="primary" style="width: 150px;" (click)="submitEditContact()">确定</button>
        </div>
    </form>
</nz-modal>

<nz-modal [(nzVisible)]="rechargeModal" nzTitle="充值" (nzOnCancel)="closeRechargeModal()" nzWidth="500px" [nzFooter]="null">
    <form nz-form [formGroup]="rechargeForm">
        <nz-form-item>
            <nz-form-label [nzSpan]="6" nzRequired >卡号</nz-form-label>
            <nz-form-control [nzSpan]="14">
                <input nz-input formControlName="cardNo" disabled />
            </nz-form-control>
        </nz-form-item>
        <nz-form-item>
            <nz-form-label [nzSpan]="6" nzRequired >充值金额</nz-form-label>
            <nz-form-control [nzSpan]="14">
                <nz-input-number style="width: 100%" formControlName="price" [nzMin]="0.01" [nzMax]="1000" [nzStep]="1" [nzPrecision]="2"></nz-input-number>
            </nz-form-control>
        </nz-form-item>
        <nz-form-item>
            <nz-form-label [nzSpan]="6" nzRequired >支付密码</nz-form-label>
            <nz-form-control [nzSpan]="14">
                <input type="password" formControlName="twoPwd" nz-input placeholder="请输入支付密码"  />
            </nz-form-control>
        </nz-form-item>
        <div style="text-align: center;">
            <button nz-button nzType="primary" style="width: 150px;" [nzLoading]="rechargeBtnLoading" (click)="submitRecharge()">确定</button>
        </div>
    </form>
</nz-modal>

<nz-modal [(nzVisible)]="recycleAmountModal" nzTitle="油卡余额回收" (nzOnCancel)="closeRecycleAmountModal()" nzWidth="500px" [nzFooter]="null">
    <form nz-form [formGroup]="recycleAmountForm">
        <nz-form-item>
            <nz-form-label [nzSpan]="6" nzRequired >卡号</nz-form-label>
            <nz-form-control [nzSpan]="14">
                <input nz-input formControlName="cardNo" disabled />
            </nz-form-control>
        </nz-form-item>
        <nz-form-item>
            <nz-form-label [nzSpan]="6" nzRequired >回收余额</nz-form-label>
            <nz-form-control [nzSpan]="14">
                <nz-input-number style="width: 100%" formControlName="amount"></nz-input-number>
            </nz-form-control>
        </nz-form-item>
        <nz-form-item>
            <nz-form-label [nzSpan]="6" nzRequired >支付密码</nz-form-label>
            <nz-form-control [nzSpan]="14">
                <input type="password" formControlName="twoPwd" nz-input placeholder="请输入支付密码"  />
            </nz-form-control>
        </nz-form-item>
        <div style="text-align: center;">
            <button nz-button nzType="primary" style="width: 150px;" [nzLoading]="recycleAmountBtnLoading" (click)="submitRecycleAmount()">确定</button>
        </div>
    </form>
</nz-modal>
