import { defHttp } from '/@/utils/http/axios';
import { message } from 'ant-design-vue';
import { useGlobSetting } from '/@/hooks/setting';
const globSetting = useGlobSetting();
const baseUploadUrl = globSetting.uploadUrl;
enum Api {
  positionList = '/sys/position/list',
  userList = '/sys/user/list',
  roleList = '/sys/role/list',
  queryDepartTreeSync = '/sys/sysDepart/queryDepartTreeSync',
  queryTreeList = '/sys/sysDepart/queryTreeList',
  loadTreeData = '/sys/category/loadTreeData',
  loadDictItem = '/sys/category/loadDictItem/',
  getDictItems = '/sys/dict/getDictItems/',
  getTableList = '/sys/user/queryUserComponentData',
  getCategoryData = '/sys/category/loadAllData',
  getHylb = '/sys/api/tree/hylb',
}

// 获取地市行政区域
export const getTown = (params) => {
  if (params?.id)
    return defHttp.get({ url: `/sys/api/xzbm/${params.id}` });
  else
    return defHttp.get({ url: `/sys/api/xzbm/${params}` });
}
// 行政区域划分三级树形
export const cityTree = () => {
  return defHttp.get({ url: `/sys/api/tree/xzbm` })
}
// 字典
export const dict = (params) => {
  return defHttp.get({ url: `/sys/api/queryDictItemsByCode/${params.key}` });
}
// 行业类别
export const categoryList = () => {
  return defHttp.get({
    url: '/sys/api/tree/hylb'
  });
};
// 下达意见
export const xiadayijian = (params) => {
  return defHttp.post({ url: `/xiadayijian`, params });
};
// 地块所处阶段详情
export const plotDetails = (params) => {
  return defHttp.get({ url: `/dklc/dkdcxx`, params });
}
// 评审记录
export const reviewRecords = (params) => {
  return defHttp.get({ url: `/qdml/psjl`, params });
}
// 获取退改历史接口
export const history = (params) => {
  return defHttp.get({ url: `/qdml/psjl`, params });
}
// 方案列表
export const repairPlan = (params) => {
  return defHttp.get({ url: `/qdml/faList`, params });
}
//地块管理 里面的提交
export const submitWrdkdc = (params) => {
  return defHttp.post({ url: `/dklc/submitWrdkdc`, params });
}

// 判断调查类型是否为空
export const existDclx = (params) => {
  return defHttp.get({ url: `/dklc/existDclx`, params });
}
// 填报方式变更
export const updateDclx = (params) => {
  return defHttp.get({ url: `/dklc/updateDclx`, params });
}
// 修改地块填报方式
export const updateJbxx = (params) => {
  return defHttp.post({ url: `/dklc/updateJbxx`, params });
}
// 编制单位接口
export const updateBzdw = (params) => {
  return defHttp.post({ url: `/dklc/updateBzdw`, params });
}
// 删除编辑单位
export const delBzdw = (params) => {
  return defHttp.post({ url: `/dklc/delBzdw`, params });
}
// 检测单位接口
export const updateJcdw = (params) => {
  return defHttp.post({ url: `/dklc/updateJcdw`, params });
}
export const delJcdw = (params) => {
  return defHttp.post({ url: `/dklc/delJcdw`, params });
}
// 初步调查调查报告基本信息
export const updateCbdc = (params) => {
  return defHttp.post({ url: `/dklc/updateCbdc`, params });
}
// 初步调查调查报告基本信息
export const updateXxdc = (params) => {
  return defHttp.post({ url: `/dklc/updateXxdc`, params });
}
// 铭感受体接口
export const updateMgst = (params) => {
  return defHttp.post({ url: `/dklc/updateMgst`, params });
}
// 风险填报基本信息
export const saveGFxpg = (params) => {
  return defHttp.post({ url: `/dklc/saveGFxpg`, params });
}
// 风险评估环境土壤信息
export const saveGTrhjfxxx = (params) => {
  return defHttp.post({ url: `/dklc/saveGTrhjfxxx`, params });
}
// 获取方案列表
export const faList = (params) => {
  return defHttp.get({ url: `/dklc/faList`, params });
}
// 新增方案列表
export const addGkxf = (params) => {
  return defHttp.post({ url: `/dklc/addGkxf`, params });
}
// 删除方案列表
export const delGkxf = (params) => {
  return defHttp.post({ url: `/dklc/delGkxf`, params });
}
// 点击评审接口 不评审
export const psOrZxps = (params) => {
  return defHttp.post({ url: `/dklc/psOrZxps`, params });
}
// 地块管理土壤环境质量信息
export const updateTrhjzlxx = (params) => {
  return defHttp.post({ url: `/dklc/updateTrhjzlxx`, params });
};

