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

@Component({
  selector: 'app-invoiced-list-detail',
  templateUrl: './invoiced-list-detail.component.html',
  styleUrls: ['./invoiced-list-detail.component.less']
})
export class InvoicedListDetailComponent implements OnInit {
  url = `/rule?_allow_anonymous=true`;
  @ViewChild('st', { static: true })
  st!: STComponent;
  @ViewChild('sf', { static: false })
  sf!: SFComponent;
  columns: STColumn[] = [
    { title: '订单号', index: 'no' },
    { title: '外部订单号', index: 'callNo' },
    { title: '装货地', index: 'callNo' },
    { title: '卸货地', index: 'callNo' },
    { title: '货物名称', index: 'callNo' },
    { title: '重量/体积', index: 'callNo' },
    { title: '开票金额', index: 'callNo' },
    { title: '总费用', index: 'callNo' },
    { title: '基础运费', index: 'callNo' },
    { title: '附加费', index: 'callNo' },
  ];
  searchSchema: SFSchema = {
    properties: {
      expand: {
        type: 'boolean',
        ui: {
          hidden: true
        }
      },
      orderSn: {
        type: 'string',
        title: '订单号',
        ui: {
          autocomplete: 'off'
        }
      },
      orderSn2: {
        type: 'string',
        title: '外部订单号',
        ui: {
          autocomplete: 'off'
        }
      },
      orderSn3: {
        type: 'string',
        title: '发票号码',
        ui: {
          autocomplete: 'off'
        }
      },
      receiveName: {
        type: 'string',
        title: '开票状态',
        enum: [
          { label: '全部', value: '' },
          { label: '待受理', value: '待受理' },
          { label: '待开票', value: '待开票' },
          { label: '开票中', value: '开票中' },
          { label: '已开票', value: '已开票' },
          { label: '已撤销', value: '已撤销' },
          { label: '已拒绝', value: '已拒绝' }
        ],
        ui: {
          widget: 'select',
          placeholder: '请选择',
          change: (i: any) => {
            this.sf.value.receiveName = i;
            this.sf?.setValue('/receiveName', i);
          },
          visibleIf: {
            expand: (value: boolean) => value
          }
        },
        default: ''
      }
    }
  };

  reqParams = {};
  _$expand = false;
  constructor(public service: TicketService, private nzModalService: NzModalService, private router: Router) {}

  ngOnInit(): void {}

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

  goBack() {
    history.go(-1);
  }

  /**
   * 重置表单
   */
  resetSF() {
    this.sf.reset();
    this._$expand = false;
  }

  /**
   * 伸缩查询条件
   */
  expandToggle() {
    this._$expand = !this._$expand;
    this.sf?.setValue('/expand', this._$expand);
  }
}
