import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { STColumn, STComponent, STData, STRequestOptions } from '@delon/abc/st';
import { SFComponent, SFSchema, SFUISchema } from '@delon/form';
import { processSingleSort } from '@shared';
import { NzModalService } from 'ng-zorro-antd/modal';
import { ClaimAuditService } from '../../services/claim-audit.service';

@Component({
  selector: 'app-parter-claim-audit-list',
  templateUrl: './list.component.html'
})
export class ParterClaimAuditListComponent implements OnInit {
  schema: SFSchema = {};
  columns1!: STColumn[];
  columns2!: STColumn[];
  @ViewChild('st1', { static: false })
  st1!: STComponent;
  @ViewChild('st2', { static: false })
  st2!: STComponent;
  ui!: SFUISchema;
  @ViewChild('sf', { static: false })
  sf!: SFComponent;
  _$expand = false;
  selectedIndex =  0;

  data=[{name1:1111}]
  constructor(
    public router: Router,
    public ar: ActivatedRoute,
    public service: ClaimAuditService,
    private modalService: NzModalService
  ) {}

  /**
   * 查询参数
   */
  get reqParams() {
    return { ...this.sf?.value };
  }
    /**
   * 查询字段个数
   */
     get queryFieldCount(): number {
      return Object.keys(this.schema?.properties || {}).length;
    }
    /**
     * 伸缩查询条件
     */
    expandToggle(): void {
      this._$expand = !this._$expand;
      this.sf?.setValue('/_$expand', this._$expand);
    }

  ngOnInit() {
    this.initSF();
    this.initST1();
    this.initST2();
  }

  initSF() {
    this.schema = {
      properties: {
        _$expand: { type: 'boolean', ui: { hidden: true } },
        name: {
          type: 'string',
          title: '认领人'
        },
        name1: {
          type: 'string',
          title: '客户名称'
        },
        name2: {
          type: 'string',
          title: '平台审核状态'
        },
        name3: {
          type: 'string',
          title: '渠道销售状态',
          ui: {
            visibleIf: {
              _$expand: (value: boolean) => value
            }
          }
        },
        name4: {
          type: 'string',
          title: 'CRM状态',
          ui: {
            visibleIf: {
              _$expand: (value: boolean) => value
            }
          }
        },
      }
    };
    this.ui = {
      '*': {
        grid: { span: 8, gutter: 4 }
      }
    };
  }

  initST1() {
    this.columns1 = [
      {
        title: '提交人',
        index: 'name1'
      },
      {
        title: '客户名称',
        index: 'name1'
      },
      {
        title: '认领备注',
        index: 'name1'
      },
      {
        title: '渠道销售审核状态',
        index: 'name1'
      },
      {
        title: 'CRM状态',
        index: 'name1'
      },
      {
        title: '平台审核状态',
        index: 'name1'
      },
      {
        title: 'CRM状态',
        index: 'name1'
      },
      {
        title: '提交时间',
        index: 'name1'
      },
      {
        title: '操作',
        className: 'text-center',
        buttons: [
          {
            text: '详情',
            click: (_record, _modal, _instance) => this.partnerView(_record),
          },
          {
            text: '审核',
            click: (_record, _modal, _instance) => this.partnerView(_record),
          },
        ]
      }
    ];
  }

  initST2() {
    this.columns2 = [
      {
        title: '提交人',
        index: 'name1'
      },
      {
        title: '客户名称',
        index: 'name1'
      },
      {
        title: '认领备注',
        index: 'name1'
      },
      {
        title: 'CRM状态',
        index: 'name1'
      },
      {
        title: '平台审核状态',
        index: 'name1'
      },
      {
        title: '提交时间',
        index: 'name1'
      },
      {
        title: '操作',
        className: 'text-center',
        buttons: [
          {
            text: '详情',
            click: (_record, _modal, _instance) => this.channelView(_record),
          },
          {
            text: '审核',
            click: (_record, _modal, _instance) => this.channelView(_record),
          },

        ]
      }
    ];
  }

  partnerView(record: STData) {
    this.router.navigate(['/partner/claim-audit/partner-detail'], { queryParams: {} });
  }
  
  channelView(record: STData) {
    this.router.navigate(['/partner/claim-audit/channel-detail'], { queryParams: {} });
  }
  /**
   * 重置表单
   */
  resetSF() {
    this.sf.reset();
  }
  search() {
    // this.st1?.load(1);
  }

  tabChange(index:any){
    console.log(index)
    switch (index) {
      case 0:
        this.initST1();
        break;
      case 1:
        this.initST2();
        break;
      default:
        break;
    }
  }

}
