import { Component, OnInit, ViewChild } from '@angular/core';
import { Router } from '@angular/router';
import { STComponent, STColumn, STChange } from '@delon/abc/st';
import { SFComponent, SFSchema, SFDateWidgetSchema } from '@delon/form';
import { NzModalService } from 'ng-zorro-antd/modal';
import { SystemStaffStaffModalComponent } from 'src/app/routes/sys-setting/components/staff-management/staff-modal/staff-modal.component';
import { SystemService } from 'src/app/routes/sys-setting/services/system.service';
import { SettingFinancialComponent } from './setting-financial/setting-financial.component';

@Component({
  selector: 'app-main-account',
  templateUrl: './main-account.component.html',
  styleUrls: ['./main-account.component.less']
})
export class MainAccountComponent implements OnInit {
  @ViewChild('st', { static: true })
  st!: STComponent;
  @ViewChild('sf', { static: false })
  sf!: SFComponent;

  url = `/rule?_allow_anonymous=true`;

  searchSchema: SFSchema = {
    properties: {
      expand: {
        type: 'boolean',
        ui: {
          hidden: true
        }
      },
      receiveName: {
        type: 'string',
        title: '公司名称',
        ui: { placeholder: '请输入' }
      },
      phone: {
        type: 'string',
        title: '纳税人识别号',
        ui: { placeholder: '请输入' }
      }
    }
  };

  columns: STColumn[] = [
    { title: '公司名称', index: 'description' },
    { title: '纳税人识别号', index: 'description' },
    { title: '发票税率', index: 'description' },
    { title: '电子发票账号', index: 'description' },
    { title: 'ETC账号', index: 'description' },
    { title: '电子合同账号', index: 'description' },
    { title: '开户行', index: 'description' },
    { title: '虚拟账户', index: 'description' },
    { title: '附加费比例', index: 'description' },
    {
      title: '操作',
      buttons: [
        {
          text: '财务设置',
          click: item => this.settingFinanical(item)
        },
        {
          text: '合同设置',
          click: item => this.routeTo(item)
        }
      ]
    }
  ];
  reqParams = { pageIndex: 1, pageSize: 10 };

  constructor(public service: SystemService, private router: Router, private nzModalService: NzModalService) {}

  ngOnInit(): void {}

  stChange(e: STChange): void {
    switch (e.type) {
      case 'filter':
        this.st.load();
        break;
    }
  }

  settingFinanical(item: any) {
    const modal = this.nzModalService.create({
      nzContent: SettingFinancialComponent,
      nzComponentParams: item ? { i: { ...item, roleId: '1,2,3', name: '用户名', phone: 18555555555 } } : { i: { id: 0 } },
      nzFooter: null
    });
    modal.afterClose.subscribe(res => {
      this.st.load();
    });
  }

  routeTo(item?: any) {
    this.router.navigate(['/financial-management/driver-account-detail/1']);
  }

  /**
   * 重置表单
   */
  resetSF() {
    this.sf.reset();
  }
}
