<!-- start 面包屑 -->
<app-breadcrumb></app-breadcrumb>
<!-- end 面包屑 -->

<!--条件搜索-->
<div class="inner-content">
    <form nz-form [formGroup]="searchForm" (ngSubmit)="getRequest(true , searchForm.value)">
        <div nz-row>

            <div nz-col nzSpan="8">
                <nz-form-item>
                    <nz-form-label [nzSpan]="6">商户名称</nz-form-label>
                    <nz-form-control [nzSpan]="16">
                        <input nz-input formControlName="merchantName"/>
                    </nz-form-control>
                </nz-form-item>
            </div>
            <div nz-col nzSpan="8">
                <nz-form-item>
                    <nz-form-label [nzSpan]="6">商户号</nz-form-label>
                    <nz-form-control [nzSpan]="16">
                        <input nz-input formControlName="mchId"/>
                    </nz-form-control>
                </nz-form-item>
            </div>
            <div nz-col nzSpan="8">
                <nz-form-item>
                    <nz-form-label [nzSpan]="6">商户电话</nz-form-label>
                    <nz-form-control [nzSpan]="16">
                        <input nz-input formControlName="phone"/>
                    </nz-form-control>
                </nz-form-item>
            </div>

            <div nz-col nzSpan="8">
                <nz-form-item>
                    <nz-form-label [nzSpan]="6">状态</nz-form-label>
                    <nz-form-control [nzSpan]="16">
                        <nz-select nzShowSearch nzAllowClear formControlName="status" nzPlaceHolder="请选择状态">
                            <nz-option nzLabel="正常" [nzValue]="100"></nz-option>
                            <nz-option nzLabel="禁用" [nzValue]="101"></nz-option>
                        </nz-select>
                    </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">
    <span>共计 {{total}} 条数据</span>
    <div class="operating-button">
        <button nz-button nzType="primary" class="right-btn" (click)="getEdit()"><i nz-icon nzType="plus" nzTheme="outline"></i>添加</button>
        <button nz-button nzType="primary" class="right-btn" (click)="showRechargeModal()" ><i nz-icon nzType="plus" nzTheme="outline"></i>账户充值</button>
    </div>
    <nz-table
            class="table"
            #ajaxTable
            nzShowSizeChanger
            [nzFrontPagination]="false"
            [nzData]="requestData"
            [nzLoading]="loading"
            [nzTotal]="total"
            [(nzPageIndex)]="pageNum"
            [(nzPageSize)]="pageSize"
            [nzScroll]="{ x: '1200px' }"
            (nzPageIndexChange)="getRequest(false , searchForm.value)"
            (nzPageSizeChange)="getRequest(false , searchForm.value)">
        <thead nzSingleSort>
        <tr>
            <th nzWidth="60px">编号</th>
            <th nzWidth="90px">商户名称</th>
            <th nzWidth="80px">联系人</th>
            <th nzWidth="80px">电话</th>
            <th nzWidth="90px">商户号</th>
            <th nzWidth="160px">商户KEY</th>
            <th nzWidth="80px">操作人员</th>
            <th nzWidth="120px">创建时间</th>
            <th nzRight nzWidth="100px">帐户余额</th>
            <th nzRight nzWidth="60px">状态</th>
            <th nzRight nzWidth="200px">操作</th>
        </tr>
        </thead>
        <tbody>
        <tr *ngFor="let data of ajaxTable.data; let i = index">
            <td>{{i + 1}}</td>
            <td>{{data.merchantName}}</td>
            <td>{{data.userName }}</td>
            <td>{{data.phone }}</td>
            <td>{{data.mchId }}</td>
            <td>{{data.apiKey }}</td>
            <td>{{data.operatorName }}</td>
            <td>{{data.createTime | date: 'yyyy-MM-dd HH:mm'}}</td>
            <td nzRight="">¥{{data.amounts}}</td>
            <td nzRight="">{{data.status== 100? '正常':'禁用'}}</td>
            <td nzRight class="table-td-operation">
                <a *ngIf="data.status != 101" (click)="getEdit(data.id)">编辑</a>
                <nz-divider nzType="vertical"></nz-divider>
                <a nz-dropdown [nzDropdownMenu]="menu">更多操作</a>
                <nz-dropdown-menu #menu="nzDropdownMenu">
                    <ul nz-menu nzSelectable>
                        <li class="li-a" nz-menu-item><a (click)="configProduct(data.id)">配置产品</a></li>
                        <li class="li-a" nz-menu-item><a (click)="showConfigProduct(data.id)">产品详情</a></li>
                        <li class="li-a" nz-menu-item><a (click)="getMerchRechargeData(data.id)">金额记录</a></li>
                        <li class="li-a" nz-menu-item><a (click)='getForbiddenUser(data.id , data.status)'>{{data.status === 101 ? '上线': '禁用'}}</a></li>
                    </ul>
                </nz-dropdown-menu>
            </td>
        </tbody>
    </nz-table>
