machineDetailsAttribute.vue 6.64 KB
Newer Older
lixiaomin committed
1 2 3 4 5 6 7 8 9
<template>
  <div>
    <el-dialog title="组件属性监控" :visible.sync="attributeDiaLog" width="700px" append-to-body class="dialogClass">
      <el-tabs v-model="activeName" >
        <el-tab-pane label="组件属性" name="first" >     
          <div v-for="item in attributeData" :key="item.id">
            <el-row style="margin-bottom: 10px;">
              <el-col :span="3"><div >组件名称:</div></el-col>
              <el-col :span="10"><div >{{item.component_name}}</div></el-col>
lixiaomin committed
10
              <el-col :span="11"><div >经验值:</div></el-col>
lixiaomin committed
11
            </el-row>
lixiaomin committed
12
            <el-row style="margin-bottom: 15px;">
lixiaomin committed
13
              <el-col :span="3"><div >组件属性:</div></el-col>
lixiaomin committed
14
              <el-col :span="15">
lixiaomin committed
15
                <el-row v-for="pro in item.property" :key="pro.property_name">
lixiaomin committed
16 17 18 19 20 21 22 23
                  <el-col :span="8"><div >{{pro.property_name}}</div></el-col>
                  <el-col :span="8"><div >{{pro.value}}</div></el-col>
                  <el-col :span="8">
                    <el-button size="mini" round v-show="showBut(pro.experience_value)"   @click="clickExperience(pro.property_id)" style="padding:2px">添加经验值</el-button>

                    <span style="color:blue;cursor:pointer" @click="showJYZ(pro);"> {{showJYZ_TEXT(pro.experience_value)}}</span>
                    
                  </el-col>
lixiaomin committed
24
                </el-row>
lixiaomin committed
25
              </el-col>              
lixiaomin committed
26 27 28 29 30 31 32 33 34 35
            </el-row>
            <el-divider/>
          </div>
        </el-tab-pane>
      </el-tabs>
      <div slot="footer" class="dialog-footer" >
        <el-button type="primary" @click="attributeDiaLogCancel" >确定</el-button>
        <el-button @click="attributeDiaLogCancel">退出</el-button>
      </div>
    </el-dialog>
lixiaomin committed
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
    <el-dialog title="添加经验值" :visible.sync="experienceValueDiaLog" width="500px" append-to-body>
      <div>
        <el-row v-for="(item,idx) in experienceList" :key="idx">          
          <el-col :span="5" style="display: flex; align-items: center;">
            <div>
              <el-input v-model="item.milli_second"/>
            </div>
            <div style="margin-left: 10px;">
              <span></span>
            </div>
          </el-col>          
          <el-col :span="5" style="display: flex; align-items: center;margin-left: 10px;">
            <div>
              <el-input v-model="item.quantity"/>
            </div>
            <div style="margin-left: 10px;">
              <span></span>
            </div>
          </el-col>
          <el-col :span="3" style="margin-left: 10px;">
            <el-button @click="addItem">+</el-button>
          </el-col> 
          <el-col :span="3">
            <el-button v-show="experienceShow"   @click="subtractItem(idx)">-</el-button>
          </el-col>        
        </el-row>
      </div>
      <div slot="footer" class="dialog-footer" >
        <el-button type="primary" @click="experienceSubmit" >确定</el-button>
        <el-button @click="experienceCancel">取消</el-button>
      </div>
    </el-dialog>
lixiaomin committed
68 69 70
  </div>
</template>
<script>
lixiaomin committed
71
import {getAttributeList,addProperty} from "@/api/machine/machineDetails";
lixiaomin committed
72 73 74 75 76
export default { 
  data() {
    return {
      attributeDiaLog:false,
      activeName:"first",
lixiaomin committed
77 78 79 80 81 82 83
      attributeData:[],
      experienceValueDiaLog:false,
      experienceList:[{quantity:null,milli_second:null}],
      experienceShow:true,
      machine_id:'',
      property_id:'',
      experienceValueShow:false
lixiaomin committed
84 85 86 87 88 89 90 91 92
    };
  },
  created() {
   
  },
  methods: {
    //弹出组件属性监控
    handleAttributeDialog(row){   
      this.attributeDiaLog=true;
lixiaomin committed
93 94
      this.machine_id=row.id;
      this.getAttributeList(this.machine_id);
lixiaomin committed
95 96 97 98 99 100 101 102
    },
    getAttributeList(id){
      getAttributeList(id).then((response) => {
        if(response.code==0){
          this.attributeData = response.data;
        }       
      });
    },
lixiaomin committed
103
    //关闭组件属性监控
lixiaomin committed
104 105
    attributeDiaLogCancel(){
      this.attributeDiaLog=false;
lixiaomin committed
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
    },
    //弹出经验值
    clickExperience(propertyId){
      this.property_id=propertyId;
      this.experienceList=[{quantity:null,milli_second:null}]
      if(this.experienceList.length==1){
        this.experienceShow=false;
      }
      this.experienceValueDiaLog=true;
    },
    //新增一行经验值
    addItem(){
      this.experienceList.push({quantity:null,milli_second:null});
      this.experienceShow=true;      
    },
    //删除一行经验值
    subtractItem(idx){
      this.experienceList.splice(idx, 1);
      if(this.experienceList.length==1){
        this.experienceShow=false;
      }
    },
    //提交经验值
    experienceSubmit(){
      var regular=/(^[+]{0,1}([0-9]+)$)/; 
      let hang=0;
      for(let i=0;i<this.experienceList.length;i++){
        hang=i+1;
        if(!regular.test(this.experienceList[i].milli_second)){         
          this.$message.error('第'+hang+'行,秒,请输入大于0的正数');
          return;          
        }else{
          this.experienceList[i].milli_second=parseFloat(this.experienceList[i].milli_second);
        }
        if(!regular.test(this.experienceList[i].quantity)){         
          this.$message.error('第'+hang+'行,克,请输入大于0的正数');
          return;          
        }else{
          this.experienceList[i].quantity=parseFloat(this.experienceList[i].quantity);
        }
      }
      let obj={
        "machine_id": this.machine_id,  
        "property_id": this.property_id,  
        "data":this.experienceList
      }
      addProperty(obj).then((response) => {
        if(response.code==0){
          this.$modal.msgSuccess("添加经验值成功!");
          this.getAttributeList(this.machine_id);         
          this.experienceValueDiaLog=false;
        }       
      });
    },
    //关闭经验值
    experienceCancel(){
      this.experienceValueDiaLog=false;
    },
    //经验值回显处理
    showBut(val){
      if(val!=""){
        this.experienceValueShow=false;
        return false;
      }else{
        this.experienceValueShow=true;
        return true;
      }
    },
    showJYZ_TEXT(exp_value){
      let rval = '';
      if(exp_value){
        exp_value = JSON.parse(exp_value)
        for(let i=0;i<exp_value.length;i++){
          let exp = exp_value[i]
          rval +=''+ exp.milli_second+"秒"+exp.quantity+"克" +'  '         
        }
      }      
      return rval
    },
    showJYZ(pro){
      this.property_id=pro.property_id;
      this.experienceList = JSON.parse(pro.experience_value);
      if(this.experienceList.length==1){
        this.experienceShow=false;
      }
      this.experienceValueDiaLog=true;
lixiaomin committed
192 193 194 195 196 197 198 199 200 201
    }
  }
};
</script>

<style lang="scss">
.dialogClass .el-dialog__body {
  padding: 0px 20px;
}
</style>