modelCom.vue 11.3 KB
Newer Older
lixiaomin committed
1 2
<template>
  <div>
lixiaomin committed
3
    <el-dialog title="机型设置" :visible.sync="comDiaLog" width="1100px" append-to-body >
lixiaomin committed
4
      <el-button type="primary" @click="handleAdd" v-hasPermi="['machine:model:add']">新增</el-button>
lixiaomin committed
5
      <el-tabs v-model="activeName" >
lixiaomin committed
6
        <el-tab-pane label="机型组件" name="first" >          
lixiaomin committed
7
          <el-table v-loading="loading" :data="modelComponentList"> 
lixiaomin committed
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
            <el-table-column label="组件类型" align="center" width="170px">
              <template slot-scope="scope">
                <p v-show=!scope.row.isShow> {{ scope.row.type_desc }}</p>
                <el-select v-model="scope.row.type" placeholder="请选择组件类型" clearable v-show="scope.row.isShow" @change="changeType(scope.row)">
                  <el-option
                    v-for="item in comTypeList"
                    :key="item.type"
                    :label="item.type_desc"
                    :value="item.type">
                  </el-option>
                </el-select>
              </template>
            </el-table-column>
            <el-table-column label="组件名称" align="center" width="170px">
              <template slot-scope="scope">
                <p v-show=!scope.row.isShow> {{ scope.row.component_name }}</p>
                <el-select v-model="scope.row.component_name" placeholder="请选择组件类型" clearable v-show="scope.row.isShow">
                  <el-option
                    v-for="item in comTypeNameList"
                    :key="item.id"
                    :label="item.component_name"
                    :value="item.component_name">
                  </el-option>
                </el-select>
              </template>
            </el-table-column>
lixiaomin committed
34
            <el-table-column label="组件编码" align="center" prop="co_serial_no" />
lixiaomin committed
35 36 37 38 39 40 41 42 43 44 45 46
            <el-table-column label="ROS硬件编码" width="150px">
              <template slot-scope="scope">
                <p v-show=!scope.row.isShow> {{ scope.row.ros_code }}</p>
                <el-input v-model="scope.row.ros_code" clearable v-show="scope.row.isShow"/>
              </template>
            </el-table-column>
            <el-table-column label="备注说明" align="center" width="180px">
              <template slot-scope="scope">
                <p v-show=!scope.row.isShow> {{ scope.row.desc }}</p>
                <el-input v-model="scope.row.desc" clearable v-show="scope.row.isShow"/>
              </template>
            </el-table-column>
lixiaomin committed
47
            <el-table-column label="组件状态" align="center"  prop="state_desc"/>
lixiaomin committed
48
            <el-table-column label="操作" align="center">
lixiaomin committed
49
              <template slot-scope="scope">
lixiaomin committed
50
                <el-button v-hasPermi="['machine:model:edit']" size="mini" type="text" @click="handleEditDialog(scope.row)" v-show=!scope.row.isShow>编辑组件属性</el-button>
lixiaomin committed
51
                <el-button size="mini" type="text" @click="handleEnter(scope.$index, scope.row)"  v-show=scope.row.isShow>确定</el-button>
lixiaomin committed
52
                <el-button v-hasPermi="['machine:model:del']" size="mini" type="text" @click="handlDelete(scope.$index,scope.row)">删除</el-button>
lixiaomin committed
53 54 55 56 57 58 59 60 61 62
              </template> 
            </el-table-column>
          </el-table>
        </el-tab-pane>
      </el-tabs>
      <div slot="footer" class="dialog-footer" >
        <el-button type="primary" @click="comDiaLogCancel" >确定</el-button>
        <el-button @click="comDiaLogCancel">退出</el-button>
      </div>
    </el-dialog>
lixiaomin committed
63
    <el-dialog title="编辑组件属性" :visible.sync="editDiaLog" width="900px" append-to-body>
lixiaomin committed
64 65
      <el-row style="margin-bottom: 10px;">
        <el-col :span="3"><div >组件名称:</div></el-col>
lixiaomin committed
66
        <el-col :span="10"><div >{{componentName}}</div></el-col>
lixiaomin committed
67 68 69
      </el-row>
      <el-row style="margin-bottom: 10px;">
        <el-col :span="3"><div >组件属性:</div></el-col>
lixiaomin committed
70
        <el-col :span="21">           
lixiaomin committed
71
          <el-row v-for="(item,idx) in comAry" :key="idx">
lixiaomin committed
72
            <el-col :span="4"><div ><el-input v-model="item.pro_name" placeholder="输入属性名" clearable/></div></el-col>