</div>

<nz-modal [(nzVisible)]="isVisible" nzTitle="商户编辑" (nzOnCancel)="handleCancel()" (nzOnOk)="handleOk()">
    <form nz-form [formGroup]="validateForm" class="login-form">
        <nz-form-item>
            <nz-form-label [nzSpan]="6" nzRequired>商户名称</nz-form-label>
            <nz-form-control [nzSpan]="16" nzErrorTip="请输入商户名称!">
                <input  nz-input formControlName="merchantName" />
            </nz-form-control>
        </nz-form-item>
        <nz-form-item>
            <nz-form-label [nzSpan]="6" nzRequired>商户联系人</nz-form-label>
            <nz-form-control [nzSpan]="16" nzErrorTip="请输入商户联系人!">
                <input  nz-input formControlName="userName" />
            </nz-form-control>
        </nz-form-item>
        <nz-form-item>
            <nz-form-label [nzSpan]="6" nzRequired>商户电话</nz-form-label>
            <nz-form-control [nzSpan]="16" nzErrorTip="请输入商户电话!">
                <input  nz-input formControlName="phone" />
            </nz-form-control>
        </nz-form-item>
    </form>
</nz-modal>

<nz-modal [(nzVisible)]="rechargeModal" nzTitle="账户充值" (nzOnCancel)="rechargeModal = false" 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">
                <nz-select nzShowSearch nzAllowClear nzPlaceHolder="请选择商户" formControlName="merchantId">
                    <nz-option *ngFor="let data of merchantArray" nzLabel="{{data.merchantName}}" nzValue="{{data.id}}"></nz-option>
                </nz-select>
            </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" [nzMin]="0" [nzMax]="9999999" [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">
                <nz-input-group nzSearch [nzAddOnAfter]="suffixButton">
                    <input nz-input formControlName="smsCode" />
                </nz-input-group>
                <ng-template #suffixButton>
                    <button nz-button nzType="primary" [disabled]="smsCodeBtnLoading" (click)="sendSmsCode()">{{smsCodeBtnName}}</button>
                </ng-template>
                <span *ngIf="smsCodeBtnLoading" nz-typography nzType="warning">验证码已发送！5分钟内有效</span>
            </nz-form-control>
        </nz-form-item>
        <div style="text-align: center;">
            <button nz-button nzType="primary" style="width: 150px;" [nzLoading]="submitRechargeBtnLoading" (click)="submitRecharge()">确定</button>
        </div>
    </form>
</nz-modal>

<nz-modal [(nzVisible)]="visible" nzTitle="商户充值记录"  (nzOnCancel)="visible = false" nzWidth="1000px" [nzFooter]="null">
    <nz-table #errorStudentTable    [nzScroll]="{ x: '1200px' }" [nzData]="merchRechargeData">
        <thead>
        <tr>
            <th nzWidth="100px">类型</th>
            <th nzWidth="100px">交易金额</th>
            <th nzWidth="120px">变更前金额</th>
            <th nzWidth="120px">变更后金额</th>
            <th nzWidth="100px">来源类型</th>
            <th nzWidth="300px">来源内容</th>
            <th nzWidth="130px">操作人</th>
            <th nzWidth="200px">记录时间</th>
        </tr>
        </thead>
        <tbody>
        <tr *ngFor="let data of errorStudentTable.data;let i = index">
            <td>{{data.amountType | companyAmountRecordType}}</td>
            <td>￥{{data.amount}}</td>
            <td>￥{{data.beforeAmount}}</td>
            <td>￥{{data.afterAmount}}</td>
            <td>{{data.sourceType | sourceType}}</td>
            <td>{{data.sourceContent}}</td>
            <td>{{data.operatorName}}</td>
            <td>{{data.createTime | date : 'yyyy-MM-dd HH:mm:ss'}}</td>
        </tr>
        </tbody>
    </nz-table>
