import { Component, OnInit, ViewChild } from '@angular/core';
import { SFComponent, SFSchema, SFUISchema } from '@delon/form';
import { EAEnterpriseService } from '@shared';
import { NzMessageService } from 'ng-zorro-antd/message';
import { NzModalRef } from 'ng-zorro-antd/modal';
import { SystemService } from 'src/app/routes/sys-setting/services/system.service';
import { UsermanageService } from 'src/app/routes/usercenter/services/usercenter.service';

@Component({
  selector: 'app-audit-admin',
  templateUrl: './audit-admin.component.html',
  styleUrls: ['./audit-admin.component.less']
})
export class AuditAdminComponent implements OnInit {
  @ViewChild('sf', { static: false })
  sf!: SFComponent;
  i: any;
  schema!: SFSchema;
  ui: SFUISchema = {
    '*': {
      spanLabelFixed: 120,
      grid: { span: 20 }
    }
  };
  constructor(public msgSrv: NzMessageService, public service: UsermanageService) {}

  ngOnInit(): void {
    this.loadUserInfo();
  }

  loadUserInfo() {
    this.service.request(this.service.$api_get_enterprise_user_by_id, { id: this.i.id }).subscribe(res => {
      console.log(res);
      if (res) {
        this.initSF(res);
      }
    });
  }

  initSF(user?: any) {
    this.schema = {
      properties: {
        oldAdminName: {
          title: '当前管理员',
          type: 'string',
          ui: { widget: 'text' },
          default: user.oldAdminName
        },
        oldAdminMobile: {
          title: '手机号',
          type: 'string',
          ui: { widget: 'text' },
          default: user.oldAdminMobile
        },
        oldAdminIdNo: {
          title: '身份证号',
          type: 'string',
          ui: { widget: 'text' },
          default: user.oldAdminIdNo
        },
        newAdminName: {
          title: '转授对象',
          type: 'string',
          ui: { widget: 'text' },
          default: user.newAdminName
        },
        newAdminMobile: {
          title: '手机号',
          type: 'string',
          ui: { widget: 'text' },
          default: user.newAdminMobile
        },
        newAdminIdNo: {
          title: '身份证号',
          type: 'string',
          ui: { widget: 'text' },
          default: user.newAdminIdNo
        },
        creditPhoto: {
          title: '企业授权函',
          type: 'string',
          ui: { widget: 'custom' }
        },
        approvalOpinion: {
          title: '备注',
          type: 'string',
          maxLength: 100,
          ui: {
            placeholder: '审核不通过需要说明原因',
            widget: 'textarea',
            autosize: { minRows: 3, maxRows: 6 }
          }
        }
      }
    };
  }
}
