<!-- 页头 -->
<page-header-wrapper [logo]="logo" [content]="content" [title]="'企业详情'">
  <ng-template #logo>
    <button nz-button nz-tooltip nzTooltipTitle="返回上一页" (click)="goBack()">
      <i nz-icon nzType="left" nzTheme="outline"></i>
    </button>
  </ng-template>
  <ng-template #content>
    <nz-skeleton [nzLoading]="false">
      <div class="user-info" nz-row>
        <div nz-col [nzXl]="18" [nzLg]="24" [nzSm]="24" [nzXs]="24" class="d-flex">
          <img [src]="detailData?.enterpriseLogo" />
          <div style="flex: 1;">
            <div nz-row>
              <div nz-col [nzLg]="12" [nzSm]="24" [nzXs]="24">
                <p style="margin-bottom: 0;">{{ detailData?.enterpriseName }}</p>
              </div>
              <div nz-col [nzLg]="12" [nzSm]="24" [nzXs]="24">
                <nz-badge nzStatus="success" nzText="正常" *ngIf="detailData?.stateLocked === 0"></nz-badge>
                <nz-badge nzStatus="error" nzText="冻结" *ngIf="detailData?.stateLocked === 1"></nz-badge>
              </div>
            </div>
            <div nz-row>
              <div nz-col [nzLg]="12" [nzSm]="24" [nzXs]="24">
                <p>{{ detailData?.unifiedSocialCreditCode }}</p>
              </div>
              <div nz-col [nzLg]="12" [nzSm]="24" [nzXs]="24">
                认证时间：{{detailData?.createTime}}
              </div>
            </div>
            <div>
              服务评级：<nz-rate [ngModel]="detailData?.serviceLevel" nzDisabled></nz-rate>
            </div>
          </div>
        </div>
        <div nz-col [nzXl]="6" [nzLg]="24" [nzSm]="24" [nzXs]="24" class="text-right mt-sm">
          <ng-container *ngIf="isEdit;else editButton">
            <button [nzLoading]="service.http.loading" nz-button (click)="reset()">
              取消
            </button>
            <button [nzLoading]="service.http.loading" nz-button nzDanger (click)="save()">
              保存
            </button>
          </ng-container>
          <ng-template #editButton>
            <ng-container *ngIf="detailData?.approvalStatus===10">
              <button [nzLoading]="service.http.loading" nz-button nzDanger (click)="auditPass()">
                通过
              </button>
              <button [nzLoading]="service.http.loading" nz-button nzDanger (click)="auditNo()">
                驳回
              </button>
            </ng-container>
            <ng-container *ngIf="detailData?.approvalStatus!=10">
              <button [nzLoading]="service.http.loading" nz-button nzDanger nz-popconfirm [nzPopconfirmTitle]="enable"
                (nzOnConfirm)="freezeOrResume(0)" nzPopconfirmPlacement="bottomRight" *ngIf="detailData?.stateLocked">
                启用
              </button>
              <button [nzLoading]="service.http.loading" nz-button nzDanger nz-popconfirm [nzPopconfirmTitle]="frozen"
                (nzOnConfirm)="freezeOrResume(1)" nzPopconfirmPlacement="bottomRight" *ngIf="!detailData?.stateLocked">
                冻结
              </button>
              <button [nzLoading]="service.http.loading" nz-button nzDanger nz-popconfirm
                [nzPopconfirmTitle]="Payfrozen" (nzOnConfirm)="PayOrResume(0)" nzPopconfirmPlacement="bottomRight"
                *ngIf="detailData?.createPay === 1">
                开通支付权限
              </button>
              <button [nzLoading]="service.http.loading" nz-button nzDanger nz-popconfirm
                [nzPopconfirmTitle]="Payenable" (nzOnConfirm)="PayOrResume(1)" nzPopconfirmPlacement="bottomRight"
                *ngIf="detailData?.createPay === 0">
                关闭支付权限
              </button>
            </ng-container>
            <button [nzLoading]="service.http.loading" nz-button nzDanger (click)="ratify()">
              修改
            </button>
          </ng-template>
        </div>
      </div>
    </nz-skeleton>
  </ng-template>

  <ng-template #frozen>
    <ng-container
      *ngTemplateOutlet="PopconfirmTempalte;context:{title:'确定冻结该企业吗？',content:'停用后，该企业将被限制使用，不限于访问受限、无法发布货源等，请谨慎操作'}">
    </ng-container>
  </ng-template>
  <ng-template #enable>
    <ng-container *ngTemplateOutlet="PopconfirmTempalte;context:{title:'确定启用该企业吗？',content:'启用后，该企业将恢复正常使用功能，请再次确认'}">
    </ng-container>
  </ng-template>
  <ng-template #Payenable>
    <ng-container
      *ngTemplateOutlet="PopconfirmTempalte;context:{title:'确定关闭该企业支付权限吗？',content:'停用后，该企业将被限制使用支付功能，请谨慎操作'}">
    </ng-container>
  </ng-template>
  <ng-template #Payfrozen>
    <ng-container
      *ngTemplateOutlet="PopconfirmTempalte;context:{title:'确定开通该企业支付权限吗？',content:'启用后，该企业将恢复正常支付功能，请再次确认'}">
    </ng-container>
  </ng-template>
