/*
 * @Author: your name
 * @Date: 2022-01-04 14:44:59
 * @LastEditTime: 2022-01-04 16:05:27
 * @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\sys-setting\components\system-waybill-logs\system-waybill-logs.component.ts
 */
import { Component, OnInit, ViewChild } from '@angular/core';
import { STComponent, STColumn, STChange, STRequestOptions } from '@delon/abc/st';
import { SFComponent, SFDateWidgetSchema, SFSchema, SFUISchema } from '@delon/form';
import { dateTimePickerUtil } from '@delon/util';
import { NzModalService } from 'ng-zorro-antd/modal';
import { LogsService } from '../../services/logs.service';

@Component({
  selector: 'app-system-logs',
  templateUrl: './system-waybill-logs.component.html',
  styleUrls: ['../../../commom/less/box.less', '../../../commom/less/expend-but.less']
})
export class SystemWaybillLogsComponent implements OnInit {
  @ViewChild('st', { static: true })
  st!: STComponent;
  @ViewChild('sf', { static: false })
  sf!: SFComponent;

  searchSchema: SFSchema = {
    properties: {
      operateObject: {
        type: 'string',
        title: '订单号',
        ui: {
          placeholder: '请输入',
        }
      },
      time: {
        title: '登录时间',
        type: 'string',
        ui: {
          widget: 'sl-from-to-search',
          format: 'yyyy-MM-dd HH:mm:ss',
          nzShowTime: true,
        } as SFDateWidgetSchema
      }
    }
  };

  columns: STColumn[] = [
    { title: 'ID', index: 'id' },
    { title: '订单号', index: 'operateObject' },
    { title: '说明', index: 'operationContent' },
    { title: '操作人', index: 'operator' },
    { title: '操作时间', index: 'operatorTimestamp', type: 'date' },
  ];

  _$expand = false;

  constructor(public service: LogsService, private nzModalService: NzModalService) {}

  ngOnInit(): void {}

  beforeReq = (requestOptions: STRequestOptions) => {
    requestOptions.body.operateType = '3'
    if (this.sf) {
      Object.assign(requestOptions.body, {
        ...this.sf.value,
        operateType: '3',
        endTime: this.sf.value.time?.[1] || null,
        startTime: this.sf.value.time?.[0] || null
      });
    }
    return requestOptions;
  };

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

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