import webapi from "../webapi";
//////////////////three 组件//////////////////////////////////////////////

export function treeSearch(reduce, gf, fields) {
  return async (dispatch, getState) => {
    // 更新查询数据
    reduce("treeSearchParam", { type: "update_search_param", data: fields });
    return [];
  };
}
export function getTreeData(reduce, gf, roleId) {
  return async (dispatch, getState) => {
    const { entity } = gf(["treeSearchParam"]);
    const root = await webapi.getTreeData(entity);
    if (root === undefined) return;
    reduce("treeData", { type: "update", data: root });
  };
}

export function getTreeChildrenData(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.getTreeData(entity);
    if (res === undefined) return null;
    reduce("treeData", {
      type: "updateChildren",
      data: { children: res, functioinId, ...orther },
    });
    return res;
  };
}
