import { EditTask } from "./artUtil.js"; import { artApi } from "./artApi"; import Material from "./material"; class MaterialType { constructor(params) { if (!params) { params = {}; } this.id = params.id; this.name = params.name; this.description = params.description; this.materialCount = params.material_count || 0; this.creator = params.creator; this.updater = params.updater; this.createTime = params.create_time; this.updateTime = params.update_time; } updateMaterialType(params) { let { name, description } = params; let editTask = new EditTask(artApi.materialTypeUpdate); editTask.addParam("_id", this.id); editTask.addParam("_description", description); editTask.addParam("_name", name); return new Promise((resolve, reject) => { editTask .execute() .then((res) => { if (res.data) { let materialType = new MaterialType(res.data); resolve(materialType); } }) .catch((err) => { reject(err); }); }); } deleteMaterialType(params) { let editTask = new EditTask(artApi.materialTypeDelete); editTask.addParam("_id", this.id); return editTask.execute(); } //新增材料 createMaterial(params) { let editTask = new EditTask(artApi.materialInsert); editTask.addParam("_material_type_id", this.id); editTask.addParam("_name", params.name); editTask.addParam("_description", params.description); editTask.addParam("_images", params.images); return new Promise((resolve, reject) => { editTask .execute() .then((res) => { if (res.data) { let materialType = new Material(res.data); resolve(materialType); } }) .catch((err) => { reject(err); }); }); } } export default MaterialType;