lixiaomin committed
73 74
            <el-col :span="6">
              <div>
lixiaomin committed
75
                <el-select  v-model="item.type" placeholder="请选择属性类型" clearable>
lixiaomin committed
76 77 78 79 80 81 82 83 84
                  <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </div>
            </el-col>
lixiaomin committed
85 86
            <el-col :span="4"><div ><el-input v-model="item.pro_ros_code" placeholder="ROS硬件编码" clearable/></div></el-col>
            <el-col :span="4"><div ><el-input v-model="item.desc" placeholder="备注描述" clearable/></div></el-col>
lixiaomin committed
87
            <el-col :span="1.5">
lixiaomin committed
88 89
              <el-button @click="addItem">+</el-button>
            </el-col>
lixiaomin committed
90
            <el-col :span="1">
lixiaomin committed
91
              <el-button v-show="comShow"   @click="subtractItem(idx)">-</el-button>
lixiaomin committed
92
            </el-col>
lixiaomin committed
93 94 95 96
          </el-row>
        </el-col>
      </el-row>
      <div slot="footer" class="dialog-footer" >
lixiaomin committed
97
        <el-button type="primary" @click="editDiaLogSubmit" >确定</el-button>
lixiaomin committed
98 99 100 101 102 103 104
        <el-button @click="editDiaLogCancel">退出</el-button>
      </div>
    </el-dialog>

  </div>
