CellMathDialog.vue
8.31 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
<template>
<div style="margin: -20px -10px">
<el-container style="height:280px">
<el-aside width="293px" style="border:1px solid #eee">
<el-scrollbar class="scrollbar-fullheight">
<ht-tree
:data="[boDefData]"
:props="defaultProps"
:default-expand-all="expandAll"
@node-click="handleNodeClick"
>
<span class="custom-tree-node" slot-scope="{ node, data }">
<i
class="icon-number bo-tree__icon"
title="数字类型的字段"
v-if="data.columnType=='number'"
/>
<i
class="icon-text bo-tree__icon"
title="字符串类型的字段"
v-if="data.columnType=='varchar'"
/>
<i class="icon-date bo-tree__icon" title="日期类型的字段" v-if="data.columnType=='date'" />
<span class="bo-tree__label" :title="node.label">{{ node.label }}</span>
</span>
</ht-tree>
</el-scrollbar>
</el-aside>
<el-main style="padding:0 0 0 20px">
<el-tag type="warning">选择左侧的业务对象字段(数字类型),结合下方的运算符生成运算表达式。
<br/>注意:如果是子表数据计算,需要将公式中的rowIndex修改为具体的行号。</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('convertCurrency')">RMB</el-button>
</el-col>
</el-row>
</div>
</el-card>
</el-main>
</el-container>
<el-container>
<el-main style="padding:0">
<el-card class="box-card operator-card" shadow="never">
<div slot="header">
<span>运算表达式</span>
<!-- <ht-checkbox
style="float:right;font-size:12px;"
v-model="countSetting.isSingleRecord"
:options="[{key: 'true', value: '子表中单条记录运算'}]"
/> -->
</div>
<div>
<el-input
v-model="countSetting.mathExp"
type="textarea"
:rows="8"
:cols="120"
autocomplete="off"
id="singleText"
/>
</div>
</el-card>
</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-dialog",
props: ["visible", "boDefData", "mathExp"],
data() {
return {
expandAll: true,
defaultProps: {
children: "children",
label: "desc"
},
countSetting: { isSingleRecord: "", mathExp: "" }
};
},
mounted() {
this.mathExpAssign(this.mathExp);
},
watch: {
mathExp(val) {
this.mathExpAssign(val);
}
},
methods: {
mathExpAssign(val) {
this.$set(this.countSetting, "mathExp", val);
},
cancel() {
this.$emit("update:visible", false);
},
confirm() {
this.$emit("update:mathExp", this.countSetting.mathExp);
try {
if(this.$parent && this.$parent.$parent.setHotCellMathExp){
this.$parent.$parent.setHotCellMathExp(this.countSetting.mathExp);
}
} catch (error) {}
this.$emit("update:visible", false);
},
//统计函数相关配置
async insert(myValue) {
const myField = document.getElementById('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.countSetting.mathExp =
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
);
} else if(!this.countSetting.mathExp){
this.countSetting.mathExp = value;
}else{
this.countSetting.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) {
path += "[rowIndex]";
}
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);
}
}
};
</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;
}
</style>