houzhongjian
2024-07-23 8501060c4f921d1e744c477e4dc08eb47b52693c
提交 | 用户 | 时间
850106 1 <template>
H 2   <el-dialog
3       :title="!dataForm.id ? '新增' : '修改'"
4       :close-on-click-modal="false"
5       width="60%"
6       :visible.sync="visible">
7     <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()"
8              label-width="100px">
9       <el-divider content-position="left">基本信息</el-divider>
10       <el-row :gutter="20">
11         <el-col :span="6">
12           <el-form-item label="煤矿" prop="mkbm">
13             <dict-select-tag v-model="dataForm.mkbm" placeholder="煤矿" dictCode="mkbm" @change="changeMkbm"/>
14           </el-form-item>
15         </el-col>
16         <el-col :span="6">
17           <el-form-item label="生产系统" prop="xtbm">
18             <dict-select-tag v-model="dataForm.xtbm" placeholder="生产安全系统" dictCode="scxtbm" @change="changeScxt"/>
19           </el-form-item>
20         </el-col>
21         <el-col :span="6">
22           <el-form-item label="监控系统" prop="jkbm">
23             <el-select v-model="dataForm.jkbm" placeholder="请选择" @change="changeJkxt">
24               <el-option
25                   v-for="item in jkxtOptions"
26                   :key="item.jkxtbm"
27                   :label="item.jkxtmc"
28                   :value="item.jkxtbm">
29               </el-option>
30             </el-select>
31           </el-form-item>
32         </el-col>
33         <el-col :span="6">
34           <el-form-item label="设备" prop="sbbm">
35             <el-select v-model="dataForm.sbbm" placeholder="请选择" @change="changeDevice">
36               <el-option
37                   v-for="item in deviceOptions"
38                   :key="item.sbbm"
39                   :label="item.sbmc"
40                   :value="item.sbbm">
41               </el-option>
42             </el-select>
43           </el-form-item>
44         </el-col>
45       </el-row>
46       <el-row :gutter="10">
47         <el-col :span="12">
48           <el-form-item label="测点编码" prop="lsh">
49             <el-input v-model="dataForm.lsh" placeholder="4位流水码(自动生成)" maxlength="4">
50               <template slot="prepend">{{dataForm.sbbm}}</template>
51             </el-input>
52           </el-form-item>
53         </el-col>
54         <el-col :span="12">
55           <el-form-item label="测点名称" prop="cdmc">
56             <el-input v-model="dataForm.cdmc" placeholder="测点名称" maxlength="40" clearable></el-input>
57           </el-form-item>
58         </el-col>
59       </el-row>
60       <el-row :gutter="20">
61         <el-col :span="24">
62           <el-form-item label="测点描述" prop="cdxxms">
63             <el-input v-model="dataForm.cdxxms" placeholder="测点信息描述" maxlength="100"></el-input>
64           </el-form-item>
65         </el-col>
66       </el-row>
67       <el-row :gutter="20">
68         <el-col :span="6">
69           <el-form-item label="测点类型" prop="cdlx">
70             <dict-select-tag v-model="dataForm.cdlx" placeholder="测点类型" dictCode="data-cdlx"/>
71           </el-form-item>
72         </el-col>
73         <el-col :span="6">
74           <el-form-item label="读写标记" prop="dxbj">
75             <dict-select-tag v-model="dataForm.dxbj" placeholder="读写标记" dictCode="data-dxbj"/>
76           </el-form-item>
77         </el-col>
78         <el-col :span="6">
79           <el-form-item label="量程下限" prop="lcxx">
80             <el-input v-model="dataForm.lcxx" placeholder="量程下限" maxlength="50" clearable></el-input>
81           </el-form-item>
82         </el-col>
83         <el-col :span="6">
84           <el-form-item label="量程上限" prop="lcsx">
85             <el-input v-model="dataForm.lcsx" placeholder="量程上限" maxlength="50" clearable></el-input>
86           </el-form-item>
87         </el-col>
88       </el-row>
89       <el-row :gutter="20">
90         <el-col :span="6">
91           <el-form-item label="默认值" prop="mrz">
92             <el-input v-model="dataForm.mrz" placeholder="默认值" maxlength="50" clearable></el-input>
93           </el-form-item>
94         </el-col>
95         <el-col :span="6">
96           <el-form-item label="数据长度" prop="sjcd">
97             <el-input v-model="dataForm.sjcd" placeholder="数据长度" maxlength="50" clearable></el-input>
98           </el-form-item>
99         </el-col>
100         <el-col :span="6">
101           <el-form-item label="寄存器长度" prop="jcqcd">
102             <el-input v-model="dataForm.jcqcd" placeholder="寄存器长度" maxlength="50" clearable></el-input>
103           </el-form-item>
104         </el-col>
105         <el-col :span="6">
106           <el-form-item label="大小端" prop="dxd">
107             <el-input v-model="dataForm.dxd" placeholder="大小端" maxlength="50" clearable></el-input>
108           </el-form-item>
109         </el-col>
110       </el-row>
111       <el-row :gutter="20">
112         <el-col :span="6">
113           <el-form-item label="掩码" prop="ym">
114             <el-input v-model="dataForm.ym" placeholder="掩码" maxlength="50" clearable></el-input>
115           </el-form-item>
116         </el-col>
117         <el-col :span="6">
118           <el-form-item label="移动" prop="yd">
119             <dict-select-tag v-model="dataForm.yd" placeholder="移动" dictCode="data-yd"/>
120           </el-form-item>
121         </el-col>
122         <el-col :span="6">
123           <el-form-item label="系数" prop="xs">
124             <el-input v-model="dataForm.xs" placeholder="系数" maxlength="50" clearable></el-input>
125           </el-form-item>
126         </el-col>
127         <el-col :span="6">
128           <el-form-item label="偏移" prop="py">
129             <el-input v-model="dataForm.py" placeholder="偏移" maxlength="50" clearable></el-input>
130           </el-form-item>
131         </el-col>
132       </el-row>
133       <el-row :gutter="20">
134         <el-col :span="6">
135           <el-form-item label="基准" prop="jz">
136             <el-input v-model="dataForm.jz" placeholder="基准" maxlength="50" clearable></el-input>
137           </el-form-item>
138         </el-col>
139         <el-col :span="6">
140           <el-form-item label="断言" prop="dy">
141             <el-input v-model="dataForm.dy" placeholder="断言" maxlength="50" clearable></el-input>
142           </el-form-item>
143         </el-col>
144         <el-col :span="6">
145           <el-form-item label="有无符号" prop="ywfh">
146             <dict-select-tag v-model="dataForm.ywfh" placeholder="有无符号" dictCode="data-ywfh"/>
147           </el-form-item>
148         </el-col>
149         <el-col :span="6">
150           <el-form-item label="小数位数" prop="xsws">
151             <el-input v-model="dataForm.xsws" placeholder="小数位数" maxlength="50" clearable></el-input>
152           </el-form-item>
153         </el-col>
154       </el-row>
155       <el-row :gutter="20">
156         <el-col :span="6">
157           <el-form-item label="结果类型" prop="cljglx">
158             <el-input v-model="dataForm.cljglx" placeholder="测量结果类型" maxlength="50" clearable></el-input>
159           </el-form-item>
160         </el-col>
161         <el-col :span="6">
162           <el-form-item label="累积量" prop="ljl">
163             <dict-select-tag v-model="dataForm.ljl" placeholder="累积量" dictCode="data-ljl"/>
164           </el-form-item>
165         </el-col>
166         <el-col :span="6">
167           <el-form-item label="计量单位" prop="jldw">
168             <el-input v-model="dataForm.jldw" placeholder="计量单位" maxlength="50" clearable></el-input>
169           </el-form-item>
170         </el-col>
171         <el-col :span="6">
172           <el-form-item label="源变量" prop="ybl">
173             <el-input v-model="dataForm.ybl" placeholder="源变量" maxlength="50" clearable></el-input>
174           </el-form-item>
175         </el-col>
176       </el-row>
177       <el-row :gutter="20">
178         <el-col :span="6">
179           <el-form-item label="控制器ID" prop="kzqId">
180             <el-input v-model="dataForm.kzqId" placeholder="控制器ID" maxlength="50" clearable></el-input>
181           </el-form-item>
182         </el-col>
183         <el-col :span="6">
184           <el-form-item label="逻辑测点" prop="ljcd">
185             <dict-select-tag v-model="dataForm.ljcd" placeholder="逻辑测点" dictCode="data-ljcd"/>
186           </el-form-item>
187         </el-col>
188         <el-col :span="6">
189           <el-form-item label="报警下限" prop="bjxx">
190             <el-input v-model="dataForm.bjxx" placeholder="报警下限" maxlength="50" clearable></el-input>
191           </el-form-item>
192         </el-col>
193         <el-col :span="6">
194           <el-form-item label="报警上限" prop="bjsx">
195             <el-input v-model="dataForm.bjsx" placeholder="报警上限" maxlength="50" clearable></el-input>
196           </el-form-item>
197         </el-col>
198       </el-row>
199       <!--采集配置-->
200       <el-divider content-position="left">采集配置</el-divider>
201       <el-row :gutter="20">
202         <el-col :span="6">
203           <el-form-item label="采集类型" prop="pointTypeId">
204             <el-select v-model="dataForm.pointTypeId" placeholder="采集类型" @change="changePointtype" clearable>
205               <el-option
206                   v-for="item in pointtypeList"
207                   :key="item.id"
208                   :label="item.descp"
209                   :value="item.id">
210               </el-option>
211             </el-select>
212           </el-form-item>
213         </el-col>
214         <!--        <el-col :span="6">-->
215         <!--          <el-form-item label="存储表" prop="storeTypeId">-->
216         <!--            <el-select v-model="dataForm.storeTypeId" placeholder="存储表" maxlength="36" clearable>-->
217         <!--              <el-option-->
218         <!--                v-for="item in storetypeList"-->
219         <!--                :key="item.id"-->
220         <!--                :label="item.storetypename"-->
221         <!--                :value="item.id">-->
222         <!--              </el-option>-->
223         <!--            </el-select>-->
224         <!--          </el-form-item>-->
225         <!--        </el-col>-->
226         <el-col :span="6">
227           <el-form-item label="采集频率" prop="minfreqid">
228             <el-select v-model="dataForm.minfreqid" placeholder="采集频率" maxlength="36" clearable>
229               <el-option
230                   v-for="item in minfreqList"
231                   :key="item.id"
232                   :label="item.minfreqname"
233                   :value="item.id">
234               </el-option>
235             </el-select>
236           </el-form-item>
237         </el-col>
238       </el-row>
239
240       <!--计量点-->
241       <el-row :gutter="20" v-if="dataForm.pointtypename === 'MEASURE'">
242         <el-col :span="12">
243           <el-form-item label="数据源" prop="measurePoint.sourceid">
244             <el-select v-model="dataForm.measurePoint.sourceid" placeholder="数据源" maxlength="36" clearable>
245               <el-option
246                   v-for="item in sourceList"
247                   :key="item.id"
248                   :label="item.sourcename"
249                   :value="item.id">
250               </el-option>
251             </el-select>
252           </el-form-item>
253         </el-col>
254         <el-col :span="12">
255           <el-form-item label="TAG编号" prop="measurePoint.tagno">
256             <tag-select v-if="dataForm.measurePoint.sourceid === ''" style="width: 100%;"
257                         v-model="dataForm.measurePoint.tagno"/>
258             <tag-select v-if="dataForm.measurePoint.sourceid === 'a8f05cd1-80cf-48a0-a46c-d4b830af3ed3'"
259                         style="width: 100%;" v-model="dataForm.measurePoint.tagno"/>
260             <el-select v-if="dataForm.measurePoint.sourceid === '33325cd1-80cf-48a0-a46c-d4b830af3ed3'" filterable
261                        style="width: 100%;" v-model="dataForm.measurePoint.xsttagno">
262               <el-option
263                   v-for="item in xsttagnoList"
264                   :key="item.pointName"
265                   :label="`deviceName=${item.deviceCode};tagName=${item.pointName}`"
266                   :value="item.pointCode">
267               </el-option>
268             </el-select>
269             <el-select v-if="dataForm.measurePoint.sourceid === '1a45c263-a09c-48af-aa61-d591dc807f8b'" filterable
270                        style="width: 100%;" v-model="dataForm.measurePoint.elelowtagno">
271               <el-option
272                   v-for="item in elelowTagnoList"
273                   :key="item.tagName"
274                   :label="item.tagName"
275                   :value="item.tagName">
276               </el-option>
277             </el-select>
278             <el-select v-if="dataForm.measurePoint.sourceid === 'cc308810-20ff-4ec2-89bd-66ba050bf639'" filterable
279                        style="width: 100%;" v-model="dataForm.measurePoint.fxjytagno">
280               <el-option
281                   v-for="item in fxjyTagnoList"
282                   :key="`${item.tagType}_${item.tagCode}`"
283                   :label="`tagType=${item.tagType};tagCode=${item.tagCode}`"
284                   :value="`${item.tagType}_${item.tagCode}`">
285               </el-option>
286             </el-select>
287           </el-form-item>
288         </el-col>
289       </el-row>
290
291       <!--计算点-->
292       <el-row :gutter="20" v-if="dataForm.pointtypename === 'CALCULATE'">
293         <el-col :span="24">
294           <el-form-item label="表达式">
295             <el-table
296                 :data="expressionList"
297                 border
298                 style="width: 100%">
299               <el-table-column
300                   type="index"
301                   align="center"
302                   width="50"
303                   label="序号">
304               </el-table-column>
305               <el-table-column
306                   prop=""
307                   label="左括号"
308                   width="120"
309                   align="center">
310                 <template slot-scope="scope">
311                   <el-input
312                       size="mini"
313                       v-model="scope.row.parenthesesLeft"
314                       placeholder=""
315                       readonly
316                       maxlength="16">
317                     <el-button slot="prepend" @click="addParenthesesLeft(scope.$index, scope.row)">+</el-button>
318                     <el-button slot="append" @click="removeParenthesesLeft(scope.$index, scope.row)">-</el-button>
319                   </el-input>
320                 </template>
321               </el-table-column>
322               <el-table-column
323                   prop=""
324                   label="采集点"
325                   align="center">
326                 <template slot-scope="scope">
327                   <el-select
328                       size="mini"
329                       v-model="scope.row.point"
330                       filterable
331                       placeholder="请选择">
332                     <el-option
333                         v-for="(item, index) in pointList"
334                         :key="index"
335                         :label="item.cdmc"
336                         :value="item.cdbm">
337                     </el-option>
338                   </el-select>
339                 </template>
340               </el-table-column>
341               <el-table-column
342                   prop=""
343                   label="运算值"
344                   align="center">
345                 <template slot-scope="scope">
346                   <el-input
347                       size="mini"
348                       v-model="scope.row.point"
349                       placeholder="运算值"
350                       maxlength="16"
351                       clearable>
352                   </el-input>
353                 </template>
354               </el-table-column>
355               <el-table-column
356                   prop=""
357                   label="右括号"
358                   width="120"
359                   align="center">
360                 <template slot-scope="scope">
361                   <el-input
362                       size="mini"
363                       v-model="scope.row.parenthesesRight"
364                       placeholder=""
365                       readonly
366                       maxlength="16">
367                     <el-button slot="prepend" @click="addParenthesesRight(scope.$index, scope.row, ')')">+</el-button>
368                     <el-button slot="append" @click="removeParenthesesRight(scope.$index, scope.row)">-</el-button>
369                   </el-input>
370                 </template>
371               </el-table-column>
372               <el-table-column
373                   prop=""
374                   label="运算符"
375                   width="90"
376                   align="center">
377                 <template slot-scope="scope">
378                   <el-select size="mini" v-model="scope.row.operator" clearable placeholder="请选择">
379                     <el-option
380                         v-for="item in operatorList"
381                         :key="item"
382                         :label="item"
383                         :value="item">
384                     </el-option>
385                   </el-select>
386                 </template>
387               </el-table-column>
388               <el-table-column
389                   prop=""
390                   label="操作"
391                   width="100"
392                   align="center">
393                 <template slot-scope="scope">
394                   <el-button
395                       @click.native.prevent="addExpressionRow(scope.$index, expressionList)"
396                       type="text"
397                       size="small">
398                     添加
399                   </el-button>
400                   <el-button
401                       @click.native.prevent="deleteExpressionRow(scope.$index, expressionList)"
402                       type="text"
403                       size="small">
404                     删除
405                   </el-button>
406                 </template>
407               </el-table-column>
408             </el-table>
409           </el-form-item>
410         </el-col>
411       </el-row>
412     </el-form>
413     <span slot="footer" class="dialog-footer">
414       <el-button :loading="loading" @click="visible = false">取消</el-button>
415       <el-button :loading="loading" type="primary" @click="dataFormSubmit()">确定</el-button>
416     </span>
417   </el-dialog>
418 </template>
419
420 <script>
421   import DictSelectTag from '@/components/dict/dict-select-tag'
422   import TagSelect from '@/components/tag/tag-select'
423   import {isPositiveInteger} from '@/utils/validate'
424
425   export default {
426     components: {
427       DictSelectTag,
428       TagSelect
429     },
430     data() {
431       let validIsPositiveInteger = (rule, value, callback) => {
432         if (value && !isPositiveInteger(value)) {
433           callback(new Error('应该为正整数'))
434         } else {
435           callback()
436         }
437       }
438       return {
439         loading: true,
440         dialogWidth: 0,
441         xsttagnoList: [],
442         fxjyTagnoList: [],
443         elelowTagnoList: [],
444         pointtypeList: [],
445         pointtypeMap: {},
446         minfreqList: [],
447         storetypeList: [],
448         datatypeList: [],
449         sourceList: [],
450         expressionList: [],
451         pointList: [],
452         pointMap: {},
453         operatorList: ['+', '-', '*', '/', '&', '|', '!', '>', '<'],
454         visible: false,
455         roleList: [],
456         jkxtOptions: [],
457         deviceOptions: [],
458         deviceMap: {},
459         allDictItems: JSON.parse(window.localStorage.getItem('DICT_ITEM_MAP')),
460         dataForm: {
461           id: '',
462           mkbm: '',
463           xtbm: '',
464           jkbm: '',
465           sbbm: '',
466           cdbm: '',
467           lsh: '',
468           cdmc: '',
469           cdmcSx: '',
470           cdxxms: '',
471           cdlx: 'float',
472           dxbj: 1,
473           lcxx: 0,
474           lcsx: 1000,
475           mrz: '',
476           sjcd: '',
477           jcqcd: '',
478           dxd: '',
479           ym: '',
480           yd: 0,
481           xs: '',
482           py: '',
483           jz: '',
484           dy: '',
485           ywfh: 0,
486           xsws: '2',
487           cljglx: '',
488           ljl: 0,
489           jldw: '',
490           ybl: '',
491           kzqId: '',
492           bjxx: '',
493           bjsx: '',
494           ljcd: 0,
495           scsj: '',
496           sjybm: '',
497           minfreqid: '',
498           dimension: 1,
499           pointTypeId: '7d9fe1db-d7a1-407a-a267-ef2edab5cb6b',
500           storeTypeId: '',
501           enable: 1,
502           pointtypename: 'MEASURE',
503           mathPoint: {
504             id: '',
505             pointid: '',
506             expression: ''
507           },
508           measurePoint: {
509             id: '',
510             pointid: '',
511             tagno: '',
512             sourceid: '',
513             xsttagno: '',
514             elelowtagno: '',
515             fxjytagno: ''
516           }
517         },
518         dataRule: {
519           'mkbm': [
520             {required: true, message: '煤矿不能为空', trigger: 'blur'}
521           ],
522           'xtbm': [
523             {required: true, message: '生产安全系统不能为空', trigger: 'blur'}
524           ],
525           'jkbm': [
526             {required: true, message: '监控系统不能为空', trigger: 'blur'}
527           ],
528           'sbbm': [
529             {required: true, message: ' 设备(系统)不能为空', trigger: 'blur'}
530           ],
531           'cdbm': [
532             {required: true, message: '名称不能为空', trigger: 'blur'}
533           ],
534           'cdmc': [
535             {required: true, message: '点类型不能为空', trigger: 'blur'}
536           ],
537           'cdxxms': [
538             {required: true, message: '测点信息描述不能为空', trigger: 'blur'}
539           ],
540           'cdlx': [
541             {required: true, message: '测点类型不能为空', trigger: 'blur'}
542           ],
543           'dxbj': [
544             {required: true, message: '读写标记不能为空', trigger: 'blur'}
545           ],
546           'lcxx': [
547             {required: true, message: '量程下限不能为空', trigger: 'blur'}
548           ],
549           'lcsx': [
550             {required: true, message: '量程上限不能为空', trigger: 'blur'}
551           ],
552           'ywfh': [
553             {required: true, message: '有无符号不能为空', trigger: 'blur'}
554           ],
555           'xsws': [
556             {required: true, message: '小数位数不能为空', trigger: 'blur'}
557           ],
558           'ljl': [
559             {required: true, message: '累积量不能为空', trigger: 'blur'}
560           ],
561           'ljcd': [
562             {required: true, message: '逻辑测点不能为空', trigger: 'blur'}
563           ],
564           'enable': [
565             {required: true, message: '启用状态不能为空', trigger: 'blur'}
566           ],
567           'pointTypeId': [
568             {required: true, message: '点类型不能为空', trigger: 'blur'}
569           ],
570           'storeTypeId': [
571             {required: true, message: '存储类型不能为空', trigger: 'blur'}
572           ],
573           'mrz': [
574             {required: false, message: '存储类型不能为空', trigger: 'blur'}
575           ],
576           'minfreqid': [
577             {required: true, message: '采集频率不能为空', trigger: 'blur'}
578           ],
579           'dimension': [
580             {required: true, message: '采样范围不能为空', trigger: 'blur'},
581             {validator: validIsPositiveInteger, trigger: 'blur'}
582           ],
583           'measurePoint.tagno||measurePoint.xsttagno||measurePoint.elelowtagno||measurePoint.fxjytagno': [
584             {required: true, message: '名称不能为空', trigger: 'blur'}
585           ],
586           'measurePoint.sourceid': [
587             {required: true, message: '采集频率不能为空', trigger: 'blur'}
588           ]
589         }
590       }
591     },
592     methods: {
593       init(id) {
594         this.dataForm.id = id || 0
595         this.loading = true
596         this.visible = true
597         this.dataForm.pointtypename = 'MEASURE'
598         this.$nextTick(() => {
599           this.$refs['dataForm'].resetFields()
600           this.expressionList = [{
601             parenthesesLeft: '',
602             point: '',
603             parenthesesRight: '',
604             operator: ''
605           }]
606           this.dataForm.measurePoint.tagno = ''
607           this.dataForm.measurePoint.xsttagno = ''
608           this.dataForm.measurePoint.elelowtagno = ''
609           this.dataForm.measurePoint.fxjytagno = ''
610           this.dataForm.measurePoint.datatypeid = ''
611           this.dataForm.measurePoint.sourceid = ''
612           this.dataForm.pointTypeId = '7d9fe1db-d7a1-407a-a267-ef2edab5cb6b'
613         })
614         Promise.all([
615           this.getPointtypeList(),
616           this.getStoretypeList(),
617           this.getMinfreqList(),
618           this.getDatatypeList(),
619           this.getSourceList(),
620           this.getPointList(),
621           this.getXsttagnoList(),
622           this.getElelowtagnoList(),
623           this.getFxjytagnoList(),
624         ]).then(() => {
625           if (id) {
626             this.getInfo()
627           } else {
628             this.loading = false
629           }
630         })
631       },
632
633       getInfo() {
634         this.$http({
635           url: `/data/data/point/info/${this.dataForm.id}`,
636           method: 'get',
637           params: this.$http.adornParams()
638         }).then(({data}) => {
639           this.expressionList = []
640           if (data && data.code === 0) {
641             this.dataForm = data.data
642             this.getJkxt(this.dataForm.xtbm)
643             this.getDevice(this.dataForm.jkbm)
644             if (this.dataForm.pointtypename &&
645               this.dataForm.pointtypename === 'CALCULATE' &&
646               this.dataForm.mathPoint.expression) {
647               let expression = this.dataForm.mathPoint.expression
648               do {
649                 let indexArray = [
650                   expression.indexOf('+'),
651                   expression.indexOf('-'),
652                   expression.indexOf('*'),
653                   expression.indexOf('/'),
654                   expression.indexOf('&'),
655                   expression.indexOf('|'),
656                   expression.indexOf('!'),
657                   expression.indexOf('>'),
658                   expression.indexOf('<')
659                 ].sort(this.numAscSort)
660                 if (indexArray[indexArray.length - 1] !== -1) {
661                   let endIndex = 0
662                   for (let key in indexArray) {
663                     if (indexArray[key] > -1) {
664                       endIndex = indexArray[key]
665                       break
666                     }
667                   }
668
669                   // 运算值
670                   let pointStr = expression.substring(0, endIndex)
671
672                   // 运算符
673                   let operator = expression.substr(endIndex, 1)
674                   let indexOfParenthesesLeft = pointStr.indexOf('(')
675                   let lastIndexOfParenthesesLeft = pointStr.lastIndexOf('(')
676
677                   // 左括号
678                   let parenthesesLeft = ''
679                   if (indexOfParenthesesLeft !== -1 && lastIndexOfParenthesesLeft !== -1) {
680                     parenthesesLeft = pointStr.substring(indexOfParenthesesLeft, lastIndexOfParenthesesLeft + 1)
681                     pointStr = pointStr.substring(lastIndexOfParenthesesLeft + 1)
682                   }
683
684                   let indexOfParenthesesRight = pointStr.indexOf(')')
685                   let lastIndexOfParenthesesRight = pointStr.lastIndexOf(')')
686
687                   // 右括号
688                   let parenthesesRight = ''
689                   if (indexOfParenthesesRight !== -1 && lastIndexOfParenthesesRight !== -1) {
690                     parenthesesRight = pointStr.substring(indexOfParenthesesRight, lastIndexOfParenthesesRight + 1)
691                     pointStr = pointStr.substring(0, indexOfParenthesesRight)
692                   }
693                   this.expressionList.push({
694                     parenthesesLeft: parenthesesLeft,
695                     point: pointStr,
696                     parenthesesRight: parenthesesRight,
697                     operator: operator
698                   })
699                   expression = expression.substring(endIndex + 1)
700                 } else {
701                   let pointStr = expression
702                   let indexOfParenthesesLeft = pointStr.indexOf('(')
703                   let lastIndexOfParenthesesLeft = pointStr.lastIndexOf('(')
704                   let parenthesesLeft = ''
705                   if (indexOfParenthesesLeft !== -1 && lastIndexOfParenthesesLeft !== -1) {
706                     parenthesesLeft = pointStr.substring(indexOfParenthesesLeft, lastIndexOfParenthesesLeft + 1)
707                     pointStr = pointStr.substring(lastIndexOfParenthesesLeft + 1)
708                   }
709                   let indexOfParenthesesRight = pointStr.indexOf(')')
710                   let lastIndexOfParenthesesRight = pointStr.lastIndexOf(')')
711                   let parenthesesRight = ''
712                   if (indexOfParenthesesRight !== -1 && lastIndexOfParenthesesRight !== -1) {
713                     parenthesesRight = pointStr.substring(indexOfParenthesesRight, lastIndexOfParenthesesRight + 1)
714                     pointStr = pointStr.substring(0, indexOfParenthesesRight)
715                   }
716                   this.expressionList.push({
717                     parenthesesLeft: parenthesesLeft,
718                     point: pointStr,
719                     parenthesesRight: parenthesesRight,
720                     operator: ''
721                   })
722                   expression = ''
723                 }
724               } while (expression && expression.length > 0)
725               this.dataForm.expressionList = this.expressionList
726             }
727             this.loading = false
728           }
729         })
730       },
731
732       changeMkbm() {
733         this.dataForm.xtbm = ''
734         this.dataForm.jkbm = ''
735         this.dataForm.sbbm = ''
736       },
737
738       changeScxt() {
739         this.dataForm.jkbm = ''
740         this.dataForm.sbbm = ''
741         if (this.dataForm.xtbm) {
742           this.jkxtOptions = []
743           this.getJkxt(this.dataForm.xtbm)
744         }
745       },
746
747       getJkxt(scxtbm) {
748         this.$http({
749           url: `/data/data/jkxt/all-list`,
750           method: 'get',
751           params: this.$http.adornParams({
752             'scxtbm': scxtbm
753           })
754         }).then(({data}) => {
755           if (data && data.code === 0) {
756             this.jkxtOptions = data.data
757           }
758         })
759       },
760
761       changeDevice() {
762         this.dataForm.cdmc = ''
763         if (this.allDictItems['mkbm']) {
764           let mkList = this.allDictItems['mkbm']
765           let mkMap = {}
766           mkList.forEach(function (item) {
767             mkMap[item.itemValue] = item.itemText
768           })
769           this.dataForm.cdmc = mkMap[this.dataForm.mkbm] + '+' + this.deviceMap[this.dataForm.sbbm]
770         }
771       },
772
773       changeJkxt() {
774         this.dataForm.sbbm = ''
775         if (this.dataForm.jkbm) {
776           this.deviceOptions = []
777           this.getDevice(this.dataForm.jkbm)
778         }
779       },
780
781       getDevice(jkbm) {
782         this.$http({
783           url: `/data/data/device/all-list`,
784           method: 'get',
785           params: this.$http.adornParams({
786             'jkxtbm': jkbm
787           })
788         }).then(({data}) => {
789           if (data && data.code === 0) {
790             this.deviceOptions = data.data
791             if (this.deviceOptions) {
792               this.deviceOptions.forEach(function (item) {
793                 this.deviceMap[item.sbbm] = item.sbmc
794               }, this)
795             }
796           }
797         })
798       },
799
800       addParenthesesLeft(index, row) {
801         if (row.parenthesesLeft) {
802           row.parenthesesLeft = row.parenthesesLeft + '('
803         } else {
804           row.parenthesesLeft = '('
805         }
806       },
807
808       removeParenthesesLeft(index, row) {
809         if (row.parenthesesLeft) {
810           row.parenthesesLeft = row.parenthesesLeft.substring(0, row.parenthesesLeft.length - 1)
811         } else {
812           row.parenthesesLeft = ''
813         }
814       },
815       addParenthesesRight(index, row) {
816         if (row.parenthesesRight) {
817           row.parenthesesRight = row.parenthesesRight + ')'
818         } else {
819           row.parenthesesRight = ')'
820         }
821       },
822       removeParenthesesRight(index, row) {
823         if (row.parenthesesRight) {
824           row.parenthesesRight = row.parenthesesRight.substring(0, row.parenthesesRight.length - 1)
825         } else {
826           row.parenthesesRight = ''
827         }
828       },
829       numAscSort(a, b) {
830         return a - b
831       },
832       resetFields(obj) {
833         for (let key in obj) {
834           if (key === 'pointtypename') {
835             continue
836           }
837           if (obj[key] instanceof Array) {
838             obj[key] = []
839           } else if (obj[key] instanceof Object) {
840             this.resetFields(obj[key])
841           } else {
842             obj[key] = ''
843           }
844         }
845       },
846       setDefaultFields(id, pointtypename) {
847         this.dataForm.id = id || 0
848         this.dataForm.pointtypename = pointtypename || ''
849         this.dataForm.point.dimension = 1
850         this.expressionList = [{
851           parenthesesLeft: '',
852           point: '',
853           parenthesesRight: '',
854           operator: ''
855         }]
856       },
857       // 采集类型
858       getPointtypeList() {
859         this.$http({
860           url: '/data/data/point-type/list',
861           method: 'get',
862           params: this.$http.adornParams({
863             'page': 1,
864             'limit': 100
865           })
866         }).then(({data}) => {
867           if (data && data.code === 0) {
868             this.pointtypeList = data.page.list
869             this.pointtypeList.forEach(function (value) {
870               this.pointtypeMap[value.id] = value.pointtypename
871             }, this)
872           } else {
873             this.pointtypeList = []
874           }
875         })
876       },
877       getMinfreqList() {
878         this.$http({
879           url: '/data/data/min-freq/list',
880           method: 'get',
881           params: this.$http.adornParams({
882             'page': 1,
883             'limit': 100
884           })
885         }).then(({data}) => {
886           if (data && data.code === 0) {
887             this.minfreqList = data.page.list
888           } else {
889             this.minfreqList = []
890           }
891         })
892       },
893       getStoretypeList() {
894         this.$http({
895           url: '/data/data/store-type/list',
896           method: 'get',
897           params: this.$http.adornParams({
898             'page': 1,
899             'limit': 100
900           })
901         }).then(({data}) => {
902           if (data && data.code === 0) {
903             this.storetypeList = data.page.list
904           } else {
905             this.storetypeList = []
906           }
907         })
908       },
909       getDatatypeList() {
910         this.$http({
911           url: '/data/data/data-type/list',
912           method: 'get',
913           params: this.$http.adornParams({
914             'page': 1,
915             'limit': 100
916           })
917         }).then(({data}) => {
918           if (data && data.code === 0) {
919             this.datatypeList = data.page.list
920           } else {
921             this.datatypeList = []
922           }
923         })
924       },
925       getSourceList() {
926         this.$http({
927           url: '/data/data/data-source/list',
928           method: 'get',
929           params: this.$http.adornParams({
930             'page': 1,
931             'limit': 100
932           })
933         }).then(({data}) => {
934           if (data && data.code === 0) {
935             this.sourceList = data.page.list
936           } else {
937             this.sourceList = []
938           }
939         })
940       },
941       getPointList() {
942         this.$http({
943           url: '/data/data/point/list/all',
944           method: 'get',
945           params: {}
946         }).then(({data}) => {
947           if (data && data.code === 0) {
948             this.pointList = data.data
949             this.pointList.forEach(function (value) {
950               this.pointMap[value.id] = value.pointname
951             }, this)
952           } else {
953             this.pointList = []
954           }
955         })
956       },
957       getXsttagnoList() {
958         this.$http({
959           url: '/data/http/xst/tag/list',
960           method: 'get'
961         }).then(({data}) => {
962           if (data && data.code === 0) {
963             this.xsttagnoList = data.data
964           } else {
965             this.xsttagnoList = []
966           }
967         })
968       },
969       getElelowtagnoList() {
970         this.$http({
971           url: '/data/http/ele-low/tag/list',
972           method: 'get'
973         }).then(({data}) => {
974           if (data && data.code === 0) {
975             this.elelowTagnoList = data.data
976           } else {
977             this.elelowTagnoList = []
978           }
979         })
980       },
981       getFxjytagnoList() {
982         this.$http({
983           url: '/data/http/fxjy/tag/list',
984           method: 'get'
985         }).then(({data}) => {
986           if (data && data.code === 0) {
987             this.fxjyTagnoList = data.data
988           } else {
989             this.fxjyTagnoList = []
990           }
991         })
992       },
993       changePointtype(value) {
994         this.dataForm.pointtypename = this.pointtypeMap[value]
995         if (this.dataForm.pointtypename === 'CONSTANT') {
996           this.dataRule['mrz'][0].required = true
997         } else {
998           this.dataRule['mrz'][0].required = false
999         }
1000       },
1001       deleteExpressionRow(index, rows) {
1002         if (!rows || rows.length === 1) {
1003           this.$message({
1004             message: '不能全部删除!',
1005             type: 'error',
1006             duration: 1500
1007           })
1008           return
1009         }
1010         rows.splice(index, 1)
1011       },
1012       addExpressionRow(index, rows) {
1013         let row = JSON.parse(JSON.stringify(rows[index]))
1014         rows.splice(index, 0, row)
1015       },
1016       // 表单提交
1017       dataFormSubmit() {
1018         this.$refs['dataForm'].validate((valid) => {
1019           if (valid) {
1020             if (this.dataForm.pointtypename !== 'CALCULATE' &&
1021               this.dataForm.pointtypename !== 'MEASURE' &&
1022               this.dataForm.pointtypename !== 'CONSTANT') {
1023               this.$message({
1024                 message: '不支持的点类型!',
1025                 type: 'error',
1026                 duration: 1500
1027               })
1028               return
1029             }
1030             if (this.dataForm.pointtypename === 'MEASURE' && this.dataForm.measurePoint.sourceid === 'a8f05cd1-80cf-48a0-a46c-d4b830af3ed3') {
1031               if (this.dataForm.measurePoint.tagno instanceof Array) {
1032                 this.dataForm.measurePoint.tagno = this.dataForm.measurePoint.tagno[this.dataForm.measurePoint.tagno.length - 1]
1033               }
1034             } else if (this.dataForm.measurePoint.sourceid === '33325cd1-80cf-48a0-a46c-d4b830af3ed3') {
1035               this.dataForm.measurePoint.tagno = this.dataForm.measurePoint.xsttagno
1036             }
1037
1038             if (this.dataForm.pointtypename === 'CALCULATE' &&
1039               this.expressionList && this.expressionList.length > 0) {
1040               let parenthesesLeftRex = /^[(]*$/
1041               let parenthesesRightRex = /^[)]*$/
1042               let expression = ''
1043               for (let i = 0; i < this.expressionList.length; i++) {
1044                 let value = this.expressionList[i]
1045                 if (!parenthesesLeftRex.test(value.parenthesesLeft)) {
1046                   this.$message({
1047                     message: `第${i + 1}行左括号输入不正确!`,
1048                     type: 'error',
1049                     duration: 1500
1050                   })
1051                   return
1052                 }
1053                 if (!parenthesesRightRex.test(value.parenthesesRight)) {
1054                   this.$message({
1055                     message: `第${i + 1}行右括号输入不正确!`,
1056                     type: 'error',
1057                     duration: 1500
1058                   })
1059                   return
1060                 }
1061                 if (i !== (this.expressionList.length - 1) && !value.operator) {
1062                   this.$message({
1063                     message: `第${i + 1}行运算符不能为空!`,
1064                     type: 'error',
1065                     duration: 1500
1066                   })
1067                   return
1068                 }
1069                 expression = expression + value.parenthesesLeft + value.point + value.parenthesesRight + (i === (this.expressionList.length - 1) ? '' : value.operator)
1070               }
1071               this.dataForm.mathPoint.expression = expression
1072             } else {
1073               this.dataForm.mathPoint.expression = ''
1074             }
1075
1076             this.$http['post'](`/data/data/point/${!this.dataForm.id ? 'add' : 'update'}`, this.dataForm).then(({data: res}) => {
1077               if (res.code !== 0) {
1078                 return this.$message.error(res.msg)
1079               }
1080               this.$message({
1081                 message: this.$t('prompt.success'),
1082                 type: 'success',
1083                 duration: 500,
1084                 onClose: () => {
1085                   this.visible = false
1086                   this.$emit('refreshDataList')
1087                 }
1088               })
1089             }).catch(() => {
1090             })
1091           }
1092         })
1093       },
1094     }
1095   }
1096 </script>
1097 <style>
1098   .el-select {
1099     width: 100%
1100   }
1101
1102   .el-input-group__append {
1103     padding: 0 5px 0 5px
1104   }
1105
1106   .el-input-group__prepend {
1107     padding: 0 5px 0 5px
1108   }
1109
1110   .el-radio + .el-radio {
1111     margin-left: 10px !important;
1112   }
1113 </style>
1114