import { EditTask, Query, QueryTask } from "./artUtil"; import { artApi } from "./artApi"; import Disease from "./disease"; class ArtCategory { constructor(params = {}) { this.code = params.code; this.createBy = params.create_by; this.createTime = params.create_time; this.description = params.description; this.hasChild = params.has_child; this.id = params.id; this.name = params.name; this.parentId = params.parent_id; this.sort = params.sort; this.updateBy = params.update_by; this.updateTime = params.update_time; } //更新分类字典信息 updateArtCategory(params = {}) { let editTask = new EditTask(artApi.cellsysSysDictCategoryUpdate); editTask.addParam("_parent_id", 1); //这里分类字典的parentId固定是1,为艺术品类别 editTask.addParam("_id", this.id); editTask.addParam("_code", params.code); editTask.addParam("_name", params.name); editTask.addParam("_sort", params.sort); editTask.addParam("_description", params.description); return new Promise((resolve, reject) => { editTask .execute() .then((res) => { if (res.data) { let artRepairFile = new ArtCategory(res.data); resolve(artRepairFile); } }) .catch((err) => { reject(err); }); }); } //删除分类字典 removeArtCategory() { let editTask = new EditTask(artApi.cellsysSysDictCategoryDelete); editTask.addParam("_id", this.id); return new Promise((resolve, reject) => { editTask .execute() .then((res) => { resolve(res); }) .catch((err) => { reject(err); }); }); } //查询病害记录 queryDisease(params = {}) { let query = new Query(); let { pageInfo, order, filter } = params; if (filter) { filter.forEach((item) => { query.addFilter(item["name"], item["operator"], item["value"]); }); } query.addFilter("category_id", "=", this.id); //病害报告模板 let queryTask = new QueryTask(artApi.viewDisease, !!pageInfo); return new Promise((resolve, reject) => { queryTask .execute(query) .then((res) => { if (pageInfo) { if (res.data) { res.data = res.data.map((item) => { return new Disease(item); }); resolve(res); } } else { let resArr = res.map((item) => { return new Disease(item); }); resolve(resArr); } }) .catch((err) => { reject(err); }); }); } //新增病害 createDisease(params = {}) { let editTask = new EditTask(artApi.diseaseInsert); editTask.addParam("_name", params.name); editTask.addParam("_description", params.description); editTask.addParam("_style", params.style); editTask.addParam("_image", params.image); editTask.addParam("_category_id", this.id); return new Promise((resolve, reject) => { editTask .execute() .then((res) => { if (res.data) { let disease = new Disease(res.data); resolve(disease); } }) .catch((err) => { reject(err); }); }); } } export default ArtCategory;