formulaNew_wev8.js
29.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
//执行新版公式
function formulaTrigger(triInfo) {
const destcellArray = triInfo.destcell;
const formulatxtArray = triInfo.formulatxt;
const cellrangeArray = triInfo.cellrange;
var triggerFieldid = triInfo.triggerFieldid;
var triggerGroupid = triInfo.triggerGroupid;
try {
for (var i = 0; i < formulatxtArray.length; i++) {
var formulatxt = formulatxtArray[i];
var cellrange = cellrangeArray[i];
//没有目标单元格时,只执行函数,不用将函数的执行结果进行赋值
if (!destcellArray || destcellArray.length == 0 || (destcellArray.length == 1 && !destcellArray[0])) {
if (formulatxt && formulatxt.indexOf("(") > -1) {
formulatxt = formulatxt.replace(/^\s+|\s+$/gm,'');//去掉前后多余空格
if (formulatxt.toUpperCase().indexOf("SYSTEMFORMULAOPERATE.IF") == 0) {
var firstParam = formulatxt.substring(formulatxt.indexOf("(") + 1, formulatxt.indexOf(","));
var divFirstParam = formulatxt.substring(formulatxt.indexOf(",") + 1);
var chars = divFirstParam.split("");
var cnt = 0;
var secondParam = "";
var thirdParam = "";
var temp = '';
var secondIdx = 0;
for (var idx = 0; idx < chars.length; idx++) {
temp = chars[idx];
if (temp == "(") {
cnt = cnt + 1;
}else if (temp == ")" && idx != chars.length - 1) {
cnt = cnt - 1;
}else if ((temp == "," && cnt == 0) || (temp == ")" && idx == chars.length - 1)) {
if (secondParam) {
thirdParam = divFirstParam.substring(secondIdx + 1, divFirstParam.length - 1);
} else {
secondParam = divFirstParam.substring(0, idx);
secondIdx = idx;
}
}
}
if (thirdParam) {
var a=formulatxt.split('');
a.splice("SYSTEMFORMULAOPERATE.IF(".length + firstParam.length + secondIdx + 2, thirdParam.length, "thirdParam");
formulatxt = a.join('');
//formulatxt = formulatxt.replace(thirdParam, "thirdParam");
}
if (secondParam.trim()) {
formulatxt = formulatxt.replace(secondParam, "secondParam");
}
//拼接触发参数
formulatxt = formulatxt.substring(0, formulatxt.length - 1);
formulatxt = formulatxt + "," + triggerFieldid + "," + triggerGroupid + ")";
}
}
if (cellrange) {
var vars = {};
var rowid = "";
if(triggerFieldid) {
triggerFieldid = triggerFieldid.toString();
if (triggerFieldid.indexOf("_")>-1) {
rowid = triggerFieldid.substring(triggerFieldid.indexOf("_")+1);
}
}
for(var idx=0;idx<cellrange.length;idx++){
var cellattr = cellrange[idx];
var fieldid = convertCellAttrToFieldid(cellattr);
//tempFunction = getFunction(formulatxt, cellattr);
if (cellattr.toLowerCase().indexOf(".id") > -1) {
var tempcellattr = cellattr.substring(0, cellattr.toLowerCase().indexOf(".id"));
tempFunction = "["+tempcellattr+"].id";
} else {
tempFunction = "["+cellattr+"]";
}
if(cellattr.indexOf("detail_")>-1){//取值字段为明细字段
tempValue = getAllRowValue(cellattr);
var varname = "var"+idx;
if (cellattr.toLowerCase().indexOf(".id") > -1) {
cellattr = cellattr.substring(0, cellattr.toLowerCase().indexOf(".id"));
newTempFunction = tempFunction.replace("["+cellattr+"].id", "vars."+varname);
} else {
newTempFunction = tempFunction.replace("["+cellattr+"]", "vars."+varname);
}
var wholeFunction = getFunction(formulatxt, cellattr);
//明细字段为数字时,将明细中所有的数相加求和后赋值给主表字段
if(isFieldNum(fieldid)) {
if (wholeFunction.toUpperCase().indexOf("MAX") > -1 || wholeFunction.toUpperCase().indexOf("MIN") > -1
|| wholeFunction.toUpperCase().indexOf("AVERAGE") > -1) {
var tempFunction = wholeFunction.replace("["+cellattr+"]", "tempValue");
vars[varname] = eval(tempFunction);
formulatxt = formulatxt.replace(wholeFunction, "Number(" + "vars."+varname + ")");
} else {
var tempSumValue = 0;
for (var i=0; tempValue && i < tempValue.length;i++){
tempSumValue = tempSumValue + tempValue[i];
}
vars[varname] = tempSumValue;
formulatxt = formulatxt.replace(tempFunction, "Number(" + newTempFunction + ")");
}
} else {
var tempSumValue = "";
for (var i=0; tempValue && i < tempValue.length;i++){
tempSumValue = tempSumValue + tempValue[i];
}
vars[varname] = tempSumValue
formulatxt = formulatxt.replace(tempFunction, newTempFunction);
}
} else if (cellattr.indexOf("sys")>-1) {//取值字段为系统字段
tempValue = getSystemValue(systemdata, cellattr, triInfo);
var varname = "var"+idx;
vars[varname] = tempValue;
if (cellattr.toLowerCase().indexOf(".id") > -1) {
cellattr = cellattr.substring(0, cellattr.toLowerCase().indexOf(".id"));
newTempFunction = tempFunction.replace("["+cellattr+"].id", "vars."+varname);
} else {
newTempFunction = tempFunction.replace("["+cellattr+"]", "vars."+varname);
}
formulatxt = formulatxt.replace(tempFunction, newTempFunction);
} else if (cellattr.indexOf("main")>-1) {//取值字段为主表字段
tempValue = getSingleFieldValue(fieldid, rowid);
var varname = "var"+idx;
vars[varname] = tempValue;
if (cellattr.toLowerCase().indexOf(".id") > -1) {
cellattr = cellattr.substring(0, cellattr.toLowerCase().indexOf(".id"));
newTempFunction = tempFunction.replace("["+cellattr+"].id", "vars."+varname);
} else {
newTempFunction = tempFunction.replace("["+cellattr+"]", "vars."+varname);
}
if(isFieldNum(fieldid)) {
formulatxt = formulatxt.replace(tempFunction, "Number(" + newTempFunction + ")");
} else {
formulatxt = formulatxt.replace(tempFunction, newTempFunction);
}
}
}
}
if (formulatxt && formulatxt.toLowerCase().indexOf("return") < 0) {
var functionStr = "var tempFormulaFunction = function() {\n var ret = " + formulatxt + "\n if(ret) return ret;\n}";
} else {
var functionStr = "var tempFormulaFunction = function() {\n " + formulatxt + "\n}";
}
eval(functionStr);
var ret = tempFormulaFunction();
if (ret || ret == 0) {
return ret;
}
} else {
var singleInfo = Object.assign({}, triInfo);
singleInfo.formulatxt = triInfo.formulatxt[i];
singleInfo.destcell = triInfo.destcell[i];
singleInfo.cellrange = triInfo.cellrange[i];
singleInfo.destfield = triInfo.destfield[i];
this.calculateNew(singleInfo);
}
}
} catch(ex){
if(window.console) console.log("9>>>>>formula calculate error: "+ex);
}
}
function calculateNew(triInfo) {
var destcell = triInfo.destcell;
var cellrange = triInfo.cellrange;
var formulatxt = triInfo.formulatxt;
var destfield = triInfo.destfield;
var rowid = triInfo.triggerRowIndex;
var systemdata = triInfo.systemdata;
var triggerGroupid = triInfo.triggerGroupid;
if (!formulatxt) {
return;
}
try {
var vars = {};
if (formulatxt) {
formulatxt = formulatxt.replace(/^\s+|\s+$/gm,'');//去掉前后多余空格
if (formulatxt.toUpperCase().indexOf("SYSTEMFORMULAOPERATE.IF") == 0) {
var firstParam = formulatxt.substring(formulatxt.indexOf("(") + 1, formulatxt.indexOf(","));
var divFirstParam = formulatxt.substring(formulatxt.indexOf(",") + 1);
var chars = divFirstParam.split("");
var cnt = 0;
var secondParam = "";
var thirdParam = "";
var temp = '';
var secondIdx = 0;
for (var idx = 0; idx < chars.length; idx++) {
temp = chars[idx];
if (temp == "(") {
cnt = cnt + 1;
}else if (temp == ")" && idx != chars.length - 1) {
cnt = cnt - 1;
}else if ((temp == "," && cnt == 0) || (temp == ")" && idx == chars.length - 1)) {
if (secondParam) {
thirdParam = divFirstParam.substring(secondIdx + 1, divFirstParam.length - 1);
} else {
secondParam = divFirstParam.substring(0, idx);
secondIdx = idx;
}
}
}
formulatxt = formulatxt.replace(secondParam, "secondParam");
formulatxt = formulatxt.replace(thirdParam, "thirdParam");
//拼接触发参数
formulatxt = formulatxt.substring(0, formulatxt.length - 1);
formulatxt = formulatxt + ",triInfo)";
}
if (destcell.indexOf("detail_")==-1) {//赋值给主表字段
for(var idx=0;cellrange && idx<cellrange.length;idx++){
var tempFunction = "";
var newTempFunction = "";
var tempValue;
var cellattr = cellrange[idx];
var fieldid = convertCellAttrToFieldid(cellattr);
// tempFunction = getFunction(formulatxt, cellattr);
if (cellattr.toLowerCase().indexOf(".id") > -1) {
var tempcellattr = cellattr.substring(0, cellattr.toLowerCase().indexOf(".id"));
tempFunction = "["+tempcellattr+"].id";
} else {
tempFunction = "["+cellattr+"]";
}
if(cellattr.indexOf("detail_")>-1){//取值字段为明细字段
tempValue = getAllRowValue(cellattr);
var varname = "var"+idx;
if (cellattr.toLowerCase().indexOf(".id") > -1) {
cellattr = cellattr.substring(0, cellattr.toLowerCase().indexOf(".id"));
newTempFunction = tempFunction.replace("["+cellattr+"].id", "vars."+varname);
} else {
newTempFunction = tempFunction.replace("["+cellattr+"]", "vars."+varname);
}
var wholeFunction = getFunction(formulatxt, cellattr);
//明细字段为数字时,将明细中所有的数相加求和后赋值给主表字段
if(isFieldNum(fieldid)) {
if (wholeFunction.toUpperCase().indexOf("MAX") > -1 || wholeFunction.toUpperCase().indexOf("MIN") > -1
|| wholeFunction.toUpperCase().indexOf("AVERAGE") > -1) {
var tempFunction = wholeFunction.replace("["+cellattr+"]", "tempValue");
vars[varname] = eval(tempFunction);
formulatxt = formulatxt.replace(wholeFunction, "Number(" + "vars."+varname + ")");
} else {
var tempSumValue = 0;
for (var i=0; tempValue && i < tempValue.length;i++){
tempSumValue = tempSumValue + tempValue[i];
}
vars[varname] = tempSumValue;
formulatxt = formulatxt.replace(tempFunction, "Number(" + newTempFunction + ")");
}
} else {
var tempSumValue = "";
for (var i=0; tempValue && i < tempValue.length;i++){
tempSumValue = tempSumValue + tempValue[i];
}
vars[varname] = tempSumValue
formulatxt = formulatxt.replace(tempFunction, newTempFunction);
}
} else if (cellattr.indexOf("sys")>-1) {//取值字段为系统字段
tempValue = getSystemValue(systemdata, cellattr, triInfo);
var varname = "var"+idx;
vars[varname] = tempValue;
if (cellattr.toLowerCase().indexOf(".id") > -1) {
cellattr = cellattr.substring(0, cellattr.toLowerCase().indexOf(".id"));
newTempFunction = tempFunction.replace("["+cellattr+"].id", "vars."+varname);
} else {
newTempFunction = tempFunction.replace("["+cellattr+"]", "vars."+varname);
}
formulatxt = formulatxt.replace(tempFunction, newTempFunction);
} else if (cellattr.indexOf("main")>-1) {//取值字段为主表字段
tempValue = getSingleFieldValue(fieldid, rowid);
var varname = "var"+idx;
vars[varname] = tempValue;
if (cellattr.toLowerCase().indexOf(".id") > -1) {
cellattr = cellattr.substring(0, cellattr.toLowerCase().indexOf(".id"));
newTempFunction = tempFunction.replace("["+cellattr+"].id", "vars."+varname);
} else {
newTempFunction = tempFunction.replace("["+cellattr+"]", "vars."+varname);
}
if(isFieldNum(fieldid)) {
formulatxt = formulatxt.replace(tempFunction, "Number(" + newTempFunction + ")");
} else {
formulatxt = formulatxt.replace(tempFunction, newTempFunction);
}
}
}
} else {//赋值给明细字段
var destGroupid = getGroupid(destcell);
var srcGroupid;
for(var idx=0;cellrange && idx<cellrange.length;idx++) {
let tempFunction = "";
let newTempFunction = "";
let tempValue;
var cellattr = cellrange[idx];
const fieldid = convertCellAttrToFieldid(cellattr);
// tempFunction = getFunction(formulatxt, cellattr);
if (cellattr.toLowerCase().indexOf(".id") > -1) {
var tempcellattr = cellattr.substring(0, cellattr.toLowerCase().indexOf(".id"));
tempFunction = "["+tempcellattr+"].id";
} else {
tempFunction = "["+cellattr+"]";
}
if(cellattr.indexOf("detail_")>-1){//取值字段为明细字段
srcGroupid = getGroupid(cellattr);
if (destGroupid === srcGroupid) {//取值字段和赋值字段在同一个明细中
tempValue = getSingleFieldValue(fieldid, rowid);
var varname = "var"+idx;
vars[varname] = tempValue;
if (cellattr.toLowerCase().indexOf(".id") > -1) {
cellattr = cellattr.substring(0, cellattr.toLowerCase().indexOf(".id"));
newTempFunction = tempFunction.replace("["+cellattr+"].id", "vars."+varname);
} else {
newTempFunction = tempFunction.replace("["+cellattr+"]", "vars."+varname);
}
if(isFieldNum(fieldid)) {
formulatxt = formulatxt.replace(tempFunction, "Number(" + newTempFunction + ")");
} else {
formulatxt = formulatxt.replace(tempFunction, newTempFunction);
}
} else {//取值字段和赋值字段在不同的明细中
tempValue = getAllRowValue(cellattr, rowid);
var varname = "var"+idx;
if (cellattr.toLowerCase().indexOf(".id") > -1) {
cellattr = cellattr.substring(0, cellattr.toLowerCase().indexOf(".id"));
newTempFunction = tempFunction.replace("["+cellattr+"].id", "vars."+varname);
} else {
newTempFunction = tempFunction.replace("["+cellattr+"]", "vars."+varname);
}
//明细字段为数字时,将明细中所有的数相加求和后赋值给主表字段
if(isFieldNum(fieldid)) {
var tempSumValue = 0;
for (var i=0; tempValue && i < tempValue.length;i++){
tempSumValue = tempSumValue + tempValue[i];
}
vars[varname] = tempSumValue;
formulatxt = formulatxt.replace(tempFunction, "Number(" + newTempFunction + ")");
} else {
formulatxt = formulatxt.replace(tempFunction, newTempFunction);
}
}
} else if (cellattr.indexOf("sys")>-1) {//取值字段为系统字段
tempValue = getSystemValue(systemdata, cellattr, triInfo);
var varname = "var"+idx;
vars[varname] = tempValue;
if (cellattr.toLowerCase().indexOf(".id") > -1) {
cellattr = cellattr.substring(0, cellattr.toLowerCase().indexOf(".id"));
newTempFunction = tempFunction.replace("["+cellattr+"].id", "vars."+varname);
} else {
newTempFunction = tempFunction.replace("["+cellattr+"]", "vars."+varname);
}
formulatxt = formulatxt.replace(tempFunction, newTempFunction);
} else if (cellattr.indexOf("main")>-1) {//取值字段为主表字段
tempValue = getSingleFieldValue(fieldid, rowid);
var varname = "var"+idx;
vars[varname] = tempValue;
if (cellattr.toLowerCase().indexOf(".id") > -1) {
cellattr = cellattr.substring(0, cellattr.toLowerCase().indexOf(".id"));
newTempFunction = tempFunction.replace("["+cellattr+"].id", "vars."+varname);
} else {
newTempFunction = tempFunction.replace("["+cellattr+"]", "vars."+varname);
}
if(isFieldNum(fieldid)) {
formulatxt = formulatxt.replace(tempFunction, "Number(" + newTempFunction + ")");
} else {
formulatxt = formulatxt.replace(tempFunction, newTempFunction);
}
}
}
}
}
var calculateResult = eval(formulatxt);
if(window.console) console.log("2>>>formulatxt: "+destcell+"=="+formulatxt+">>>calResult: "+calculateResult);
setValue(destcell, rowid, triggerGroupid, calculateResult);
} catch(ex) {
if(window.console) console.log("Formula calculate error: "+ex);
}
}
function setValue(destcell, rowid, triggerGroupid, calculateResult) {
var destGroupid = getGroupid(destcell);
var destFieldid;
if (destcell.indexOf("detail_") == -1) {//目标字段为主表字段
if(destcell && destcell.indexOf(".")>-1) {
destcell = destcell.substring(destcell.indexOf(".")+1);
}
destFieldid = "field"+destcell;
WfForm.changeFieldValue(destFieldid, {value:calculateResult});
} else if (destGroupid == triggerGroupid) {
//目标字段为明细字段,并且与触发字段在同一个明细表中,
//值更新触发字段所在行的目标字段值
if(destcell && destcell.indexOf(".")>-1) {
destcell = destcell.substring(destcell.indexOf(".")+1);
}
destFieldid = "field"+destcell + "_" + rowid;
WfForm.changeFieldValue(destFieldid, {value:calculateResult});
} else {
//目标字段为明细字段,但是与触发字段不在同一个明细表中
//目标字段的所有行的字段数据都更新
if(destcell && destcell.indexOf(".")>-1) {
destcell = destcell.substring(destcell.indexOf(".")+1);
}
var destDetailMark = "detail_" + destGroupid;
var destDetailAllRowIndex = WfForm.getDetailAllRowIndexStr(destDetailMark);
!!destDetailAllRowIndex && destDetailAllRowIndex.split(",").map(rowIndex =>{
try{
destFieldid = "field"+destcell + "_" + rowIndex;
WfForm.changeFieldValue(destFieldid, {value:calculateResult});
}catch(ev){}
});
}
}
//获取属于哪个明细表groupid
function getGroupid(cellattr){
cellattr = cellattr.toUpperCase();
var idx = cellattr.indexOf("DETAIL_");
var groupid = -1;
if(idx == -1)
return groupid;
if (cellattr.indexOf(".") == -1) {
groupid = cellattr.substring(idx+7 ,cellattr.length);
} else {
groupid = cellattr.substring(idx+7 ,cellattr.indexOf("."));
}
return groupid;
}
//获取单个字段值
const getSingleFieldValue = (fieldid, rowIndex) =>{
let fieldMark = "";
if (rowIndex) {
fieldMark = `field${fieldid}` + "_" + rowIndex;
} else {
fieldMark = `field${fieldid}`;
}
let fieldValue = window.WfForm.getFieldValue(fieldMark);
const fieldAttr = window.WfForm.getFieldInfo(fieldid);
if(fieldAttr.htmltype === 1 && fieldAttr.detailtype === 5)
fieldValue = fieldValue.toString().replace(/,/g, "");
if(fieldAttr.htmltype === 1 && fieldAttr.detailtype === 2) {
if (fieldValue != "") {
fieldValue = parseInt(fieldValue);
} else {
fieldValue = 0;
}
} else if (fieldAttr.htmltype === 1 &&
(fieldAttr.detailtype === 3 || fieldAttr.detailtype === 5)) {
if (fieldValue != "") {
fieldValue = parseFloat(fieldValue);
} else {
fieldValue = 0;
}
}
return fieldValue;
}
//返回所有行数据,以数组形式返回
function getAllRowValue(cellattr) {
const fieldid = convertCellAttrToFieldid(cellattr);
var groupid = getGroupid(cellattr);
if(groupid==0) throw new Error("Get detail groupid error!");
var retArray = [];
const detailMark = "detail_"+groupid;
const allRowIndex = window.WfForm.getDetailAllRowIndexStr(detailMark);
!!allRowIndex && allRowIndex.split(",").map(rowIndex =>{
try{
const rowValue = getSingleFieldValue(fieldid, rowIndex);
retArray.push(rowValue);
}catch(ev){}
});
return retArray;
}
//获取系统信息值
function getSystemValue(systeminfo, cellattr, triInfo) {
var cellValue = ""; //请求标题
if(cellattr && cellattr.indexOf(".")>-1) {
cellattr = cellattr.substring(cellattr.indexOf(".")+1);
}
if (cellattr === "-1") {
cellValue = this.getSingleFieldValue(cellattr, -1);
}
//紧急程度
else if (cellattr === "-2") {
cellValue = this.getSingleFieldValue(cellattr, -2);
}
//创建人
else if (cellattr === "-10") {
cellValue = systeminfo.creater;
}
//创建日期
else if (cellattr === "-11") {
cellValue = systeminfo.createdate;
}
//工作流ID
else if (cellattr === "-12") {
if (triInfo) {
cellValue = triInfo.workflowid;
}
}
//当前节点ID
else if (cellattr === "-13") {
cellValue = systeminfo.currentnodeid;
}
//未操作者
else if (cellattr === "-14") {
cellValue = systeminfo.nooperator;
}
//流程状态
else if (cellattr === "-15") {
cellValue = systeminfo.status;
}
//归档日期
else if (cellattr === "-16") {
cellValue = systeminfo.receivedate;
}
//签字意见
else if (cellattr === "-17") {
cellValue = systeminfo.remark;
}
//当前操作者
else if (cellattr === "-18") {
cellValue = systeminfo.userid;
}
//表单ID
else if (cellattr === "-51") {
if (triInfo) {
cellValue = triInfo.formid;
}
}
//是否表单
else if (cellattr === "-52") {
if (triInfo) {
cellValue = triInfo.isbill;
}
}
//请求ID
else if (cellattr === "-53") {
if (triInfo) {
cellValue = triInfo.requestid;
}
}
return cellValue;
}
//判断字段是不是数值类型
const isFieldNum = (fieldid) => {
const fieldAttr = window.WfForm.getFieldInfo(fieldid);
if(fieldAttr && fieldAttr.htmltype === 1 && fieldAttr.detailtype != 1) {
return true;
} else {
return false;
}
}
//main.21943 => 21943
const convertCellAttrToFieldid = (cellAttr) =>{
const symbol = cellAttr.split(".")[0].toLowerCase();
const fieldid = cellAttr.split(".")[1];
return fieldid;
}
//SUM(ABS([main.6306]),ABS([main.6307]))
//返回[main.6306]
function getFunction(formulatxt, cellattr) {
var index = formulatxt.indexOf(cellattr);
var beforeIndex = formulatxt.substring(0, index);
var afterIndex = formulatxt.substring(index + cellattr.length);
var funcStr = cellattr;
var char = "";
var flag = 0;
var isFunc = false;
while (beforeIndex) {
char = beforeIndex.substring(beforeIndex.length - 1);
beforeIndex = beforeIndex.substring(0, beforeIndex.length - 1);
if (char == "(") {
if (flag == 0) {
isFunc = true;
funcStr = char + funcStr;
} else {
flag += 1;
isFunc = false;
funcStr = char + funcStr;
}
} else if (char == ")") {
flag -= 1;
isFunc = false;
funcStr = char + funcStr;
} else if (isFunc == true && /[\+\-\-\>\≥\=\×\÷\<\≤\≠\%\,]/.test(char)) {
break;
} else {
funcStr = char + funcStr;
}
}
char = "";
flag = 0;
isFunc = false;
while (afterIndex) {
char = afterIndex.substring(0, 1);
afterIndex = afterIndex.substring(1);
if (char == ")") {
if (flag == 0) {
isFunc = true;
funcStr = funcStr + char;
} else {
flag = flag + 1;
isFunc = false;
funcStr = funcStr + char;
}
} else if (char == "(") {
flag = flag - 1;
isFunc = false;
funcStr = funcStr + char;
} else if (isFunc == true && /[\+\-\-\>\≥\=\×\÷\<\≤\≠\%\,]/.test(char)) {
break;
} else {
funcStr = funcStr + char;
}
}
return funcStr;
}