import { Component, OnInit } from '@angular/core';
import { STColumn } from '@delon/abc/st';
import { SFSchema, SFUISchema } 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 '../../services/supply-management.service';

@Component({
  selector: 'app-supply-management-assigned-car',
  templateUrl: './assigned-car.component.html',
})
export class SupplyManagementAssignedCarComponent implements OnInit {
  record: any = {};
  i: any;
  schema: SFSchema = {};
  ui: SFUISchema = {};
  columns: STColumn[] = [];
  constructor(
    private modal: NzModalRef,
    private msgSrv: NzMessageService,
    public service: SupplyManagementService
  ) {
    this.initSF();
    this.initSt();
  }

  /**
* 初始化查询表单
*/
  initSF() {
    this.schema = {
      properties: {
        _$expand: { type: 'boolean', ui: { hidden: true } },
        no: {
          type: 'string',
          title: '',
          ui: {
            placholder: '请输入司机姓名/手机号'
          }
        },
        no2: {
          type: 'string',
          title: '',
          ui: {
            placholder: '请输入车牌号'
          }
        },
      },
      type: 'object',
    };
    this.ui = { '*': { spanLabelFixed: 80, grid: { span: 12, gutter: 4 } } };
  }

  /**
   * 初始化数据列表
   */
  initSt() {
    this.columns = [
      { width: 50, type: 'checkbox', className: 'text-center' },
      { title: '司机姓名', width: 80, index: 'owner', className: 'text-center' },
      { title: '手机号', index: 'goodsQuantity', width: 100, className: 'text-center' },
      { title: '车牌号', width: 100, index: 'carNo', className: 'text-center' },
      { title: '状态', index: 'status', width: 100, className: 'text-center' },
    ];
  }

  ngOnInit(): void {
  }

  save(value: any): void {
    this.service.request(`/user/${this.record.id}`, value).subscribe(res => {
      this.msgSrv.success('保存成功');
      this.modal.close(true);
    });
  }

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