Browse Source

点位配置第三步编辑

GuoYuFu123 6 years ago
parent
commit
593f7241f9

+ 11 - 1
src/components/config_point/step3_edit/auto_handle.vue

@@ -42,7 +42,8 @@ export default {
         devFlag: {
             default: true,
             type: Boolean
-        }
+        },
+        autoHandleShow: {}
     },
     methods: {
         validateUnit(rule, value, callback) {
@@ -107,6 +108,15 @@ export default {
             handler() {
                 this.$refs['form'].validateField('unit')
             }
+        },
+        autoHandleShow: {
+            deep: true,
+            immediate: true,
+            handler(val) {
+                if(val){
+                    this.form = val;
+                }
+            }
         }
     }
 }

+ 15 - 2
src/components/config_point/step3_edit/enum_handle.vue

@@ -55,7 +55,8 @@ export default {
         devFlag: {
             default: true,
             type: Boolean
-        }
+        },
+        enumHandleShow:{}
     },
     methods: {
         getForm(cb) {
@@ -74,7 +75,19 @@ export default {
             return { from: '', to: '' }
         },
         deleteRow(index) {
-            this.pointArr.splice(index, 1)
+            this.form.pointArr.splice(index, 1)
+        }
+    },
+    watch:{
+        enumHandleShow: {
+            deep: true,
+            immediate: true,
+            handler(val) {
+                if(val) {
+                    this.form = val
+                }
+                
+            }
         }
     }
 }

+ 77 - 34
src/components/config_point/step3_edit/formula_handle.vue

@@ -12,25 +12,32 @@
                 截取:
                 <el-switch v-model='subStrVal' active-color='#13ce66' inactive-color='#ff4949'></el-switch>
                 <p class='sub-p'>
-                    <el-input-number v-model='from' :min='1' :max='10' label='描述文字' :disabled="!subStrVal"></el-input-number>位 - 第
-                    <el-input-number  v-model='to' :min='1' :max='10' label='描述文字' :disabled="!subStrVal" @change='subToChange'></el-input-number>位(从1开始)
+                    <el-input-number v-model='from' :min='1' :max='10' label='描述文字' :disabled='!subStrVal'></el-input-number>位 - 第
+                    <el-input-number
+                        v-model='to'
+                        :min='1'
+                        :max='10'
+                        label='描述文字'
+                        :disabled='!subStrVal'
+                        @change='subToChange'
+                    ></el-input-number>位(从1开始)
                 </p>
             </div>
             <p class='xia-2'>👇</p>
+             <p>
+                仅提取其中的数值:
+                <el-switch v-model='extract' active-color='#13ce66' inactive-color='#ff4949'></el-switch>
+            </p>
+            <p class='xia-3'>👇</p>
             <p>
                 数值计算:
                 <el-switch v-model='valCountVal' active-color='#13ce66' inactive-color='#ff4949'></el-switch>
             </p>
             <p>
-                <el-select class='mark' v-model="mark" placeholder="请选择" :disabled="!valCountVal">
-                    <el-option
-                    v-for="item in markArr"
-                    :key="item.value"
-                    :label="item.label"
-                    :value="item.value">
-                    </el-option>
+                <el-select class='mark' v-model='mark' placeholder='请选择' :disabled='!valCountVal'>
+                    <el-option v-for='item in markArr' :key='item.value' :label='item.label' :value='item.value'></el-option>
                 </el-select>
-                <el-input class='mark-value' v-model='markValue' :disabled="!valCountVal"></el-input>
+                <el-input class='mark-value' v-model='markValue' :disabled='!valCountVal'></el-input>
             </p>
         </div>
     </div>
