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 { UsermanageService } from '../../../../services/usercenter.service';

@Component({
  selector: 'app-supplier-components-list-view',
  templateUrl: './detail.component.html',
  styleUrls: ['./detail.component.less']
})
export class FreightComponentsListDetailComponent implements OnInit {
  detailData: any;
  suppliersData: any = {};

  constructor(public service: UsermanageService, private route: ActivatedRoute) {}

  ngOnInit() {
    this.initData();
  }
  initData() {
    this.service
      .request(this.service.$api_get_freight_detail, {
        id: this.route.snapshot.params.id
      })
      .subscribe(res => {
        if (res) {
          this.detailData = res;
        }
        console.log(res);
      });
    // // 商品资质
    // if (res.enterpriseBusinessJson) {
    //   res.enterpriseBusinessJson.aptitudes = res.enterpriseBusinessJson?.aptitudes ? res.enterpriseBusinessJson.aptitudes.split(',') : [];
    // }
    // // // 申请人身份证证件
    // // res.applyUserJson.imagelist = [];
    // // res.applyUserJson.imagelist.push(res.applyUserJson.certificatePhotoFront);
    // // res.applyUserJson.imagelist.push(res.applyUserJson.certificatePhotoBack);
    // // res.applyUserJson.imagelist.push(res.applyUserJson.handCertificate);

    // 法人身份证证件
    // const imagelist = [];
    // imagelist.push(res?.certificatePhotoFront);
    // imagelist.push(res?.certificatePhotoBack);
    // res.certificatePhoto = imagelist;

    // // 营业执照
    // res.enterpriseQualificationCertificate = res.enterpriseQualificationCertificate
    //   ? res.enterpriseQualificationCertificate.split(',')
    //   : [];

    // // 返回所在地
    // res.enterpriseAddressCodeStr = await this.getRegionFullName(res.enterpriseAddressCode);

    // this.detailData = res;
    // this.suppliersData = {
    //   suppliersType: res?.suppliersType,
    //   externalSuppliersId: res?.externalSuppliersId
    // };
  }

  /**
   * 根据地区code查询地区详情
   * @param code 地区代码
   */
  async getRegionFullName(code: any) {
    const params = {
      regionCode: code
    };
    const res = await this.service.asyncRequest(this.service.$api_get_one, params, 'POST', true);
    // if (res && res.regionFullName) {
    //   const arr = res.regionFullName.split(',');
    //   res.regionFullName = arr.reverse().join('-');
    // }
    return res && res.regionFullName;
  }
  goBack() {
    window.history.go(-1);
  }
  /**
   * 冻结
   */
  freezeOrResume(type: number) {
    this.service.http
      .post(this.service.$api_lock_freight, {
        id: this.route.snapshot.params.id,
        statedLocked: !!type
      })
      .subscribe(res => {
        if (res.data === true) {
          if (type === 1) {
            this.service.msgSrv.success(`启用成功！`);
          } else {
            this.service.msgSrv.success(`冻结成功！`);
          }
          this.initData();
        } else {
          this.service.msgSrv.error(res.msg || '操作失败！');
        }
      });
  }

  /**
   * 支付权限
   */
  PayOrResume(type: number) {
    this.service.http
      .post(this.service.$api_lock_freight, {
        id: this.route.snapshot.params.id,
        statedLocked: !!type
      })
      .subscribe(res => {
        if (res.data === true) {
          if (type === 1) {
            this.service.msgSrv.success(`开启成功！`);
          } else {
            this.service.msgSrv.success(`关闭成功！`);
          }
          this.initData();
        } else {
          this.service.msgSrv.error(res.msg || '操作失败！');
        }
      });
  }
}
