cellsysArt/artRepairPlan.js

129 lines
4.5 KiB
JavaScript

import ArtImage from './artImage';
import { formatterMillisecond } from './utils/date';
import { EditTask, Query, QueryTask } from './artUtil.js';
import { artApi } from './artApi';
import { artRepairPlanStatus } from './artEnum';
import RepairPlanAudit from './repairPlanAudit';
class ArtRepairPlan {
constructor(params = {}) {
this.id = params.id;
this.name = params.name;
this.repairRecordId = params.repair_record_id;
this.repairNodes = params.repair_nodes;
this.creatorSignatureImage = params.creator_signature_image;
this.status = params.status;
this.creator = params.creator;
this.updater = params.updater;
this.createTime = params.create_time;
this.updateTime = params.update_time;
this.artworkRecord = {
artworkRecordId: params.artwork_record_id, //关联的艺术品id
};
if (params.artwork_record) {
let { record_number, old_name, images } = params.artwork_record;
this.artworkRecord['recordNumber'] = record_number;
this.artworkRecord['oldName'] = old_name;
this.artworkRecord['artworkImages'] = images.map((url) => {
return new ArtImage(url);
});
}
}
//艺术品封面图
get coverImageUrl() {
if (this.artworkRecord && this.artworkRecord['artworkImages'].length > 0) {
return this.artworkRecord['artworkImages'][0].compressionUrl;
}
}
//艺术品封面图
get oldNameFormat() {
return `${this.artworkRecord['oldName']}`;
}
get createTimeFormat() {
return formatterMillisecond(this.createTime);
}
get updateTimeFormat() {
return formatterMillisecond(this.updateTime);
}
get statusMsg() {
return artRepairPlanStatus[this.status];
}
updateRepairPlan(params = {}) {
let editTask = new EditTask(artApi.repairPlanUpdate);
editTask.addParam('_id', this.id);
editTask.addParam('_repair_record_id', params.repairRecordId);
editTask.addParam('_name', params.name);
editTask.addParam('_repair_nodes', params.repairNodes);
return new Promise((resolve, reject) => {
editTask
.execute()
.then((res) => {
if (res.data) {
let artRepairFile = new ArtRepairPlan(res.data);
resolve(artRepairFile);
}
})
.catch((err) => {
reject(err);
});
});
}
deleteRepairPlan() {
let editTask = new EditTask(artApi.repairPlanDelete);
editTask.addParam('_id', this.id);
return editTask.execute();
}
//变更修复方案
modificationRepairPlan(params) {
let editTask = new EditTask(artApi.repairPlanInsert);
editTask.addParam('_repair_record_id', params.repairRecordId);
editTask.addParam('_id', params.id);
editTask.addParam('_name', params.name);
editTask.addParam('_repair_nodes', params.repairNodes);
return new Promise((resolve, reject) => {
editTask
.execute()
.then((res) => {
if (res.data) {
let artRepairFile = new ArtRepairPlan(res.data);
resolve(artRepairFile);
}
})
.catch((err) => {
reject(err);
});
});
}
//创建审核
createRepairPlanReview(params = {}) {
let { signatureImage } = params;
let editTask = new EditTask(artApi.repairPlanReviewInsert);
editTask.addParam('_repair_plan_id', this.id);
editTask.addParam('_applicant_signature_image', signatureImage);
return editTask.execute();
}
//获取修复方案审核结果批注信息
queryRepairPlanReview(params = {}) {
let query = new Query();
query.addFilter('repair_plan_id', '=', this.id);
let queryTask = new QueryTask(artApi.viewRepairPlanReview, false);
return new Promise((resolve, reject) => {
queryTask
.execute(query)
.then((res) => {
let resArr = res.map((item) => {
return new RepairPlanAudit(item);
});
resolve(resArr);
})
.catch((err) => {
reject(err);
});
});
}
}
export default ArtRepairPlan;