102 lines
3.4 KiB
JavaScript
102 lines
3.4 KiB
JavaScript
import { EditTask } from './artUtil';
|
|
import { artApi } from './artApi';
|
|
import Equipment from './equipment';
|
|
|
|
class ArtworkEquipmentType {
|
|
constructor(params) {
|
|
if (!params) {
|
|
params = {};
|
|
}
|
|
this.id = params.id;
|
|
this.name = params.name;
|
|
this.description = params.description;
|
|
this.dataType = params.data_type;
|
|
|
|
if (params.chart_option) {
|
|
this.chartConfiguration = {
|
|
type: '折线图',
|
|
xAxis: params.chart_option.xAxis,
|
|
yAxis: params.chart_option.yAxis,
|
|
};
|
|
} else {
|
|
this.chartConfiguration = {
|
|
type: '折线图',
|
|
xAxis: {
|
|
key: null,
|
|
unit: null,
|
|
},
|
|
yAxis: {
|
|
key: null,
|
|
unit: null,
|
|
},
|
|
};
|
|
}
|
|
this.equipmentCount = params.equipment_count || 0;
|
|
this.style = params.style;
|
|
this.tags = [];
|
|
if (params.tag_name) {
|
|
this.tags = params.tag_name.map((item) => {
|
|
return { name: item };
|
|
});
|
|
}
|
|
this.creator = params.creator;
|
|
this.updater = params.updater;
|
|
this.createTime = params.create_time;
|
|
this.updateTime = params.update_time;
|
|
}
|
|
updateEquipmentType(params) {
|
|
let { name, description, style, tags, dataType, chartConfiguration } = params;
|
|
let editTask = new EditTask(artApi.equipmentTypeUpdate);
|
|
editTask.addParam('_id', this.id);
|
|
editTask.addParam('_description', description);
|
|
editTask.addParam('_name', name);
|
|
editTask.addParam('_style', style);
|
|
editTask.addParam('_data_type', dataType);
|
|
editTask.addParam('_chart_option', chartConfiguration);
|
|
|
|
return new Promise((resolve, reject) => {
|
|
editTask
|
|
.execute()
|
|
.then((res) => {
|
|
if (res.data) {
|
|
let materialType = new ArtworkEquipmentType(res.data);
|
|
resolve(materialType);
|
|
}
|
|
})
|
|
.catch((err) => {
|
|
reject(err);
|
|
});
|
|
});
|
|
}
|
|
deleteEquipmentType(params) {
|
|
let editTask = new EditTask(artApi.equipmentTypeDelete);
|
|
editTask.addParam('_id', this.id);
|
|
return editTask.execute();
|
|
}
|
|
createEquipment(params) {
|
|
let editTask = new EditTask(artApi.equipmentInsert);
|
|
editTask.addParam('_type_id', this.id);
|
|
editTask.addParam('_description', params.description);
|
|
editTask.addParam('_manufacture', params.manufacturers);
|
|
editTask.addParam('_number', params.serialNumber);
|
|
editTask.addParam('_model', params.equipmentModel);
|
|
editTask.addParam('_laboratory_id', params.laboratoryAddress);
|
|
editTask.addParam('_name', params.name);
|
|
|
|
return new Promise((resolve, reject) => {
|
|
editTask
|
|
.execute()
|
|
.then((res) => {
|
|
if (res.data) {
|
|
let equipment = new Equipment(res.data);
|
|
resolve(equipment);
|
|
}
|
|
})
|
|
.catch((err) => {
|
|
reject(err);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
export default ArtworkEquipmentType;
|