import { Component, OnInit, ViewChild } from '@angular/core';
import { Router } from '@angular/router';
import { STComponent, STColumn, STChange, STRequestOptions } from '@delon/abc/st';
import { SFComponent, SFDateWidgetSchema, SFSchema } from '@delon/form';
import { NzModalService } from 'ng-zorro-antd/modal';
import { TicketService } from '../../../services/ticket.service';

@Component({
  selector: 'app-transaction-details',
  templateUrl: './transaction-details.component.html'
})
export class TransactionDetailsComponent implements OnInit {
  data = [];
  selectedData = [];
  url = `/api/fcc/ficoEtcInvoiceH/list/page`;
  @ViewChild('st', { static: true })
  st!: STComponent;
  @ViewChild('sf', { static: false })
  sf!: SFComponent;
  columns: STColumn[] = [
    { title: '交易id', index: 'id' },
    { title: '交易流水号', index: 'tradeFlowNo' },
    { title: '交易金额', index: 'fee' },
    { title: '开票状态', index: 'state', type: 'enum', enum: { '0': '待开具', '1': '开具中', '2': '已开具', '3': '开票失败' } },
    { title: '交易时间', index: 'exTime', type: 'date' }
  ];
  searchSchema: SFSchema = {
    properties: {
      state: {
        type: 'string',
        title: '开票状态',
        enum: [
          { label: '全部', value: '' },
          { label: '待开具', value: '1' },
          { label: '开具中', value: '2' },
          { label: '已开具', value: '3' },
          { label: '交易异常', value: '4' }
        ],
        ui: {
          widget: 'select',
          placeholder: '请选择'
        },
        default: ''
      },
      exTime: {
        title: '交易时间',
        type: 'string',
        ui: {
          widget: 'sl-from-to-search',
          format: 'yyyy-MM-dd'
        } as SFDateWidgetSchema
      }
    }
  };

  reqParams = {};

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

  ngOnInit(): void {}

  beforeReq = (requestOptions: STRequestOptions) => {
    if (this.sf) {
      Object.assign(requestOptions.body, {
        ...this.sf.value,
        exTime: {
          start: this.sf.value.exTime?.[0] || null,
          end: this.sf.value.exTime?.[1] || null
        }
      });
    }
    return requestOptions;
  };

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