MathRowDialog.vue
9.86 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
<template>
<div style="margin: -20px -10px">
<el-container style="height:220px">
<el-main style="padding:0 0 0 20px">
<el-tag type="warning">单列跨行统计函数说明:1、行号从1开始;2、编写规则:中括号包含行号+运算符;3、示例:(1)第一行乘以第二行除以100:[1]*[2]/100,</el-tag>
<el-tag type="warning">(2)统计第1行到第20行的和:FormMath.sum([1:20])</el-tag>
<el-card class="box-card operator-card" shadow="never">
<div slot="header">
<span>通用运算符</span>
</div>
<div>
<el-row style="margin-top: 10px;">
<el-col :span="5">
<el-button circle title="加" @click="insert('+')">+</el-button>
</el-col>
<el-col :span="5">
<el-button circle title="减" @click="insert('-')">-</el-button>
</el-col>
<el-col :span="5">
<el-button circle title="乘" @click="insert('*')">×</el-button>
</el-col>
<el-col :span="5">
<el-button circle title="除" @click="insert('/')">÷</el-button>
</el-col>
<el-col :span="4">
<el-button circle title="括号" @click="insert('()')">()</el-button>
</el-col>
</el-row>
<el-row style="margin-top: 20px;">
<el-col :span="5">
<el-button circle title="绝对值" @click="insert('abs')">|x|</el-button>
</el-col>
<el-col :span="5">
<el-button circle title="四舍五入" @click="insert('round')">≈</el-button>
</el-col>
<el-col :span="5">
<el-button circle title="开平方" @click="insert('sqrt')">开方</el-button>
</el-col>
<el-col :span="5">
<el-button circle title="保留小数点后2位" @click="insert('tofixed')">保留</el-button>
</el-col>
<el-col :span="4">
<el-button circle title="求和" @click="insert('sum')">∑</el-button>
</el-col>
</el-row>
</div>
</el-card>
</el-main>
</el-container>
<el-container style="height:280px">
<el-header style="height:30px;line-height:30px;background: #fafafa; font-weight: bold;font-size: 14px;">
<el-button size="small" type="text" icon="el-icon-plus" @click="addMathExp()">添加</el-button>
</el-header>
<el-main style="padding:0 0 0 20px">
<table class="form-table" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr class="linkageTable-tr">
<td width="120px">描述</td>
<td width="90px">统计行号(从1开始)</td>
<td width="180px">公式</td>
<td width="150px">操作</td>
</tr>
<tr
class="linkageTable-tr"
v-for="(field, index) in countSetting.rowMathExps"
:key="index" @click="rowClick(index)"
>
<td><ht-input v-model="field.desc" /></td>
<td><el-input-number v-model="field.sn" controls-position="right" :min="0" :max="1000"></el-input-number></td>
<td>
<el-input
v-model="field.mathExp"
type="textarea"
:rows="2"
:cols="60"
autocomplete="off"
:id="index+'_singleText'"
/>
</td>
<td>
<el-button
icon="el-icon-delete"
@click="mathExpRemove(field)"
></el-button>
<el-button size="small"
icon="el-icon-arrow-up"
@click="up(index,countSetting.rowMathExps)"
></el-button>
<el-button
icon="el-icon-arrow-down"
@click="down(index,countSetting.rowMathExps)"
></el-button>
</td>
</tr>
</tbody>
</table>
</el-main>
</el-container>
<div slot="footer" class="dialog-footer" style="margin-top:20px;text-align:right;">
<el-button type="primary" @click="confirm">确 定</el-button>
<el-button @click="cancel">取 消</el-button>
</div>
</div>
</template>
<script>
export default {
name: "math-row-dialog",
props: ["visible", "boDefData", "rowMathExp","boSubEntity","subTables"],
data() {
return {
expandAll: true,
defaultProps: {
children: "children",
label: "desc"
},
countSetting: { isSingleRecord: false, rowMathExps: [] },
curMathExp:'',
curMathExpIndex:-1,
};
},
mounted() {
this.mathExpAssign(this.rowMathExp);
},
watch: {
mathExp(val) {
this.mathExpAssign(val);
},
},
methods: {
mathExpAssign(val) {
if(!val){
val = [];
}
this.$set(this.countSetting, "rowMathExps", val);
},
cancel() {
this.$emit("update:visible", false);
},
confirm() {
this.$emit("update:rowMathExp", this.countSetting.rowMathExps);
try {
if(this.$parent && this.$parent.$parent.setHotColumRowMathExp){
this.$parent.$parent.setHotColumRowMathExp(this.countSetting.rowMathExps);
}
} catch (error) {}
this.$emit("update:visible", false);
},
//统计函数相关配置
async insert(myValue) {
const cindex = this.curMathExpIndex;
const myField = document.getElementById(cindex+'_singleText');
var value = myValue;
var endPosition = 0;
if (myValue == "abs") {
value = "FormMath.abs()";
endPosition = 1;
} else if (myValue == "round") {
value = "FormMath.round()";
endPosition = 1;
} else if (myValue == "sqrt") {
value = "FormMath.sqrt()";
endPosition = 1;
} else if (myValue == "tofixed") {
endPosition = 3;
value = "FormMath.tofixed(,2)";
} else if (myValue == "convertCurrency") {
value = "FormMath.convertCurrency()";
endPosition = 1;
} else if (myValue == "()") {
endPosition = 1;
} else if (myValue == "sum") {
value = "FormMath.sum()";
endPosition = 1;
} else if (myValue == "max") {
value = "FormMath.max()";
endPosition = 1;
} else if (myValue == "min") {
value = "FormMath.min()";
endPosition = 1;
} else if (myValue == "average") {
value = "FormMath.average()";
endPosition = 1;
}
if (myField.selectionStart || myField.selectionStart === 0) {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
this.curMathExp =
myField.value.substring(0, startPos) +
value +
myField.value.substring(endPos, myField.value.length);
await this.$nextTick(); // 这句是重点, 圈起来
myField.focus();
myField.setSelectionRange(
endPos + value.length,
endPos + value.length - endPosition
);
}
if(!this.countSetting.rowMathExps[cindex]['mathExp']){
this.countSetting.rowMathExps[cindex]['mathExp'] = value;
}else{
this.countSetting.rowMathExps[cindex]['mathExp'] += value;
}
},
handleNodeClick(data, treeNode) {
if (data.dataType != "number") {
this.$message({ message: "请选择数字类型的字段! ", type: "warning" });
return;
}
var isMain = treeNode.parent.data.nodeType == "main";
var path = "data." + data.path + "." + data.name;
if (!isMain && this.countSetting.isSingleRecord) {
path = "item." + data.name;
}
if (isMain && this.countSetting.isSingleRecord) {
this.$message({
message: "子表中单条记录运算模式下,不能选择主表字段!",
type: "warning"
});
return;
}
var desc = "";
if (isMain || this.countSetting.isSingleRecord) {
desc = "{" + data.desc + "(" + path + ")" + "}";
} else {
desc = "[{" + data.desc + "(" + path + ")" + "}]";
}
this.insert(desc);
},
addMathExp(){
this.countSetting.rowMathExps.push({desc:'',mathExp:''});
},
rowClick(index){
this.curMathExpIndex = index;
this.curMathExp = this.countSetting.rowMathExps[index]['mathExp'];
},
mathExpRemove(item){
this.countSetting.rowMathExps.remove(item);
},
up(index, data) {
if (index === 0) {
this.$message({
message: "已经是列表中第一位",
type: "warning"
});
} else {
let temp = data[index - 1];
Vue.set(data, index - 1, data[index]);
Vue.set(data, index, temp);
}
},
down(index, data) {
if (index === data.length - 1) {
this.$message({
message: "已经是列表中最后一位",
type: "warning"
});
} else {
this.isTransition = true;
let i = data[index + 1];
Vue.set(data, index + 1, data[index]);
Vue.set(data, index, i);
}
},
}
};
</script>
<style lang="scss" scoped>
.operator-card {
margin-top: 10px;
}
.operator-card >>> .el-card__header,
.operator-card >>> .el-card__body {
padding: 10px;
}
.operator-card >>> .el-card__header {
background: #fafafa;
color: #777;
font-size: 14px;
font-weight: bold;
}
.operator-card .el-button {
width: 32px;
height: 32px;
padding: 0;
line-height: 32px;
text-align: center;
color: #777;
font-weight: bold;
}
.bo-tree__label {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.bo-tree__icon {
outline: 2px solid #999;
}
.bo-tree__icon + .bo-tree__label {
margin-left: 8px;
}
.form-table>tfoot>tr>td, .form-table>thead>tr>th{
padding: 5px;
}
</style>