@@ -44,6 +51,7 @@ export default {
             form: {
                 EquipmentMark: '',
             },
+            extract: true,
             rules: {
                 EquipmentMark: [{ required: true, message: '请输入设备标识', trigger: 'blur' }]
             },
@@ -51,57 +59,89 @@ export default {
             from: 1,
             to: 1,
             valCountVal: true,
-            mark:'plus',
+            mark: 'plus',
             markValue: '',
-            markArr:[{
-                label: '+',
-                value: 'plus'
-            }]
+            markArr: [
+                {
+                    label: '+',
+                    value: 'plus'
+                }
+            ]
         }
     },
     props: {
         devFlag: {
             default: true,
             type: Boolean
-        }
+        },
+        formulaHandleShow: {}
     },
     methods: {
         getForm(cb) {
-            this.$refs["form"].validate((valid) => {
-                if(valid){
-                    if(this.subStrVal) {
-                        this.form.from = this.from;
-                        this.form.to = this.to;
+            this.$refs['form'].validate(valid => {
+                if (valid) {
+                    if (this.subStrVal) {
+                        this.form.from = this.from
+                        this.form.to = this.to
                     }
-                    if(this.valCountVal) {
+                    if (this.valCountVal) {
                         if (!this.markValue) {
                             this.$message({
-                            message: '请填写数值计算',
-                            type: 'warning'
-                            });
+                                message: '请填写数值计算',
+                                type: 'warning'
+                            })
                             return
                         } else {
-                            this.form.mark = this.mark;
-                            this.form.markValue = this.markValue;
+                            this.form.mark = this.mark
+                            this.form.markValue = this.markValue
                         }
-                            
                     }
-                    
+                    this.form.extract = this.extract
                     cb(this.form)
                 } else {
                     cb(false)
                 }
             })
         },
-        subToChange(val) {
-
-        }
+        subToChange(val) {}
     },
     watch: {
         from(val) {
-            if(val > this.to) {
+            if (val > this.to) {
                 this.to = val
-            } 
+            }
+        },
+        formulaHandleShow: {
+            deep: true,
+            immediate: true,
+            handler(val) {
+                if (val) {
+                    this.form = val
+                    if (this.form.cut) {
+                        this.subStrVal = true
+                        this.from = this.form.cut.from
+                        this.to = this.form.cut.to
+                    } else {
+                        this.subStrVal = false
+                        this.from =1
+                        this.to = 1
+                    }
+                    if(this.form.count) {
+                        this.valCountVal = true
+                        this.mark = this.form.count.calculationtype
+                        this.markValue = this.form.count.value
+                    } else {
+                        this.valCountVal = false
+                        this.mark = 'plus'
+                        this.markValue = ''
+                    }
+                    if(this.form.extractArr && this.form.extractArr.length) {
+                        this.extract = true
+                    } else {
+                        this.extract = false
+                    }
+                }
+            }
         }
     }
 }
@@ -117,6 +157,9 @@ export default {
         .xia-2 {
             padding-left: 50px;
         }
+        .xia-3 {
+            padding-left: 100px;
+        }
         .mark {
             width: 100px;
         }

+ 192 - 61
src/components/config_point/step3_edit/index.vue

@@ -4,27 +4,27 @@
             <ul>
                 <li>
                     <span>原始点位信息:</span>&nbsp;&nbsp;&nbsp;
-                    <span>{{editData.Description || '--'}}</span>
+                    <span>{{editData.Point.Description || '--'}}</span>
                 </li>
                 <li>
                     <span>位置标签:</span>&nbsp;&nbsp;&nbsp;
-                    <span>{{editData.LocationFlag || '--'}}</span>
+                    <span>{{editData.Point.LocationFlag.toString() || '--'}}</span>
                 </li>
                 <li>
                     <span>设备类型:</span>&nbsp;&nbsp;&nbsp;
-                    <span>{{editData.KeyEquipmentType || '--'}}</span>
+                    <span>{{editData.Point.KeyEquipmentType || '--'}}</span>
                 </li>
                 <li>
                     <span>设备参数:</span>&nbsp;&nbsp;&nbsp;
-                    <span>{{editData.KeyEquipmentParameter || '--'}}</span>
+                    <span>{{editData.Point.KeyEquipmentParameter || '--'}}</span>
                 </li>
                 <li>
                     <span>值/单位说明:</span>&nbsp;&nbsp;&nbsp;
-                    <span>{{editData.ValueDescription || '--'}}</span>
+                    <span>{{editData.Point.ValueDescription || '--'}}</span>
                 </li>
                 <li>
                     <span>备注:</span>&nbsp;&nbsp;&nbsp;
-                    <span>{{editData.Remarks || '--'}}</span>
+                    <span>{{editData.Point.Remarks || '--'}}</span>
                 </li>
             </ul>
         </div>
@@ -48,9 +48,14 @@
                         <!-- <p class='top'>
                             <i class='el-icon-plus'></i>
                             <el-button type='text'>添加自定义信息点</el-button>
-                        </p> -->
+                        </p>-->
                         <p class='btm'>
-                            <el-input type='textarea' :rows='2' placeholder='信息点的单位及值的说明' v-model='form.ValueDescription'></el-input>
+                            <el-input
+                                type='textarea'
+                                :rows='2'
+                                placeholder='信息点的单位及值的说明'
+                                v-model='form.ValueDescription'
+                            ></el-input>
                         </p>
                     </div>
                 </el-form-item>
@@ -65,11 +70,24 @@
                     </el-select>
                 </el-form-item>
                 <!-- components -->
-                <no-handle ref='noHandle' v-if='form.DataRuleType == "无需处理,直接使用"'></no-handle>
-                <auto-handle ref='autoHandle' v-else-if='form.DataRuleType == "需自动单位转换"' :unitObj='unitObj'></auto-handle>
-                <enum-handle ref='enumHandle' v-else-if='form.DataRuleType == "需按设置枚举转换"'></enum-handle>
-                <formula-handle ref='formulaHandle' v-else-if='form.DataRuleType == "需按公式转换"'></formula-handle>
-                <split-handle ref='splitHandle' v-else></split-handle>
+                <no-handle ref='noHandle' v-if='form.DataRuleType == "无需处理,直接使用"' :noHandleShow='noHandleShow'></no-handle>
+                <auto-handle
+                    ref='autoHandle'
+                    v-else-if='form.DataRuleType == "需自动单位转换"'
+                    :unitObj='unitObj'
+                    :autoHandleShow='autoHandleShow'
+                ></auto-handle>
+                <enum-handle
+                    ref='enumHandle'
+                    v-else-if='form.DataRuleType == "需按设置枚举转换"'
+                    :enumHandleShow='enumHandleShow'
+                ></enum-handle>
+                <formula-handle
+                    ref='formulaHandle'
+                    v-else-if='form.DataRuleType == "需按公式转换"'
+                    :formulaHandleShow='formulaHandleShow'
+                ></formula-handle>
+                <split-handle ref='splitHandle' v-else :splitHandleShow='splitHandleShow'></split-handle>
             </el-form>
             <div class='btn-box'>
                 <el-button type='primary' @click='save'>保存</el-button>
@@ -95,7 +113,7 @@ export default {
             options: [],
             optionObj: {},
             infoDict: {}, //信息点字典
-            dataDict:{}, //数据字典
+            dataDict: {}, //数据字典
             InfomationPoint: null, //信息点
             unitObj: {}, //传给自动单位转换的obj
             props: {
@@ -105,7 +123,7 @@ export default {
             },
             form: {
                 dict: [],
-                ValueDescription: '', 
+                ValueDescription: '',
                 DataRuleType: '无需处理,直接使用'
             },
             rules: {
@@ -129,10 +147,16 @@ export default {
                     value: '需按公式转换'
                 },
                 {
-                    label: '需按拆分枚举转换',
-                    value: '需按拆分枚举转换'
+                    label: '需拆分处理',
+                    value: '需拆分处理'
                 }
-            ]
+            ],
+            /**值回显******* */
+            noHandleShow: null,
+            autoHandleShow: null,
+            enumHandleShow: null,
+            formulaHandleShow: null,
+            splitHandleShow: null
         }
     },
     props: {
@@ -160,11 +184,10 @@ export default {
         save() {
             this.$refs['form'].validate(valid => {
                 if (valid) {
-                    var flag = this.form.DataRuleType                    
+                    var flag = this.form.DataRuleType
                     switch (flag) {
                         case '无需处理,直接使用':
                             this.$refs['noHandle'].getForm(noHandle => {
-                                console.log(noHandle)
                                 if (noHandle) {
                                     this.saveForm(this.form, noHandle)
                                 } else {
@@ -174,7 +197,6 @@ export default {
                             break
                         case '需自动单位转换':
                             this.$refs['autoHandle'].getForm(autoHandle => {
-                                console.log(autoHandle)
                                 if (autoHandle) {
                                     this.saveForm(this.form, autoHandle)
                                 } else {
@@ -200,7 +222,7 @@ export default {
                                 }
                             })
                             break
-                        case '需按拆分枚举转换':
+                        case '需拆分处理':
                             this.$refs['splitHandle'].getForm(splitHandle => {
                                 if (splitHandle) {
                                     this.saveForm(this.form, splitHandle)
@@ -217,21 +239,20 @@ export default {
             })
         },
         saveForm(basic, other) {
-            console.log(basic, other)
             let type = basic.DataRuleType
             let basicParams = {
                 SpecialtyCode: basic.dict[0],
-                SystemCode: basic.dict[1], //code                
-                EquipmentTypeCode:basic.dict[2],
+                SystemCode: basic.dict[1], //code
+                EquipmentTypeCode: basic.dict[2],
                 InfomationPointCode: basic.dict[3],
-                System: this.dataDict[basic.dict[0]].name, //系统
-                Specialty: this.dataDict[basic.dict[1]].name, //专业
-                EquipmentType: this.dataDict[basic.dict[2]].name, //设备类
-                Funcid: "1", //信息点id
+                Specialty: this.dataDict[basic.dict[0]].name, //专业
+                System: this.dataDict[basic.dict[1]].name, //系统
+                EquipmentType: this.dataDict[basic.dict[2]].name, //设备
                 InfomationPoint: this.InfomationPoint, //信息点
                 DataRuleType: basic.DataRuleType, //值处理方式
                 DataSourceId: '4',
-                PointId: this.editData.Id, //点位ID
+                PointId: this.editData.Point.Id,  //点位ID
+                ValueDescription: basic.ValueDescription //信息点单位和值说明
             }
             let otherParams = {}
             switch (type) {
@@ -241,16 +262,21 @@ export default {
                     }
                     break
                 case '需自动单位转换':
-                    let DataRuleContent1 = JSON.stringify([{
-                        "seq": 1,
-                        "ruletype": "type1",
-                        "content": [{
-                            "from":other.unit[0] + '-' + other.unit[1] ,
-                            "to": this.unitObj.unit
-                        }]
-                    }]);
+                    let DataRuleContent1 = JSON.stringify([
+                        {
+                            seq: 1,
+                            ruletype: 'type1',
+                            content: [
+                                {
+                                    from: other.unit[0] + '-' + other.unit[1],
+                                    to: this.unitObj.unit
+                                }
+                            ]
+                        }
+                    ])
                     otherParams = {
-                        DataRuleContent:DataRuleContent1
+                        DataRuleContent: DataRuleContent1,
+                        EquipmentMark: other.EquipmentMark
                     }
                     break
                 case '需按设置枚举转换':
@@ -275,9 +301,20 @@ export default {
                               ]
                           }
                         : undefined
+                    let extractRule = {
+                        seq: 2,
+                        ruletype: 'type5',
+                        content: other.extract
+                            ? [
+                                  {
+                                      extract: 'number'
+                                  }
+                              ]
+                            : []
+                    }
                     let countRule = other.mark
                         ? {
-                              seq: 1,
+                              seq: 3,
                               ruletype: 'type6',
                               content: [
                                   {
@@ -292,6 +329,7 @@ export default {
                     if (subRule) {
                         DataRuleContent3.push(subRule)
                     }
+                    DataRuleContent3.push(extractRule)
                     if (countRule) {
                         DataRuleContent3.push(countRule)
                     }
@@ -301,35 +339,45 @@ export default {
                         DataRuleContent: DataRuleContent3
                     }
                     break
-                case '需按拆分枚举转换':
+                case '需拆分处理':
                     let SplitPoints = other.devArr.length ? other.devArr : undefined
-                    let DataRuleContent4 = undefined;
+                    let DataRuleContent4 = undefined
+                    var enum5 = null
                     if (other.tranfVal) {
-                        DataRuleContent4 = other.pointArr
-                            ? JSON.stringify([
-                                  {
-                                      seq: 1,
-                                      ruletype: 'type4',
-                                      content: other.pointArr
-                                  }
-                              ])
-                            : undefined
+                        enum5 = { seq: 2, ruletype: 'type2', content: other.pointArr }
+                    } else {
+                        enum5 = { seq: 2, ruletype: 'type2', content: [] }
                     }
+                    SplitPoints.forEach(ele => {
+                        let cutStr = {
+                            seq: 1,
+                            ruletype: 'type4',
+                            content: [
+                                {
+                                    from: ele.SplitStart,
+                                    to: ele.SplitEnd
+                                }
+                            ]
+                        }
+                        ele.DataRuleContent = JSON.stringify([cutStr, enum5])
+                    })
                     otherParams = {
-                        SplitPoints: SplitPoints,
-                        DataRuleContent: DataRuleContent4
+                        SplitPoints: SplitPoints
                     }
                     break
             }
             let params = [Object.assign(basicParams, otherParams)]
-            console.log(params)
-            batchCreate(params, res=> {
-                console.log(res);
-                if(res.Result == 'Success') {
+            this.create(params)
+
+        },
+        create(params) {
+            batchCreate(params, res => {
+                if (res.Result == 'success') {
                     this.$message({
                         message: '保存成功',
                         type: 'success'
                     })
+                    this.$emit('refresh')
                 }
             })
         },
@@ -343,7 +391,7 @@ export default {
             this.unitObj = this.infoDict[arr[3]]
             this.InfomationPoint = this.unitObj.infoPointName || '--'
         },
-        handleItemChange(val) {
+        handleItemChange(val, cb) {
             if (val.length == 3) {
                 let params = { type: val[2] }
                 getQueryProperty(params, res => {
@@ -371,6 +419,10 @@ export default {
                         } else {
                             this.optionObj.content = undefined
                         }
+
+                        if (typeof cb == 'function') {
+                            cb()
+                        }
                     }
                 })
             }
@@ -398,7 +450,7 @@ export default {
             let params = { format: true }
             getEquipmentAll(params, res => {
                 if (res.Result == 'success') {
-                    this.options = res.Content;
+                    this.options = res.Content
                     this.getDataDict(this.options)
                 }
             })
@@ -406,6 +458,86 @@ export default {
         init() {
             //获取所有的设备
             this.getEqAll()
+        },
+        //回显数值
+        async showValue(val) {
+            await this.getEqAll()
+            let length = val.RelationList.length
+            if (length) {
+                var data = val.RelationList[0]
+                let dict = [data.SpecialtyCode, data.SystemCode, data.EquipmentTypeCode]
+                this.handleItemChange(dict, () => {
+                    this.form = {
+                        dict: [...dict, data.InfomationPointCode],
+                        ValueDescription: data.ValueDescription || '',
+                        DataRuleType: data.DataRuleType
+                    }
+                    this.unitObj = this.infoDict[data.InfomationPointCode]
+                    this.InfomationPoint = this.unitObj.infoPointName || '--'
+                })
+                if (length == 1) {
+                    let flag = data.DataRuleType
+                    var dataRules = null
+                    switch (flag) {
+                        case '无需处理,直接使用':
+                            this.noHandleShow = {
+                                EquipmentMark: data.EquipmentMark
+                            }
+                            break
+                        case '需自动单位转换':
+                            dataRules = JSON.parse(data.DataRuleContent)
+                            let auto = dataRules[0].content[0].from.split('-')
+                            this.autoHandleShow = {
+                                EquipmentMark: data.EquipmentMark,
+                                unit: auto
+                            }
+                            break
+                        case '需按设置枚举转换':
+                            dataRules = JSON.parse(data.DataRuleContent)
+                            let pointArr = dataRules[0].content
+                            this.enumHandleShow = {
+                                EquipmentMark: data.EquipmentMark,
+                                pointArr: pointArr
+                            }
+                            break
+                        case '需按公式转换':
+                            var cut = null
+                            var count = null
+                            var extractArr = []
+                            if (data.DataRuleContent) {
+                                dataRules = JSON.parse(data.DataRuleContent)
+                                cut = dataRules[0].content[0]
+                                extractArr = dataRules[1].content
+                                count = dataRules[2].content[0]
+                            }
+                            this.formulaHandleShow = {
+                                EquipmentMark: data.EquipmentMark,
+                                cut: cut,
+                                count: count,
+                                extractArr: extractArr
+                            }
+                            break
+                            
+                    }
+                } else {
+                    let dataRules = JSON.parse(data.DataRuleContent)
+                    let devArr = val.RelationList.map(ele => {
+                        let arr = JSON.parse(ele.DataRuleContent)
+
+                        return {
+                            EquipmentMark: ele.EquipmentMark,
+                            SplitStart:arr[0].content[0].from ,
+                            SplitEnd: arr[0].content[0].to
+                        }
+                    }) 
+                    let pointArr = dataRules[1].content;
+                    this.splitHandleShow = {
+                        EquipmentMark: data.EquipmentMark,
+                        pointArr: pointArr,
+                        devArr: devArr
+                    }
+                }
+            }
         }
     },
     mounted() {
@@ -415,8 +547,7 @@ export default {
         editData: {
             immediate: true,
             handler(val) {
-                console.log('editData')
-                console.log(val)
+                this.showValue(val)
             }
         }
     }

+ 15 - 1
src/components/config_point/step3_edit/no_handle.vue

@@ -23,7 +23,8 @@ export default {
         devFlag: {
             default: true,
             type: Boolean
-        }
+        },
+        noHandleShow : { }
     },
     methods: {
         getForm(cb) {
@@ -35,6 +36,19 @@ export default {
                 }
             })
         }
+    },
+    watch: {
+        noHandleShow: {
+            deep: true,
+            immediate: true,
+            handler(val) {
+                if(val) {
+                    this.form = val
+                }
+                
+            }
+
+        }
     }
 }
 </script>

+ 18 - 6
src/components/config_point/step3_edit/split_handle.vue

@@ -72,7 +72,7 @@ export default {
                     {
                         EquipmentMark: '',
                         SplitStart: 1,
-                        SplitEnd: 2
+                        SplitEnd: 1
                     }
                 ],
                 pointArr: []
@@ -84,7 +84,8 @@ export default {
         devFlag: {
             default: true,
             type: Boolean
-        }
+        },
+        splitHandleShow: {}
     },
     methods: {
         getForm(cb) {
@@ -104,7 +105,7 @@ export default {
             return {
                 EquipmentMark: '',
                 SplitStart: 1,
-                SplitEnd: 2
+                SplitEnd: 1
             }
         },
         delDev(index) {
@@ -126,9 +127,20 @@ export default {
             this.form.pointArr = [{ from: '', to: '' }]
         }
     },
-    mounted() {
-     this.init()   
-    },
+    watch: {
+        splitHandleShow: {
+            immediate: true,
+            deep: true,
+            handler(val) {
+                if(val) {                    
+                    this.form = val;
+                    console.log(this.form)
+                } else {
+                    this.init()   
+                }
+            }
+        }
+    }
 }
 </script>
 

+ 6 - 1
src/views/point/config_point/steps/step3.vue

@@ -13,7 +13,7 @@
             <steps-main v-if="isDataform"></steps-main>
         </own-dialog>        
         <own-dialog :width="'1000px'" :dialogVisible="isEditDialogShow" @cancel="closeEdit">
-            <step3-edit v-if="isEditDialogShow" :editData='editData'></step3-edit>
+            <step3-edit v-if="isEditDialogShow" :editData='editData' @refresh='refreshData'></step3-edit>
         </own-dialog>
     </div>
 </template>
@@ -132,6 +132,11 @@
                     this.hot = this.$refs.handsontable.init(settings)
                     console.log(this.hot)
                 })
+            },
+            //刷新数据
+            refreshData() {
+                this.getData()
+                this.isEditDialogShow = false;
             }
         },
         components: {