<!-- 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="agentName"/>
                    </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="agentPhone"/>
                    </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="0"></nz-option>
                            <nz-option nzLabel="正常" nzValue="1"></nz-option>
                        </nz-select>
                    </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="type" nzPlaceHolder="请选择代理商类型">
                            <nz-option nzLabel="卡券代理商" nzValue="1"></nz-option>
                            <nz-option nzLabel="汇联通代理商" nzValue="3"></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/agent/agent-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="80px">标识链接</th>
            <th nzWidth="80px">联系人</th>
            <th nzWidth="70px">联系方式</th>
            <th nzWidth="100px">创建时间</th>
            <th nzWidth="80px" nzRight="0px">操作</th>
        </tr>
        </thead>
        <tbody>
        <tr *ngFor="let data of ajaxTable.data; let i = index">
            <td>{{i + 1}}</td>
            <td>{{data.agentName}}</td>
            <td>{{data.agentAddress}}</td>
            <td nzBreakWord>{{inviteUrl + data.id}}</td>
            <td>{{data.agentUser}}</td>
            <td>{{data.agentPhone}}</td>
 
            <td>{{data.createTime | date: 'yyyy-MM-dd HH:mm'}}</td>
            <td nzRight="0px" class="table-td-operation">
                <a (click)="getEdit(data.id)">编辑</a>
                <a nz-dropdown [nzDropdownMenu]="menu">更多</a>
                <nz-dropdown-menu #menu="nzDropdownMenu">
                    <ul nz-menu nzSelectable>
                        <li class="li-a" nz-menu-item><a (click)="getDistribution(data.id)">分发卡券</a></li>
                        <li class="li-a" nz-menu-item><a (click)="generateAgentQrCode(data.id)">生成二维码</a></li>
                        <li class="li-a" nz-menu-item><a (click)="getDiscount(data.id)">绑定优惠券</a></li>
                        <li class="li-a" nz-menu-item><a (click)="getDiscountList(data.id)">优惠券列表</a></li>
                        <li class="li-a" nz-menu-item><a (click)="getDistributionList(data.id)">分发列表</a></li>
                        <li class="li-a" nz-menu-item><a (click)='getForbiddenUser(data.id , data.status)'>{{data.status === 1 ? '禁用': '启用'}}</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="请选择优惠券!">
                <nz-select nzShowSearch nzAllowClear formControlName="discountId" nzPlaceHolder="请选择优惠券">
                    <nz-option *ngFor="let item of discountList" nzLabel="{{item.discountName}}"
                               nzValue="{{item.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]="16" nzErrorTip="分配优惠券数量!">
                <input [type]="'number'" nz-input formControlName="stockCount"/>
            </nz-form-control>
        </nz-form-item>
    </form>
</nz-modal>

<nz-modal [(nzVisible)]="isVisibleDiscount" nzWidth="1000" nzTitle="代理商优惠券列表" (nzOnCancel)="handleCancelDiscount()"
          (nzOnOk)="handleCancelDiscount()" [nzFooter]="null">
    <nz-table
            class="table"
            #ajaxTableDiscount
            nzShowSizeChanger
            [nzFrontPagination]="false"
            [nzData]="requestDataDiscount"
            [nzLoading]="loadingDiscount"
            [nzTotal]="totalDiscount"
            [(nzPageIndex)]="pageNumDiscount"
            [(nzPageSize)]="pageSizeDiscount"
            [nzScroll]="{ x: '1200px' }"
            (nzPageIndexChange)="getRequestDiscount(false)"
            (nzPageSizeChange)="getRequestDiscount(false)">
        <thead nzSingleSort>
        <tr>
            <th nzWidth="80px">优惠券KEY</th>
            <th nzWidth="80px">优惠券名称</th>
            <th nzWidth="80px">优惠券类型</th>
            <th nzWidth="70px">优惠内容</th>
            <th nzWidth="70px">有效天数</th>
            <th nzWidth="100px">截止日期</th>
            <th nzWidth="100px">库存数量</th>
            <th nzWidth="100px">操作</th>
        </tr>
        </thead>
        <tbody>
        <tr *ngFor="let data of ajaxTableDiscount.data; let i = index">
            <td>{{data['highDiscount'].discountKey}}</td>
            <td>{{data['highDiscount'].discountName}}</td>
            <td>{{data['highDiscount'].discountType | discountType}}</td>
            <td>
                <span *ngIf="data['highDiscount'].discountType === 1">
                      满{{data['highDiscount'].discountCondition}}抵扣{{data['highDiscount'].discountPrice}}
                </span>
                <span *ngIf="data['highDiscount'].discountType === 2">
                      抵扣{{data['highDiscount'].discountPrice}}
                </span>
                <span *ngIf="data['highDiscount'].discountType === 3">
                      {{data['highDiscount'].discountPrice}}折
                </span>
            </td>
            <td>{{data['highDiscount'].effectiveDay}}</td>
            <td>{{data['highDiscount'].salesEndTime | date: 'yyyy-MM-dd HH:mm'}}</td>
            <td>{{data.stockCount}}</td>
            <td>
                <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 (click)="copyReceiveDiscountLink(data.id)">复制领取链接</li>
