import request, { downloadExcelRequest } from '../utils/request';
import { ResultList } from './types';
// 机构
export interface OrgFields {
  orgCode: string;
  orgName: string;
  orgPhone: string;
  orgLevel: string;
  orgDegree: string;
  personCount: string;
  partmentCount: string;
  bedCount: string;
  orgStatus: string;
  version: string;
  belProvince: string;
  belCity: string;
  belCountyarea: string;
  belTown: string;
  belVillages: string;
  belHousenum: string;
  orgDesc: string;
  manProvince: string;
  manCity: string;
  manCountyarea: string;
  manTown: string;
  manVillages: string;
  manHousenum: string;
  supOrgCode: string;
  orgResName: string;
  orgResPhone: string;
  orgType: string;
  orgClassCode: string;
  ecoClassCoecoClassCode: string;
  postCode: string;
  orgLongitude: string;
  orgLatitude: string;
  openingDate: string;
  orgFullName: string;
  registeredCapital: string;
  socialCreditCode: string;
}
// 列表
interface GetList_Params {
  pageNum?: string;
  pageSize?: string;
  orgName?: string;
  orgStatus?: string;
}
type ListResult = ResultList<OrgFields[]>;

/** 基础数据列表 */
export async function getListApi(data: Partial<GetList_Params>) {
  return request<Partial<ListResult>>({
    url: '/orginfo/list',
    method: 'get',
    params: data,
  });
}
// 详情列表
interface GetSupList_Params {
  uuid: string;
}
export async function getSupListApi(data: GetSupList_Params) {
  return request<Partial<ListResult>>({
    url: `/orgbase/${data.uuid}`,
    method: 'get',
    params: data,
  });
}

// 新增
type _Add_Params = Partial<OrgFields>;
export async function addApi(data: _Add_Params) {
  return request({
    url: '/orginfo',
    method: 'post',
    data,
  });
}
// 编辑
type _Update_Params = Partial<OrgFields>;
export async function updateApi(data: _Update_Params) {
  return request({
    url: '/orginfo/edit',
    method: 'post',
    data,
  });
}
/**
 * @name 导入
 * @param data
 * @returns
 */
export async function importOrg(data: FormData) {
  return request({
    url: '/orginfo/import',
    method: 'post',
    data,
  });
}

// 批量删除
export async function delApi(params: string) {
  return request({
    url: `/orginfo/delete/${params}`,
    method: 'get',
  });
}

// 批量操作
interface BatchProps {
  orgCodes: string;
  orgStatus: string;
}
export async function batchApi(params: BatchProps) {
  return request({
    url: '/orginfo/batch',
    method: 'post',
    params,
  });
}

type DomainValueType = {
  domainCode: string;
  standardId: string;
  pageNum: string;
  pageSize: string;
};
/**
 * @name 标准
 * @param domainCode
 * @param standardId
 * @returns
 */
export async function getDomainValueApi(data: DomainValueType) {
  return request({
    url: `/standard/domain_value/list`,
    method: 'get',
    params: data,
  });
}

export async function exportOrgApi() {
  return downloadExcelRequest(
    {
      url: '/orginfo/export',
      params: { tempOnly: 1 },
      method: 'post',
    },
    '机构模板',
  );
}