</page-header-wrapper>

<nz-card [class]="isEdit?'edit-box':'readOnly-box'">
  <sv-container col="3">
    <sv-title>企业管理员信息</sv-title>
    <sv label="姓名">
      <input nz-input type="text" [(ngModel)]="detailData.adminUserInfo.name" [readonly]="!isEdit"
        [nzBorderless]="!isEdit" [placeholder]="isEdit?'':'-'">
    </sv>
    <sv label="手机号">
      {{detailData.adminUserInfo?.mobile}}
    </sv>
    <sv label="身份证号">
      <input nz-input type="text" [(ngModel)]="detailData.adminUserInfo.certificateNumber" [readonly]="!isEdit"
        [nzBorderless]="!isEdit" [placeholder]="isEdit?'':'-'">
    </sv>
    <sv label="身份证照" col="2">
      <div class="d-flex">
        <ng-container
          *ngTemplateOutlet="uploadTemplate;context:{data:detailData?.adminUserInfo,status:isEdit,key:'certificatePhotoFrontWatermark',key2:'certificatePhotoFront',hover:'certificateBackFront'}">
        </ng-container>
        <ng-container
          *ngTemplateOutlet="uploadTemplate;context:{data:detailData?.adminUserInfo,status:isEdit,key:'certificatePhotoBackWatermark',key2:'certificatePhotoBack',hover:'certificateBack'}">
        </ng-container>
      </div>
    </sv>
    <sv label="企业授权函" col="2">
      <ng-container
        *ngTemplateOutlet="uploadTemplate;context:{data:detailData,status:isEdit,key:'creditPhotoWatermark',key2:'creditPhoto',hover:'adminPhoto'}">
      </ng-container>
    </sv>
  </sv-container>

  <nz-divider></nz-divider>
  <sv-container col="3" class="mt16">
    <sv-title>
      <label class="mr-md">企业基本信息</label>
      <label *ngIf="detailData?.approvalStatus===10" style="color: #1890ff;"><i nz-icon nzType="info-circle"
          nzTheme="fill" class="mr-xs"></i>待审核
      </label>
      <label *ngIf="detailData?.approvalStatus===20" style="color: #52c41a;"><i nz-icon nzType="check-circle"
          nzTheme="fill" class="mr-xs"></i>审核通过
      </label>
      <label *ngIf="detailData?.approvalStatus===30" style="color: #ff4d4f;"><i nz-icon nzType="close-circle"
          nzTheme="fill" class="mr-xs"></i>驳回
      </label>
    </sv-title>
    <sv label="公司名称">
      <input nz-input type="text" [(ngModel)]="detailData.enterpriseName" [readonly]="!isEdit" [nzBorderless]="!isEdit"
        [placeholder]="isEdit?'':'-'">
    </sv>
    <sv label="统一社会信用代码">
      <input nz-input type="text" [(ngModel)]="detailData.unifiedSocialCreditCode" [readonly]="!isEdit"
        [nzBorderless]="!isEdit" [placeholder]="isEdit?'':'-'">
    </sv>
    <sv label="公司类型">
      <input nz-input type="text" [(ngModel)]="detailData.enterpriseType" [readonly]="!isEdit" [nzBorderless]="!isEdit"
        [placeholder]="isEdit?'':'-'">
    </sv>
    <sv label="注册资本">
      <ng-container *ngIf="isEdit; else registrationCapitalTemplate">
        <input nz-input type="number" [(ngModel)]="detailData.registrationCapital" [readonly]="!isEdit"
          [nzBorderless]="!isEdit" [placeholder]="isEdit?'':'-'" class="mr-sm">
      </ng-container>
      <ng-template #registrationCapitalTemplate>
        {{detailData?.registrationCapital}}
      </ng-template>
      <span *ngIf="detailData?.registrationCapital">万元</span>
    </sv>
    <sv label="成立日期">
      <nz-date-picker [(ngModel)]="detailData.enterpriseRegistrationTime" [nzDisabled]="!isEdit"
        [nzPlaceHolder]="isEdit?'':'-'" [nzBorderless]="!isEdit" [nzSuffixIcon]="isEdit?'calendar':''"></nz-date-picker>
    </sv>
    <sv label="营业期限">
      <nz-date-picker [(ngModel)]="detailData.operatingStartTime" [nzDisabled]="!isEdit" nzPlaceHolder=" "
        [nzBorderless]="!isEdit" [nzSuffixIcon]="isEdit?'calendar':''" style="width: 100px;" class="calendar">
      </nz-date-picker>
      -
      <ng-container *ngIf="!isEdit && !detailData?.operatingEndTime && detailData?.operatingStartTime">
        <label style="padding-left: 11px;">长期</label>
      </ng-container>
      <nz-date-picker [(ngModel)]="detailData.operatingEndTime" [nzDisabled]="!isEdit" nzPlaceHolder=" "
        [nzBorderless]="!isEdit" [nzSuffixIcon]="isEdit?'calendar':''" style="width: 100px;" class="calendar">
      </nz-date-picker>
      <ng-container *ngIf="isEdit">
        <label nz-checkbox [ngModel]="!!!detailData.operatingEndTime"
          (ngModelChange)="$event?detailData.operatingEndTime='':''" class="ml-sm">长期</label>
      </ng-container>

    </sv>
    <sv label="公司所在地" col="3">
      <ng-container *ngIf="isEdit; else cascaderelseTemplate">
        <nz-cascader [(ngModel)]="enterpriseAddressCode" [nzLoadData]="loadRegionData">
        </nz-cascader>
      </ng-container>
      <ng-template #cascaderelseTemplate>
        {{ detailData?.fullRegionVO?.provinceName }}{{ detailData?.fullRegionVO?.cityName }}{{
        detailData?.fullRegionVO?.areaName }}
      </ng-template>
    </sv>
    <sv label="公司详细地址" col="2">
      <input nz-input type="text" [(ngModel)]="detailData.enterpriseAddress" [readonly]="!isEdit"
        [nzBorderless]="!isEdit" [placeholder]="isEdit?'':'-'">
    </sv>
    <sv label="经营范围" col="1">
      <input nz-input type="text" [(ngModel)]="detailData.businessScope" [readonly]="!isEdit" [nzBorderless]="!isEdit"
        [placeholder]="isEdit?'':'-'">
    </sv>
    <sv label="税务机关" col="2">
      <input nz-input type="text" [(ngModel)]="detailData.taxAuthority" [readonly]="!isEdit" [nzBorderless]="!isEdit"
        [placeholder]="isEdit?'':'-'">
    </sv>
    <sv label="营业执照" col="2">
      <ng-container
        *ngTemplateOutlet="uploadTemplate;context:{data:detailData,status:isEdit,key:'licensePhotoWatermark',key2:'licensePhoto',hover:'detailPhoto'}">
      </ng-container>
    </sv>
  </sv-container>
  <nz-divider></nz-divider>
  <sv-container col="3" class="mt16">
    <sv-title>法人信息</sv-title>
    <sv label="法定代表人">
      <input nz-input type="text" [(ngModel)]="detailData.legalPersonIdentityVO.name" [readonly]="!isEdit"
        [nzBorderless]="!isEdit" [placeholder]="isEdit?'':'-'">
    </sv>
    <sv label="身份证号码">
      <input nz-input type="text" [(ngModel)]="detailData.legalPersonIdentityVO.certificateNumber" [readonly]="!isEdit"
        [nzBorderless]="!isEdit" [placeholder]="isEdit?'':'-'">
    </sv>
    <sv label="身份证有效期">
      <nz-date-picker [(ngModel)]="detailData.legalPersonIdentityVO.validStartTime" [nzDisabled]="!isEdit"
        nzPlaceHolder=" " [nzBorderless]="!isEdit" [nzSuffixIcon]="isEdit?'calendar':''" style="width: 100px;"
        class="calendar"></nz-date-picker>
      -
      <ng-container
        *ngIf="!isEdit && !detailData?.legalPersonIdentityVO?.validEndTime && detailData.legalPersonIdentityVO.validStartTime">
        <label style="padding-left: 11px;">长期</label>
      </ng-container>
      <nz-date-picker [(ngModel)]="detailData.legalPersonIdentityVO.validEndTime" [nzDisabled]="!isEdit"
        nzPlaceHolder=" " [nzBorderless]="!isEdit" [nzSuffixIcon]="isEdit?'calendar':''" style="width: 100px;"
        class="calendar"></nz-date-picker>
      <ng-container *ngIf="isEdit">
        <label nz-checkbox [ngModel]="!!!detailData.legalPersonIdentityVO.validEndTime"
          (ngModelChange)="$event?detailData.legalPersonIdentityVO.validEndTime='':''" class="ml-sm">长期</label>
      </ng-container>

    </sv>
    <sv label="身份证照" col="1">
      <div class="d-flex">
        <ng-container
          *ngTemplateOutlet="uploadTemplate;context:{data:detailData,status:isEdit,key:'licensePhotoWatermark',key2:'licensePhoto',hover:'detailPhoto'}">
        </ng-container>
        <ng-container
          *ngTemplateOutlet="uploadTemplate;context:{data:detailData?.legalPersonIdentityVO,status:isEdit,key:'certificatePhotoFrontWatermark',key2:'certificatePhotoFront',hover:'legalFront'}">
        </ng-container>
        <ng-container
          *ngTemplateOutlet="uploadTemplate;context:{data:detailData?.legalPersonIdentityVO,status:isEdit,key:'certificatePhotoBackWatermark',key2:'certificatePhotoBack',hover:'legalBack'}">
        </ng-container>
      </div>
    </sv>
  </sv-container>
  <nz-divider></nz-divider>
  <sv-container col="3" class="mt16">
    <sv-title>企业开票信息</sv-title>
    <sv label="开户银行">
      <input nz-input type="text" [(ngModel)]="detailData.createBank" [readonly]="!isEdit" [nzBorderless]="!isEdit"
        [placeholder]="isEdit?'':'-'">
    </sv>
    <sv label="银行账户">
      <input nz-input type="text" [(ngModel)]="detailData.bankAccount" [readonly]="!isEdit" [nzBorderless]="!isEdit"
        [placeholder]="isEdit?'':'-'">
    </sv>
    <sv label="注册电话">
      <input nz-input type="text" [(ngModel)]="detailData.registerPhone" [readonly]="!isEdit" [nzBorderless]="!isEdit"
        [placeholder]="isEdit?'':'-'">
    </sv>
    <sv label="注册地址">
      <input nz-input type="text" [(ngModel)]="detailData.registerAddress" [readonly]="!isEdit" [nzBorderless]="!isEdit"
        [placeholder]="isEdit?'':'-'">
    </sv>
  </sv-container>
