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 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":[],', ""));
    }
  }
};