</template>
<script>
lixiaomin committed
105
import {getModelComponentList,getComponentList,addComponent,addComponentProperty,getComponentPropertyList,delComponent} from "@/api/model/model";
lixiaomin committed
106 107 108 109 110 111 112 113 114 115 116 117
export default { 
  data() {
    return {
      // 遮罩层
      loading: true,
      comDiaLog:false,
      activeName:"first",
      modelId:"",
      modelComponentList:[],
      editDiaLog:false,
      options:[
        {
lixiaomin committed
118
          value: 1,
lixiaomin committed
119 120 121
          label: '开关'
        },
        {
lixiaomin committed
122
          value: 2,
lixiaomin committed
123 124 125
          label: '状态'
        },
        {
lixiaomin committed
126
          value: 3,
lixiaomin committed
127 128 129
          label: '时间(年月日)'
        },
        {
lixiaomin committed
130
          value: 4,
lixiaomin committed
131 132 133
          label: '时间(日分秒)'
        },
        {
lixiaomin committed
134
          value: 5,
lixiaomin committed
135 136 137
          label: '值'
        }
      ],
lixiaomin committed
138 139 140 141 142
      comAry:[{pro_name:"",type:null,pro_ros_code:null,desc:""}],  
      comTypeList:[],
      comTypeNameList:[],
      componentList:[],
      componentName:'',
lixiaomin committed
143 144
      com_ros_code:'',
      comShow:true
lixiaomin committed
145 146 147 148 149 150 151 152
    };
  },
  created() {
   
  },

  methods: {
    addItem(){
lixiaomin committed
153
      this.comAry.push({pro_name:"",type:null,pro_ros_code:null,desc:""});      
lixiaomin committed
154
    },
lixiaomin committed
155
    subtractItem(idx){      
lixiaomin committed
156
      this.comAry.splice(idx, 1);
lixiaomin committed
157 158 159
      if(this.comAry.length==1){
        this.comShow=false
      }
lixiaomin committed
160
    },      
lixiaomin committed
161 162 163 164 165 166
    //弹出机型组件页面
    handleModelComDialog(id){
      this.comDiaLog=true;
      this.modelId=id;
      this.activeName="first"; 
      this.getModelComponentList();
lixiaomin committed
167
      this.getComponentList();
lixiaomin committed
168 169 170 171 172
    },
    getModelComponentList(){
      this.loading = true;
      getModelComponentList(this.modelId).then((response) => {
        if(response.code==0){
lixiaomin committed
173
          this.modelComponentList = response.data.list;
lixiaomin committed
174 175 176 177 178
          this.loading = false;
        }       
      });
    },
    //弹出编辑组件属性
lixiaomin committed
179 180 181 182
    handleEditDialog(row){
      this.componentName=row.component_name;
      this.com_ros_code=row.ros_code;
      this.comAry=[{pro_name:"",type:null,pro_ros_code:null,desc:""}], 
lixiaomin committed
183
      this.editDiaLog=true;
lixiaomin committed
184
      this.getComponentPropertyList(row.model_id,row.ros_code);
lixiaomin committed
185 186 187 188
    },
    comDiaLogCancel(){
      this.comDiaLog=false
    },
lixiaomin committed
189
    //关闭组件属性
lixiaomin committed
190
    editDiaLogCancel(){
lixiaomin committed
191 192 193 194
      this.editDiaLog=false
    },
    //编辑组件属性
    editDiaLogSubmit(){
lixiaomin committed
195 196
      var regular=/(^[+]{0,1}([0-9]+)$)/; 
      let hang=0;
lixiaomin committed
197
      for(let i=0;i<this.comAry.length;i++){
lixiaomin committed
198 199 200 201 202 203 204
        if(!regular.test(this.comAry[i].pro_ros_code)){
          hang=i+1;
          this.$message.error('第'+hang+'行,ROS硬件编码,请输入大于0的正数');
          return;          
        }else{
          this.comAry[i].pro_ros_code=parseFloat(this.comAry[i].pro_ros_code);
        }        
lixiaomin committed
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
      }
      let obj={
        com_ros_code:this.com_ros_code,
        model_id:this.modelId,
        data:this.comAry
      }
      addComponentProperty(obj).then((response) => {
        if(response.code==0){
          this.$modal.msgSuccess("修改组件属性成功!");
          this.editDiaLog=false
        }       
      });    
    },
    //新增组件
    handleAdd(){
      var row={
        type_desc: '',
        type: '',  
        ros_code:'',
        desc:'',
        co_serial_no:'',
        isShow:true
      }
      this.modelComponentList.push(row);
    },
    //获取组件类型list
    getComponentList(){
      this.comTypeList=[];
      getComponentList().then((response) => {
        if(response.code==0){
          if(response.data.length>0){
            this.componentList=response.data;
            for(let i=0;i<response.data.length;i++){
              this.comTypeList.push({"type":response.data[i].type,"type_desc":response.data[i].type_desc});
            }
          }
        }       
      });
    },
    //获取组件类型下面的组件名称
    changeType(row){
      if(this.componentList.length>0){
        for(let i=0;i<this.componentList.length;i++){
          if(this.componentList[i].type==row.type){
            row.type_desc=this.componentList[i].type_desc;
            this.comTypeNameList=this.componentList[i].data;
            break;
          }
        }
      }
    },
    //提交组件
    handleEnter(index,row){
lixiaomin committed
258 259 260 261 262 263 264 265 266 267 268 269 270 271
      if(row.type==""){
        this.$message.error('请选择组件类型!');
        return;    
      }       
      var regular=/(^[+]{0,1}([0-9]+)$)/; 
      if(row.ros_code==""){
        this.$message.error('请选择输入ROS硬件编码!');
        return;  
      }else{
        if(!regular.test(row.ros_code)){      
          this.$message.error('ROS硬件编码,请输入大于0的正数');
          return;          
        }
      }
lixiaomin committed
272 273 274 275 276 277 278 279 280 281 282 283 284
      row.isShow = false;
      let obj={
        "model_id":this.modelId,
        "component_name":row.component_name,
        "co_serial_no":0,
        "ros_code":parseFloat(row.ros_code),
        "desc":row.desc,
        "type":row.type
      }
      addComponent([obj]).then((response) => {
        if(response.code==0){
          this.$modal.msgSuccess("添加组件成功!");
          this.getModelComponentList();    
285 286 287 288
        }else if(response.code==21001){          
          this.$message.error('该机型已有机器绑定,请重新填写!');
        }    
      })
lixiaomin committed
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
    },
    //获取组件属性列表
    getComponentPropertyList(model_id,ros_code){
      this.comAry=[];
      getComponentPropertyList(model_id,ros_code).then((response) => {
        if(response.code==0){
          if(response.data.length>0){
            for(let i=0;i<response.data.length;i++){
              this.comAry.push({pro_name:response.data[i].pro_name,type:response.data[i].type,
              pro_ros_code:response.data[i].pro_ros_code,desc:response.data[i].desc})
            }
          }else{
            this.comAry=[{pro_name:"",type:null,pro_ros_code:null,desc:""}];
          }    
        }       
      });
    },
lixiaomin committed
306 307 308 309 310
    handlDelete(index,row){
      if(!row.id){
        this.modelComponentList.splice(index,1);
        return;
      }
lixiaomin committed
311 312 313 314 315 316
      delComponent(row.id,row.model_id).then((response) => {
        if(response.code==0){
          this.$modal.msgSuccess("删除组件成功!");
          this.getModelComponentList();    
        }       
      });
lixiaomin committed
317
    }   
lixiaomin committed
318 319 320 321 322 323 324
  }
};
</script>

<style lang="scss">

</style>