</nz-card>

<ng-template #PopconfirmTempalte let-title="title" let-content="content">
  <div class="ant-popover-message">
    <i nz-icon nzType="info-circle" nzTheme="fill"></i>
    <div class="ant-popover-message-title ng-star-inserted self-ant-popover-title" style="font-size: 16px">{{title}}
    </div>
    <div class="ant-popover-message-title ng-star-inserted">
      {{content}}
    </div>
  </div>
</ng-template>

<ng-template #approvedModal>
  <div nz-row nzGutter="8">
    <div nz-col nzSpan="24" se-container [labelWidth]="120">
      <se [col]="1" label="公司名称">
        {{ detailData?.enterpriseName }}
      </se>
      <se [col]="1" label="网络货运人" required>
        <nz-select nzPlaceHolder="请选择" [(ngModel)]="networkTransporter">
          <nz-option [nzValue]="1" nzLabel="Jack"></nz-option>
          <nz-option [nzValue]="2" nzLabel="Lucy"></nz-option>
        </nz-select>
      </se>
    </div>
  </div>
</ng-template>

<ng-template #redectModal>
  <div nz-row nzGutter="8">
    <div nz-col nzSpan="24" se-container [labelWidth]="120">
      <se [col]="1" label="公司名称">
        {{ detailData?.enterpriseName }}
      </se>
      <se [col]="1" label="备注" required>
        <textarea nz-input rows="3" style="width: 325px;margin-left: 14px;" [(ngModel)]="approvalOpinion"></textarea>
      </se>
    </div>
  </div>