<!--                        <li nz-menu-item>赠送用户优惠券</li>-->
                    </ul>
                </nz-dropdown-menu>
            </td>
        </tbody>
    </nz-table>
</nz-modal>


<nz-modal [(nzVisible)]="isVisibleDistribute" nzTitle="分发卡券" (nzOnCancel)="handleCancelDistribute()" [nzOkLoading]="isOkLoading" (nzOnOk)="addApprove()">
    <nz-spin [nzSpinning]="isSpinningDistribute">
        <form nz-form [formGroup]="validateFormDistribute" class="login-form">
            <nz-form-item>
                <nz-form-label [nzSpan]="6" nzRequired>卡券</nz-form-label>
                <nz-form-control [nzSpan]="16" nzErrorTip="请选择卡券!">
                    <nz-select nzShowSearch nzAllowClear formControlName="couponId" nzPlaceHolder="请选择卡券">
                        <nz-option *ngFor="let item of distributeList" nzLabel="【{{item['displayArea'] | displayArea}}】{{ item.couponName + '-(有效库存:' + item.stockCount + ')'}}"
                                   nzValue="{{item.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]="16" nzErrorTip="请选择卡券!">
                    <nz-select nzShowSearch nzAllowClear formControlName="type" nzPlaceHolder="请选择卡券">
                        <nz-option nzLabel="销售码" nzValue="1"></nz-option>
                        <nz-option nzLabel="兑换码" nzValue="2"></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="分发数量!">
                    <input [type]="'number'" nz-input formControlName="stockCount" nzPlaceHolder="请填写分发数量" />
                </nz-form-control>
            </nz-form-item>
        </form>
    </nz-spin>
</nz-modal>


<nz-modal [(nzVisible)]="isVisibleList" nzWidth="1000" nzTitle="分发卡券列表" (nzOnCancel)="handleCancelList()" (nzOnOk)="handleCancelList()">
    <nz-table
            class="table"
            #ajaxTableList
            nzShowSizeChanger
            [nzFrontPagination]="false"
            [nzData]="requestDataList"
            [nzLoading]="loadingList"
            [nzTotal]="totalList"
            [(nzPageIndex)]="pageNumList"
            [(nzPageSize)]="pageSizeList"
            (nzPageIndexChange)="getRequestList(false)"
            (nzPageSizeChange)="getRequestList(false)">
        <thead nzSingleSort>
        <tr>
            <th nzWidth="50px">展示专区</th>
            <th nzWidth="100px">卡券名称</th>
            <th nzWidth="50px">卡券价格</th>
            <th nzWidth="50px">库存数量</th>
            <th nzWidth="50px">销售数量</th>
            <th nzWidth="70px">分发时间</th>
            <th nzWidth="70px">操作</th>
        </tr>
        </thead>
        <tbody>
        <tr *ngFor="let data of ajaxTableList.data; let i = index">
            <td>{{data['highCoupon']['displayArea'] | displayArea}}</td>
            <td>{{data['couponName']}}</td>
            <td>{{data['salesPrice']}}元</td>
            <td>{{data['stockCount']}}</td>
            <td>{{data['salesCount']}}</td>
            <td>{{data['createTime'] | date: 'yyyy-MM-dd HH:mm'}}</td>
            <td>
                <a (click)="getList(data['id'])">分发历史</a>
            </td>

        </tbody>
    </nz-table>
</nz-modal>

<nz-modal [(nzVisible)]="isVisibleShow" nzWidth="700" nzTitle="分发记录" (nzOnCancel)="handleCancelListShow()" (nzOnOk)="handleCancelListShow()">
    <nz-table #basicTable [nzData]="dataSet">
        <thead>
        <tr>
            <th>卡券名称</th>
            <th>代理商</th>
            <th>分发数量</th>
            <th>分发时间</th>
        </tr>
        </thead>
        <tbody>
        <tr *ngFor="let data of basicTable.data">
            <td>{{data.couponName}}</td>
            <td>{{data.agentName}}</td>
            <td>{{data.stockCount}}</td>
            <td>{{data['createTime'] | date: 'yyyy-MM-dd HH:mm'}}</td>
        </tr>
        </tbody>
    </nz-table>
</nz-modal>
