import { Component, OnInit, ViewChild } from '@angular/core';
import { apiConf } from '@conf/api.conf';
import { SFComponent, SFSchema, SFTextWidgetSchema, SFUISchema, SFUploadWidgetSchema } from '@delon/form';
import { ShipperBaseService } from '@shared';
import { NzModalRef } from 'ng-zorro-antd/modal';
import { FreightAccountService } from '../../../services/freight-account.service';

const IMAGECONFIG = {
  action: apiConf.waterFileUpload,
  fileType: 'image/png,image/jpeg,image/jpg,image/gif',
  fileSize: 5120,
  limit: 1,
  limitFileCount: 1,
  resReName: 'data.fullFileWatermarkPath',
  urlReName: 'data.fullFileWatermarkPath',
  widget: 'upload',
  name: 'multipartFile',
  multiple: false,
  listType: 'picture-card'
};

@Component({
  selector: 'app-clearing-modal',
  templateUrl: './clearing-modal.component.html',
  styleUrls: ['./clearing-modal.component.less']
})
export class ClearingModalComponent implements OnInit {
  @ViewChild('sf', { static: false })
  sf!: SFComponent;
  i: any;
  schema!: SFSchema;
  ui: SFUISchema = {
    '*': {
      spanLabelFixed: 120,
      grid: { span: 18 }
    }
  };

  constructor(
    private modal: NzModalRef,
    public service: FreightAccountService,
    public shipperservice: ShipperBaseService,
    ) {}

  ngOnInit(): void {
    this.initSF(this.i);
  }
  initSF(staff: any) {
    this.schema = {
      properties: {
        name: {
          title: '入账金额',
          type: 'string',
          ui: {
            widget: 'text'
          } as SFTextWidgetSchema,
          default: '10000.00'
        },
        enterpriseInfoId: {
          type: 'string',
          title: '网络货运人',
          ui: {
            widget: 'select',
            placeholder: '请选择',
            visibleIf: {
              _$expand: (value: boolean) => value,
            },
            allowClear: true,
            asyncData: () => this.shipperservice.getNetworkFreightForwarder(),
          },
        },
        name3: {
          title: '银行类型',
          type: 'string',
          ui: {
            widget: 'text'
          } as SFTextWidgetSchema,
          default: '平安银行'
        },
        receiveName: {
          type: 'string',
          title: '分配对象',
          enum: [{ label: '全部', value: '全部' }],
          ui: {
            widget: 'select',
            placeholder: '请选择'
          },
          default: ''
        },
        licensePhotoWatermark: {
          type: 'string',
          title: '上传凭证',
          ui: {
            ...IMAGECONFIG,
            change: args => {
              if (args.type === 'success') {
                this.sf.setValue('/licensePhoto', args.fileList[0].response.data.fullFilePath);
              }
            }
          } as SFUploadWidgetSchema
        }
      },
      required: ['name', 'name2', 'name3', 'receiveName']
    };
  }
}
