/*
 * @Author: your name
 * @Date: 2021-12-03 15:31:52
 * @LastEditTime: 2022-01-18 14:36:38
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \tms-obc-web\src\app\routes\order-management\components\vehicle-detail\vehicle-detail.component.ts
 */
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { STColumn } from '@delon/abc/st';
import { _HttpClient } from '@delon/theme';
import { NzCardComponent } from 'ng-zorro-antd/card';
import { NzMessageService } from 'ng-zorro-antd/message';
import { NzModalService } from 'ng-zorro-antd/modal';
import { VehicleSureArriveComponent } from 'src/app/routes/order-management/modal/vehicle/sure-arrive/sure-arrive.component';
import { VehicleSureDepartComponent } from 'src/app/routes/order-management/modal/vehicle/sure-depart/sure-depart.component';
import { WaybillManagementServe } from '../../services/waybill-management.service';
@Component({
  selector: 'app-supply-management-vehicle-detail',
  templateUrl: './vehicle-detail.component.html',
  styleUrls: ['./vehicle-detail.component.less']
})
export class WaybillManagementVehicleDetailComponent implements OnInit {

  id = this.route.snapshot.params.id;
  i: any;
  totalObj: any;
  attObj: any;
  isVisible = false;
  logColumns: STColumn[] = [
    { title: '款项', index: 'costName' },
    { title: '运输费（元）', index: 'price', render: 'price' },
    { 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' },
      },
    },
  ];
  imges: any;
  unLoadingPlaceVOList: any = [];

  constructor(
    private route: ActivatedRoute,
    private msgSrv: NzMessageService,
    private service: WaybillManagementServe,
    private modal: NzModalService,
  ) {

  }

  ngOnInit(): void {
    this.initData()
   
  }
  initData() {
    const params = {
      id: this.id
    }
    this.service.request(this.service.$api_get_getWholeDetail, params).subscribe((res) => {
      console.log(res)
      this.unLoadingPlaceVOList.push(...res.loadingPlace)
      this.unLoadingPlaceVOList.push(...res.dischargePlace)
      console.log(this.unLoadingPlaceVOList)
      this.i = res;
      this.attObj = this.i?.billExpenseDetailVOList?.filter((data: any) => data.expenseCode === 'ATT')[0];
      this.totalObj = this.i?.billExpenseDetailVOList?.filter((data: any) => data.expenseCode === 'TOTAL')[0];
    })
  }

  goBack() {
    window.history.go(-1);
  }
  agreement(value: any) {
    console.log('123')
    console.log(value)
    if(value === '1') {
      this.imges = this.i?.supplementAgreement
    } else if (value === '2') {
      this.imges = this.i?.loadingCertificate
    } else if (value === '3') {
      this.imges = this.i?.unLoadingCertificate
    } else if (value === '4') {
      this.imges = this.i?.receiptCertificate
    }
    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' });
  }
}
  //  *确认发车

  sureDepart(item: any) {
    const modalRef = this.modal.create({
      nzTitle: '确认发车',
      nzWidth: '50%',
      nzContent: VehicleSureDepartComponent,
      nzComponentParams: {
        i: item,
        Status: 1
      },
      nzFooter: null
    });
    modalRef.afterClose.subscribe((result: any) => {
      this.initData()
  
  });
  }
  // 确认到车
  sureArrive(item: any) {
    const modalRef = this.modal.create({
      nzTitle: '确认到车',
      nzWidth: '50%',
      nzContent: VehicleSureArriveComponent,
      nzComponentParams: {
        i: item,
        Status: 1
      },
      nzFooter: null
    });
    modalRef.afterClose.subscribe((result: any) => {
      this.initData()
   
  });
  }
}
