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

@Component({
  selector: 'app-recharge-record',
  templateUrl: './recharge-record.component.html',
  styleUrls: ['./recharge-record.component.less']
})
export class RechargeRecordComponent 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' },
    { title: '银行流水号', index: 'callNo' }
  ];
  searchSchema: SFSchema = {
    properties: {
      expand: {
        type: 'boolean',
        ui: {
          hidden: true
        }
      },
      orderSn2: {
        type: 'string',
        title: '充值单号',
        ui: {
          placeholder: '请输入',
          autocomplete: 'off'
        }
      },
      receiveName: {
        type: 'string',
        title: '充值状态',
        enum: [
          { label: '全部', value: '' },
          { label: '充值中', value: '充值中' },
          { label: '已完成', value: '已完成' }
        ],
        ui: {
          widget: 'select',
          placeholder: '请选择',
          change: (i: any) => {
            this.sf.value.receiveName = i;
            this.sf?.setValue('/receiveName', i);
          }
        },
        default: ''
      },
      createTime: {
        title: '充值时间',
        type: 'string',
        ui: {
          widget: 'date',
          mode: 'range',
          format: 'yyyy-MM-dd'
        } as SFDateWidgetSchema
      },
      orderSn3: {
        type: 'string',
        title: '账户名称',
        ui: {
          placeholder: '请输入',
          autocomplete: 'off',
          visibleIf: {
            expand: (value: boolean) => value
          }
        }
      },
      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: ''
      },
      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) {}

  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);
  }
}
