import { Component, Input, OnInit } from '@angular/core';
import { NzModalRef } from 'ng-zorro-antd/modal';
import { ShipperBaseService } from 'src/app/shared/services/business/shipper-base.service';

@Component({
  selector: 'app-enter-auth',
  templateUrl: './enter-auth.component.html'
})
export class EnterAuthComponent implements OnInit {
  @Input()
  enterpriseId = '';
  @Input()
  roleId = '';

  roles: any[] = [];

  constructor(private service: ShipperBaseService, private modalHelp: NzModalRef) {
    this.loadRoles();
  }

  ngOnInit(): void {
    console.log(this.enterpriseId);

    this.loadEnterRole();
  }

  loadEnterRole() {
    this.service.request('/api/mdc/cuc/enterpriseInfo/operate/getRole', { enterpriseId: this.enterpriseId }).subscribe(res => {
      if (res) {
        this.roleId = res.roleId;
      }
    });
  }
  loadRoles() {
    this.service.getRoles({ enterpriseId: 0, projectId: 0 }).subscribe(res => {
      if (res) {
        this.roles = res;
      }
    });
  }

  saveAction() {
    this.service
      .request('/api/mdc/cuc/enterpriseInfo/operate/updateRole', { enterpriseIdList: [this.enterpriseId], roleId: this.roleId })
      .subscribe(res => {
        if (res) {
          this.service.msgSrv.success('修改成功');
          this.modalHelp.destroy(true);
        }
      });
  }
}
