import { artApi } from './artApi'; import { Query, QueryTask, EditTask } from './artUtil'; import EquipmentData from './equipmentData'; import ArtSystem from './artSystem'; class Equipment { constructor(params) { if (!params) { params = {}; } this.id = params.id; this.name = params.name; this.description = params.description; this.equipmentTypeId = params.type_id; this.manufacturers = params.manufacture; //厂商 this.serialNumber = params.number; //SN码--设备编号 this.equipmentModel = params.model; //设备型号 this.laboratoryId = params.laboratory_id; //实验室id if (params.artwork_equipment_type) { let { name, chart_option, data_type } = params.artwork_equipment_type; this.equipmentTypeName = name; this.chartConfiguration = chart_option; this.dataType = data_type; } this.dataType = params.data_type||0; 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.creator = params.creator; this.updater = params.updater; this.createTime = params.create_time; this.updateTime = params.update_time; } updateEquipment(params = {}) { let editTask = new EditTask(artApi.equipmentUpdate); editTask.addParam('_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.laboratoryId); editTask.addParam('_name', params.name); editTask.addParam('_data_type', params.dataType); editTask.addParam('_chart_option', params.chartConfiguration); return new Promise((resolve, reject) => { editTask .execute() .then((res) => { if (res.data) { let materialType = new Equipment(res.data); resolve(materialType); } }) .catch((err) => { reject(err); }); }); } deleteEquipment(params) { let editTask = new EditTask(artApi.equipmentDelete); editTask.addParam('_id', this.id); return editTask.execute(); } createEquipmentData(params) { let editTask = new EditTask(artApi.artworkEquipmentDataInsert); editTask.addParam('_equipment_id', this.id); editTask.addParam('_images', params.images); editTask.addParam('_name', params.name); editTask.addParam('_data', params.data); editTask.addParam('_material_id', params.materialId); editTask.addParam('_remarks', params.remarks); editTask.addParam('_date_time', params.dateTime); editTask.addParam('_geometry', params.geometry); return new Promise((resolve, reject) => { editTask .execute() .then((res) => { if (res.data) { let materialType = new EquipmentData(res.data); resolve(materialType); } }) .catch((err) => { reject(err); }); }); } //获取设备所在实验室信息 queryLaboratory(params = {}) { let { filter, pageInfo } = params; if (!filter) { filter = []; } filter.push({ name: 'id', operator: '=', value: this.laboratoryId, }); return ArtSystem.queryLaboratoryList({ filter, pageInfo }); } //查询设备数据 queryEquipmentDatas(params = {}) { let { filter, pageInfo } = params; if (!filter) { filter = []; } filter.push({ name: 'equipment_id', operator: '=', value: this.id, }); return ArtSystem.viewArtworkEquipmentData({ filter, pageInfo }); } } export default Equipment;