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',
  check = '/dkcx/save',
  checkList = '/dkcx/findList',
  tbzjxx = '/zjcq/tbzjxx',
  getDkDetail = '/qdml/getDkDetail', //获取当前地块所处阶段的
  codeLogin = '/sys/oauth/token'

}

export const check = (params) => defHttp.post({ url: Api.check, params }); // 确认抽查
export const checkList = (params) => defHttp.get({ url: Api.checkList, params }); // 确认列表
export const getDkDetail = (params) => defHttp.get({ url: Api.getDkDetail, params }); // 确认列表

export const tokenLogin = (params) => {
  return defHttp.get({ url: Api.codeLogin, params })
}

// 加密码
export const encryptData = (params) => {
  return defHttp.get({ url: '/encryptData', params })
}
// 解密
export const decryptData = (params) => {
  return defHttp.get({ url: '/decryptData', params })
}

// 评审材料上传
export const tbzjxx = (params) => {
  return defHttp.get({ url: Api.tbzjxx, params })
}

// 获取地市行政区域
export const getTown = (params) => {
  if (params instanceof Object) {
    if (params?.id) {
      return defHttp.get({ url: `/sys/api/xzbm/${params.id}` });
    }
  } else if (typeof params === 'number' || typeof params === 'string') {
    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 updatePassword = (params) => {
  return defHttp.post({
    url: '/sys/user/updatePassword', params
  });
};

// 下达意见
export const xiadayijian = (params) => {
  return defHttp.post({ url: `/dklc/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.post({ 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: `/dklc/bianjieyijian`, params });
};
// 退回或者受理
export const submiSlyj = (params) => {
  return defHttp.post({ url: `/dklc/submiSlyj`, params });
};
// 预受理
export const submiYsl = (params) => {
  return defHttp.post({ url: `/dklc/submiYsl`, params });
};
// 查看是否有预受理
export const findYsl = (params) => {
  return defHttp.get({ url: `/dklc/findYsl`, params });
};


// 初步调查污染信息列表
export const getWrwList = (params) => {
  return defHttp.get({ url: `/dklc/getWrwList`, params });
};
// 初步调查污染信息新增
export const addWrw = '/dklc/addWrw';
// 删除初步调查西信息
export const deleteWrw = (params) => {
  return defHttp.get({ url: `/dklc/deleteWrw`, params });
};

// 点位信息获取
export const getHjjcList = (params) => {
  return defHttp.get({ url: `/dklc/getHjjcList`, params });
};

// 添加环境污染信息上传接口
export const addHjjc = '/dklc/addHjjc';

// 点位上传附件
export const updateHjjc = (params) => {
  return defHttp.post({ url: `/dklc/updateHjjc`, params });
};
// 点位信息删除
export const deleteHjjc = (params) => {
  return defHttp.get({ url: `/dklc/deleteHjjc`, params });
};

// 点位信息全部删除
export const deleteHjjcAll = (params) => {
  return defHttp.get({ url: `/dklc/deleteHjjcAll`, params });
};

// 获取样品信息
export const getJcypList = (params) => {
  return defHttp.get({ url: `/dklc/getJcypList`, params });
};
// 样品信息附件上传
export const updateJcyp = (params) => {
  return defHttp.post({ url: `/dklc/updateJcyp`, params });
};
// 样品信息删除
export const deleteJcyp = (params) => {
  return defHttp.get({ url: `/dklc/deleteJcyp`, params });
};

// 获取样点信息
export const getJcypInfoList = (params) => {
  return defHttp.get({ url: `/dklc/getJcypInfoList`, params });
};
// 获取污染信息模板接口
export const wrwmb = '/dklc/wrwmb';

// 抽查中土地使用权人上传材料
// 地块退回
export const updateCx = (params) => {
  return defHttp.post({ url: `/dkcx/updateCx`, params });
};
//查询是否存在污染土壤外运处置

export const isSfczwrtrwycz = (params) => {
  return defHttp.get({ url: `/dklc/isSfczwrtrwycz`, params });
};
// 更新是否存在污染土壤外运处置
export const updateSfczwrtrwycz = (params) => {
  return defHttp.post({ url: `/dklc/updateSfczwrtrwycz`, params });
};
// 检验效果评填报
export const checkXgpgTb = (params) => {
  return defHttp.get({ url: `/dklc/checkXgpgTb`, params });
};

// 检验效果评估退出
export const checkXgpgTc = (params) => {
  return defHttp.get({ url: `/dklc/checkXgpgTc`, params });
};

// 预览边界地图
export const getScjdShp = (params) => {
  return defHttp.get({ url: `/dklc/getScjdShp`, params });
};
// 上传边界文件的保存之前调用
export const checkShp = (params) => {
  return defHttp.post({ url: `/dklc/checkShp`, params });
};

// 上传边界文件侯获取的数据
export const saveBjxx = (params) => {
  return defHttp.post({ url: `/dklc/saveBjxx`, 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 }
  );
};

/**
 * 下载ZIP文件
 * @param url 文件路径
 * @param parameter
 * @returns {*}
 */
export function downloadFileBacth(url, 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], { type: "application/zip" }), parameter.fileName)
    } else {
      let url = window.URL.createObjectURL(new Blob([data], { type: "application/zip" }))
      let link = document.createElement('a')
      link.href = url
      link.setAttribute('download', '批量下载')
      document.body.appendChild(link)
      link.click()
      document.body.removeChild(link) //下载完成移除元素
      window.URL.revokeObjectURL(url) //释放掉blob对象
    }
  })
}


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