/*
 * @Description  :
 * @Version      : 1.0
 * @Author       : Shiming
 * @Date         : 2021-12-29 16:48:16
 * @LastEditors  : Shiming
 * @LastEditTime : 2022-01-24 20:19:31
 * @FilePath     : \\tms-obc-web\\src\\app\\routes\\order-management\\modal\\vehicle\\freight-people\\freight-people.component.ts
 * Copyright (C) 2022 huzhenhong. All rights reserved.
 */
import { Component, OnInit, ViewChild } from '@angular/core';
import { SFComponent, SFSchema, SFUISchema } from '@delon/form';
import { ShipperBaseService } from '@shared';
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,
    public shipperservice: ShipperBaseService
  ) {}

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

  save(value: any): void {
    console.log(this.sf.value);
    if(!this.sf.valid) {
      this.service.msgSrv.error("请选择网络货运人！")
      return;
    }
    const params = {
      billIds: this.data?.ids,
      enterpriseInfoId: this.sf.value?.enterpriseInfoId
    };
    console.log(params);
    this.service.request(this.service.$api_set_updateEnterpriseInfoBatch, params).subscribe((res: any) => {
      if (res) {
        this.modal.destroy(true);
        this.service.msgSrv.success('修改网络货运人成功！');
      }
    });
  }

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