</ng-template>

<ng-template #uploadTemplate let-data="data" let-status="status" let-key="key" let-key2="key2" let-hover="hover">
  <nz-upload class="avatar-uploader" [nzAction]="uploadURl" nzName="multipartFile" nzListType="picture-card"
    [nzShowUploadList]="false" nzFileType="image/png,image/jpeg,image/jpg,image/gif"
    [nzDisabled]="!isEdit || disabledUpload" (nzChange)="changeUpload($event,data,key,key2)">
    <ng-container *ngIf="!data[key] && isEdit">
      <i class="upload-icon" nz-icon [nzType]="service.http.loading ? 'loading' : 'plus'"></i>
      <div class="ant-upload-text">上传</div>
    </ng-container>
    <div *ngIf="data[key]" (mouseover)="detailData[hover]=true" (mouseleave)="detailData[hover]=false"
      (click)="$event.cancelBubble=true" class="image-hover">
      <img [src]="data[key]" style="width: 200px;height: 160px;" (click)="service.showImg(data[key])" />
      <div class="mask" *ngIf="detailData[hover] && isEdit"></div>
      <div class="mask-over" *ngIf="detailData[hover] && isEdit">
        <i nz-icon nzType="close-circle" nzTheme="fill" class="delete-icon" (click)="deleteImg(data,key,key2)"></i>
        <div style="display: flex;align-items: center;">
          <i nz-icon nzType="eye" nzTheme="fill" class="show-icon" (click)="service.showImg(data[key])"></i>
        </div>
      </div>
    </div>
  </nz-upload>
</ng-template>