import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { STColumn, STComponent } from '@delon/abc/st';
import { SFComponent, SFDateWidgetSchema, SFSchema, SFUISchema } from '@delon/form';
import { ModalHelper, _HttpClient } from '@delon/theme';
import { NzMessageService } from 'ng-zorro-antd/message';
import { NzModalService } from 'ng-zorro-antd/modal';
import { UsermanageService } from '../../../../services/usercenter.service';

@Component({
  selector: 'app-supplier-components-list-view',
  templateUrl: './detail.component.html',
  styleUrls: ['./detail.component.less']
})
export class FreightComponentsUserDetailComponent implements OnInit {
  @ViewChild('redectModal', { static: false })
  redectModal!: any;

  userDetail: any = {};
  userIdentityDetail: any = {};
  @ViewChild('st', { static: false }) st!: STComponent;
  columns: STColumn[] = [
    { title: '企业名称', index: 'perPrice', width: 300, className: 'text-center' },
    { title: '项目名称', index: 'goodsQuantity', width: 300, className: 'text-center' },
    { title: '角色', index: 'totalPrice', width: 300, className: 'text-center' }
  ];

  approvalOpinion = '';
  reasonTags = ['身份证照片太丑', '姓名与身份证号不匹配'];
  constructor(private nzModalService: NzModalService, public service: UsermanageService, private route: ActivatedRoute) {}

  ngOnInit() {
    this.initData();
    // this.launchSign();
  }
  async initData() {
    console.log(this.route.snapshot, 'this.route.snapshot');

    const params = {
      id: this.route.snapshot.params.id
      // tenantId: this.route.snapshot.queryParams.tenantId,
    };

    // 获取司机头部信息
    this.service
      .request(this.service.$api_get_user_detail, {
        appUserId: this.route.snapshot.params.id
      })
      .subscribe(res => {
        if (res) {
          this.userDetail = res;
        }
      });
    // 获取用户个人信息
    this.service
      .request(this.service.$api_get_user_identity, {
        id: this.route.snapshot.params.id
      })
      .subscribe(res => {
        if (res) {
          this.userIdentityDetail = res;
        }
      });
  }

  userAction(status: number) {
    this.nzModalService.warning({
      nzTitle: status === 1 ? '确定启用该用户吗？' : '确定冻结该用户吗？',
      nzContent:
        status === 1
          ? '停用后，该用户将被限制使用，不限于访问受限、无法发布货源等，请谨慎操作'
          : '启用后，该用户将恢复正常使用功能，请再次确认',
      nzOnOk: () => {
        // this.service.request(this.service.$api_lock_user)
        this.st.reload();
      }
    });
  }

  auditPass() {
    this.nzModalService.confirm({
      nzTitle: '审核通过',
      nzContent: `是否确认通过(姓名:${this.userIdentityDetail?.name})审核`,
      nzOnOk: () => {
        this.auditEnterprise(0);
      }
    });
  }

  auditNo() {
    this.approvalOpinion = '';
    this.nzModalService.create({
      nzTitle: '审核驳回',
      nzContent: this.redectModal,
      nzOnOk: () => {
        if (!this.approvalOpinion) {
          return false;
        }
        this.auditEnterprise(1);
        return;
      }
    });
  }

  private auditEnterprise(auditStatus: number) {
    this.service
      .request(this.service.$api_approve_identity, {
        auditStatus: auditStatus,
        identityId: this.userIdentityDetail.id,
        auditType: 0,
        certificationOpinions: this.approvalOpinion
      })
      .subscribe(res => {
        if (res) {
          this.service.msgSrv.success(auditStatus === 0 ? '审核通过' : '驳回成功');
        }
        this.initData();
      });
  }

  ratify() {}

  goBack() {
    window.history.go(-1);
  }
}
