<!-- start 面包屑 -->
<app-breadcrumb></app-breadcrumb>
<!-- end 面包屑 -->
<!--条件搜索-->

<nz-spin [nzSpinning]="loadingObject.spinning" nzTip="{{loadingObject.msg}}">
    <div class="inner-content">
        <form nz-form [formGroup]="searchForm" (ngSubmit)="search(searchForm.value)">
            <div nz-row>
                <div nz-col nzSpan="8" *ngIf="roleType == 1">
                    <nz-form-item>
                        <nz-form-label [nzSpan]="8">地区</nz-form-label>
                        <nz-form-control [nzSpan]="14">
                            <input nz-input formControlName="regionName" />
                        </nz-form-control>
                    </nz-form-item>
                </div>
                <div nz-col nzSpan="8">
                    <nz-form-item>
                        <nz-form-label [nzSpan]="8">加油站名称</nz-form-label>
                        <nz-form-control [nzSpan]="14">
                            <input nz-input formControlName="storeName" />
                        </nz-form-control>
                    </nz-form-item>
                </div>
                <div nz-col nzSpan="8"  *ngIf="roleType == 5 && adminFlag == 1" >
                    <nz-form-item>
                        <nz-form-label [nzSpan]="8">分配代理公司</nz-form-label>
                        <nz-form-control [nzSpan]="14">
                            <nz-select nzAllowClear  formControlName="isAssignOrgId">
                                <nz-option nzValue="true" nzLabel="是"></nz-option>
                                <nz-option nzValue="false" nzLabel="否"></nz-option>
                            </nz-select>
                        </nz-form-control>
                    </nz-form-item>
                </div>
                <div nz-col nzSpan="8"  *ngIf="roleType == 5 && adminFlag == 1" >
                    <nz-form-item>
                        <nz-form-label [nzSpan]="8">代理公司</nz-form-label>
                        <nz-form-control [nzSpan]="14">
                            <input nz-input formControlName="organizationName" />
                        </nz-form-control>
                    </nz-form-item>
                </div>
                <div nz-col nzSpan="8"  *ngIf="roleType == 5 && adminFlag == 0" >
                    <nz-form-item>
                        <nz-form-label [nzSpan]="8">分配代理商</nz-form-label>
                        <nz-form-control [nzSpan]="14">
                            <nz-select nzAllowClear  formControlName="isAssignTyAgent">
                                <nz-option nzValue="true" nzLabel="是"></nz-option>
                                <nz-option nzValue="false" nzLabel="否"></nz-option>
                            </nz-select>
                        </nz-form-control>
                    </nz-form-item>
                </div>
                <div nz-col nzSpan="8" *ngIf="roleType == 5 && adminFlag == 0" >
                    <nz-form-item>
                        <nz-form-label [nzSpan]="8">代理商</nz-form-label>
                        <nz-form-control [nzSpan]="14">
                            <input nz-input formControlName="tyAgentName" />
                        </nz-form-control>
                    </nz-form-item>
                </div>
                <div nz-col nzSpan="8"  *ngIf="roleType == 8" >
                    <nz-form-item>
                        <nz-form-label [nzSpan]="8">分配业务员</nz-form-label>
                        <nz-form-control [nzSpan]="14">
                            <nz-select nzAllowClear  formControlName="isAssignTySalesman">
                                <nz-option nzValue="true" nzLabel="是"></nz-option>
                                <nz-option nzValue="false" nzLabel="否"></nz-option>
                            </nz-select>
                        </nz-form-control>
                    </nz-form-item>
                </div>
                <div nz-col nzSpan="8" *ngIf="roleType == 8">
                    <nz-form-item>
                        <nz-form-label [nzSpan]="8">业务员</nz-form-label>
                        <nz-form-control [nzSpan]="14">
                            <input nz-input formControlName="tySalesmanName" />
                        </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>共计 {{dataObject.total?dataObject.total:0}} 条数据</span>
        <div class="operating-button">
            <button nz-button nzType="primary" class="right-btn" *ngIf="(roleType == 5 && adminFlag == 1) || (roleType == 8) || (roleType == 9)" (click)="showBatchDiscountConfigModal()"><i nz-icon nzType="edit" nzTheme="outline"></i>批量设置优惠</button>
            <button nz-button nzType="primary" class="right-btn" *ngIf="roleType == 5 && adminFlag == 1" (click)="showBatchConfigOilNoModal()"><i nz-icon nzType="edit" nzTheme="outline"></i>批量配置油品</button>
            <button nz-button nzType="primary" class="right-btn" *ngIf="roleType == 5 && adminFlag == 1" (click)="showAssignOrgModal()"><i nz-icon nzType="plus" nzTheme="outline"></i>分配代理公司</button>
            <button nz-button nzType="primary" class="right-btn" *ngIf="roleType == 5 && adminFlag == 1" (click)="showUnbindOrgConfirm()"><i nz-icon nzType="minus" nzTheme="outline"></i>解绑代理公司</button>
            <button nz-button nzType="primary" class="right-btn" *ngIf="roleType == 5 && adminFlag == 0" (click)="showAssignAgentModal()"><i nz-icon nzType="plus" nzTheme="outline"></i>分配代理商</button>
            <button nz-button nzType="primary" class="right-btn" *ngIf="roleType == 5 && adminFlag == 0" (click)="showUnbindAgentConfirm()"><i nz-icon nzType="minus" nzTheme="outline"></i>解绑代理商</button>
            <button nz-button nzType="primary" class="right-btn" *ngIf="roleType == 8" (click)="showAssignSalesmanModal()"><i nz-icon nzType="plus" nzTheme="outline"></i>分配业务员</button>
            <button nz-button nzType="primary" class="right-btn" *ngIf="roleType == 8" (click)="showUnbindSalesmanConfirm()"><i nz-icon nzType="minus" nzTheme="outline"></i>解绑业务员</button>
        </div>

        <!--数组表格 -->
        <nz-table #basicTable
                  nzShowSizeChanger
                  [nzPageSizeOptions]="[10,20,50,100]"
                  [nzData]="dataObject.list"
                  [nzTotal]="dataObject.total"
                  [nzFrontPagination]="false"
                  [nzLoading]="tableLoading"
                  [nzPageIndex]="whereObject.pageNum"
                  (nzPageIndexChange)="requestData($event)"
                  (nzPageSizeChange)="pageSizeChange($event)"
                  [nzScroll]="{ x: '1150px'}">
            <thead>
            <tr>
                <th nzWidth="50px" [(nzChecked)]="allChecked" [nzShowCheckbox]="true" (nzCheckedChange)="onAllChecked($event)"></th>
                <th nzWidth="90px">加油站ID</th>
                <th nzWidth="70px">地区</th>
                <th nzWidth="130px">加油站名称</th>
                <th nzWidth="130px">加油站地址</th>
                <th nzWidth="100px">代理公司</th>
                <th nzWidth="100px">代理商</th>
                <th nzWidth="100px">业务员</th>
                <th nzWidth="100px" nzRight="0px">操作</th>
            </tr>
            </thead>
            <tbody>
            <tr *ngFor="let data of basicTable.data;let i = index">
                <td
                        [nzShowCheckbox]="true"
                        [nzChecked]="data.checked"
                        [nzDisabled]="data.disabled"
                        (nzCheckedChange)="checkedChange(data, $event)"
                ></td>
                <td>{{data.storeKey}}</td>
                <td>{{data.regionName}}</td>
                <td>{{data.storeName}}</td>
                <td>{{data.address}}</td>
                <td>{{data.organizationName?data.organizationName:'未分配'}}</td>
                <td>{{data.tyAgentName?data.tyAgentName:'未分配'}}</td>
                <td>{{data.tySalesmanName?data.tySalesmanName:'未分配'}}</td>
                <td nzRight="0px" class="table-td-operation">
                    <a nz-dropdown [nzDropdownMenu]="menu"> 操作列表 <i nz-icon nzType="down"></i> </a>
                    <nz-dropdown-menu #menu="nzDropdownMenu">
                        <ul nz-menu nzSelectable>
                            <li *ngIf="(roleType == 5 && adminFlag == 1) || roleType == 8 || roleType == 9" nz-menu-item (click)="showDiscountConfigModal(data.storeId)">优惠配置</li>
                            <li *ngIf="roleType == 5 && adminFlag == 1" (click)="showOilConfigModal(data.storeId)" nz-menu-item>油品配置</li>
                        </ul>
                    </nz-dropdown-menu>
                </td>
            </tr>
            </tbody>
        </nz-table>
    </div>

    <nz-modal [(nzVisible)]="assignOrgModal" nzTitle="分配代理商公司" (nzOnCancel)="closeAssignOrgModal()" nzWidth="500px" [nzFooter]="null">
        <form nz-form [formGroup]="assignOrgForm">
            <nz-form-item>
                <nz-form-label [nzSpan]="6">
                    代理商公司
                </nz-form-label>
                <nz-form-control [nzSpan]="14">
                    <nz-select nzShowSearch nzAllowClear nzPlaceHolder="请选择代理商公司" formControlName="orgId">
                        <nz-option *ngFor="let data of orgArray" nzLabel="{{data.name}}" nzValue="{{data.id}}"></nz-option>
                    </nz-select>
                </nz-form-control>
            </nz-form-item>
            <div style="text-align: center;">
                <button nz-button nzType="primary" style="width: 150px;" (click)="submitAssignOrg()">确定</button>
            </div>
        </form>
    </nz-modal>

    <nz-modal [(nzVisible)]="assignAgentModal" nzTitle="分配代理商" (nzOnCancel)="closeAssignAgentModal()" nzWidth="500px" [nzFooter]="null">
        <form nz-form [formGroup]="assignAgentForm">
            <nz-form-item>
                <nz-form-label [nzSpan]="6">
                    代理商
                </nz-form-label>
                <nz-form-control [nzSpan]="14">
                    <nz-select nzShowSearch nzAllowClear nzPlaceHolder="请选择代理商" formControlName="agentId">
                        <nz-option *ngFor="let data of agentArray" nzLabel="{{data.agentName}}" nzValue="{{data.id}}"></nz-option>
                    </nz-select>
                </nz-form-control>
            </nz-form-item>
            <div style="text-align: center;">
                <button nz-button nzType="primary" style="width: 150px;" (click)="submitAssignAgent()">确定</button>
            </div>
        </form>
    </nz-modal>

    <nz-modal [(nzVisible)]="assignSalesmanModal" nzTitle="分配业务员" (nzOnCancel)="closeAssignSalesmanModal()" nzWidth="500px" [nzFooter]="null">
        <form nz-form [formGroup]="assignSalesmanForm">
            <nz-form-item>
                <nz-form-label [nzSpan]="6">
                    业务员
                </nz-form-label>
                <nz-form-control [nzSpan]="14">
                    <nz-select nzShowSearch nzAllowClear nzPlaceHolder="请选择业务员" formControlName="salesmanId">
                        <nz-option *ngFor="let data of salesmanArray" nzLabel="{{data.salesmanName}}" nzValue="{{data.id}}"></nz-option>
                    </nz-select>
                </nz-form-control>
            </nz-form-item>
            <div style="text-align: center;">
                <button nz-button nzType="primary" style="width: 150px;" (click)="submitAssignSalesman()">确定</button>
            </div>
        </form>
    </nz-modal>

    <nz-modal [(nzVisible)]="discountConfigModal" nzTitle="优惠配置" (nzOnCancel)="closeDiscountConfigModal()" nzWidth="350px" [nzBodyStyle]="{ padding: '10px 24px 24px 24px' }" [nzFooter]="null">
        <div nz-row *ngFor="let item of discountConfigData" style="margin-top: 10px;">
            <div nz-col [nzSpan]="3" style="margin-top: 5px;">{{item.oilNoName}}</div>
            <div nz-col [nzSpan]="10">
                <nz-input-number
                        [(ngModel)]="item.priceRate"
                        [nzMin]="item.lowPrice"
                        [nzMax]="100"
                        [nzStep]="1"
                        [nzFormatter]="formatterPercent"
                        [nzParser]="parserPercent"
                        [nzPrecision]="2"
                        style="width: 100%;" >
                </nz-input-number>
            </div>
            <div nz-col [nzSpan]="11" style="margin-top: 5px;">
                <span nz-typography nzType="warning">（最低折扣价 {{item.lowPrice}} 折）</span>
            </div>
        </div>
        <div style="text-align: center;">
            <button nz-button nzType="primary" style="margin-top: 15px;width: 150px;" (click)="submitDiscountConfig()">保存</button>
        </div>
    </nz-modal>

    <nz-modal [(nzVisible)]="oilConfigModal" nzTitle="油品配置" (nzOnCancel)="closeOilConfigModal()" nzWidth="550px" [nzBodyStyle]="{ padding: '10px 24px 24px 24px' }" [nzFooter]="null">
        <div nz-row *ngFor="let item of discountConfigData" style="margin-top: 10px;">
            <div nz-col [nzSpan]="3" style="margin-top: 5px;">
                {{item.oilNoName}}
            </div>
            <div nz-col [nzSpan]="10">
                <nz-input-number
                        [(ngModel)]="item.priceRate"
                        [nzMin]="item.lowPrice"
                        [nzMax]="100"
                        [nzStep]="1"
                        [nzFormatter]="formatterPercent"
                        [nzParser]="parserPercent"
                        [nzPrecision]="2"
                        [disabled]="true"
                        style="width: 100%;" >
                </nz-input-number>
            </div>
            <div nz-col [nzSpan]="11" style="margin-top: 5px;left: 15px;">
                <span nz-typography nzType="warning" *ngIf="item.status == 1">正常销售中<a (click)="showOilDisabledConfirm(item.oilStationId, item.oilNo)">【点击暂停销售】</a></span>
                <span nz-typography nzType="danger"  *ngIf="item.status == 2">已暂停销售<a (click)="showOilEnableConfirm(item.oilStationId, item.oilNo)">【点击恢复正常销售】</a></span>
            </div>
        </div>
    </nz-modal>

    <nz-modal [(nzVisible)]="batchDiscountConfigModal" nzTitle="批量配置优惠" (nzOnCancel)="closeBatchDiscountConfigModal()" nzWidth="350px" [nzFooter]="null">
        <form nz-form [formGroup]="batchDiscountConfigForm">
            <nz-form-item>
                <nz-form-label [nzSpan]="6">
                    油品
                </nz-form-label>
                <nz-form-control [nzSpan]="14">
                    <nz-select nzShowSearch nzAllowClear nzPlaceHolder="请选择油品" formControlName="oilNo">
                        <nz-option *ngFor="let data of oilNoArray" nzLabel="{{data.codeName}}" nzValue="{{data.codeValue}}"></nz-option>
                    </nz-select>
                </nz-form-control>
            </nz-form-item>
            <nz-form-item>
                <nz-form-label [nzSpan]="6">
                    折扣
                </nz-form-label>
                <nz-form-control [nzSpan]="14">
                    <nz-input-number
                            [nzMin]="1"
                            [nzMax]="100"
                            [nzStep]="1"
                            [nzFormatter]="formatterPercent"
                            [nzParser]="parserPercent"
                            [nzPrecision]="2"
                            formControlName="priceRate"
                            style="width: 100%;" >
                    </nz-input-number>
                </nz-form-control>
            </nz-form-item>
            <div style="text-align: center;">
                <button nz-button nzType="primary" style="width: 150px;" (click)="submitBatchDiscountConfig()">确定</button>
            </div>
        </form>
    </nz-modal>

    <nz-modal [(nzVisible)]="batchConfigOilNoModal" nzTitle="批量配置油品" (nzOnCancel)="closeBatchConfigOilNoModal()" nzWidth="350px" [nzFooter]="null">
        <form nz-form [formGroup]="batchConfigOilNoForm">
            <nz-form-item>
                <nz-form-label [nzSpan]="6">
                    油品
                </nz-form-label>
                <nz-form-control [nzSpan]="14">
                    <nz-select nzShowSearch nzAllowClear nzPlaceHolder="请选择油品" formControlName="oilNo">
                        <nz-option *ngFor="let data of oilNoArray" nzLabel="{{data.codeName}}" nzValue="{{data.codeValue}}"></nz-option>
                    </nz-select>
                </nz-form-control>
            </nz-form-item>
            <nz-form-item>
                <nz-form-label [nzSpan]="6">
                    销售状态
                </nz-form-label>
                <nz-form-control [nzSpan]="14">
                    <nz-select nzShowSearch nzAllowClear nzPlaceHolder="请选择销售状态" formControlName="status">
                        <nz-option nzLabel="正常销售" nzValue="1"></nz-option>
                        <nz-option nzLabel="暂停销售" nzValue="2"></nz-option>
                    </nz-select>
                </nz-form-control>
            </nz-form-item>
            <div style="text-align: center;">
                <button nz-button nzType="primary" style="width: 150px;" (click)="submitBatchConfigOilNo()">确定</button>
            </div>
        </form>
    </nz-modal>

</nz-spin>
