import { Component, OnInit, ViewChild } from '@angular/core';
import { STColumn, STComponent } from '@delon/abc/st';
import { NzModalService } from 'ng-zorro-antd/modal';
import { TicketService } from '../../../services/ticket.service';

@Component({
  selector: 'app-requested-invoice-modal',
  templateUrl: './requested-invoice-modal.component.html',
  styleUrls: ['./requested-invoice-modal.component.less']
})
export class RequestedInvoiceModalComponent implements OnInit {
  @ViewChild('st', { static: false })
  st!: STComponent;
  columns: STColumn[] = this.initST();
  data = [
    {
      key: 0,
      disabled: true,
      href: 'https://ant.design',
      avatar: 'https://gw.alipayobjects.com/zos/rmsportal/eeHMaZBwmTvLdIwMfBpg.png',
      no: 'TradeCode 0'
    },
    {
      key: 1,
      disabled: false,
      href: 'https://ant.design',
      avatar: 'https://gw.alipayobjects.com/zos/rmsportal/udxAbMEhpwthVVcjLXik.png',
      no: 'TradeCode 1'
    }
  ];

  info = {};

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

  ngOnInit(): void {}

  /**
   * 移除订单
   * @returns
   */
  removeOrder(item: any[]) {
    if (this.data?.length <= 0) {
      this.service.msgSrv.warning('无订单');
      return;
    }
    this.nzModalService.warning({
      nzTitle: '确定从当前批次中移除所有订单？',
      nzContent: '移除后相关订单可以重新提交开票申请',
      nzOnOk: () => {
        console.log(this.data);
      }
    });
  }

  private initST(): STColumn[] {
    return [
      { title: '订单号', index: 'no', width: 150 },
      { title: '订单完成日期', index: 'updatedAt', type: 'date', width: 150 },
      { title: '所属项目', index: 'callNo', width: 120 },
      { title: '订单类型', index: 'callNo', width: 90 },
      { title: '装货地', index: 'callNo', width: 90 },
      { title: '卸货地', index: 'callNo', width: 100 },
      { title: '货物信息', index: 'callNo', width: 90 },
      { title: '承运司机', index: 'callNo', width: 140, format: item => `特朗普</br>13789040523</br>粤GT8419` },
      { title: '总费用', index: 'callNo', width: 90 },
      { title: '运输费', index: 'callNo', width: 90 },
      { title: '附加费', index: 'callNo', width: 90 },
      {
        title: '操作',
        width: 80,
        fixed: 'right',
        className: 'text-center',
        buttons: [
          {
            text: '移除',
            click: item => this.removeOrder([item])
          }
        ]
      }
    ];
  }
}
