<!-- 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">优惠券KYE</nz-form-label>
                    <nz-form-control [nzSpan]="16">
                        <input nz-input formControlName="discountKey"/>
                    </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="discountName"/>
                    </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="discountType" nzPlaceHolder="请选择优惠券类型">
                            <nz-option nzLabel="满减" nzValue="1"></nz-option>
                            <nz-option nzLabel="抵扣" nzValue="2"></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/discount/discount-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="60px">编号</th>
            <th nzWidth="150px">优惠券KEY</th>
            <th nzWidth="130px">优惠券名称</th>
            <th nzWidth="100px">优惠券类型</th>
            <th nzWidth="100px">优惠内容</th>
            <th nzWidth="100px">有效天数</th>
            <th nzWidth="100px">可领取次数</th>
            <th nzWidth="100px">截止日期</th>
            <th nzWidth="100px">创建时间</th>
            <th nzWidth="100px">状态</th>
            <th nzWidth="110px" nzRight="0px">操作</th>
        </tr>
        </thead>
        <tbody>
        <tr *ngFor="let data of ajaxTable.data; let i = index">
            <td>{{i + 1}}</td>
            <td>{{data.discountKey}}</td>
            <td>{{data.discountName}}</td>
            <td>{{data.discountType | discountType}}</td>
            <td>
                <span *ngIf="data.discountType === 1">
                      满{{data.discountCondition}}抵扣{{data.discountPrice}}
                </span>
                <span *ngIf="data.discountType === 2">
                      抵扣{{data.discountPrice}}
                </span>
                <span *ngIf="data.discountType === 3">
                      {{data.discountPrice}}折
                </span>
            </td>
            <td>{{data.effectiveDay}}</td>
            <td>{{data.receiveNumber}}</td>
            <td>{{data.salesEndTime | date: 'yyyy-MM-dd HH:mm:ss'}}</td>
            <td>{{data.createTime  | date: 'yyyy-MM-dd HH:mm:ss'}}</td>
            <td>{{data.status | discountStatus}}</td>
            <td nzRight="0px" class="table-td-operation">
<!--                                <a (click)="getEdit(data.id)"><i nz-icon nzType="form" nzTheme="outline" nz-tooltip="编辑"></i></a>-->
<!--                                <nz-divider nzType="vertical"></nz-divider>-->
                <a (click)="getCoupon(this.searchFormCoupon.value , data.id)"><i nz-icon nzType="money-collect" nzTheme="outline" nz-tooltip="绑定卡券"></i></a>
                <nz-divider nzType="vertical"></nz-divider>
                <a (click)="getCouponList(data.id)"><i nz-icon nzType="unordered-list" nzTheme="outline" nz-tooltip="查询绑定列表"></i></a>
                <nz-divider nzType="vertical"></nz-divider>
                <a (click)='getForbiddenUser(data.id , data.status)'><i nz-icon
                                                                        nzType="{{data.status === 2 ? 'arrow-down': 'arrow-up'}}"
                                                                        nzTheme="outline"
                                                                        nz-tooltip="{{data.status === 2 ? '下架': '上架'}}"></i></a>
            </td>
        </tbody>
    </nz-table>
</div>


