import { post } from "@/request/axios.js";
import { useUserStore } from "@/pinia/user.js";
import pinia from "@/pinia/index.js";
import { layoutFnGetEveryProvinceHiddenDangerType } from "@/assets/js/data_dictionary.js";

// 获取数据字典
export const getLevels = (params) =>
  post("/dictionaries/getLevels", {
    loading: false,
    ...params,
  });
// 获取数据字典
export const getLevelsCorp = (params) =>
  post("/dictionariesCorp/getLevels", {
    loading: false,
    ...params,
  });
// 获取数据字典
export const getLevelsByParentId = (params) =>
  post("/dictionaries/listDictToParId", {
    loading: false,
    ...params,
  });
// 获取数据字典包括子级数量
export const getLevelsAndChildrenNumber = (params) =>
  post("/dictionaries/getLevelsAndSCount", {
    loading: false,
    ...params,
  });
// 监管类型
export const getRegulatoryType = (params) =>
  post("/corptype/corptypelist", {
    loading: false,
    ...params,
  });
// 获取用户
export const getUserListAllByCorp = (params) =>
  post("/user/listUserByCorp", {
    loading: false,
    ...params,
  });
// 部门树 有限制只有主账号能选子集
export const getDepartmentTree = (params) =>
  post("/department/listTree", {
    loading: false,
    ...params,
  });
// 部门树
export const getDepartmentzTree = (params) =>
  post("/department/listzTree", {
    loading: false,
    ...params,
  });
// 电子围栏树
export const getElectronicFenceTree = (params) =>
  post("/electronicfence/listTree", {
    loading: false,
    ...params,
  });
// 下拉选择树
export const getListSelectTree = (params) =>
  post("/dictionaries/listSelectTree", {
    loading: false,
    ...params,
  });
// 获取岗位
export const getPostListAll = (params) =>
  post("/post/listAll", {
    loading: false,
    ...params,
  });
// 获取用户
export const getUserListAll = (params) =>
  post("/user/listAll", {
    loading: false,
    ...params,
  });

// 获取当前用户省隐患类型
export const getHiddenDangerType = async () => {
  const userStore = useUserStore(pinia);
  const { value } = await layoutFnGetEveryProvinceHiddenDangerType();
  for (let i = 0; i < value.length; i++) {
    if (value[i].BIANMA.indexOf(userStore.getUserInfo.PROVINCE) > -1) {
      const resData = await post("/dictionaries/listAllDictToParId", {
        parentId: value[i].DICTIONARIES_ID,
        loading: false,
      });
      return JSON.parse(resData.zTreeNodes.replaceAll('"nodes":[],', ""));
    }
  }
};
export const getVehicleColor = (params) =>
  post("/dictionaries/getVehicleColor", {
    loading: false,
    ...params,
  });

export const getTransportationEnterprise = (params) =>
  post("/dictionaries/getTransportationEnterprise", {
    loading: false,
    ...params,
  });

export const getNetworkStatus = (params) =>
  post("/dictionaries/getNetworkStatus", {
    loading: false,
    ...params,
  });

export const getDynamicSupervision = (params) =>
  post("/dictionaries/getDynamicSupervision", {
    loading: false,
    ...params,
  });

export const getActiveSafety = (params) =>
  post("/dictionaries/getActiveSafety", {
    loading: false,
    ...params,
  });

export const getLicenseStatus = (params) =>
  post("/dictionaries/getLicenseStatus", {
    loading: false,
    ...params,
  });

// 获取数据字典-检查类别
export const getStandardLevels = () =>
  post("/hiddenstandardDictionary/list", {
    loading: false,
  });
// 培训类型
export const getTrainingType = (params) =>
  post("/trainingtype/privateList", {
    loading: false,
    ...params,
  });
// 行业类型
export const getIndustryType = (params) =>
  post("/industrytype/getIndustryTree", {
    loading: false,
    ...params,
  });
// 岗位类型
export const getPostType = (params) =>
  post("/posttype/listAll", {
    loading: false,
    ...params,
  });
// 培训级别
export const getTrainingLevel = (params) =>
  post("/trainleveltype/listAll", {
    loading: false,
    ...params,
  });
