import webapi from "../webapi";

// 更新查询
export function roleSearch(reduce, gf, fields) {
  return async (dispatch, getState) => {
    // 更新查询数据
    reduce("roleSearchParam", { type: "update_search_param", data: fields });
    return [];
  };
}
// table数据
export function roleData(reduce, gf, param) {
  return async (dispatch, getState) => {
    let data = [];
    let pager = {};
    param = gf(["roleSearchParam"]);
    if (param) {
      let res = await webapi.roleData(param);
      data = res.data;
      pager = res.pager;
    }
    console.log(param, "role提交的查询条件");
    reduce("roleData", { type: "show-table", data: data });
    reduce("roleSearchParam", { type: "update_search_page", data: pager });
  };
}
//批量回收
export function deleteItems(reduce, gf, data) {
  return async (dispatch, getState) => {
    const param = [];
    data.filter((item) => {
      param.push(item.roleId);
      return item.roleId;
    });
    //批量回收接口。提交roleId参数
    let res = await webapi.roleData(param);
    reduce("roleData", { type: "show-table", data: res.data });
    reduce("roleSearchParam", { type: "update_search_page", data: res.pager });
  };
}
//批量分配
export function addItems(reduce, gf, data) {
  return async (dispatch, getState) => {
    const param = [];
    data.filter((item) => {
      param.push(item.roleId);
      return item.roleId;
    });
    console.log(param);
    //批量分配接口。提交roleId参数
    let res = await webapi.roleData(param);
    reduce("roleData", { type: "show-table", data: res.data });
    reduce("roleSearchParam", { type: "update_search_page", data: res.pager });
  };
}
