/*
 * @Description  : 
 * @Version      : 1.0
 * @Author       : Shiming
 * @Date         : 2022-01-20 10:00:39
 * @LastEditors  : Shiming
 * @LastEditTime : 2022-01-25 15:40:10
 * @FilePath     : \\tms-obc-web\\src\\app\\routes\\financial-management\\components\\receipt-order\\receipt-order-detail\\receipt-order-detail.component.ts
 * Copyright (C) 2022 huzhenhong. All rights reserved.
 */
import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { STComponent, STColumn, STRequestOptions } from '@delon/abc/st';
import { FreightAccountService } from '../../../services/freight-account.service';

@Component({
  selector: 'app-receipt-order-detail',
  templateUrl: './receipt-order-detail.component.html',
  styleUrls: ['./receipt-order-detail.component.less'],
})
export class ReceiptOrderDetailComponent implements OnInit {
  @ViewChild('st', { static: true })
  st!: STComponent;
  columns: { [key: string]: STColumn[] } = this.initST();
  costInfo: any = {};
  id: any = null;
  constructor(public service: FreightAccountService, private route: ActivatedRoute) {
    this.id = route.snapshot.params.id;
    this.loadDetail(this.id);
  }

  ngOnInit(): void {}

  beforeReq = (requestOptions: STRequestOptions) => {
    Object.assign(requestOptions.body, {
      id: this.id
    });
    return requestOptions;
  };

  loadDetail(id: any) {
    this.service.request(this.service.$api_get_receipt_header, { id }).subscribe(res => {
      if (res) {
        this.costInfo = res;
      }
    });
  }

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

  private initST(): { [key: string]: STColumn[] } {
    return {
      cost: [
        { title: '序号', render: 'no', width: 70, className: 'text-left' },
        { title: '费用号', index: 'feeHId', className: 'text-left', width: 200 },
        { title: '费用日期', index: 'billHId', className: 'text-center', width: 150 },
        { title: '订单号', index: 'callNo', className: 'text-left', width: 200 },
        { title: '订单日期', index: 'waybillHId', className: 'text-center', width: 150 },
        { title: '订单费用类型', index: 'waybillDate', className: 'text-center', width: 160 },
        { title: '费用类型', index: 'callNo', className: 'text-center', width: 160 },
        { title: '费用科目', index: 'billLType', className: 'text-left', width: 160 },
        { title: '结算客户', index: 'feeSubId', className: 'text-left', width: 150 },
        {
          title: '已收金额',
          index: 'hrvatrate',
          type: 'widget',
          className: 'text-right',
          widget: { type: 'currency-chy', params: ({ record }) => ({ value: record.yskmoney }) },
          width: 140
        }
      ],
      requested: [
        { title: '序号', render: 'no', width: 70, className: 'text-left' },
        { title: '结算客户', index: 'cnoName', className: 'text-left', width: 200 },
        {
          title: '预收金额',
          index: 'yskmoney',
          type: 'widget',
          className: 'text-right',
          widget: { type: 'currency-chy', params: ({ record }) => ({ value: record.yskmoney }) },
          width: 200
        },
        { title: '预收备注', index: 'vatapptype', className: 'text-left', width: 200 }
      ]
    };
  }
}
