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

<div class="inner-content">
    <span>共计 {{total}} 条数据</span>
    <nz-table
            class="table"
            #ajaxTable
            nzShowSizeChanger
            [nzFrontPagination]="false"
            [nzData]="requestData"
            [nzLoading]="loading"
            [nzTotal]="total"
            [(nzPageIndex)]="pageNum"
            [(nzPageSize)]="pageSize"
            [nzScroll]="{ x: '1200px' }"
            (nzPageIndexChange)="getRequest(false , {})"
            (nzPageSizeChange)="getRequest(false , {})">
        <thead nzSingleSort>
        <tr>
            <th nzWidth="50px">编号</th>
            <th nzWidth="120px">优惠券KEY</th>
            <th nzWidth="150px">优惠券名称</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>
            <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['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['highDiscount'].createTime}}</td>
            <td>{{data['highDiscount'].status | discountStatus}}</td>
            <td nzRight="0px" class="table-td-operation">
                <a (click)="getDetail(data.id)">使用情况</a>

            </td>
        </tbody>
    </nz-table>
</div>

<nz-modal [(nzVisible)]="isVisible" nzTitle="使用情况" nzWidth="1000" (nzOnCancel)="handleCancel()" (nzOnOk)="handleCancel()">
    <form nz-form [formGroup]="searchForm" (ngSubmit)="getRequestCode(true , searchForm.value)">
        <div nz-row>
            <div nz-col nzSpan="9">
                <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="1"></nz-option>
                            <nz-option nzLabel="待使用" nzValue="2"></nz-option>
                            <nz-option nzLabel="已使用" nzValue="3"></nz-option>
                            <nz-option nzLabel="已过期" nzValue="4"></nz-option>
                            <nz-option nzLabel="预支付" nzValue="99"></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>

    <span>共计 {{totalCode}} 条数据</span>
    <div class="operating-button">
        <button nz-button nzType="primary" class="right-btn" (click)="getEditStatus()" >修改优惠券状态</button>
    </div>
    <nz-table
            class="table"
            #ajaxTableCode
            nzShowSizeChanger
            [nzFrontPagination]="false"
            [nzData]="requestDataCode"
            [nzLoading]="loadingCode"
            [nzTotal]="totalCode"
            [(nzPageIndex)]="pageNumCode"
            [(nzPageSize)]="pageSizeCode"
            (nzPageIndexChange)="getRequestCode(false , searchForm.value)"
            (nzPageSizeChange)="getRequestCode(false , searchForm.value)">
        <thead nzSingleSort>
        <tr>
            <th nzWidth="50px">编号</th>
            <th nzWidth="70px">优惠券名称</th>
            <th nzWidth="70px">用户名称</th>
            <th nzWidth="70px">使用门店</th>
            <th nzWidth="70px">使用时间</th>
            <th nzWidth="70px">二维码生成时间</th>
            <th nzWidth="50px">状态</th>
        </tr>
        </thead>
        <tbody>
        <tr *ngFor="let data of ajaxTableCode.data; let i = index">
            <td>{{data.id}}</td>
            <td>{{data['highDiscount'].discountName}}</td>
            <td>
              {{data['highUser'] == null ? '暂无':  data['highUser'].name}}
            </td>
            <td>{{data['highCouponCode']?.storeName}}</td>
            <td>{{data['highCouponCode']?.consumeTime | date: 'yyyy-MM-dd HH:mm'}}</td>
            <td>{{data.createTime | date: 'yyyy-MM-dd HH:mm'}}</td>
            <td>{{data.status | discountCodeStatus}}</td>
        </tbody>
    </nz-table>
</nz-modal>

<nz-modal [(nzVisible)]="isVisibleS" nzTitle="修改优惠券状态" nzWidth="800" [nzOkLoading]="loadingS" (nzOnCancel)="handleCancelS()" (nzOnOk)="handleOk()">

    <form nz-form [formGroup]="validateFormPost" 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="status" nzPlaceHolder="请选择优惠券状态">
                    <nz-option nzLabel="待领取" nzValue="1"></nz-option>
                    <nz-option nzLabel="已过期" nzValue="4"></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-group nzCompact>
                    <input type="number" nz-input placeholder="开始编号" formControlName="minNumber" style="width:100px; text-align: center;" />
                    <input
                            type="text"
                            disabled
                            nz-input
                            placeholder="~"
                            style="width: 30px; border-left: 0px; pointer-events: none; background-color: rgb(255, 255, 255);"
                    />
                    <input type="number" nz-input placeholder="结束编号"  formControlName="maxNumber" style="width: 100px; text-align: center; border-left: 0px;" />
                </nz-input-group>
            </nz-form-control>
        </nz-form-item>
    </form>
</nz-modal>
