<page-header-wrapper [title]="'合伙人列表'"> </page-header-wrapper>

<nz-card class="search-box" nzBordered>
  <div nz-row nzGutter="8">
    <div nz-col [nzXl]="_$expand ? 24 : 17" [nzLg]="24" [nzSm]="24" [nzXs]="24">
      <sf #sf [schema]="searchSchema" [ui]="{ '*': { spanLabelFixed: 110, grid: { lg: 8, md: 12, sm: 12, xs: 24 } } }"
        [compact]="true" [button]="'none'"></sf>
    </div>
    <div nz-col [nzXl]="_$expand ? 24 : 7" [nzLg]="24" [nzSm]="24" [nzXs]="24" class="text-right"
      [class.expend-options]="_$expand">
      <button nz-button nzType="primary" [nzLoading]="service.http.loading" (click)="st?.load(1)">查询</button>
      <button nz-button (click)="resetSF()">重置</button>
      <button nz-button nzType="link" (click)="expandToggle()">
        {{ !_$expand ? '展开' : '收起' }}
        <i nz-icon [nzType]="!_$expand ? 'down' : 'up'"></i>
      </button>
    </div>
  </div>
</nz-card>

<nz-card class="content-box" nzBordered>
  <div class="d-flex align-items-center mb-md mt-md">
    <button nz-button (click)="this.routeTo('/partner/partner-list/add-etp-partner')" nzType="primary">新增企业合伙人</button>
    <button nz-button (click)="this.routeTo('/partner/partner-list/add-personal-partner')"
      nzType="primary">新增个人合伙人</button>
  </div>

  <st #st [data]="service.$api_get_partner_page" [columns]="columns" [req]="{ process: beforeReq }"
    [loading]="service.http.loading" [scroll]="{ x: '1200px' }" [page]="{}">
  </st>
</nz-card>

<ng-template #editTemplate>
  <div nz-row nzGutter="8">
    <div nz-col nzSpan="24" se-container [labelWidth]="120">
      <se [col]="1" label="合伙人名称"> {{selectItem?.enterpriseName || selectItem?.contactName}} </se>
      <se [col]="1" label="返佣模板" required>
        <nz-select [(ngModel)]="templateId" style="width: 100%">
          <nz-option [nzValue]="item.value" [nzLabel]="item.label" *ngFor="let item of customers"></nz-option>
        </nz-select>
      </se>
    </div>
  </div>
  <p class="text-center mt-md">说明：修改模板后，当月开始返佣收益将会按新模板计算</p>
</ng-template>

<ng-template #editCannel>
  <div nz-row nzGutter="8">
    <div nz-col nzSpan="24" se-container [labelWidth]="140" [col]="1">
      <se label="合伙人名称"> {{selectItem?.enterpriseName || selectItem?.contactName}} </se>
      <se label="当前渠道销售"> {{selectItem?.channelId}} </se>
      <se label="渠道销售修改为" required>
        <nz-select [(ngModel)]="cannelItem.channelId" style="width: 100%">
          <nz-option [nzValue]="item.value" [nzLabel]="item.label" *ngFor="let item of cannels"></nz-option>
        </nz-select>
      </se>
      <se label="备注" required>
        <textarea rows="3" nz-input [(ngModel)]="cannelItem.remark"></textarea>
      </se>
      <se label="一并转移的客户">
        <p style="margin-top: 8px">已选（{{selectedRows?.length}}）</p>
        <st #rest [data]="service.$api_get_enterprice_rel_list" [columns]="[
        { title: '', index: 'key', type: 'checkbox' },
        { title: '客户名称', index: 'enterpriceName' }
        ]" [req]="{ process: beforeReq,params:{effectiveStatus:2 ,newPartnerId:selectItem.id} }"
          [loading]="service.http.loading" [page]="{show:false}" (change)="stChange($event)">
        </st>
      </se>
      <se label="生效节点" required>
        <nz-radio-group [(ngModel)]="cannelItem.effectiveNode">
          <label nz-radio [nzValue]="1">修改成功后立即生效</label>
          <label nz-radio [nzValue]="2">CRM流程审核通过后生</label>
        </nz-radio-group>
      </se>
    </div>
  </div>
  <p class="text-center mt-md">客户转移：客户跟着上级合伙人转移一并到新渠道销售下，会同步发起CRM《客户转移》流程；不转移的，客户会与上级合伙人解绑，成为渠道销售的直客</p>
</ng-template>