import { Component, OnInit, ViewChild } from '@angular/core';
import { STColumn, STColumnButton, STComponent, STData } from '@delon/abc/st';
import { SFSchema, SFUISchema } from '@delon/form';
import { ModalHelper, _HttpClient } from '@delon/theme';
import { SupplyManagementService } from '../../services/supply-management.service';

@Component({
  selector: 'app-supply-management-add-drivers',
  templateUrl: './add-drivers.component.html',
})
export class SupplyManagementAddDriversComponent implements OnInit {
  url = `/user?_allow_anonymous=true`;
  i: any;
  searchSchema: SFSchema = {
    properties: {
      no: {
        type: 'string',
        title: '编号'
      }
    }
  };
  @ViewChild('st') private readonly st!: STComponent;
  @ViewChild('selectedST') private readonly selectedST!: STComponent;
  ui: SFUISchema = {

  }
  columns: STColumn[] = [];
  selectedColumn: STColumn[] = [];
  isVisible = false;
  addCarSchema: SFUISchema = {
    properties: {
      mobile: {
        type: 'string',
        title: '司机手机号',
        ui: {
          placeholder: '请输入'
        }
      },
    }
  };

  constructor(public service: SupplyManagementService, private modal: ModalHelper) { }

  ngOnInit(): void {
    this.initSF();
    this.initST();
  }

  /**
* 初始化查询表单
*/
  initSF() {
    this.searchSchema = {
      properties: {
        mobile: {
          type: 'string',
          title: '',
          ui: {
            placeholder: '请输入司机姓名/手机号'
          }
        },
        no: {
          type: 'string',
          title: '',
          ui: {
            placeholder: '请输入车牌号'
          }
        },
      },
      type: 'object',
    };
    this.ui = { '*': { spanLabelFixed: 80, grid: { span: 8, gutter: 4 } } };
  }

  /**
   * 初始化数据列表
   */
  initST() {
    this.columns = [
      {
        title: '司机姓名',
        width: '100px',
        className: 'text-center',
        render: 'goodsId'
      },
      { title: '手机号', render: 'externalSn', width: '120px', className: 'text-center' },
      { title: '货源类型', index: 'linkUrl', width: '120px', className: 'text-center' },
      {
        title: '车牌号',
        className: 'text-center',
        width: '120px',
      }, {
        title: '状态',
        className: 'text-center',
        width: '120px',
      },

      {
        title: '操作',
        fixed: 'right',
        width: '200px',
        className: 'text-center',
        buttons: [
          {
            text: '选择',
            iif: (item: STData, btn: STColumnButton, column: STColumn) => item?.status > 0,
            iifBehavior: 'disabled'
            // click: (_record) => this.editOne(_record),
          },
        ],
      },
    ];
    this.selectedColumn = [
      {
        title: '司机姓名',
        width: '100px',
        className: 'text-center',
        render: 'goodsId'
      },
      { title: '手机号', render: 'externalSn', width: '120px', className: 'text-center' },
      { title: '车牌号', index: 'linkUrl', width: '120px', className: 'text-center' },
      {
        title: '操作',
        fixed: 'right',
        width: '200px',
        className: 'text-center',
        buttons: [
          {
            text: '移除',
            // click: (_record) => this.editOne(_record),
          },
        ],
      },
    ];
  }

  /**
   * 添加熟车
   */
  add(): void {
    this.isVisible = true;
  }

  handleCancel() {
    this.isVisible = false;
  }

  handleOk() {

  }

}
