import { preloaderFinished } from '@delon/theme';
/*
 * @Author: your name
 * @Date: 2021-12-14 14:03:07
 * @LastEditTime: 2021-12-14 17:38:20
 * @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\modal\bulk\update-freight\update-freight.component.ts
 */
import { Component, OnInit, ViewChild } from '@angular/core';
import {
  SFComponent,
  SFCustomWidgetSchema,
  SFDateWidgetSchema,
  SFNumberWidgetSchema,
  SFRadioWidgetSchema,
  SFSchema,
  SFSelectWidgetSchema,
  SFTextareaWidgetSchema,
  SFUISchema,
  SFUploadWidgetSchema
} from '@delon/form';
import { _HttpClient } from '@delon/theme';
import { NzMessageService } from 'ng-zorro-antd/message';
import { NzModalRef } from 'ng-zorro-antd/modal';
import { SupplyManagementService } from 'src/app/routes/supply-management/services/supply-management.service';
import { Observable, Observer } from 'rxjs';

@Component({
  selector: 'app-order-management-vehicle-sure-arrive',
  templateUrl: './sure-arrive.component.html',
  styleUrls: ['./sure-arrive.component.less']
})
export class VehicleSureArriveComponent implements OnInit {
  record: any = {};
  i: any;
  data: any ={
    place1: '',
    place2: ''
  };
  @ViewChild('sf', { static: false }) sf!: SFComponent;
  schema: SFSchema = {};
  ui: SFUISchema = {};
  constructor(private modal: NzModalRef, private msgSrv: NzMessageService, public http: _HttpClient, public service: SupplyManagementService ) {}

