import { ModalHelper } from '@delon/theme';
import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { STColumn, STComponent, STData, STRequestOptions } from '@delon/abc/st';
import { SFComponent, SFDateWidgetSchema, SFSchema, SFSelectWidgetSchema, SFUISchema } from '@delon/form';
import { processSingleSort, ShipperBaseService } from '@shared';
import { NzModalService, NzModalRef } from 'ng-zorro-antd/modal';
import { RebateManagementService } from '../../services/rebate-management.service';
import { NzButtonSize } from 'ng-zorro-antd/button';

@Component({
  selector: 'app-parter-channel-rebate-management-record-detail',
  templateUrl: './record-detail.component.html'
})
export class ParterRebateManageMenRecordDetailComponent implements OnInit {
  schema: SFSchema = {};
  columns!: STColumn[];
  ui!: SFUISchema;
  @ViewChild('st', { static: false })
  st!: STComponent;
  @ViewChild('sf', { static: false })
  sf!: SFComponent;
  spuStatus = '1';
  size: NzButtonSize = 'large';
  _$expand = false;
  data = [{ name1: 1111 }];
  constructor(
    public router: Router,
    public ar: ActivatedRoute,
    public service: RebateManagementService,
    private modalService: NzModalService,
    public shipperservice: ShipperBaseService,
    public modalRef: NzModalRef,
  ) {}
  /**
   * 查询字段个数
   */
  get queryFieldCount(): number {
    return Object.keys(this.schema?.properties || {}).length;
  }
    /**
  * 伸缩查询条件
  */
     expandToggle(): void {
      this._$expand = !this._$expand;
      this.sf?.setValue('/_$expand', this._$expand);
    }
  /**
 * 查询参数
 */
   get reqParams() {
    const params: any = Object.assign({}, this.sf?.value || {});
    delete params._$expand;
    return { 
      ...params,
     };
  }
  ngOnInit() {
    this.initSF();
    this.initST();
  }

  initSF() {
    this.schema = {
      properties: {
        enterpriseInfoId: {
          type: 'string',
          title: '网络货运人',
          ui: {
            widget: 'select',
            placeholder: '请选择',
            allowClear: true,
            asyncData: () => this.shipperservice.getNetworkFreightForwarder(),
            change: (value: any) => {
              console.log(value)
              this.st.reload()
            }
          }
        },
        paymentStatus: {
          title: '银行类型',
          type: 'string',
          ui: {
            widget: 'dict-select',
            params: { dictKey: 'overall:payment:status' },
            containsAllLabel: true,
            change: (value: any) => {
              console.log(value)
              this.st.reload()
            }
          } as SFSelectWidgetSchema
        },
      }
    };
    this.ui = {
      '*': {
        spanLabelFixed: 140,
        grid: { span: 8, gutter: 4 }
      }
    };
  }

  initST() {
    this.columns = [
      {
        title: '订单号',
        index: 'billCode'
      },
      {
        title: '订单金额（元）',
        index: 'name1'
      },
      {
        title: '付款金额（元）',
        index: 'name1'
      },
      {
        title: '预估返佣金额（元）',
        index: 'name1'
      },
      {
        title: '附加费率',
        index: 'name1'
      },
      {
        title: '下单客户',
        index: 'name1'
      },
      {
        title: '网络货运人',
        index: 'name1'
      },
      {
        title: '销售渠道',
        index: 'name1'
      },
      {
        title: '合伙人名称',
        index: 'name1'
      },
      {
        title: '合伙人等级',
        index: 'name1'
      },
      {
        title: '管理费比例',
        index: 'name1'
      },
      {
        title: '固定结算费率',
        index: 'name1'
      },
      {
        title: '返佣时间',
        index: 'name1'
      }
    ];
  }

  /**
   * 重置表单
   */
  resetSF() {
    this.sf.reset();
    this.st.load(1);
  }
  close() {
    this.modalRef.destroy()
  }
}

