import { Component, OnInit } from '@angular/core';
import { SFSchema, SFUISchema } from '@delon/form';
import { NzModalRef } from 'ng-zorro-antd/modal';
import { TaxManagementService } from '../../../services/tax-management.service';


@Component({
  selector: 'app-datatable-upload-setting',
  templateUrl: './upload-setting.component.html',
})
export class TaxManagementUploadSettingComponent implements OnInit {
  record: any = {};
  i: any = {};
  schema!: SFSchema;
  ui!: SFUISchema;

  constructor(
    private modal: NzModalRef,
    public service: TaxManagementService
  ) { }

  ngOnInit(): void {
    this.initSF();
    // this.loadData();
  }

  /**
 * 初始化查询表单
 */
  initSF() {
    this.schema = {
      properties: {
        no: {
          type: 'string',
          title: '订单数据',
          enum: [
            {
              label: '手动上传',
              value: '1'
            },
            {
              label: '自动上传',
              value: '2'
            }
          ],
          description: '开启自动上传后，订单将在支付完成且风险单校验通过后自动上传',
          ui: {
            widget: 'radio',

          }
        },
        owner: {
          type: 'string',
          title: '资金数据',
          enum: [
            {
              label: '手动上传',
              value: '1'
            },
            {
              label: '自动上传',
              value: '2'
            }
          ],
          description: '开启自动上传后，订单将在支付完成且风险单校验通过后自动上传',
          ui: {
            widget: 'radio',

          }
        },
      },
      required: ['owner', 'no'],
    }
    this.ui = {
      '*': {
        spanLabelFixed: 100,
        grid: { span: 24 },
      },
    };
  }

  /**
   * 获取设置数据
   */
  loadData() {
    this.service.request(this.service.$api_get_upload_setting, {}).subscribe(res => {
      if (res) {
        this.i = res;

      }
    })
  }

  /**
   * 修改
   * @param value
   */
  save(value: any): void {
    this.service.request(this.service.$api_upload_setting_save, { ...value }).subscribe(res => {
      if (res) {
        this.service.msgSrv.success('保存成功');
        this.modal.close(true);
      }
    })
  }

  close(): void {
    this.modal.destroy();
  }
}
