<!-- 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="6">
                <nz-form-item>
                    <nz-form-label [nzSpan]="6">商户编号</nz-form-label>
                    <nz-form-control [nzSpan]="16">
                        <input nz-input formControlName="merchantKey"/>
                    </nz-form-control>
                </nz-form-item>
            </div>
            <div nz-col nzSpan="6">
                <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="6">
                <nz-form-item>
                    <nz-form-label [nzSpan]="6">商户电话</nz-form-label>
                    <nz-form-control [nzSpan]="16">
                        <input nz-input formControlName="telephone"/>
                    </nz-form-control>
                </nz-form-item>
            </div>
            <div nz-col nzSpan="6">
                <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="0"></nz-option>
                            <nz-option nzLabel="正常" nzValue="1"></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" [routerLink]="['/admin/merchant/merchant-edit']" ><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="50px">编号</th>
            <th nzWidth="80px">商户编号</th>
            <th nzWidth="80px">商户名称</th>
            <th nzWidth="70px">商户LOGO</th>
            <th nzWidth="100px">商户电话</th>
            <th nzWidth="100px">创建时间</th>
            <th nzWidth="50px">状态</th>
            <th nzWidth="50px" nzRight="0px">操作</th>
        </tr>
        </thead>
        <tbody>
        <tr *ngFor="let data of ajaxTable.data; let i = index">
            <td>{{i+1}}</td>
            <td>{{data.merchantKey}}</td>
            <td>{{data.merchantName}}</td>
            <td>
                <img class="head_img" src="{{WEB_SERVE_URL + data.merchantLogo}}" onerror="this.src='../../../../assets/admin/navigation/icon.png'" alt="">
            </td>
            <td>{{data.telephone}}</td>
            <td>{{data.createTime | date: 'yyyy-MM-dd HH:mm'}}</td>
            <td>{{data.status ===1 ? '正常' : '禁用'}}</td>
            <td nzRight="0px" class="table-td-operation">
                <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>
                            <a (click)="getEdit(data.id)">编辑</a>
                        </li>
                        <li nz-menu-item>
                            <a (click)="getDetail(data.id)">商户详情</a>
                        </li>
                        <li nz-menu-item>
                            <a (click)="getList(data.id , data.merchantName)">门店列表</a>
                        </li>
                        <li nz-menu-item>
                            <a *ngIf="data.status  === 1" (click)='disableMerchant(data.id)'>禁用</a>
                            <a *ngIf="data.status  !== 1"  (click)='enableMerchant(data.id)'>启用</a>
                        </li>
                        <li nz-menu-item>
                            <a (click)='showRechargeModal(data.id)'>余额充值</a>
                        </li>
                        <li nz-menu-item>
                            <a (click)='jumpMerAccountRecord(data.id)'>余额充值记录</a>
                        </li>
                        <li nz-menu-item>
                            <a (click)='showTripartitePlatformModal(data.id)'>商户平台配置</a>
                        </li>
                    </ul>
                </nz-dropdown-menu>
            </td>
        </tbody>
    </nz-table>
</div>

