<!-- start 面包屑 -->
<app-breadcrumb></app-breadcrumb>
<!-- end 面包屑 -->
<nz-spin [nzSpinning]="exportLoading" nzTip="导出中...">
    <!--条件搜索-->
    <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">消费码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-option nzValue="99" 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>
    </div>

    <div class="inner-content">
        <span>共计 {{total}} 条数据</span>
        <span *ngIf="id != null" style="margin-left: 30px;;">
            卡券名称:
            <span style="font-weight: bold; font-size: 20px">{{name}}({{type === 1 ? '内部券' : '外部券'}})</span>
        </span>
        <div class="operating-button">
            <button *ngIf="type === 1" nz-button nzType="primary" class="right-btn" (click)="showModal()"><i nz-icon
                                                                                          nzType="import"
                                                                                          nzTheme="outline"></i>生成消费码
            </button>
            <nz-upload
                    *ngIf="type === 2"
                    [nzAccept]="'.xls,.xlsx'"
                    nzAction="{{WEB_SERVE_URL}}coupon/importStock?couponId={{id}}"
                    [nzHeaders]="{ authorization: 'authorization-text' }"
                    (nzChange)="handleChange($event)"
                    [nzShowUploadList]="false"
            >
                <button  nz-button nzType="primary" ><i nz-icon nzType="import" nzTheme="outline"></i>导入消费码</button>
            </nz-upload>
            <button (click)="showExportSalesCodeModal()" nz-button nzType="primary" ><i nz-icon nzType="import" 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="200px">消费码key</th>
                <th nzWidth="230px">消费码</th>
                <th nzWidth="100px">是否分发</th>
                <th nzWidth="150px">使用门店</th>
                <th nzWidth="150px">领取时间</th>
                <th nzWidth="150px">消费时间</th>
                <th nzWidth="150px">销售截止时间</th>
                <th nzWidth="150px">使用截止时间</th>
                <th nzWidth="150px">创建时间</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.codeKey}}</td>
                <td>{{data.salesCode}}</td>
                <td>{{data.isAssignAgent === true ? '已分发' : '未分发'}}</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>
    </div>
</nz-spin>
<nz-modal [(nzVisible)]="isVisible" nzTitle="生成消费码" (nzOnCancel)="handleCancel()" (nzOnOk)="handleOk()">
    <ng-container>
        <form nz-form [formGroup]="codeForm">
            <div nz-row>
                <div nz-col nzSpan="24">
                    <nz-form-item>
                        <nz-form-label [nzFor]="'salesEndTime'" nzRequired>销售截止日期</nz-form-label>
                        <nz-form-control nzErrorTip="请选择销售截止日期!">
                            <nz-date-picker nzFormat="yyyy-MM-dd" [formControlName]="'salesEndTime'"
                            ></nz-date-picker>
                        </nz-form-control>
                    </nz-form-item>
                </div>
                <div nz-col nzSpan="24">
                    <nz-form-item>
                        <nz-form-label [nzFor]="'useEndTime'" nzRequired>使用截止日期</nz-form-label>
                        <nz-form-control nzErrorTip="请选择使用截止日期!">
                            <nz-date-picker nzFormat="yyyy-MM-dd" [formControlName]="'useEndTime'"
                            ></nz-date-picker>
                        </nz-form-control>
                    </nz-form-item>
                </div>
                <div nz-col nzSpan="12">
                    <nz-form-item>
                        <nz-form-label [nzFor]="'generateNum'" nzRequired>消费码数量</nz-form-label>
                        <nz-form-control nzErrorTip="请输入消费码!">
                            <input nz-input placeholder="请输入消费码 ..."  [formControlName]="'generateNum'"  />
                        </nz-form-control>
                    </nz-form-item>
                </div>
            </div>


        </form>
    </ng-container>
</nz-modal>


<nz-modal [(nzVisible)]="errorStudentVisible" nzTitle="导入失败数据" (nzOnCancel)="handleCancelError()" nzWidth="900px" [nzFooter]="null">
    <nz-table #errorStudentTable [nzData]="importErrorStudentArray">
        <thead>
        <tr>
            <th nzWidth="80px">序号</th>
            <th nzWidth="150px">销售码</th>
            <th nzWidth="150px">销售截止时间</th>
            <th nzWidth="150px">使用截止时间</th>
            <th nzWidth="300px">原因</th>
        </tr>
        </thead>
        <tbody>
        <tr *ngFor="let data of errorStudentTable.data;let i = index">
            <td>{{ i + 1}}</td>
            <td>{{data.salesCode}}</td>
            <td>{{data.salesEndTime}}</td>
            <td>{{data.useEndTime}}</td>
            <td>{{data.errorMessage}}</td>
        </tr>
        </tbody>
    </nz-table>
</nz-modal>


<nz-modal [(nzVisible)]="exportSalesCodeModal" nzTitle="导出销售码" (nzOnCancel)="closeExportSalesCodeModal()" [nzFooter]="null">
    <nz-spin [nzSpinning]="exportLoading" nzTip="导出中...">
        <form nz-form [formGroup]="exportSalesCodeForm" >
            <nz-form-item>
                <nz-form-label [nzSm]="4" [nzXs]="24">
                      <span><i nz-icon nz-tooltip nzTooltipTitle="创建时间：导入销售码的时间 或 生成销售码的时间" nzType="question-circle" nzTheme="outline"></i>创建时间</span>
                </nz-form-label>
                <nz-form-control [nzSm]="18" [nzXs]="24">
                    <nz-range-picker formControlName="createTime"
                                     [nzFormat]="'yyyy-MM-dd HH:mm:ss'"
                                     [nzShowTime]="{ nzHideDisabledOptions: true }"

                    ></nz-range-picker>
                </nz-form-control>
            </nz-form-item>
            <nz-form-item>
                <nz-form-label [nzSm]="4" [nzXs]="24">
                      <span>销售码状态</span>
                </nz-form-label>
                <nz-form-control [nzSm]="18" [nzXs]="24">
                    <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-option nzValue="99" nzLabel="预支付"></nz-option>
                    </nz-select>
                </nz-form-control>
            </nz-form-item>
            <div *nzModalFooter style="text-align: center;">
                <button nz-button nzType="primary" [nzLoading]="exportLoading" (click)="exportSalesCodeData()">导出销售码</button>
            </div>
        </form>
    </nz-spin>
</nz-modal>
