import { Params } from '@angular/router';
/*
 * @Author: your name
 * @Date: 2021-12-14 14:03:07
 * @LastEditTime: 2022-01-04 09:37:50
 * @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, Input, OnInit, ViewChild } from '@angular/core';
import {SFComponent, SFNumberWidgetSchema, SFSchema, SFUISchema} from '@delon/form';
import { NzMessageService } from 'ng-zorro-antd/message';
import { NzModalRef } from 'ng-zorro-antd/modal';
import { OrderManagementService } from '../../../services/order-management.service';


@Component({
  selector: 'app-order-management-vehicle-freight-people',
  templateUrl: './freight-people.component.html',
  styleUrls: ['./freight-people.component.less']
})
export class VehicleFreightPeopleComponent implements OnInit {
  @ViewChild('sf', { static: false }) sf!: SFComponent;
  schema: SFSchema = {};
  ui: SFUISchema = {};

  aggreechecked = false;

  data: any;

  constructor(private modal: NzModalRef, private msgSrv: NzMessageService, public service: OrderManagementService, ) {}

  ngOnInit(): void {
    console.log(this.data)
    this.initSF();
  }
  initSF() {
    this.schema = {
      properties: {
        enterpriseInfoName: {
          type: 'string',
          title: '网络货运人',
          ui: {
            widget: 'select',
            placeholder: '请选择',
            visibleIf: {
              _$expand: (value: boolean) => value,
            },
            allowClear: true,
            asyncData: () => this.service.getNetworkFreightForwarderHistory(this.data),
          },
        },
      },
      required: ['enterpriseInfoName']
    };
    this.ui = {
      '*': {
        spanLabelFixed: 100,
        grid: { span: 16 }
      }
    };
  }

  save(value: any): void {
    console.log(this.sf.value)
    const params = {
      billIds: this.data?.ids,
      enterpriseInfoId: this.sf.value?.enterpriseInfoName
    };
    console.log(params)
    this.service.request(this.service.$api_set_updateEnterpriseInfoBatch, params).subscribe((res: any) => {
      if (res) {
        this.modal.destroy();
        this.service.msgSrv.success('变更运费成功');
      }
    });
  }

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

}
