import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { FreightAccountService } from 'src/app/routes/financial-management/services/freight-account.service';

@Component({
  selector: 'app-partner-account-management-withdrawals-detail',
  templateUrl: './withdrawals-detail.component.html',
  styleUrls: ['./withdrawals-detail.component.less']
})
export class PartnerAccountManagementWithdralDetailComponent implements OnInit {
  formData: any = {};

  timeLineData: any = [];

  constructor(public service: FreightAccountService, private route: ActivatedRoute) {
    const id = route.snapshot.params.id;
    this.loadRefundDetail(id);
  }

  ngOnInit(): void {}

  loadRefundDetail(id: string) {
    this.service.request(this.service.$api_get_refund_detail, { id }).subscribe(res => {
      if (res) {
        this.formData = res;
        // 处理流程节点数据
        // 流程是否结束
        let isEnd = false;
        if (res.successTime) {
          isEnd = true;
          if (res.refundStatus === '3') {
            this.timeLineData.push({ time: res.successTime, value: `到账成功`, color: 'green' });
          } else {
            this.timeLineData.push({ time: res.successTime, value: `提现失败`, color: 'red' });
          }
        }
        if (res.agreeTime && res.refundStatus !== '4') {
          this.timeLineData.push({ time: res.agreeTime, value: `银行处理中`, color: 'gray' });
        }
        if (res.agreeTime) {
          if (res.refundStatus === '4') {
            isEnd = true;
            this.timeLineData.push({
              time: res.agreeTime,
              value: `拒绝提现<br/>操作人员：${res.handlerUserIdLabel}`,
              color: 'red'
            });
          } else {
            this.timeLineData.push({
              time: res.agreeTime,
              value: `审核通过<br/>操作人员：${res.handlerUserIdLabel}`,
              color: 'gray'
            });
          }
        }
        if (res.createTime) {
          this.timeLineData.push({
            time: res.createTime,
            value: `提交提现申请<br/>提现${res.amount}元至${res.bankName}(${res.bankCardNumber})<br/>操作人员：${res.userIdLabel}`,
            color: 'gray'
          });
        }
        if (this.timeLineData?.length > 0 && !isEnd) {
          this.timeLineData[0].color = 'green';
        }
      }
    });
  }

  downBack() {
    if (this.formData?.refundStatus !== '3') {
      return;
    }
    this.service.getReceiptUrl(this.formData.receiptUrl, {
      bankType: this.formData.bankType,
      rmYll: this.formData.userId,
      snglFlgCd: this.formData.coreSerNo,
      bussType: '06',
      ltdId: this.formData.ltdId,
      accountType: this.formData.accountType
    });
  }

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