<!-- 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" *ngIf="roleType === 1">
                <nz-form-item>
                    <nz-form-label [nzSpan]="6">区域公司</nz-form-label>
                    <nz-form-control [nzSpan]="16">
                        <nz-select nzShowSearch nzAllowClear [formControlName]="'companyId'" (ngModelChange)="getMerchantListByCompany($event)">
                            <nz-option *ngFor="let item of companyData" nzValue="{{item.id}}" nzLabel="{{item.name}}"></nz-option>
                        </nz-select>
                    </nz-form-control>
                </nz-form-item>
            </div>
            <div nz-col nzSpan="8" *ngIf="roleType === 5 || roleType === 1">
                <nz-form-item>
                    <nz-form-label [nzSpan]="6">商户</nz-form-label>
                    <nz-form-control [nzSpan]="16">
                        <nz-select nzShowSearch nzAllowClear [formControlName]="'merchantId'"  (ngModelChange)="getMerchantStoreById($event)">
                            <nz-option *ngFor="let item of merchantData" nzValue="{{item.id}}" nzLabel="{{item.merchantName}}"></nz-option>
                        </nz-select>
                    </nz-form-control>
                </nz-form-item>
            </div>
            <div nz-col nzSpan="8"  *ngIf="roleType === 5 || roleType === 1 || roleType === 2">
                <nz-form-item>
                    <nz-form-label [nzSpan]="6">门店</nz-form-label>
                    <nz-form-control [nzSpan]="16">
                        <nz-select nzShowSearch nzAllowClear [formControlName]="'merchantStoreId'">
                            <nz-option *ngFor="let item of merchantStoreData" nzValue="{{item.id}}" nzLabel="{{item.storeName}}"></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">
                        <input nz-input formControlName="orderNo"/>
                    </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">
                        <input nz-input formControlName="preOrderNo"/>
                    </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">
                        <input nz-input formControlName="goodsName"/>
                    </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">
                        <input nz-input formControlName="preUserName"/>
                    </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">
                        <input nz-input formControlName="userPhone"/>
                    </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 nzPlaceHolder="请选择订单状态" formControlName="status">
                            <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-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-range-picker [nzShowTime]="{ nzFormat: 'HH:mm' }" formControlName="createTime"></nz-range-picker>
                    </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" *ngIf="'BTN_export_order' | button" (click)="downloadTemplate(searchForm.value)" ><i nz-icon nzType="download" 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="180px">商品名称</th>
            <th nzWidth="180px">用户名称</th>
            <th nzWidth="180px">用户电话</th>
            <th nzWidth="180px">订单号</th>
            <th nzWidth="180px">预约订单号</th>
            <th nzWidth="120px">实付金额</th>
            <th nzWidth="140px">生成时间</th>
            <th nzRight nzWidth="100px">额外状态</th>
            <th nzRight nzWidth="100px">状态</th>
            <th nzWidth="120px" nzRight>操作</th>
        </tr>
        </thead>
        <tbody>
        <tr *ngFor="let data of ajaxTable.data; let i = index">
            <td>{{i+1}}</td>
            <td>{{data.goodsName}}</td>
            <td>{{data.preUserName}}</td>
            <td>{{data.preUserPhone}}</td>
            <td>{{data.orderNo}}</td>
            <td>{{data.preOrderNo}}</td>
            <td>{{data.payRealPrice}}</td>
            <td>{{data.createTime | date: 'yyyy-MM-dd HH:mm:ss'}}</td>
            <td nzRight>{{data.ext1 === null ? '暂无' : data.ext1 }}</td>
            <td nzRight>{{data.status | preOrderStatus}}</td>
            <td nzRight class="table-td-operation">
                <a (click)="getDetail(data.orderId , data.id)">详情</a>
                <span *ngIf=" data.ext1 !== '退款中'">
                   <nz-divider   *ngIf="(data.status === 4 && 'BTN_pre-order-refund' | button) || (data.status === 1 && 'BTN_pre-order-success' | button)"  nzType="vertical"></nz-divider>
                   <a  *ngIf="(data.status === 4 && 'BTN_pre-order-refund' | button) || (data.status === 1 && 'BTN_pre-order-success' | button)"   nz-dropdown [nzDropdownMenu]="menu">更多</a>
                </span>
                <nz-dropdown-menu #menu="nzDropdownMenu">
                    <ul nz-menu nzSelectable>
                        <li class="dropdown_menu" *ngIf="data.status === 1 && 'BTN_pre-order-success' | button" (click)="getPreSuccess(data.id)" nz-menu-item>预约成功</li>
                        <li class="dropdown_menu" *ngIf="data.status === 1 && 'BTN_pre-order-fail' | button" (click)="getPreFail(data.id)" nz-menu-item>预约失败</li>
                        <li class="dropdown_menu" *ngIf="(data.status === 4 && 'BTN_pre-order-refund' | button) && data.ext1 === null" (click)="postRefund(data.orderNo)" nz-menu-item>申请退款</li>
                    </ul>
                </nz-dropdown-menu>
            </td>
        </tbody>
    </nz-table>
</div>


