/*
 * @Author: your name
 * @Date: 2021-12-14 14:03:07
 * @LastEditTime: 2022-01-05 16:27:22
 * @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 { STColumn, STComponent } from '@delon/abc/st';
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-modify-captain',
  templateUrl: './modify-captain.component.html',
  styleUrls: ['./modify-captain.component.less']
})
export class VehicleModifyCaptainComponent implements OnInit {
  @ViewChild('sf', { static: false }) sf!: SFComponent;
  @ViewChild('st', { static: false }) st!: STComponent;
  schema: SFSchema = {};
  ui: SFUISchema = {};
  Columns: STColumn[] =[]
  aggreechecked = false;
  dataList: any =[]
  data: any;
  bankData: any;

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

  ngOnInit(): void {
    console.log(this.data)
    this.initSF();
    this.initST();
  }
  initSF() {
    this.schema = {
      properties: {
        mobile: {
          type: 'string',
          title: '车队长手机号',
          maxLength: 11
        },
      },
      required: ['mobile']
    };
    this.ui = {
      '*': {
        spanLabelFixed: 130,
        grid: { span: 16 }
      }
    };
  }
  initST() {
    this.Columns = [
       { title: '司机头像', render: 'avatar',width: '120px', },
       { title: '司机姓名', index: 'name' ,width: '120px',},
       {
        title: '实名认证状态',
        className: 'text-center',
        index: 'certificationStatus',
        type: 'badge',
        width: '120px',
        badge: {
          '-1': { text: '未提交', color: 'warning' },
          '0': { text: '待审核', color: 'warning' },
          '1': { text: '通过', color: 'success' },
          '2': { text: '驳回', color: 'error' },
        },
      },
       { title: '收款账户',width: '200px', render: 'bankList' },
       {
        title: '操作',
        width: '120px',
        className: 'text-center',
        buttons: [
          {
            text: '设置',
            click: item => {
              this.set(item)
            }
          }
        ]
      }
   
     ];
   }
   set(value: any): void {
    console.log(this.st?._data)
    console.log(this.data)
    console.log(value)
    console.log(this.bankData)
    const params = {
      billIds: this.data?.ids,
      carCaptainId: value.id,
      bankData: this.bankData
    };
    this.service.request(this.service.$api_get_updateCarCaptainBatch, params).subscribe((res: any) => {
      if (res) {
        this.modal.destroy();
        this.service.msgSrv.success('修改成功');
      } else {
        this.service.msgSrv.error(res?.msg);
      }
    });
  }
  initDate() {
    const params = {
      fetchBank: 1,
      ...this.sf?.value,
    };
    this.service.request(this.service.$api_get_getCarCaptainByMobile, params).subscribe((res: any) => {
      console.log(res)
      if (res) {
        this.dataList = [res]
      }
    });
  }
  close(): void {
    this.modal.destroy();
  }
}
