65 lines
2.0 KiB
JavaScript
65 lines
2.0 KiB
JavaScript
import { EditTask } from './artUtil.js';
|
|
import { artApi } from './artApi';
|
|
import ArtImage from './artImage';
|
|
|
|
class Material {
|
|
constructor(params) {
|
|
if (!params) {
|
|
params = {};
|
|
}
|
|
this.id = params.id;
|
|
this.name = params.name;
|
|
this.description = params.description;
|
|
this.images = [];
|
|
if (params.images) {
|
|
this.images = params.images.map((url) => {
|
|
return new ArtImage(url);
|
|
});
|
|
}
|
|
this.materialTypeId = params.material_type_id; //材料类型ID
|
|
this.materialType = params.material_type;
|
|
this.creator = params.creator;
|
|
this.updater = params.updater;
|
|
this.createTime = params.create_time;
|
|
this.updateTime = params.update_time;
|
|
}
|
|
//封面图(表格展示缩略图)
|
|
get compressionUrl() {
|
|
if (this.images && this.images.length > 0) {
|
|
return this.images[0].compressionUrl;
|
|
}
|
|
}
|
|
get imageUrl() {
|
|
if (this.images && this.images.length > 0) {
|
|
return this.images[0].url;
|
|
}
|
|
}
|
|
updateMaterial(params) {
|
|
let { name, description, images } = params;
|
|
let editTask = new EditTask(artApi.materialUpdate);
|
|
editTask.addParam('_id', this.id);
|
|
editTask.addParam('_description', description);
|
|
editTask.addParam('_name', name);
|
|
editTask.addParam('_images', images);
|
|
return new Promise((resolve, reject) => {
|
|
editTask
|
|
.execute()
|
|
.then((res) => {
|
|
if (res.data) {
|
|
let material = new Material(res.data);
|
|
resolve(material);
|
|
}
|
|
})
|
|
.catch((err) => {
|
|
reject(err);
|
|
});
|
|
});
|
|
}
|
|
deleteMaterial(params) {
|
|
let editTask = new EditTask(artApi.materialDelete);
|
|
editTask.addParam('_id', this.id);
|
|
return editTask.execute();
|
|
}
|
|
}
|
|
export default Material;
|