<nz-modal [(nzVisible)]="isVisible" nzTitle="发起预约" (nzOnCancel)="isVisible = false" (nzOnOk)="handleOk()">
    <nz-form-item>
        <nz-form-label  nzRequired>预计时间</nz-form-label>
        <nz-form-control nzErrorTip="请选择预计时间!">
            <nz-date-picker [(ngModel)]="reachTime" ></nz-date-picker>
        </nz-form-control>
    </nz-form-item>
    <nz-form-item>
        <nz-form-label nzRequired>安装地址</nz-form-label>
        <nz-form-control>
            <textarea [(ngModel)]="reachAddress" nz-input rows="2" placeholder="请输入安装地址"></textarea>
        </nz-form-control>
    </nz-form-item>
    <nz-form-item>
        <nz-form-label nzRequired>预约备注</nz-form-label>
        <nz-form-control>
            <textarea [(ngModel)]="preUserRemark" nz-input rows="2" placeholder="请输入预约备注"></textarea>
        </nz-form-control>
    </nz-form-item>
</nz-modal>

<nz-modal [(nzVisible)]="isVisibleFail" nzTitle="预约失败" (nzOnCancel)="handleCancelFail()" (nzOnOk)="handleOkFail()">
    <nz-form-item>
        <nz-form-label nzRequired>失败备注</nz-form-label>
        <nz-form-control>
            <textarea [(ngModel)]="statusFailDesc" nz-input rows="2" placeholder="请输入失败备注"></textarea>
        </nz-form-control>
    </nz-form-item>
</nz-modal>


<nz-modal [(nzVisible)]="isVisibleDetail" nzTitle="订单详情" nzWidth="1200"  (nzOnCancel)="isVisibleDetail = false" (nzOnOk)="isVisibleDetail = false">
    <nz-descriptions  nzTitle="支付订单详情" nzBordered [nzColumn]="{ xxl: 4, xl: 3, lg: 3, md: 3, sm: 2, xs: 1 }">
        <nz-descriptions-item nzTitle="商品名称">{{orderDetail['highChildOrderList'][0]['goodsName']}}</nz-descriptions-item>
        <nz-descriptions-item nzTitle="支付类型">{{orderDetail['payType'] | paytype}}</nz-descriptions-item>
        <nz-descriptions-item nzTitle="支付金额">{{orderDetail['payPrice']}}</nz-descriptions-item>
        <nz-descriptions-item nzTitle="客户名称">{{orderDetail['memName']}}</nz-descriptions-item>
        <nz-descriptions-item nzTitle="客户电话">{{orderDetail['memPhone']}}</nz-descriptions-item>
        <nz-descriptions-item nzTitle="订单号">{{orderDetail['orderNo']}}</nz-descriptions-item>
        <nz-descriptions-item nzTitle="创建时间">{{orderDetail['createTime'] | date: 'yyyy-MM-dd HH:mm:ss'}}</nz-descriptions-item>
        <nz-descriptions-item nzTitle="支付时间">{{orderDetail['payTime'] | date: 'yyyy-MM-dd HH:mm:ss'}}</nz-descriptions-item>
        <nz-descriptions-item nzTitle="订单状态">{{orderDetail['orderStatus'] | orderCouponStatus}}</nz-descriptions-item>
    </nz-descriptions>

    <nz-descriptions  nzTitle="预约订单详情" nzBordered [nzColumn]="{ xxl: 4, xl: 3, lg: 3, md: 3, sm: 2, xs: 1 }">
        <nz-descriptions-item nzTitle="商品名称">{{preOrderDetail['goodsName']}}</nz-descriptions-item>
        <nz-descriptions-item nzTitle="操作人员">{{preOrderDetail['opUserName']}}</nz-descriptions-item>
        <nz-descriptions-item nzTitle="预约订单号">{{preOrderDetail['preOrderNo']}}</nz-descriptions-item>
        <nz-descriptions-item nzTitle="预约备注">{{preOrderDetail['preUserRemark'] == null ? '暂无': preOrderDetail['preUserRemark']}}</nz-descriptions-item>
        <nz-descriptions-item nzTitle="客户姓名">{{preOrderDetail['preUserName']}}</nz-descriptions-item>
        <nz-descriptions-item nzTitle="客户电话">{{preOrderDetail['preUserPhone']}}</nz-descriptions-item>
        <nz-descriptions-item nzTitle="到店地址">{{preOrderDetail['reachAddress'] == null ? '暂无': preOrderDetail['reachAddress']}}</nz-descriptions-item>
        <nz-descriptions-item nzTitle="到店时间">{{preOrderDetail['reachTime'] == null ? '暂无': preOrderDetail['reachTime'] | date: 'yyyy-MM-dd'}}</nz-descriptions-item>
        <nz-descriptions-item nzTitle="预约时间">{{preOrderDetail['preTime'] | date: 'yyyy-MM-dd'}}</nz-descriptions-item>
        <nz-descriptions-item nzTitle="创建时间">{{preOrderDetail['createTime'] | date: 'yyyy-MM-dd'}}</nz-descriptions-item>
        <nz-descriptions-item nzTitle="预约失败备注">{{preOrderDetail['statusFailDesc']}}</nz-descriptions-item>
        <nz-descriptions-item nzTitle="订单状态">{{preOrderDetail['status'] | preOrderStatus}}</nz-descriptions-item>
    </nz-descriptions>
</nz-modal>


