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

<div class="inner-content">
    <nz-form-item>
        <nz-form-label [nzSm]="2" [nzXs]="24" >卡券类型</nz-form-label>
        <nz-form-control [nzSm]="7" [nzXs]="24" >
            <nz-select nzShowSearch nzAllowClear nzPlaceHolder="请选择类型" (ngModelChange)="getAgentCount($event)" [(ngModel)]="type">
                <nz-option nzLabel="消核码" [nzValue]="1"></nz-option>
                <nz-option nzLabel="兑换码" [nzValue]="2"></nz-option>
            </nz-select>
        </nz-form-control>
    </nz-form-item>
    <nz-card nzTitle="销售统计">
        <div nz-card-grid [ngStyle]="gridStyle">销售总额: ￥{{countData['salesCountPrice']}}</div>
        <div nz-card-grid [ngStyle]="gridStyle">剩余总额: ￥{{countData['surplusCountPrice']}}</div>
        <div nz-card-grid [ngStyle]="gridStyle">今日流水: ￥{{countData['turnoverPrice']}}</div>
        <div nz-card-grid [ngStyle]="gridStyle">库存数量: {{countData['laveStockCount']}}</div>
        <div nz-card-grid [ngStyle]="gridStyle">销售数量: {{countData['soldCount']}}</div>
        <div nz-card-grid [ngStyle]="gridStyle">今日订单: {{countData['orderCount']}}</div>
    </nz-card>
</div>

<div class="inner-content">
    <nz-table #basicTable [nzData]="countData['list']">
        <thead>
        <tr>
            <th>卡券名称</th>
            <th>卡券金额</th>
            <th>库存数量</th>
            <th>销售数量</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <tr *ngFor="let data of basicTable.data">
            <td>{{data.couponName}}</td>
            <td>￥{{data.salesPrice}}</td>
            <td>{{data.stockCount}}</td>
            <td>{{data.salesCount}}</td>
            <td>
                <a (click)="getDetail(data.couponId)">使用情况</a>
            </td>
        </tr>
        </tbody>
    </nz-table>
</div>

<nz-modal [(nzVisible)]="isVisible" nzTitle="使用情况" nzWidth="1000" (nzOnCancel)="handleCancel()" (nzOnOk)="handleCancel()">
    <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">消费码KEY</nz-form-label>
                    <nz-form-control [nzSpan]="16">
                        <input nz-input formControlName="salesCode"/>
                    </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 formControlName="status">
                            <nz-option nzValue="1" nzLabel="待销售"></nz-option>
                            <nz-option nzValue="2" nzLabel="待使用"></nz-option>
                            <nz-option nzValue="3" nzLabel="已使用"></nz-option>
                            <nz-option nzValue="4" nzLabel="已过期"></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>共计 {{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 , searchForm.value)"
            (nzPageSizeChange)="getRequest(false , searchForm.value)">
        <thead nzSingleSort>
        <tr>
            <th nzWidth="50px">编号</th>
            <th nzWidth="180px">消费码</th>
            <th nzWidth="120px">使用门店</th>
            <th nzWidth="120px">领取时间</th>
            <th nzWidth="120px">消费时间</th>
            <th nzWidth="120px">销售截止时间</th>
            <th nzWidth="120px">使用截止时间</th>
            <th nzWidth="120px">创建时间</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.salesCode}}</td>
            <td>{{data.storeName == null ? '暂无' : data.storeName}}</td>
            <td>{{data.receiveTime == null ? '未领取' : data.receiveTime | date: 'yyyy-MM-dd HH:mm'}}</td>
            <td>{{data.consumeTime == null ? '未消费' : data.consumeTime | date: 'yyyy-MM-dd HH:mm'}}</td>
            <td>{{data.salesEndTime | date: 'yyyy-MM-dd HH:mm'}}</td>
            <td>{{data.useEndTime | date: 'yyyy-MM-dd HH:mm'}}</td>
            <td>{{data.createTime | date: 'yyyy-MM-dd HH:mm'}}</td>
            <td nzRight="0px">{{data.status | couponCode}}</td>
        </tbody>
    </nz-table>

</nz-modal>
