|
@@ -1,14 +1,16 @@
|
|
|
'use strict';
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 计量单元计算模板
|
|
|
|
|
|
|
+ * 计算模板
|
|
|
|
|
+ *
|
|
|
|
|
+ * 如需修改请联系作者,常量&私有方法(以下划线开头)勿动
|
|
|
*
|
|
*
|
|
|
* @author Mai
|
|
* @author Mai
|
|
|
* @date
|
|
* @date
|
|
|
* @version
|
|
* @version
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
-const ValidTemplateType = ['posCalc'];
|
|
|
|
|
|
|
+const ValidTemplateType = ['posCalc', 'cost'];
|
|
|
const PosCalc = (function(){
|
|
const PosCalc = (function(){
|
|
|
const EmptySpreadCache = {
|
|
const EmptySpreadCache = {
|
|
|
cols: [],
|
|
cols: [],
|
|
@@ -29,7 +31,7 @@ const PosCalc = (function(){
|
|
|
const ValidColInfo = [
|
|
const ValidColInfo = [
|
|
|
{ key: 'str', name: '文本', fields: ['str1', 'str2', 'str3', 'str4'], valid: ['title', 'width'], def: { title: '文字', width: 80, type: 'str'} },
|
|
{ key: 'str', name: '文本', fields: ['str1', 'str2', 'str3', 'str4'], valid: ['title', 'width'], def: { title: '文字', width: 80, type: 'str'} },
|
|
|
{ key: 'num', name: '数值', fields: ['num1', 'num2', 'num3', 'num4', 'num5', 'num6', 'num7', 'num8', 'num9'], valid: ['title', 'width', 'calc_code', 'decimal', 'unit'], def: { title: '数值', width: 80, decimal: 2, type: 'num', unit: ''} },
|
|
{ key: 'num', name: '数值', fields: ['num1', 'num2', 'num3', 'num4', 'num5', 'num6', 'num7', 'num8', 'num9'], valid: ['title', 'width', 'calc_code', 'decimal', 'unit'], def: { title: '数值', width: 80, decimal: 2, type: 'num', unit: ''} },
|
|
|
- { key: 'spec', name: '规格', fields: ['spec'], valid: ['title', 'width', 'rela_col'], def: { title: '规格', width: 80, rela_col: '', type: 'spec'} },
|
|
|
|
|
|
|
+ { key: 'spec', name: '规格', fields: ['spec'], valid: ['title', 'width', 'rela_col', 'spec_set'], def: { title: '规格', width: 80, rela_col: '', type: 'spec'} },
|
|
|
{ key: 'qty', name: '数量', fields: ['qty'], valid: ['title', 'width', 'expr', 'decimal'], def: { title: '数量', width: 80, decimal: 2, expr: '', type: 'qty' } },
|
|
{ key: 'qty', name: '数量', fields: ['qty'], valid: ['title', 'width', 'expr', 'decimal'], def: { title: '数量', width: 80, decimal: 2, expr: '', type: 'qty' } },
|
|
|
];
|
|
];
|
|
|
ValidColInfo.forEach(vci => { return vci.count = vci.fields.length; });
|
|
ValidColInfo.forEach(vci => { return vci.count = vci.fields.length; });
|
|
@@ -44,7 +46,34 @@ const PosCalc = (function(){
|
|
|
};
|
|
};
|
|
|
return { EmptySpreadCache, BaseSpreadColSetting, ValidColInfo, TestData };
|
|
return { EmptySpreadCache, BaseSpreadColSetting, ValidColInfo, TestData };
|
|
|
})();
|
|
})();
|
|
|
-
|
|
|
|
|
|
|
+const Cost = (function(){
|
|
|
|
|
+ const EmptySpreadCache = {
|
|
|
|
|
+ cols: [],
|
|
|
|
|
+ emptyRows: 3,
|
|
|
|
|
+ headRows: 1,
|
|
|
|
|
+ headRowHeight: [32],
|
|
|
|
|
+ defaultRowHeight: 21,
|
|
|
|
|
+ headerFont: '12px 微软雅黑',
|
|
|
|
|
+ font: '12px 微软雅黑',
|
|
|
|
|
+ frozenLineColor: '#93b5e4',
|
|
|
|
|
+ };
|
|
|
|
|
+ const BaseSpreadColSetting = {
|
|
|
|
|
+ str: { title: '', colSpan: '1', rowSpan: '1', field: '', hAlign: 0, width: 80, formatter: '@' },
|
|
|
|
|
+ num: { title: '', colSpan: '1', rowSpan: '1', field: '', hAlign: 2, width: 80, type: 'Number' },
|
|
|
|
|
+ };
|
|
|
|
|
+ const ValidColInfo = [
|
|
|
|
|
+ { key: 'str', name: '文本', fields: ['str1', 'str2', 'str3', 'str4', 'str5', 'str6'], valid: ['title', 'width'], def: { title: '文本', width: 80, type: 'str'} },
|
|
|
|
|
+ {
|
|
|
|
|
+ key: 'num', name: '数值/计算',
|
|
|
|
|
+ fields: ['num_a', 'num_b', 'num_c', 'num_d', 'num_e', 'num_f', 'num_g', 'num_h', 'num_i', 'num_j', 'num_k', 'num_l', 'num_m', 'num_n', 'num_o', 'num_p'],
|
|
|
|
|
+ valid: ['title', 'width', 'calc_code', 'decimal', 'unit', 'expr'],
|
|
|
|
|
+ def: { title: '数值/计算', width: 80, decimal: 2, type: 'num', unit: ''}
|
|
|
|
|
+ },
|
|
|
|
|
+ { key: 'memo', name: '长文本', fields: ['memo1', 'memo2'], valid: ['title', 'width'], def: { title: '长文本', width: 120, type: 'memo'} },
|
|
|
|
|
+ ];
|
|
|
|
|
+ ValidColInfo.forEach(vci => { return vci.count = vci.fields.length; });
|
|
|
|
|
+ return { EmptySpreadCache, BaseSpreadColSetting, ValidColInfo };
|
|
|
|
|
+})();
|
|
|
function randomWord(randomFlag, min, max){
|
|
function randomWord(randomFlag, min, max){
|
|
|
let str = "",
|
|
let str = "",
|
|
|
range = min,
|
|
range = min,
|
|
@@ -73,57 +102,101 @@ module.exports = app => {
|
|
|
constructor(ctx) {
|
|
constructor(ctx) {
|
|
|
super(ctx);
|
|
super(ctx);
|
|
|
this.tableName = 'calc_tmpl';
|
|
this.tableName = 'calc_tmpl';
|
|
|
- this.TemplateRela = { posCalc: PosCalc };
|
|
|
|
|
|
|
+ this.TemplateRela = { posCalc: PosCalc, cost: Cost };
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async getAllTemplate(tid, type, sort = 'asc') {
|
|
|
|
|
|
|
+ async getAllTemplate(spid, type, sort = 'asc') {
|
|
|
return this.getAllDataByCondition({
|
|
return this.getAllDataByCondition({
|
|
|
- columns: ['id', 'name', 'create_user_id'],
|
|
|
|
|
- where: { tid, type },
|
|
|
|
|
|
|
+ columns: ['id', 'spid', 'name', 'create_user_id'],
|
|
|
|
|
+ where: { spid, type },
|
|
|
orders: [['create_time', sort]]
|
|
orders: [['create_time', sort]]
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
- analysisTemplate(data) {
|
|
|
|
|
|
|
+ async analysisTemplate(data) {
|
|
|
const datas = data instanceof Array ? data : [data];
|
|
const datas = data instanceof Array ? data : [data];
|
|
|
datas.forEach(x => {
|
|
datas.forEach(x => {
|
|
|
x.col_set = x.col_set ? JSON.parse(x.col_set) : [];
|
|
x.col_set = x.col_set ? JSON.parse(x.col_set) : [];
|
|
|
x.spread_cache = x.spread_cache ? JSON.parse(x.spread_cache) : {};
|
|
x.spread_cache = x.spread_cache ? JSON.parse(x.spread_cache) : {};
|
|
|
x.field_cache = x.field_cache ? JSON.parse(x.field_cache) : {};
|
|
x.field_cache = x.field_cache ? JSON.parse(x.field_cache) : {};
|
|
|
x.decimal = x.decimal ? JSON.parse(x.decimal) : {};
|
|
x.decimal = x.decimal ? JSON.parse(x.decimal) : {};
|
|
|
|
|
+ x.multi_header = x.multi_header ? JSON.parse(x.multi_header) : undefined;
|
|
|
});
|
|
});
|
|
|
|
|
+ for (const d of datas) {
|
|
|
|
|
+ if (d.spec_set) {
|
|
|
|
|
+ d.specValue = await this.ctx.service.stdExtra.getAllDataByCondition({ columns: ['spec', 'value'], where: { list_id: d.spec_set }, orders:[['order', 'asc']]});
|
|
|
|
|
+ } else {
|
|
|
|
|
+ d.specValue = [];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- async getAllTemplateDetail(tid, type) {
|
|
|
|
|
|
|
+ async getAllTemplateDetail(spid, type) {
|
|
|
const result = await this.getAllDataByCondition({
|
|
const result = await this.getAllDataByCondition({
|
|
|
- where: { tid, type },
|
|
|
|
|
|
|
+ where: { spid, type },
|
|
|
orders: [['create_time', 'desc']]
|
|
orders: [['create_time', 'desc']]
|
|
|
});
|
|
});
|
|
|
- this.analysisTemplate(result);
|
|
|
|
|
|
|
+ await this.analysisTemplate(result);
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
async getTemplate(id) {
|
|
async getTemplate(id) {
|
|
|
const result = await this.getDataById(id);
|
|
const result = await this.getDataById(id);
|
|
|
- this.analysisTemplate(result);
|
|
|
|
|
- return result;
|
|
|
|
|
- }
|
|
|
|
|
- async getLedgerCalcTemplate(tid, lid) {
|
|
|
|
|
- const sql = `SELECT ct.*, l.id FROM ${this.ctx.service.ledgerExtra.departTableName(tid)} l LEFT JOIN ${this.tableName} ct ON l.calc_template = l.id WHERE l.tid = ? and lid = ?`;
|
|
|
|
|
- const result = await this.db.query(sql, [tid, lid]);
|
|
|
|
|
- this.analysisTemplate(result);
|
|
|
|
|
|
|
+ await this.analysisTemplate(result);
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ //-------------------------- 以下方法不可随意修改 --------------------------
|
|
|
// 根据列设置计算spreadjs配置相关,方法命名须严格按照【方法_类型】命名
|
|
// 根据列设置计算spreadjs配置相关,方法命名须严格按照【方法_类型】命名
|
|
|
- transExpr_posCalc(expr, colSet) {
|
|
|
|
|
|
|
+ _getFillRowCount(rowSpan) {
|
|
|
|
|
+ let count = 0;
|
|
|
|
|
+ rowSpan.forEach(x => {
|
|
|
|
|
+ count = count + x ? x : 1;
|
|
|
|
|
+ });
|
|
|
|
|
+ return count;
|
|
|
|
|
+ }
|
|
|
|
|
+ _calcMultiColHeader(iCol, spreadCol, colTitle, multiHeader) {
|
|
|
|
|
+ if (multiHeader) {
|
|
|
|
|
+ const colSpan = [], rowSpan = [], title = [];
|
|
|
|
|
+ for (let iRow = 0; iRow < multiHeader.headRows - 1; iRow ++) {
|
|
|
|
|
+ const setSpan = multiHeader.headSpan.find(x => { return x.col === iCol && x.row === iRow; });
|
|
|
|
|
+ if (setSpan) {
|
|
|
|
|
+ colSpan.push(setSpan.colCount);
|
|
|
|
|
+ rowSpan.push(setSpan.rowCount);
|
|
|
|
|
+ title.push(setSpan.title);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ const relaSpan = multiHeader.headSpan.find(x => { return iCol >= x.col && iCol < x.col + x.colCount && iRow >= x.row && iRow < x.row + x.rowCount; });
|
|
|
|
|
+ if (relaSpan) {
|
|
|
|
|
+ colSpan.push('');
|
|
|
|
|
+ rowSpan.push('');
|
|
|
|
|
+ title.push('');
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (colSpan.length === 0) {
|
|
|
|
|
+ spreadCol.rowSpan = multiHeader.headRows + '';
|
|
|
|
|
+ spreadCol.title = colTitle;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ colSpan.push(1);
|
|
|
|
|
+ rowSpan.push(multiHeader.headRows - this._getFillRowCount(rowSpan));
|
|
|
|
|
+ title.push(colTitle);
|
|
|
|
|
+ spreadCol.colSpan = colSpan.join('|');
|
|
|
|
|
+ spreadCol.rowSpan = rowSpan.join('|');
|
|
|
|
|
+ spreadCol.title = title.join('|');
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ spreadCol.title = colTitle;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ _transExpr(expr, colSet) {
|
|
|
|
|
+ if (!expr) return '';
|
|
|
|
|
+
|
|
|
let newExpr = expr;
|
|
let newExpr = expr;
|
|
|
colSet.forEach(x => {
|
|
colSet.forEach(x => {
|
|
|
if (x.type === 'num' && x.calc_code) newExpr = newExpr.replace(new RegExp(x.calc_code, 'gm'), x.field);
|
|
if (x.type === 'num' && x.calc_code) newExpr = newExpr.replace(new RegExp(x.calc_code, 'gm'), x.field);
|
|
|
});
|
|
});
|
|
|
return newExpr;
|
|
return newExpr;
|
|
|
}
|
|
}
|
|
|
- calcSpreadCache_posCalc(colSet) {
|
|
|
|
|
|
|
+ _calcSpreadCache_posCalc(colSet) {
|
|
|
const relaConst = this.TemplateRela.posCalc;
|
|
const relaConst = this.TemplateRela.posCalc;
|
|
|
const result = JSON.parse(JSON.stringify(relaConst.EmptySpreadCache));
|
|
const result = JSON.parse(JSON.stringify(relaConst.EmptySpreadCache));
|
|
|
- let specCol;
|
|
|
|
|
for (const col of colSet) {
|
|
for (const col of colSet) {
|
|
|
const info = relaConst.ValidColInfo.find(x => { return x.key === col.type });
|
|
const info = relaConst.ValidColInfo.find(x => { return x.key === col.type });
|
|
|
const spreadCol = JSON.parse(JSON.stringify(relaConst.BaseSpreadColSetting[col.type]));
|
|
const spreadCol = JSON.parse(JSON.stringify(relaConst.BaseSpreadColSetting[col.type]));
|
|
@@ -132,10 +205,8 @@ module.exports = app => {
|
|
|
if (v === 'unit' && col.unit) {
|
|
if (v === 'unit' && col.unit) {
|
|
|
spreadCol.title = col.title + '(' + col.unit + ')';
|
|
spreadCol.title = col.title + '(' + col.unit + ')';
|
|
|
} else if (v === 'expr') {
|
|
} else if (v === 'expr') {
|
|
|
- spreadCol.expr = this.transExpr_posCalc(col.expr, colSet);
|
|
|
|
|
- } else if (v === 'spec') {
|
|
|
|
|
- // todo
|
|
|
|
|
- specCol = spreadCol;
|
|
|
|
|
|
|
+ spreadCol.expr = this._transExpr(col.expr, colSet);
|
|
|
|
|
+ spreadCol.readOnly = true;
|
|
|
} else {
|
|
} else {
|
|
|
if (col[v] !== undefined) spreadCol[v] = col[v];
|
|
if (col[v] !== undefined) spreadCol[v] = col[v];
|
|
|
}
|
|
}
|
|
@@ -144,6 +215,7 @@ module.exports = app => {
|
|
|
if (col.expr) spreadCol.title = spreadCol.title + '\n' + col.expr;
|
|
if (col.expr) spreadCol.title = spreadCol.title + '\n' + col.expr;
|
|
|
result.cols.push(spreadCol);
|
|
result.cols.push(spreadCol);
|
|
|
}
|
|
}
|
|
|
|
|
+ const specCol = colSet.find(x => { return x.type === 'spec'; });
|
|
|
if (specCol) {
|
|
if (specCol) {
|
|
|
const relaSet = colSet.find(x => { return x.calc_code === specCol.rela_col; });
|
|
const relaSet = colSet.find(x => { return x.calc_code === specCol.rela_col; });
|
|
|
const relaCol = result.cols.find(x => { return x.field === relaSet.field; });
|
|
const relaCol = result.cols.find(x => { return x.field === relaSet.field; });
|
|
@@ -151,28 +223,95 @@ module.exports = app => {
|
|
|
}
|
|
}
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
- calcSpreadCache(colSet, type) {
|
|
|
|
|
- const funName = 'calcSpreadCache_' + type;
|
|
|
|
|
- if (this[funName]) return this[funName](colSet);
|
|
|
|
|
- return null;
|
|
|
|
|
|
|
+ _calcSpreadCache_cost(colSet, multiHeader) {
|
|
|
|
|
+ const relaConst = this.TemplateRela.cost;
|
|
|
|
|
+ const result = JSON.parse(JSON.stringify(relaConst.EmptySpreadCache));
|
|
|
|
|
+ if (multiHeader) {
|
|
|
|
|
+ result.headRows = multiHeader.headRows;
|
|
|
|
|
+ result.headRowHeight = multiHeader.headRowHeight;
|
|
|
|
|
+ }
|
|
|
|
|
+ for (const [iCol, col] of colSet.entries()) {
|
|
|
|
|
+ const info = relaConst.ValidColInfo.find(x => { return x.key === col.type });
|
|
|
|
|
+ const spreadCol = JSON.parse(JSON.stringify(relaConst.BaseSpreadColSetting[col.type]));
|
|
|
|
|
+ spreadCol.field = col.field;
|
|
|
|
|
+ let colTitle = col.title;
|
|
|
|
|
+ info.valid.forEach(v => {
|
|
|
|
|
+ if (v === 'unit' && col.unit) {
|
|
|
|
|
+ colTitle = colTitle + '(' + col.unit + ')';
|
|
|
|
|
+ } else if (v === 'expr') {
|
|
|
|
|
+ spreadCol.expr = this._transExpr(col.expr, colSet);
|
|
|
|
|
+ spreadCol.readOnly = true;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (col[v] !== undefined) spreadCol[v] = col[v];
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ if (col.calc_code) {
|
|
|
|
|
+ if (col.expr) {
|
|
|
|
|
+ colTitle = colTitle + '\n' + col.calc_code + '(' + col.expr + ')';
|
|
|
|
|
+ } else {
|
|
|
|
|
+ colTitle = colTitle + '\n' + col.calc_code;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ this._calcMultiColHeader(iCol, spreadCol, colTitle, multiHeader);
|
|
|
|
|
+
|
|
|
|
|
+ result.cols.push(spreadCol);
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+ calcSpreadCache(type, colSet, multiHeader) {
|
|
|
|
|
+ const funName = '_calcSpreadCache_' + type;
|
|
|
|
|
+ if (this[funName]) return this[funName](colSet, multiHeader);
|
|
|
|
|
+ return this.TemplateRela[type] ? this.TemplateRela[type].EmptySpreadCache : {};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- getCalcTestData_posCalc(colSet, count) {
|
|
|
|
|
|
|
+ async getCalcTestData_posCalc(colSet, count) {
|
|
|
const result = [];
|
|
const result = [];
|
|
|
- const testData = {};
|
|
|
|
|
- colSet.forEach(x => {
|
|
|
|
|
- if (x.type === 'num') testData[x.field] = Math.max(Math.floor(Math.random()*10), 1);
|
|
|
|
|
- if (x.type === 'str') testData[x.field] = randomWord(true, 3, 6);
|
|
|
|
|
- });
|
|
|
|
|
- result.push(testData);
|
|
|
|
|
|
|
+ const specCol = colSet.find(x => { return x.type === 'spec'; });
|
|
|
|
|
+ const specSet = specCol && specCol.spec_set ? await this.ctx.service.stdExtra.getAllDataByCondition({ columns: ['spec', 'value'], where: { list_id: specCol.spec_set }, orders:[['order', 'asc']]}) : [];
|
|
|
|
|
+ const relaCol = specCol && specCol.rela_col ? colSet.find(x => { return x.calc_code === specCol.rela_col; }) : null;
|
|
|
|
|
+
|
|
|
|
|
+ for (let i = 0; i < count; i++) {
|
|
|
|
|
+ const testData = {};
|
|
|
|
|
+ colSet.forEach(x => {
|
|
|
|
|
+ if (x.type === 'num') testData[x.field] = Math.max(Math.floor(Math.random()*10), 1);
|
|
|
|
|
+ if (x.type === 'str') testData[x.field] = randomWord(true, 3, 6);
|
|
|
|
|
+ });
|
|
|
|
|
+ if (specCol && specSet.length > 0) {
|
|
|
|
|
+ testData.spec = specSet[0].spec;
|
|
|
|
|
+ if (relaCol) testData[relaCol.field] = specSet[0].value;
|
|
|
|
|
+ }
|
|
|
|
|
+ result.push(testData);
|
|
|
|
|
+ }
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
- getCalcTestData(colSet, type, count = 1) {
|
|
|
|
|
|
|
+ async getCalcTestData(colSet, type, count = 1) {
|
|
|
const funName = 'getCalcTestData_' + type;
|
|
const funName = 'getCalcTestData_' + type;
|
|
|
- if (this[funName]) return this[funName](colSet);
|
|
|
|
|
|
|
+ if (this[funName]) return await this[funName](colSet, count);
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ async _checkTemplateUsed_posCalc(template) {
|
|
|
|
|
+ const templates = template instanceof Array ? template : [template];
|
|
|
|
|
+ templates.forEach(x => { x.used = []; x.used_count = 0; });
|
|
|
|
|
+ const tender = await this.ctx.service.tender.getAllDataByCondition({ columns: ['id'], where: { spid: templates[0].spid }});
|
|
|
|
|
+ for (const t of tender) {
|
|
|
|
|
+ const used = await this.ctx.service.ledgerExtra.getUsedCalcTemplate(t.id);
|
|
|
|
|
+ templates.forEach(x => {
|
|
|
|
|
+ const u = used.find(ut => { return ut.calc_template === x.id; });
|
|
|
|
|
+ if (u) {
|
|
|
|
|
+ x.used.push(t.id);
|
|
|
|
|
+ x.used_count = this.ctx.helper.add(x.used_count + u.count);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ async checkTemplateUsed(template, type) {
|
|
|
|
|
+ const funName = '_checkTemplateUsed_' + type;
|
|
|
|
|
+ if (this[funName]) return await this[funName](template);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ // -----------------------------------------------------------------------
|
|
|
|
|
+
|
|
|
async _addTemplate(name, type) {
|
|
async _addTemplate(name, type) {
|
|
|
if (ValidTemplateType.indexOf(type) < 0) throw '新增的模板类型非法';
|
|
if (ValidTemplateType.indexOf(type) < 0) throw '新增的模板类型非法';
|
|
|
|
|
|
|
@@ -180,7 +319,8 @@ module.exports = app => {
|
|
|
const insertData = {
|
|
const insertData = {
|
|
|
id: this.uuid.v4(),
|
|
id: this.uuid.v4(),
|
|
|
pid: this.ctx.session.sessionProject.id,
|
|
pid: this.ctx.session.sessionProject.id,
|
|
|
- tid: this.ctx.tender.id,
|
|
|
|
|
|
|
+ spid: this.ctx.subProject.id,
|
|
|
|
|
+ // tid: this.ctx.tender.id,
|
|
|
name: name || '新增计算模板',
|
|
name: name || '新增计算模板',
|
|
|
type,
|
|
type,
|
|
|
create_user_id: this.ctx.session.sessionUser.accountId,
|
|
create_user_id: this.ctx.session.sessionUser.accountId,
|
|
@@ -198,7 +338,7 @@ module.exports = app => {
|
|
|
async checkTemplateEdit(id) {
|
|
async checkTemplateEdit(id) {
|
|
|
const template = await this.getDataById(id);
|
|
const template = await this.getDataById(id);
|
|
|
if (!template) throw '编辑的模板不存在';
|
|
if (!template) throw '编辑的模板不存在';
|
|
|
- if (template.tid !== this.ctx.tender.id) throw '模板不属于当前标段,请刷新后重试';
|
|
|
|
|
|
|
+ if (template.spid !== this.ctx.subProject.id) throw '模板不属于当前项目,请刷新后重试';
|
|
|
if (template.create_user_id !== this.ctx.session.sessionUser.accountId) throw '非您创建的模板';
|
|
if (template.create_user_id !== this.ctx.session.sessionUser.accountId) throw '非您创建的模板';
|
|
|
return template;
|
|
return template;
|
|
|
}
|
|
}
|
|
@@ -206,9 +346,13 @@ module.exports = app => {
|
|
|
const org = await this.checkTemplateEdit(id);
|
|
const org = await this.checkTemplateEdit(id);
|
|
|
const updateData = { id };
|
|
const updateData = { id };
|
|
|
if (data.name !== undefined) updateData.name = data.name;
|
|
if (data.name !== undefined) updateData.name = data.name;
|
|
|
- if (data.col_set !== undefined) {
|
|
|
|
|
|
|
+ if (data.col_set !== undefined || data.multi_header !== undefined) {
|
|
|
|
|
+ await this.checkTemplateUsed(org);
|
|
|
|
|
+ if (org.used.length > 0) throw '模板已使用,不可修改配置!';
|
|
|
|
|
+
|
|
|
updateData.col_set = JSON.stringify(data.col_set);
|
|
updateData.col_set = JSON.stringify(data.col_set);
|
|
|
- const spread_cache = this.calcSpreadCache(data.col_set, org.type);
|
|
|
|
|
|
|
+ updateData.multi_header = JSON.stringify(data.multi_header);
|
|
|
|
|
+ const spread_cache = this.calcSpreadCache(org.type, data.col_set, data.multi_header);
|
|
|
updateData.spread_cache = JSON.stringify(spread_cache);
|
|
updateData.spread_cache = JSON.stringify(spread_cache);
|
|
|
const field_cache = {};
|
|
const field_cache = {};
|
|
|
data.col_set.forEach(x => { field_cache[x.field] = x.title; });
|
|
data.col_set.forEach(x => { field_cache[x.field] = x.title; });
|
|
@@ -218,6 +362,14 @@ module.exports = app => {
|
|
|
updateData.decimal = JSON.stringify(decimal);
|
|
updateData.decimal = JSON.stringify(decimal);
|
|
|
const qtyCol = spread_cache.cols.find(x => { return x.field === 'qty'; });
|
|
const qtyCol = spread_cache.cols.find(x => { return x.field === 'qty'; });
|
|
|
updateData.calc_expr = qtyCol ? qtyCol.expr : '';
|
|
updateData.calc_expr = qtyCol ? qtyCol.expr : '';
|
|
|
|
|
+ const specCol = data.col_set.find(x => { return x.field === 'spec' });
|
|
|
|
|
+ if (specCol) {
|
|
|
|
|
+ updateData.spec_set = specCol.spec_set;
|
|
|
|
|
+ updateData.spec_rela = data.col_set.find(x => { return x.calc_code === specCol.rela_col; }).field;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ updateData.spec_set = 0;
|
|
|
|
|
+ updateData.spec_rela = '';
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
await this.db.update(this.tableName, updateData);
|
|
await this.db.update(this.tableName, updateData);
|
|
|
return await this.getTemplate(id);
|
|
return await this.getTemplate(id);
|
|
@@ -227,7 +379,6 @@ module.exports = app => {
|
|
|
await this.db.delete(this.tableName, { id });
|
|
await this.db.delete(this.tableName, { id });
|
|
|
return template;
|
|
return template;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
async saveTemplate(data) {
|
|
async saveTemplate(data) {
|
|
|
const result = {};
|
|
const result = {};
|
|
|
if (data.add) result.add = await this._addTemplate(data.add.name, data.type);
|
|
if (data.add) result.add = await this._addTemplate(data.add.name, data.type);
|