import webapi from "../webapi";

//////////////////three 组件//////////////////////////////////////////////

export function getCheckTree(reduce, gf, roleId) {
  return async (dispatch, getState) => {
    const checkTreeData = gf(["checkTreeData"]);
    const { entity } = gf(["treeSearchParam"]);
    const root = await webapi.getcheckTree(entity);
    if (root === undefined) return;
    reduce("checkTreeData", { type: "update", data: root });
  };
}

export function getCheckTreeChildren(reduce, gf, { functioinId, ...orther }) {
  return async (dispatch, getState) => {
    reduce("treeSearchParam", {
      type: "update_search_param",
      data: { pid: functioinId },
    });
    const { entity } = gf(["treeSearchParam"]);
    const res = await webapi.getcheckTree(entity);
    if (res === undefined) return null;
    reduce("checkTreeData", {
      type: "updateChildren",
      data: { children: res, functioinId, ...orther },
    });
    return res;
  };
}
