import request from '@/utils/request';

//条件查询工厂
// export async function getFactoryarea(params) {
//   const res = await request.get(`/main/factoryarea/page`, {
//     params
//   });
//   if (res.data.code == 0) {
//     return res.data.data;
//   }
//   return Promise.reject(new Error(res.data.message));
// }

// // 仓储管理-仓库信息的保存
// export async function warehouseSave(data) {
//   return request.post('/warehouseGoodsshelves/newWarehouse/save', data);
// }
export default {
  //条件查询工厂
  getFactoryarea: async (params) => {
    const res = await request.get('/main/factoryarea/page', { params });
    if (res.data.code == 0) {
      return res.data.data;
    }
    return Promise.reject(new Error(res.data.message));
  },
  // /wms/warehouse/page
  //获取部门
  tree: async () => {
    // const res = await request.get('/wms/warehouse/getTrees');
    const res = await request.get('/main/group/getGroupList');
    // /wms/warehouse/getTrees
    if (res.data.code == 0) {
      return res.data.data;
    }
    return Promise.reject(new Error(res.data.message));
  },
  //根据部门获取员工
  getUserPage: async (params) => {
    const res = await request.get('/main/user/getUserPage', { params });
    if (res.data.code == 0) {
      return res.data.data;
    }
    return Promise.reject(new Error(res.data.message));
  },
  //仓库定义列表
  list: async (params) => {
    const res = await request.post(
      '/wms/warehouse/select/warehouseList',
      params
    );
    if (res.data.code == 0) {
      return res.data.data;
    }
  },
  //新增和修改
  save: function (data) {
    return request.post('/wms/warehouse/saveNew', data);
  },

  //新增库区
  warehouseareaSave: async (data) => {
    const res = await request.post('/wms/warehouse/save', data);

    return res;
  },
  //新增仓库
  saveOrUpdateWarehouse: async (data) => {
    const res = await request.post(
      '/wms/warehouse/saveOrUpdateWarehouse',
      data
    );

    return res;
  },
  //修改货位状态是不是满的
  warehouseChangeStatus: async (data) => {
    const res = await request.put(
      '/wms/warehouseareagoodsshelvesallocation/update',
      data
    );
    if (res.data.code == 0) {
      return res.data.message;
    }
  },
  //删除
  delete: async (id) => {
    const res = await request.get(`/wms/warehouse/delete/${id}`);
    if (res.data.code == 0) {
      return res.data.message;
    }
  },
  //删除
  isDelete: async (id) => {
    const res = await request.get('/wms/warehouse/isDelete/' + id);
    if (res.data.code == 0) {
      return res.data.data;
    }
  },
  //根据ID获取
  getById: async (params) => {
    const res = await request.get(`/wms/warehouse/getById/${params.id}`, {});
    if (res.data.code == 0) {
      return res.data.data;
    }
  },
  //详情
  info: function (params) {
    return request.get('/main/org/info/info', { params });
  },
  //树
  // tree: function (params) {
  //     return http.asyncCall("/main/org/dept/tree", params,'get')
  // },

  //查询仓库详情

  warehouseDetail: async (warehouseId) => {
    const res = await request.post(
      `/wms/warehouse/warehouseDetail/${warehouseId}`
    );
    if (res.data.code == 0) {
      return res.data.data;
    }
  },
  //根据仓库查询库区
  getListByWarehouseId: async (id) => {
    const res = await request.get(
      `/wms/warehousearea/getListByWarehouseId/${id}`,
      {}
    );
    if (res.data.code == 0) {
      return res.data.data;
    }
  },
  //根据库区查货架
  getListByAreaId: async (id) => {
    const res = await request.get(
      `/wms/warehouseareagoodsshelves/getListByAreaId/${id}`
    );
    if (res.data.code == 0) {
      return res.data.data;
    }
  },
  //根据货架查货位
  getListByGoodId: async (goodId) => {
    const res = await request.get(
      `/wms/warehouseareagoodsshelvesallocation/getListByGoodId/${goodId}`
    );
    if (res.data.code == 0) {
      return res.data.data;
    }
  }
};
