cellsysArt/wareHouseType.js
2025-02-25 09:47:45 +08:00

103 lines
2.8 KiB
JavaScript

import { CellsysMarkerStyle } from "@airkoon/cellsys/cellsysStyle";
import { EditTask, Query, QueryTask } from "./artUtil.js";
import { artApi } from "./artApi";
class WareHouseType {
constructor(params) {
if (!params) {
params = {};
}
this.id = params.id;
this.orgId = params.org_id;
this.name = params.name;
this.typeCount = params.type_count;
this.description = params.description;
this.style = params.style
? params.style
: CellsysMarkerStyle.getDefaultStyle();
let creator = params.creator;
this.creator = {
memberId: null,
name: null,
};
if (creator) {
this.creator = {
memberId: creator.member_id,
name: creator.name,
};
}
let updater = params.updater;
this.updater = {
memberId: null,
name: null,
};
if (updater) {
this.updater = {
memberId: updater.member_id,
name: updater.name,
};
}
}
static createWareHouseType(params) {
let editTask = new EditTask(artApi.wareHouseTypeInsert);
editTask.addParam("_name", params.name);
editTask.addParam("_description", params.description);
editTask.addParam("_style", params.style);
return editTask.execute();
}
static updateWareHouseType(params) {
let editTask = new EditTask(artApi.wareHouseTypeUpdate);
editTask.addParam("_id", params.id);
editTask.addParam("_name", params.name);
editTask.addParam("_description", params.description);
editTask.addParam("_style", params.style);
return editTask.execute();
}
static deleteWareHouseType(params) {
let editTask = new EditTask(artApi.wareHouseTypeDelete);
editTask.addParam("_id", params.id);
return editTask.execute();
}
static queryWareHouseType(pageInfo, filters, order) {
let query = new Query();
if (pageInfo) {
query.setCurrPage(pageInfo.currPage);
query.setPageSize(pageInfo.pageSize);
}
if (filters && filters.length > 0) {
filters.forEach((item) => {
query.addFilter(item["name"], item["operator"], item["value"]);
});
}
if (order) {
query.setOrder(order);
} else {
query.setOrder({ id: "desc" });
}
let queryTask = new QueryTask(artApi.viewWareHouseType, pageInfo);
return new Promise((resolve, reject) => {
queryTask
.execute(query)
.then((res) => {
if (pageInfo) {
if (res.data) {
res.data = res.data.map((item) => {
return new WareHouseType(item);
});
resolve(res);
}
} else {
let resArr = res.map((item) => {
return new WareHouseType(item);
});
resolve(resArr);
}
})
.catch((err) => {
reject(err);
});
});
}
}
export default WareHouseType;