<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">
                <nz-input-number style="width: 100%" formControlName="merBalance"></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-number style="width: 100%" formControlName="amount" [nzMin]="0.01" [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-switch formControlName="marketingStatus" nzCheckedChildren="是" nzUnCheckedChildren="否"></nz-switch>
            </nz-form-control>
        </nz-form-item>

        <nz-form-item *ngIf="rechargeForm.controls.marketingStatus.value == 1">
            <nz-form-label [nzSpan]="6" nzRequired>营销类型</nz-form-label>
            <nz-form-control [nzSpan]="14">
                <nz-select formControlName="marketingType">
                    <nz-option nzValue="1" nzLabel="充值赠送"></nz-option>
                    <nz-option nzValue="2" nzLabel="充值返点"></nz-option>
                    <nz-option nzValue="3" nzLabel="加油减免"></nz-option>
                </nz-select>
            </nz-form-control>
        </nz-form-item>

        <nz-form-item *ngIf="rechargeForm.controls.marketingStatus.value == 1
                && (rechargeForm.controls.marketingType.value == 1 || rechargeForm.controls.marketingType.value == 2)">
            <nz-form-label [nzSpan]="6" nzRequired >营销金额（{{rechargeForm.controls.marketingType.value == 1?'￥':''}}
                                                            {{rechargeForm.controls.marketingType.value == 2?'%':''}}）</nz-form-label>
            <nz-form-control [nzSpan]="14">
                <nz-input-number formControlName="marketingPrice" [nzMin]="0" [nzMax]="9999" [nzStep]="1" [nzPrecision]="4" [nzPlaceHolder]="'注意：营销金额(单位)'"></nz-input-number>
            </nz-form-control>
        </nz-form-item>
    </form>

    <div nz-row *ngIf="rechargeForm.controls.marketingType.value == 3">
        <span nz-typography><mark>注意：减免的是油站价。<br>例如：油站价8元减免0.1元，结算时每升以7.9元结算扣除商户余额。</mark></span>
        <div nz-col [nzSpan]="2"></div>
        <div nz-col [nzSpan]="18">
            <nz-table style="text-align: center;" #editRowTable nzBordered [nzData]="oilNoData" [nzShowPagination]="false">
                <thead>
                <tr>
                    <th>油号</th>
                    <th>减免金额（￥）</th>
                </tr>
                </thead>
                <tbody>
                <tr *ngFor="let data of editRowTable.data;" class="editable-row">
                    <td>{{ data.oilNo }}</td>
                    <td>
                        <div [hidden]="editOilNo === data.oilNo" (click)="startEdit(data.oilNo)">{{ data.price }}</div>
                        <nz-input-number  [hidden]="editOilNo !== data.oilNo" [(ngModel)]="data.price" [nzMin]="0" [nzMax]="9999" [nzStep]="1" [nzPrecision]="2" (blur)="stopEdit()"></nz-input-number>
                    </td>
                </tr>
                </tbody>
            </nz-table>
        </div>
    </div>

    <div style="margin-top:15px;text-align: center;">
        <button nz-button nzType="primary" style="width: 150px;" (click)="submitRecharge()">确定</button>
    </div>
</nz-modal>

<nz-modal [(nzVisible)]="tripartitePlatformModal" nzTitle="商户配置" (nzOnCancel)="closeTripartitePlatformModal()" nzWidth="500px" [nzFooter]="null">
    <form nz-form [formGroup]="tripartitePlatformForm">
        <nz-form-item>
            <nz-form-label [nzSpan]="6" nzRequired >第三方平台</nz-form-label>
            <nz-form-control [nzSpan]="14">
                <nz-select formControlName="platformType">
                    <nz-option nzValue="1" nzLabel="微信"></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">
                <input nz-input placeholder="请输入第三方平台商户全称" formControlName="platformMerName" />
            </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 placeholder="请输入第三方平台商户号" formControlName="platformMerNumber" />
            </nz-form-control>
        </nz-form-item>

        <nz-form-item>
            <nz-form-label [nzSpan]="6" nzRequired >是否分账</nz-form-label>
            <nz-form-control [nzSpan]="14">
                <nz-radio-group formControlName="profitSharingStatus">
                    <label nz-radio nzValue="true">是</label>
                    <label nz-radio nzValue="false">否</label>
                </nz-radio-group>
            </nz-form-control>
        </nz-form-item>

        <nz-form-item *ngIf="tripartitePlatformForm.value.profitSharingStatus == 'true'">
            <nz-form-label [nzSpan]="6" nzRequired >分账比例(%)</nz-form-label>
            <nz-form-control [nzSpan]="14">
                <nz-input-number formControlName="profitSharingRatio" [nzPrecision]="2" [nzMin]="0" [nzMax]="30" [nzPlaceHolder]="'分账比例(%)'"></nz-input-number>
            </nz-form-control>
        </nz-form-item>

        <nz-form-item *ngIf="tripartitePlatformForm.value.profitSharingStatus == 'true'">
            <nz-form-label [nzSpan]="6" nzRequired >接收方商户号</nz-form-label>
            <nz-form-control [nzSpan]="14">
                <input nz-input placeholder="分账接收方商户号" formControlName="profitSharingReceiversNumber" />
            </nz-form-control>
        </nz-form-item>

        <nz-form-item *ngIf="tripartitePlatformForm.value.profitSharingStatus == 'true'">
            <nz-form-label [nzSpan]="6" nzRequired >接收方全称</nz-form-label>
            <nz-form-control [nzSpan]="14">
                <input nz-input placeholder="分账接收方全称" formControlName="profitSharingReceiversName" />
            </nz-form-control>
        </nz-form-item>

        <div style="text-align: center;">
            <button nz-button nzType="primary" style="width: 150px;" (click)="submitTripartitePlatform()">确定</button>
        </div>
    </form>
</nz-modal>




