import { Component, OnInit, ViewChild, Type } from '@angular/core';
import { STComponent, STColumn, STChange } from '@delon/abc/st';
import {
  SFComponent,
  SFDateWidgetSchema,
  SFRadioWidgetSchema,
  SFSchema,
  SFSchemaEnum,
  SFSelectWidgetSchema,
  SFUISchema
} from '@delon/form';
import { ShipperBaseService } from '@shared';
import { NzModalService, NzModalRef } from 'ng-zorro-antd/modal';
import { of } from 'rxjs';
import { map } from 'rxjs/operators';
import { RebateManagementService } from '../../../services/rebate-management.service';

@Component({
  selector: 'app-add-partnerlist',
  templateUrl: './add-partnerlist.component.html',
  styleUrls: ['./add-partnerlist.component.less']
})
export class ParterRebateManageMentAddPartnerListComponent implements OnInit {
  @ViewChild('st', { static: true })
  st!: STComponent;
  @ViewChild('sf', { static: false }) sf!: SFComponent;
  ui: SFUISchema = {};
  i: any;
  schema: SFSchema = {};
  addSchema: SFSchema = {};
  _$expand = false;
  editText = '';
  formData: any;
  isVisible = false;
  edit = false;
  editId = false;
  selectedIndex = 0;

  columns: STColumn[] = [
    { title: '', type: 'checkbox', width: '50px', className: 'text-center' },
    {
      title: '合伙人名称',
      index: 'enterpriseName',
      width: 180,
      format: item => (item.partnerType ? `${item.enterpriseName || item.contactName}` : '')
    },
    { title: '联系人', index: 'contactName', width: 150, format: item => (item.partnerType ? `${item.contactName}` : '') },
    { title: '手机号', index: 'contactMobile', className: 'text-center', width: 150 },
    { title: '类型', index: 'partnerType', className: 'text-center', width: 130, type: 'enum', enum: { 1: '企业', 2: '个人' } },
    {
      title: '操作',
      width: '90px',
      fixed: 'right',
      buttons: [
        {
          text: '添加',
          click: _record => this.add(_record),
          acl: { ability: ['AbnormalAppear-reply'] }
        }
      ]
    }
  ];

  get reqParams() {
    // signStatus固定传20    代表签约完成 signStatus: 20
    let params: any = { ...this.sf?.value,  };
    return params;
  }

  get selectedRows() {
    return this.st?.list.filter(item => item.checked) || [];
  }

  constructor(
    public service: RebateManagementService,
    public shipperSrv: ShipperBaseService,
    private modal: NzModalService,
    private modals: NzModalRef
  ) {}

  ngOnInit(): void {
    this.initSF();
  }
  initSF() {
    this.schema = {
      properties: {
        enterpriseName: {
          type: 'string',
          title: '合伙人名称'
        },
        partnerType: {
          type: 'string',
          title: '类型',
          enum: [
            { value: '', label: '全部' },
            { value: 1, label: '企业' },
            { value: 2, label: '个人' }
          ],
          ui: {
            widget: 'select',
            placeholder: '请选择',
            visibleIf: {
              expand: (value: boolean) => value
            }
          },
          default: ''
        }
      }
    };
    this.ui = { '*': { spanLabelFixed: 110, grid: { span: 8, gutter: 4 } } };
  }

  search() {
    this.st?.load(1);
  }

  selectedIndexChange(event: any) {
    if (this.selectedIndex === 0) {
      this.st?.load(1);
    }
  }
  /**
   * 重置表单
   */
  resetSF() {
    this.sf.reset();
  }
  // 回复操作
  add(item: any) {
    console.log(item);
    this.modals.destroy([item]);
  }
  // 批量回复操作
  batchReply() {
    // if (this.selectedRows.length === 0) {
    //   this.service.msgSrv.warning('请勾选数据！')
    //   return;
    // }
    this.modals.destroy(this.selectedRows);
  }
}
