import { Component, OnInit, ViewChild } from '@angular/core';
import { Router } from '@angular/router';
import { STComponent, STColumn, STChange } from '@delon/abc/st';
import { SFComponent, SFDateWidgetSchema, SFSchema } from '@delon/form';
import { NzModalService } from 'ng-zorro-antd/modal';
import { TicketService } from 'src/app/routes/ticket-management/services/system.service';

@Component({
  selector: 'app-freight-account-detail',
  templateUrl: './freight-account-detail.component.html',
  styleUrls: ['./freight-account-detail.component.less']
})
export class FreightAccountDetailComponent implements OnInit {
  url = `/rule?_allow_anonymous=true`;
  @ViewChild('st', { static: true })
  st!: STComponent;
  @ViewChild('sf', { static: false })
  sf!: SFComponent;
  columns: STColumn[] = [
    { title: '交易时间', index: 'updatedAt', type: 'date' },
    { title: '流水号', index: 'callNo' },
    { title: '交易类型', index: 'callNo' },
    { title: '订单号', index: 'callNo' },
    { title: '所属项目', index: 'callNo' },
    { title: '收支类型', index: 'callNo' },
    { title: '交易金额', index: 'callNo' },
    { title: '账户余额', index: 'callNo' },
    { title: '无车承运人', index: 'callNo' }
  ];
  searchSchema: SFSchema = {
    properties: {
      expand: {
        type: 'boolean',
        ui: {
          hidden: true
        }
      },
      createTime: {
        title: '交易时间',
        type: 'string',
        ui: {
          widget: 'date',
          mode: 'range',
          format: 'yyyy-MM-dd',
          visibleIf: {
            expand: (value: boolean) => value
          }
        } as SFDateWidgetSchema
      },
      orderSn2: {
        type: 'string',
        title: '流水号',
        ui: {
          placeholder: '请输入',
          autocomplete: 'off'
        }
      },
      orderSn3: {
        type: 'string',
        title: '订单号',
        ui: {
          placeholder: '请输入',
          autocomplete: 'off'
        }
      },
      receiveName: {
        type: 'string',
        title: '交易类型',
        enum: [
          { label: '全部', value: '' },
          { label: '订单支付', value: '订单支付' },
          { label: '余额充值', value: '余额充值' },
          { label: '余额提现', value: '余额提现' },
          { label: '资金分配', value: '资金分配' },
          { label: '资金回收', value: '资金回收' }
        ],
        ui: {
          widget: 'select',
          placeholder: '请选择',
          change: (i: any) => {
            this.sf.value.receiveName = i;
            this.sf?.setValue('/receiveName', i);
          },
          visibleIf: {
            expand: (value: boolean) => value
          }
        },
        default: ''
      },
      receiveName2: {
        type: 'string',
        title: '收支类型',
        enum: [
          { label: '全部', value: '' },
          { label: '收入', value: '收入' },
          { label: '支出', value: '支出' }
        ],
        ui: {
          widget: 'select',
          placeholder: '请选择',
          change: (i: any) => {
            this.sf.value.receiveName2 = i;
            this.sf?.setValue('/receiveName2', i);
          },
          visibleIf: {
            expand: (value: boolean) => value
          }
        },
        default: ''
      },
      receiveName3: {
        type: 'string',
        title: '所属项目',
        enum: [{ label: '全部', value: '' }],
        ui: {
          widget: 'select',
          placeholder: '请选择',
          change: (i: any) => {
            this.sf.value.receiveName3 = i;
            this.sf?.setValue('/receiveName3', i);
          },
          visibleIf: {
            expand: (value: boolean) => value
          }
        },
        default: ''
      },
      receiveName4: {
        type: 'string',
        title: '无车承运人',
        enum: [{ label: '全部', value: '' }],
        ui: {
          widget: 'select',
          placeholder: '请选择',
          change: (i: any) => {
            this.sf.value.receiveName4 = i;
            this.sf?.setValue('/receiveName4', i);
          },
          visibleIf: {
            expand: (value: boolean) => value
          }
        },
        default: ''
      }
    }
  };

  reqParams = {};
  _$expand = false;
  constructor(public service: TicketService, private nzModalService: NzModalService, private router: Router) {}

  ngOnInit(): void {}

  stChange(e: STChange): void {
    switch (e.type) {
      case 'filter':
        this.st.load();
        break;
    }
  }

  goBack() {
    history.go(-1);
  }

  /**
   * 重置表单
   */
  resetSF() {
    this.sf.reset();
    this._$expand = false;
  }

  /**
   * 伸缩查询条件
   */
  expandToggle() {
    this._$expand = !this._$expand;
    this.sf?.setValue('/expand', this._$expand);
  }
}