<nz-modal [(nzVisible)]="isVisible" nzTitle="绑定卡券" nzWidth="1100" (nzOnCancel)="handleCancel()" (nzOnOk)="handleOk()">
    <div class="inner-content">
        <form nz-form [formGroup]="searchFormCoupon" (ngSubmit)="getCoupon(searchFormCoupon.value , this.discountId)">
            <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="couponName"/>
                        </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="merchantId" nzPlaceHolder="请选择商户">
                                <nz-option *ngFor="let item of optionList" nzLabel="{{item.merchantName}}" nzValue="{{item.id}}"></nz-option>
                            </nz-select>
                        </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 [formControlName]="'couponType'">
                                <nz-option nzValue="1" nzLabel="内部卷"></nz-option>
                                <nz-option nzValue="2" nzLabel="外部卷"></nz-option>
                            </nz-select>
                        </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 [formControlName]="'couponSource'">
                                <nz-option nzValue="1" nzLabel="中石化"></nz-option>
                                <nz-option nzValue="2" 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)="resetCouponForm()"><i nz-icon nzType="reload" nzTheme="outline"></i>重置</button>
                </div>
            </div>
        </form>
    </div>
    <div class="inner-content">
        <nz-table
                class="table"
                #couponTable
                nzShowSizeChanger
                [nzFrontPagination]="false"
                [nzData]="requestCouponData"
                [nzLoading]="loadingCoupon"
                [nzScroll]="{ x: '1200px' ,  y: '340px' }"
                >
            <thead nzSingleSort>
            <tr>
                <th
                        nzWidth="50px"
                        nzLeft
                        [(nzChecked)]="checked"
                        [nzIndeterminate]="indeterminate"
                        (nzCheckedChange)="onAllChecked($event)"
                ></th>
                <th nzWidth="150px">卡券编号</th>
                <th nzWidth="160px">卡券名称</th>
                <th nzWidth="100px">销售价格</th>
                <th nzWidth="100px">有效库存</th>
                <th nzWidth="100px">卡券类型</th>
                <th nzWidth="120px">卡券状态</th>
                <th nzWidth="150px">销售截止时间</th>
            </tr>
            </thead>
            <tbody>
            <tr *ngFor="let data of couponTable.data; let i = index">
                <td nzLeft [nzChecked]="setOfCheckedId.has(data.id)" (nzCheckedChange)="onItemChecked(data.id, $event)"></td>
                <td>{{data.couponKey}}</td>
                <td>{{data.couponName}}</td>
                <td>¥{{data.salesPrice}}</td>
                <td>{{data.stockCount}}</td>
                <td>{{data.couponType === 1 ? '内部卷' : '外部卷'}}</td>
                <td>{{data.status | couponStatus}}</td>
                <td>{{data.salesEndTime | date: 'yyyy-MM-dd HH:mm'}}</td>
            </tbody>
        </nz-table>
    </div>
</nz-modal>

<nz-modal [(nzVisible)]="isVisibleList" nzTitle="绑定卡券列表" nzWidth="1100" (nzOnCancel)="handleCancelList()" (nzOnOk)="handleCancelList()">
    <div class="inner-content">
        <nz-table
                class="table"
                #discountCouponTable
                nzShowSizeChanger
                [nzFrontPagination]="false"
                [nzData]="discountCoupon"
                [nzLoading]="loadingDiscountCoupon"
                [nzScroll]="{ x: '1200px' ,  y: '340px' }"
        >
            <thead nzSingleSort>
            <tr>
                <th nzWidth="150px">卡券编号</th>
                <th nzWidth="160px">卡券名称</th>
                <th nzWidth="100px">销售价格</th>
                <th nzWidth="100px">有效库存</th>
                <th nzWidth="100px">卡券类型</th>
                <th nzWidth="120px">卡券状态</th>
                <th nzWidth="150px">销售截止时间</th>
                <th nzWidth="150px">绑定时间</th>
                <th nzRight nzWidth="60px">操作</th>
            </tr>
            </thead>
            <tbody>
            <tr *ngFor="let data of discountCouponTable.data; let i = index">
                <td>{{data['highCoupon'].couponKey}}</td>
                <td>{{data['highCoupon'].couponName}}</td>
                <td>¥{{data['highCoupon'].salesPrice}}</td>
                <td>{{data['highCoupon'].stockCount}}</td>
                <td>{{data['highCoupon'].couponType === 1 ? '内部卷' : '外部卷'}}</td>
                <td>{{data['highCoupon'].status | couponStatus}}</td>
                <td>{{data['highCoupon'].salesEndTime | date: 'yyyy-MM-dd HH:mm'}}</td>
                <td>{{data.createTime | date: 'yyyy-MM-dd HH:mm'}}</td>
                <td nzRight><a (click)="showDeleteConfirmDelete(data.id)">删除</a></td>
            </tbody>
        </nz-table>
    </div>
</nz-modal>
