<!-- 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="couponName"/>
                    </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 nzPlaceHolder="请选择展示区域"  [formControlName]="'displayArea'">
                            <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="5" nzLabel="工会卡专区"></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  nzPlaceHolder="请选择商品分类" (ngModelChange)="getBrandByList($event)"  [formControlName]="'goodsTypeId'">
                            <nz-option *ngFor="let item of goodsTypeData" nzValue="{{item.id}}" nzLabel="{{item.title}}"></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  nzPlaceHolder="请选择品牌"  [formControlName]="'brandId'">
                            <nz-option *ngFor="let item of brandData" nzValue="{{item.id}}" nzLabel="{{item.title}}"></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
                                (nzScrollToBottom)="loadMore()"
                                (nzOnSearch)="search($event)"
                                nzShowSearch
                                [formControlName]="'merchantId'"
                                nzServerSearch
                                nzPlaceHolder="请选择商户"
                                nzAllowClear
                                [nzDropdownRender]="renderTemplate"
                        >
                            <nz-option *ngFor="let o of optionList" [nzValue]="o.id" [nzLabel]="o.merchantName"></nz-option>
                        </nz-select>
                        <ng-template #renderTemplate>
                            <nz-spin *ngIf="isLoading"></nz-spin>
                        </ng-template>
                    </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]="'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="8">
                <nz-form-item>
                    <nz-form-label [nzSpan]="6">卡券状态</nz-form-label>
                    <nz-form-control [nzSpan]="16">
                        <nz-select nzShowSearch nzAllowClear [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="101" nzLabel="上架审批中"></nz-option>
                            <nz-option nzValue="102" 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}}</span>
    </span>
    <div class="operating-button">
        <button nz-button nzType="primary" class="right-btn" [routerLink]="['/admin/coupon/coupon-edit']" ><i nz-icon nzType="plus" nzTheme="outline"></i>添加</button>
        <button nz-button nzType="primary" class="right-btn" (click)="getGuizhouSinopec()" ><i nz-icon nzType="redo" 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="150px">卡券编号</th>
            <th nzWidth="160px">卡券名称</th>
            <th nzWidth="100px">销售价格</th>
            <th nzWidth="100px">折扣价格</th>
            <th nzWidth="100px">有效库存</th>
            <th nzWidth="100px">卡券类型</th>
            <th nzWidth="100px">是否赠券</th>
            <th nzWidth="150px">销售截止时间</th>
            <th nzWidth="150px">创建时间</th>
            <th nzWidth="100px" nzRight>展示区域</th>
            <th nzWidth="120px" nzRight>卡券状态</th>
            <th nzWidth="150px" nzRight>操作</th>
        </tr>
        </thead>
        <tbody>
        <tr *ngFor="let data of ajaxTable.data; let i = index">
            <td>{{i+1}}</td>
            <td>{{data.couponKey}}</td>
            <td>{{data.couponName}}</td>
            <td>¥{{data.salesPrice}}</td>
            <td>¥{{data.discountPrice}}</td>
            <td>{{data.stockCount}}</td>
            <td>{{data.couponType === 1 ? '内部卷' : '外部卷'}}</td>
            <td>{{data.isPresent === true ? '赠券' : '无赠券'}}</td>
            <td>{{data.salesEndTime | date: 'yyyy-MM-dd HH:mm'}}</td>
            <td>{{data.createTime | date: 'yyyy-MM-dd HH:mm'}}</td>
            <td nzRight>{{data.displayArea | displayArea}}</td>
            <td nzRight>
                <span *ngIf="data.status === 2" style="color: limegreen">{{data.status | couponStatus}}</span>
                <span *ngIf="data.status === 3" style="color: red">{{data.status | couponStatus}}</span>
                <span *ngIf="data.status === 1 || data.status === 102  || data.status === 101">{{data.status | couponStatus}}</span>

            </td>
            <td nzRight class="table-td-operation">
                <a *ngIf="data.status === 2" (click)="disableMerchant(data.id)">下架</a>
                <a *ngIf="data.status === 1 || data.status === 3 || data.status === 102" (click)="enableMerchant(data.id)">上架</a>
                <nz-divider nzType="vertical" ></nz-divider>
                <a nz-dropdown [nzDropdownMenu]="menu">更多</a>
                <nz-dropdown-menu #menu="nzDropdownMenu">
                    <ul nz-menu nzSelectable>
                        <li class="li-a" *ngIf="data.status === 1 || data.status === 3 || data.status === 102"  nz-menu-item> <a (click)="getEdit(data.id)">编辑</a></li>
                        <li class="li-a" nz-menu-item><a (click)="getList(data.id , data.couponName , data.couponType)">销售码列表</a></li>
                    </ul>
                </nz-dropdown-menu>
            </td>
        </tbody>
    </nz-table>
</div>



