/*
 * @Description  :
 * @Version      : 1.0
 * @Author       : Shiming
 * @Date         : 2021-12-28 14:42:03
 * @LastEditors  : Shiming
 * @LastEditTime : 2022-02-16 16:37:16
 * @FilePath     : \\tms-obc-web\\src\\app\\routes\\order-management\\components\\vehicle-detail\\vehicle-detail.component.ts
 * Copyright (C) 2022 huzhenhong. All rights reserved.
 */
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { STColumn } from '@delon/abc/st';
import { NzCardComponent } from 'ng-zorro-antd/card';
import { NzMessageService } from 'ng-zorro-antd/message';
import { NzModalService } from 'ng-zorro-antd/modal';
import { OrderManagementService } from '../../services/order-management.service';
@Component({
  selector: 'app-supply-management-vehicle-detail',
  templateUrl: './vehicle-detail.component.html',
  styleUrls: ['./vehicle-detail.component.less']
})
export class OrderManagementVehicleDetailComponent implements OnInit {
  id = this.route.snapshot.params.id;
  MapList: any;
  i: any = {
    unLoadingPlaceList: [],
    billExpenseDetails: [],
    goodsInfoList: [],
    goodsResource: []
  };
  imges: any;
  attObj: any;
  totalObj: any;
  approvalLsit: any;
  isVisible = false;
  logColumns: STColumn[] = [
    { title: '款项', index: 'expenseCodeLabel' },
    { title: '小计（元）', render: 'price' },
    { title: '运输费（元）', render: 'price' },
    { title: '附加费（元）', render: 'surcharge' },
    { title: '支付时间', index: 'paymentTime' },
    {
      title: '支付状态',
      className: 'text-center',
      index: 'paymentStatus',
      type: 'badge',
      width: '120px',
      badge: {
        '1': { text: '待申请', color: 'warning' },
        '2': { text: '已支付', color: 'success' },
        '3': { text: '已拒绝', color: 'warning' },
        '4': { text: '申请中', color: 'warning' }
      }
    }
  ];

  constructor(
    private route: ActivatedRoute,
    private msgSrv: NzMessageService,
    private service: OrderManagementService,
    private router: Router,
    private modal: NzModalService
  ) {}

  ngOnInit(): void {
    this.initData();
    this.MapInit();
  }

  initData() {
    this.service.request(this.service.$api_get_getWholeBillDetail, { id: this.id }).subscribe(res => {
      if (res) {
        this.i = res;
        this.approvalLsit = res.scheduleVOList;
        this.attObj = this.i?.billExpenseDetails?.filter((data: any) => data.expenseCode === 'ATT')[0];
        this.totalObj = this.i?.billExpenseDetails?.filter((data: any) => data.expenseCode === 'TOTAL')[0];
        this.approvalLsit.map((item: any, key: any) => {
          if (item.displayStatus === 'HIDE') {
            delete this.approvalLsit[key];
          }
        });
      }
    });
  }
  // 取消订单
  cancellation() {
    // api_get_cancelAnOrder
    this.modal.confirm({
      nzTitle: '<b>确定取消该订单吗?</b>',
      nzContent: `<b>取消后无法恢复，请确认</b>`,
      nzOnOk: () =>
        this.service.request(this.service.$api_get_cancelAnOrder, { id: this.id }).subscribe(res => {
          if (res === true) {
            this.service.msgSrv.success('操作成功！');
            this.initData();
          }
        })
    });
  }
  goBack() {
    window.history.go(-1);
  }
  // 修改订单
  changeOrder() {
    this.router.navigate(['order-management/vehicle-detailChange', this.id]);
  }
  agreement(value: any) {
    if (value === '1') {
      this.imges = this.i?.agreementFilePath;
    } else if (value === '2') {
      this.imges = this.i?.agreementFilePath;
    }
    this.isVisible = true;
  }
  handleCancel() {
    this.isVisible = false;
  }
  handleOK() {
    this.isVisible = false;
  }

  goDistance(elf: NzCardComponent) {
    if (elf) {
      elf['elementRef'].nativeElement.scrollIntoView({ behavior: 'smooth', block: 'start', inline: 'start' });
      // elf['elementRef'].nativeElement.className = 'target-fix'
    }
  }
  MapInit() {
    this.service.request('/api/sdc/billShipper/getTrajectoryByBillId', { id: this.id }).subscribe(res => {
      if (res?.trackArray) {
        const points = res?.trackArray;
        const list: any[] = [];
        points.forEach((item: any) => {
          list.push({
            name: item?.hgt,
            lnglat: [Number((Number(item?.lon) / 600000).toFixed(6)), Number((Number(item?.lat) / 600000).toFixed(6))]
          });
        });
        console.log(list);
        this.MapList = list;
      }
    });
  }
}
