import { Component, OnInit, ViewChild } from '@angular/core';
import { Router } from '@angular/router';
import { STColumn, STComponent, STRequestOptions } from '@delon/abc/st';
import { NzModalRef } from 'ng-zorro-antd/modal';
import { ReportingService } from '../../services/reporting.service';

@Component({
  selector: 'app-datatable-verify-result',
  templateUrl: './verify-result.component.html',
})
export class DatatableReportingVerifyResultComponent implements OnInit {
  @ViewChild('st') private readonly st!: STComponent;
  columns: STColumn[] = [];
  record: any = {};

  tabs: any[] = [
    { name: '订单信息', value: 3 },
    { name: '司机信息', value: 2 },
    { name: '车辆信息', value: 4 },
  ];
  subjectType = 3;
  subjectId = '';
  get reqParams() {
    return {
      subjectType: this.subjectType,
      subjectId: this.record?.orderId,

    };
  }

  constructor(public service: ReportingService, private modalRef: NzModalRef, public router: Router) {

  }

  beforeReq(requestOptions: STRequestOptions) {
    delete requestOptions?.body?.pageSize;
    delete requestOptions?.body?.pageIndex;
    return requestOptions;
  }

  ngOnInit(): void {
    this.initST();
  }

  /**
 * 初始化数据列表
 */
  initST() {
    this.columns = [
      { title: '序号', type: 'no', className: 'text-center', width: '60px', },
      { title: '监管平台字段', index: 'thirdPartyFieldName', className: 'text-center', width: '120px', },
      { title: '系统字段', index: 'checkFieldName', className: 'text-center', width: '100px', },
      { title: '归属模块', index: 'orderStatus', className: 'text-center', width: '120px', },
      {
        title: '是否必填',
        index: 'requiredStatus',
        className: 'text-center',
        width: '100px',
        type: 'enum',
        enum: {
          0: '否',
          1: '是'
        }
      },
      { title: '上传值', index: 'fieldValue', className: 'text-center', width: '150px', },
      {
        title: '本地校验', render: 'checkStatus', className: 'text-center', width: '100px',
        // type: 'enum',
        // enum: {
        //   0: '校验中',
        //   1: '通过',
        //   2: '不通过'
        // }
      },
      { title: '错误内容', index: 'remark', className: 'text-center', width: '150px', },
    ]
  }


  add(): void {
    // this.modal
    //   .createStatic(FormEditComponent, { i: { id: 0 } })
    //   .subscribe(() => this.st.reload());
  }

  selectTab(e: any) {
    this.subjectType = e?.value;
    setTimeout(() => {
      this.st.load(1);
    })
  }

  update() {
    switch (this?.subjectType) {
      case 2:
        this.openNewPage(`/usercenter/driver/detail/${this.record?.driverId}`);
        break;
      case 3:
        if (this.record?.billType === '1') {
          this.openNewPage(`/order-management/vehicle-detailChange/${this.record?.orderId}`);
        } else if (this.record.billType === '2') {
          this.openNewPage(`/order-management/bulk-detailChange/${this.record?.orderId}`);
        }
        break;
      case 4:
        this.openNewPage(`/vehicle/list/detail/${this.record?.carId}`);
        break;
      default:
        break;
    }



  }


  close(): void {
    this.modalRef.destroy();
  }
  filterCheckStatus(status: number) {
    switch (status) {
      case 0:
        return '检测中';
      case 1:
        return '通过';
      case 2:
        return '不通过';
      default:
        return '';

    }
  }

  openNewPage(url: string) {
    window.open(location.origin + `/#` + url);
  }

}