</nz-modal>

<nz-modal [(nzVisible)]="configVisible" nzTitle="产品配置" (nzOnCancel)="handleCancelConfig()" (nzOnOk)="handleOkConfig()">
    <form nz-form [formGroup]="configValidateForm" class="login-form">
        <nz-form-item *ngIf="!edit">
            <nz-form-label [nzSpan]="6" nzRequired>选择产品</nz-form-label>
            <nz-form-control [nzSpan]="16" nzErrorTip="请选择选择产品!">
                <nz-select
                        nzMode="multiple"
                        formControlName="productIds"
                        nzPlaceHolder="请选择充值金额"
                >
                    <nz-option *ngFor="let item of productArray" nzValue="{{item.id}}" nzLabel="{{item.operatorType | rechargePrice}}|{{item.phoneRechargeType== 1? '快充':'慢充'}}|{{item.rechargePrice}}元"></nz-option>
                </nz-select>
            </nz-form-control>
        </nz-form-item>
        <nz-form-item>
            <nz-form-label [nzSpan]="6" nzRequired>折扣比例</nz-form-label>
            <nz-form-control [nzSpan]="16" nzErrorTip="请输入折扣比例!">
                <nz-input-number
                        style="width: 200px"
                        formControlName="discount"
                        [nzMin]="1"
                        [nzMax]="100"
                        [nzStep]="1"
                        [nzPrecision]="2"
                        nzPrecisionMode="cut"
                        nzPlaceHolder="请输入折扣比例!"
                        [nzFormatter]="formatterPercent"
                        [nzParser]="parserPercent"
                ></nz-input-number>
            </nz-form-control>
        </nz-form-item>

    </form>
</nz-modal>



<nz-modal [(nzVisible)]="visibleConfigProduct" nzTitle="商户产品"  (nzOnCancel)="visibleConfigProduct = false" nzWidth="1000px" [nzFooter]="null">
    <nz-table #productConfigTable    [nzScroll]="{ x: '1200px' }" [nzData]="productConfigArray">
        <thead>
        <tr>
            <th nzWidth="60px">编号</th>
            <th nzWidth="90px">充值金额</th>
            <th nzWidth="90px">折扣金额</th>
            <th nzWidth="120px">运营商</th>
            <th nzWidth="90px">充值类型</th>
            <th nzWidth="80px">状态</th>
            <th nzRight nzWidth="100px">操作</th>
        </tr>
        </thead>
        <tbody>
        <tr *ngFor="let data of productConfigTable.data;let i = index">
            <td>{{i + 1}}</td>
            <td>{{data.rechargePrice}}</td>
            <td>{{data.discountPrice}}</td>
            <td>{{data.operatorType | rechargePrice}}</td>
            <td>{{data.phoneRechargeType== 1? '快充':'慢充'}}</td>
            <td>{{data.configStatus== 101? '正常':'下架中'}}</td>
            <td nzRight class="table-td-operation">
                <a *ngIf="data.configStatus != 101" (click)="getEditConfigProduct(data.apiConfigProductId)">编辑</a>
                <a style="margin-left: 20px;" (click)='getEditConfigProductStatus(data.apiConfigProductId , data.configStatus)'>{{data.configStatus === 101 ? '下线': '上线'}}</a>
            </td>
        </tr>
        </tbody>
    </nz-table>
</nz-modal>


<nz-modal [(nzVisible)]="editConfigVisible" nzTitle="编辑产品折扣" (nzOnCancel)="editConfigVisible = false" (nzOnOk)="handleOkConfigEdit()">
        <nz-form-item>
            <nz-form-label [nzSpan]="6" nzRequired>折扣比例</nz-form-label>
            <nz-form-control [nzSpan]="16" nzErrorTip="请输入折扣比例!">
                <nz-input-number
                        style="width: 200px"
                        [(ngModel)]="discount"
                        [nzMin]="1"
                        [nzMax]="100"
                        [nzStep]="1"
                        [nzPrecision]="2"
                        nzPrecisionMode="cut"
                        nzPlaceHolder="请输入折扣比例!"
                        [nzFormatter]="formatterPercent"
                        [nzParser]="parserPercent"
                ></nz-input-number>
            </nz-form-control>
        </nz-form-item>
</nz-modal>