// 风险管控与修复添加方案
export const addXgpg = (params) => {
  return defHttp.post({ url: `/dklc/addXgpg`, params });
};
// 风险管控与修复删除方案
export const delXgpg = (params) => {
  return defHttp.post({ url: `/dklc/delXgpg`, params });
};
// 添加管控与修复方案基本信息保存
export const saveGkxf = (params) => {
  return defHttp.post({ url: `/dklc/saveGkxf`, params });
};
// 效果评估保存
export const saveXgpg = (params) => {
  return defHttp.post({ url: `/dklc/saveXgpg`, params });
};
// 效果评估提交
export const submitXgpg = (params) => {
  return defHttp.post({ url: `/dklc/submitXgpg`, params });
};
// 申请地块退出
export const tcsq = (params) => {
  return defHttp.get({ url: `/dklc/tcsq`, params });
};
// 确认退出
export const qrtc = (params) => {
  return defHttp.post({ url: `/dklc/qrtc`, params });
};
// 地块退出
export const dktc = (params) => {
  return defHttp.get({ url: `/dklc/dktc`, params });
};
//退回无需评审
export const sendBack = (params) => {
  return defHttp.post({ url: `/dklc/sendBack`, params });
};
// 退回已评审
export const thyps = (params) => {
  return defHttp.post({ url: `/dklc/thyps`, params });
};
// 地块退回
export const back = (params) => {
  return defHttp.post({ url: `/dklc/back`, params });
};
// 地块调查退改历史
export const backHis = (params) => {
  return defHttp.get({ url: `/dklc/backHis`, params });
};
// 待确认
export const submiDqr = (params) => {
  return defHttp.post({ url: `/dklc/submiDqr`, params });
};

// 确认里面的历史
export const fhHis = (params) => {
  return defHttp.post({ url: `/dklc/fhHis`, params });
};

// 边界知道意见
export const bianjieyijian = (params) => {
  return defHttp.post({ url: `/bianjieyijian`, params });
};




/**
 * 上传父路径
 */
export const uploadUrl = `${baseUploadUrl}sys/common/upload`;

/**
 * 职务列表
 * @param params
 */
export const getPositionList = (params) => {
  return defHttp.get({ url: Api.positionList, params });
};

/**
 * 用户列表
 * @param params
 */
export const getUserList = (params) => {
  return defHttp.get({ url: Api.userList, params });
};

/**
 * 角色列表
 * @param params
 */
export const getRoleList = (params) => {
  return defHttp.get({ url: Api.roleList, params });
};

/**
 * 异步获取部门树列表
 */
export const queryDepartTreeSync = (params?) => {
  return defHttp.get({ url: Api.queryDepartTreeSync, params });
};
/**
 * 获取部门树列表
 */
export const queryTreeList = (params?) => {
  return defHttp.get({ url: Api.queryTreeList, params });
};

/**
 * 分类字典树控件 加载节点
 */
export const loadTreeData = (params?) => {
  return defHttp.get({ url: Api.loadTreeData, params });
};

/**
 * 根据字典code加载字典text
 */
export const loadDictItem = (params?) => {
  return defHttp.get({ url: Api.loadDictItem, params });
};

/**
 * 根据字典code加载字典text
 */
export const getDictItems = (dictCode) => {
  return defHttp.get({ url: Api.getDictItems + dictCode }, { joinTime: false });
};
/**
 * 部门用户modal选择列表加载list
 */
export const getTableList = (params) => {
  return defHttp.get({ url: Api.getTableList, params });
};
/**
 * 加载全部分类字典数据
 */
export const loadCategoryData = (params) => {
  return defHttp.get({ url: Api.getCategoryData, params });
};
/**
 * 行业类别
 */
export const getHylb = (params) => {
  return defHttp.get({ url: Api.getHylb, params });
};
/**
 * 文件上传
 */
export const uploadFile = (params, success) => {
  return defHttp.uploadFile({ url: uploadUrl }, params, { success });
};


/**
 * 下载文件
 * @param url 文件路径
 * @param fileName 文件名
 * @param parameter
 * @returns {*}
 */
export const downloadFile = (url, fileName?, parameter?) => {
  return getFileblob(url, parameter).then((data) => {
    if (!data || data.size === 0) {
      message.warning('文件下载失败');
      return;
    }
    if (typeof window.navigator?.msSaveBlob !== 'undefined') {
      window.navigator?.msSaveBlob(new Blob([data]), fileName);
    } else {
      let url = window.URL.createObjectURL(new Blob([data]));
      let link = document.createElement('a');
      link.style.display = 'none';
      link.href = url;
      link.setAttribute('download', fileName);
      document.body.appendChild(link);
      link.click();
      document.body.removeChild(link); //下载完成移除元素
      window.URL.revokeObjectURL(url); //释放掉blob对象
    }
  });
};

/**
 * 下载文件 用于excel导出
 * @param url
 * @param parameter
 * @returns {*}
 */
export const getFileblob = (url, parameter) => {
  return defHttp.get(
    {
      url: url,
      params: parameter,
      responseType: 'blob',
    },
    { isTransformResponse: false }
  );
};

/**
 * 【用于评论功能】自定义文件上传-方法
 */
export const uploadMyFile = (url, data) => {
  return defHttp.uploadMyFile(url, data);
};
