import { Component, OnInit, ViewChild } from '@angular/core';
import { Router } from '@angular/router';
import { STColumn, STComponent } from '@delon/abc/st';
import { SFComponent, SFSchema, SFUISchema } from '@delon/form';
import { ModalHelper, _HttpClient } from '@delon/theme';
import { BussinessStatisticsService } from '../../services/bussiness-statistics.service';

@Component({
  selector: 'app-partner-partner-custom-detail',
  templateUrl: './partner-custom-detail.component.html',
  styleUrls: ['./partner-custom-detail.component.less']
})
export class PartnerPartnerCustomDetailComponent implements OnInit {
  schema: SFSchema = {};
  ui!: SFUISchema;
  detailInfo: any = {
    logo: './assets/images/user/logo.svg',
    company: '张三',
    code: '91440300357887492H',
    proxy: '企业合伙人',
    belongCity: '深圳、上海、北京',
    createTime: '2021-09-23 14:43:31'
  }
  @ViewChild('st') private readonly st!: STComponent;
  @ViewChild('sf') private readonly sf!: SFComponent;
  columns: STColumn[] = [
    { title: '编号', index: 'no' },
    { title: '调用次数', type: 'number', index: 'callNo' },
    { title: '头像', type: 'img', width: '50px', index: 'avatar' },
    { title: '时间', type: 'date', index: 'updatedAt' },
    {
      title: '',
      buttons: [
        // { text: '查看', click: (item: any) => `/form/${item.id}` },
        // { text: '编辑', type: 'static', component: FormEditComponent, click: 'reload' },
      ]
    }
  ];
  _$expand = false;

  constructor(public service: BussinessStatisticsService, public router: Router) {

  }

  get reqParams() {
    return { ...this.sf?.value };
  }

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

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

  add(): void {
    // this.modal
    //   .createStatic(FormEditComponent, { i: { id: 0 } })
    //   .subscribe(() => this.st.reload());
  }
  search() {
    this.st.load(1);
  }
  export() {

  }

  initSF() {
    this.schema = {
      properties: {
        abnormalCause: {
          title: '客户名称',
          type: 'string',
          ui: {
            placeholder: '请输入',
          },
        },
        abnormalCause1: {
          title: '客户状态',
          type: 'string',
          default: '',
          enum: [
            {
              label: '全部',
              value: ''
            },
            {
              label: '个人',
              value: '1'
            },
            {
              label: '企业',
              value: '2'
            }
          ],
          ui: {
            widget: 'select'
          },
        },
      }
    }
    this.ui = {
      '*': { spanLabelFixed: 100, grid: { span: 11, gutter: 4 } },
    };
  }
  /**
 * 初始化数据列表
 */
  initST() {
    this.columns = [
      { title: '客户名称', index: 'carNo', className: 'text-center', width: 150 },
      { title: '客户状态', render: 'carModelLabel', className: 'text-center', width: 120 },
      { title: '结算时间段', index: 'carNo', className: 'text-center', width: 200 },
      { title: '本月交易数', render: 'approvalStatus0', className: 'text-center', sort: true, width: 150 },
      { title: '客户总数', render: 'approvalStatus', className: 'text-center', sort: true, width: 150 },
      { title: '累计交易数', render: 'approvalStatus1', className: 'text-center', sort: true, width: 120 },
      { title: '本月已结算订单', render: 'approvalStatus2', className: 'text-center', sort: true, width: 180 },
      { title: '累计已结算订单', render: 'approvalStatus3', className: 'text-center', sort: true, width: 180 },
      { title: '本月交易金额（元）', index: 'approvalStatus5', className: 'text-right', sort: true, type: 'currency', width: 180 },
      { title: '累计交易金额（元）', index: 'approvalStatus6', className: 'text-right', sort: true, type: 'currency', width: 180 },
      { title: '本月已结算金额（元）', index: 'approvalStatus7', className: 'text-right', sort: true, type: 'currency', width: 200 },
      { title: '累计已结算金额（元）', index: 'approvalStatus8', className: 'text-right', sort: true, type: 'currency', width: 200 },
      { title: '本月已开票金额（元）', index: 'approvalStatus9', className: 'text-right', sort: true, type: 'currency', width: 200 },
      { title: '累计已开票金额（元）', index: 'approvalStatus10', className: 'text-right', sort: true, type: 'currency', width: 200 },
      { title: '本月申请开票金额（元）', index: 'approvalStatus11', className: 'text-right', sort: true, type: 'currency', width: 200 },
      {
        title: '操作',
        width: 150,
        buttons: [
          {
            text: '查看订单明细',
            click: (_record) => this.viewOrderDetail(_record)
          }
        ]
      },
    ];
  }

  /**
   * 查看订单明细
   * @param record 当前对象
   */
  viewOrderDetail(record: any) {
    this.router.navigate([`/partner/business-statistics/partner/custom-order-detail/${record?.id}`])
  }
  goBack() {
    window.history.go(-1);
  }

}
