import { Component, OnInit, ViewChild } from '@angular/core';
import { Router } from '@angular/router';
import { STComponent, STColumn, STRequestOptions } from '@delon/abc/st';
import { SFComponent, SFSchema, SFDateWidgetSchema } from '@delon/form';
import { NzModalService } from 'ng-zorro-antd/modal';
import { FreightAccountService } from '../../services/freight-account.service';
import { ClearingModalComponent } from '../abnormal-gold/clearing-modal/clearing-modal.component';

@Component({
  selector: 'app-payment-record',
  templateUrl: './payment-record.component.html',
  styleUrls: ['./payment-record.component.less']
})
export class PaymentRecordComponent implements OnInit {
  @ViewChild('st', { static: true })
  st!: STComponent;
  @ViewChild('sf', { static: false })
  sf!: SFComponent;
  columns: STColumn[] = this.initST();
  searchSchema: SFSchema = this.initSF();


  _$expand = false;

  constructor(public service: FreightAccountService, private nzModalService: NzModalService, private router: Router) {}

  ngOnInit(): void {}

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

  refund(item: any) {
    this.nzModalService.warning({
      nzTitle: '确定要关闭所选支付记录？',
      nzOnOk: () => {}
    });
  }

  /**
   * 重置表单
   */
  resetSF() {
    this.sf.reset();
    this._$expand = false;
  }

  /**
   * 伸缩查询条件
   */
  expandToggle() {
    this._$expand = !this._$expand;
    this.sf?.setValue('/expand', this._$expand);
  }

  private initSF(): SFSchema {
    return {
      properties: {
        expand: {
          type: 'boolean',
          ui: {
            hidden: true
          }
        },
        orderSn: {
          type: 'string',
          title: '支付编号',
          ui: {
            placeholder: '请输入'
          }
        },
        order2Sn: {
          type: 'string',
          title: '订单号',
          ui: {
            placeholder: '请输入'
          }
        },
        orderSn22: {
          type: 'string',
          title: '货源编号',
          ui: {
            placeholder: '请输入'
          }
        },
        orderSn2: {
          type: 'string',
          title: '服务类型',
          enum: [{ label: '全部', value: '全部' }],
          ui: {
            widget: 'select',
            placeholder: '请选择',
            visibleIf: {
              expand: (value: boolean) => value
            }
          }
        },
        orderSn221: {
          type: 'string',
          title: '承运司机',
          ui: {
            placeholder: '请输入',
            visibleIf: {
              expand: (value: boolean) => value
            }
          }
        },
        orderS2n221: {
          type: 'string',
          title: '车牌号',
          ui: {
            placeholder: '请输入',
            visibleIf: {
              expand: (value: boolean) => value
            }
          }
        },
        orderS2n2221: {
          type: 'string',
          title: '收款人',
          ui: {
            placeholder: '请输入收款人姓名/手机号',
            visibleIf: {
              expand: (value: boolean) => value
            }
          }
        },
        orderSn221f: {
          type: 'string',
          title: '车队长收款',
          enum: [{ label: '全部', value: '全部' }],
          ui: {
            widget: 'select',
            placeholder: '请选择',
            visibleIf: {
              expand: (value: boolean) => value
            }
          }
        },
        ord1erSn221f: {
          type: 'string',
          title: '支付类型',
          enum: [{ label: '全部', value: '全部' }],
          ui: {
            widget: 'select',
            placeholder: '请选择',
            visibleIf: {
              expand: (value: boolean) => value
            }
          }
        },
        createTime: {
          title: '申请时间',
          type: 'string',
          ui: {
            widget: 'date',
            mode: 'range',
            format: 'yyyy-MM-dd',
            visibleIf: {
              expand: (value: boolean) => value
            }
          } as SFDateWidgetSchema
        },
        create1Time: {
          title: '处理时间',
          type: 'string',
          ui: {
            widget: 'date',
            mode: 'range',
            format: 'yyyy-MM-dd',
            visibleIf: {
              expand: (value: boolean) => value
            }
          } as SFDateWidgetSchema
        },
        orderSn5221f: {
          type: 'string',
          title: '银行类型',
          enum: [{ label: '全部', value: '全部' }],
          ui: {
            widget: 'select',
            placeholder: '请选择',
            visibleIf: {
              expand: (value: boolean) => value
            }
          }
        },
        orde1rSn5221f: {
          type: 'string',
          title: '网络货运人',
          enum: [{ label: '全部', value: '全部' }],
          ui: {
            widget: 'select',
            placeholder: '请选择',
            visibleIf: {
              expand: (value: boolean) => value
            }
          }
        }
      }
    };
  }

  private initST(): STColumn[] {
    return [
      { title: '支付编号', index: 'no', width: 150, format: item => `JS20210930000001</br><label class="text-orange">支付中</label>` },
      { title: '支付金额', index: 'callNo', width: 100, format: item => `￥2000.00` },
      { title: '运费明细', index: 'callNo', width: 150, format: item => `预付:￥ 4000.00</br>附加费:￥ 200.00` },
      { title: '支付类型', index: 'callNo', width: 100 },
      { title: '货主', index: 'callNo', width: 100 },
      { title: '订单号', index: 'callNo', width: 100, format: item => `DZ210817466436972</br><label class="text-orange">待签收</label>` },
      { title: '运单号', index: 'callNo', width: 100, format: item => `DZ210817466436972</br><label class="text-orange">待签收</label>` },
      { title: '货源编号', index: 'callNo', width: 100 },
      { title: '服务类型', index: 'callNo', type: 'date', width: 150 },
      { title: '承运司机', index: 'callNo', width: 120, format: item => `特朗普</br>13789040523</br>粤GT8419` },
      { title: '收款人', index: 'callNo', width: 120, format: item => `拜登</br>13789040523` },
      { title: '银行类型', index: 'callNo', type: 'date', width: 150 },
      { title: '网络货运人', index: 'callNo', width: 120 },
      { title: '申请时间', index: 'callNo', width: 150 },
      { title: '申请人', index: 'callNo', width: 90 },
      { title: '处理时间', index: 'callNo', width: 150 },
      { title: '处理人', index: 'callNo', width: 90 },
      { title: '失败原因', index: 'callNo', width: 100 },
      {
        title: '操作',
        fixed: 'right',
        className: 'text-center',
        width: 120,
        buttons: [
          {
            text: '关闭',
            click: item => this.refund(item)
          }
        ]
      }
    ];
  }
}