  ngOnInit(): void {
    this.initSF();
  }
  initSF() {
    this.schema = {
      properties: {
        datetime: {
          type: 'string',
          title: '卸货时间',
          format: 'date-time',
        },
        no2: {
          type: 'string',
          title: '卸货重量',
          ui: {
            widget: 'custom',
           }
        },
        no3: {
          type: 'string',
          title: '卸货体积',
          ui: {
            widget: 'custom',
           }
        },
     
        avatar: {
          type: 'string',
          title: '装货凭证',
          ui: {
            action: `/scm/cms/cms/upload/multipartFile/fileModel`,
            fileType: 'image/png,image/jpeg,image/jpg',
            limit: 1,
            limitFileCount: 1,
            resReName: 'url',
            urlReName: 'url',
            widget: 'upload',
            descriptionI18n: ' 提单号',
            data: {
              // appId: environment.appId,
            },
            name: 'multipartFile',
            multiple: true,
            listType: 'picture-card',
            change: (args: any) => {
              if (args.type === 'success') {
                const avatar = [
                  {
                    uid: -1,
                    name: 'LOGO',
                    status: 'done',
                    url: args.fileList[0].response.url,
                    response: {
                      url: args.fileList[0].response.url
                    }
                  }
                ];
                this.sf?.setValue('/avatar', avatar);
              }
            },
            beforeUpload: (file: any, _fileList: any) => {
              return new Observable((observer: Observer<boolean>) => {
                const isLt2M = file.size / 1024 / 1024 < 5;
                if (!isLt2M) {
                  this.service.msgSrv.warning('图片大小超过5M!');
                  observer.complete();
                  return;
                }
                observer.next(isLt2M);
                observer.complete();
              });
            }
          } as SFUploadWidgetSchema
        },
        avatar2: {
          type: 'string',
          title: '',
          ui: {
            action: `/scm/cms/cms/upload/multipartFile/fileModel`,
            fileType: 'image/png,image/jpeg,image/jpg',
            limit: 1,
            limitFileCount: 1,
            resReName: 'url',
            urlReName: 'url',
            widget: 'upload',
            descriptionI18n: '人车货照片',
            data: {
              // appId: environment.appId,
            },
            name: 'multipartFile',
            multiple: true,
            listType: 'picture-card',
            change: (args: any) => {
              if (args.type === 'success') {
                const avatar = [
                  {
                    uid: -1,
                    name: 'LOGO',
                    status: 'done',
                    url: args.fileList[0].response.url,
                    response: {
                      url: args.fileList[0].response.url
                    }
                  }
                ];
                this.sf?.setValue('/avatar', avatar);
              }
            },
            beforeUpload: (file: any, _fileList: any) => {
              return new Observable((observer: Observer<boolean>) => {
                const isLt2M = file.size / 1024 / 1024 < 5;
                if (!isLt2M) {
                  this.service.msgSrv.warning('图片大小超过5M!');
                  observer.complete();
                  return;
                }
                observer.next(isLt2M);
                observer.complete();
              });
            }
          } as SFUploadWidgetSchema
        },
        no4: {
          type: 'string',
          title: '',
          ui: {
            widget: 'text',
           },
           default: '单张大小不超过5M，支持.jpg、.jpeg和 .png格式',
        },
        avatar3: {
          type: 'string',
          title: '卸货凭证',
          ui: {
            action: `/scm/cms/cms/upload/multipartFile/fileModel`,
            fileType: 'image/png,image/jpeg,image/jpg',
            limit: 1,
            limitFileCount: 1,
            resReName: 'url',
            urlReName: 'url',
            widget: 'upload',
            descriptionI18n: ' 提单号',
            data: {
              // appId: environment.appId,
            },
            name: 'multipartFile',
            multiple: true,
            listType: 'picture-card',
            change: (args: any) => {
              if (args.type === 'success') {
                const avatar = [
                  {
                    uid: -1,
                    name: 'LOGO',
                    status: 'done',
                    url: args.fileList[0].response.url,
                    response: {
                      url: args.fileList[0].response.url
                    }
                  }
                ];
                this.sf?.setValue('/avatar', avatar);
              }
            },
            beforeUpload: (file: any, _fileList: any) => {
              return new Observable((observer: Observer<boolean>) => {
                const isLt2M = file.size / 1024 / 1024 < 5;
                if (!isLt2M) {
                  this.service.msgSrv.warning('图片大小超过5M!');
                  observer.complete();
                  return;
                }
                observer.next(isLt2M);
                observer.complete();
              });
            }
          } as SFUploadWidgetSchema
        },
        avatar4: {
          type: 'string',
          title: '',
          ui: {
            action: `/scm/cms/cms/upload/multipartFile/fileModel`,
            fileType: 'image/png,image/jpeg,image/jpg',
            limit: 1,
            limitFileCount: 1,
            resReName: 'url',
            urlReName: 'url',
            widget: 'upload',
            descriptionI18n: '人车货照片',
            data: {
              // appId: environment.appId,
            },
            name: 'multipartFile',
            multiple: true,
            listType: 'picture-card',
            change: (args: any) => {
              if (args.type === 'success') {
                const avatar = [
                  {
                    uid: -1,
                    name: 'LOGO',
                    status: 'done',
                    url: args.fileList[0].response.url,
                    response: {
                      url: args.fileList[0].response.url
                    }
                  }
                ];
                this.sf?.setValue('/avatar', avatar);
              }
            },
            beforeUpload: (file: any, _fileList: any) => {
              return new Observable((observer: Observer<boolean>) => {
                const isLt2M = file.size / 1024 / 1024 < 5;
                if (!isLt2M) {
                  this.service.msgSrv.warning('图片大小超过5M!');
                  observer.complete();
                  return;
                }
                observer.next(isLt2M);
                observer.complete();
              });
            }
          } as SFUploadWidgetSchema
        }
      },
      required: ['reason']
    };
    this.ui = {
      '*': {
        spanLabelFixed: 100,
        grid: { span: 20 }
      },
      $avatar: { grid: { span: 12} },
      $avatar2: { grid: { span: 12} },
      $avatar3: { grid: { span: 12} },
      $avatar4: { grid: { span: 12} },
    };
  }
  save(value: any): void {
    console.log(value)
    // this.http.post(`/user/${this.record.id}`, value).subscribe(res => {
    //   this.msgSrv.success('保存成功');
    //   this.modal.close(true);
    // });
  }

  close(): void {
    this.modal.destroy();
  }

}
