vue iview列表循环生成swich按钮及按钮判断事件

22 篇文章 0 订阅
<div class="smart-info">
          <div class="smart-left">
            <p class="title-p"><span>机器设备1号</span><i-switch v-model="switchParams.switch" true-value="0" false-value="1" @on-change="switchChangebox"></i-switch></span></p>
            <div class="two-info">
              <p>
                <span>当前模式&nbsp;</span>
                <span v-for="(item, index) in smartTag" :key="index" :class="switchParams.switch == item.switchTap ? 'is-active' : ''">{{ item.name}}</span>
              </p>
              <p>机器人已开启{{switchParams.switch == '1' ? '手动' : '自动'}}模式</p>
            </div>
            <p class="nomal-ps">
              <span class="nomal-span">名称</span>
              <span class="nomal-span">状态</span>
              <span class="nomal-span">调控</span>
            </p>
            <p class="nomal-p" v-for="(item, index) in smartItems" :key="index">
              <span class="nomal-span">
                {{item.name}}
              </span>
              <span v-if="device">{{ item.deviceName }}</span>
              <span class="nomal-span">{{item.startupstatus == '0' ? '未工作' : '工作中'}}</span>
              <span class="nomal-span">
                <i-switch v-model="item.startupstatus" true-value="1" false-value="0" v-show="modelview"  @on-change="switchChange(item,item.startupstatus)"></i-switch>
              </span>
            </p>
            <p v-if="!smartLeftItems || smartLeftItems.length === 0" style="text-align:center;padding-top:28%">暂无数据信息</p>
          </div>
// switch开关控制
    switchChange(item, type) {
      if(this.switchParams.switch == '1') {
        if(this.swichchange  == '333' && (item.deviceName == '666' && type == '1') ) {
          this.$Message.info('“第一指令正在执行前进,请关闭后再执行第二指令”')
          setTimeout(()=>{
              item.startupstatus = '0'
          },0)
        }else if(this.swichchange  == '666' && (item.deviceName == '333' && type == '1') ) {
          this.$Message.info('“第二指令正在执行前进,请关闭后再执行第一指令”')
          setTimeout(()=>{
              item.startupstatus = '0'
          },0)
        }else if((item.deviceName == '666' && type == '0') || (item.deviceName == '333' && type == '0')){
          this.swichchange = null
          setTimeout(()=>{
            this.initSwitchRobot(item, type)
          },5)
        }else{
          if((item.deviceName == '666' && type == '1') || (item.deviceName == '333' && type == '1') ){
            this.swichchange = item.deviceName
          }
          setTimeout(()=>{
            this.initSwitchRobot(item, type)
          },5)
        }
      }else{
        if(type == '1' && this.swichchangeAuto) {
          this.$Message.info('“全部状态已执行一条指令,请关闭后再执行新指令”')
          setTimeout(()=>{
              item.startupstatus = '0'
          },0)
        }else{
           if(type=='0'&& this.swichchangeAuto==item.deviceName){
             this.swichchangeAuto = null
           }
           if(type=='1'){
             this.swichchangeAuto = item.deviceName
           }
           setTimeout(()=>{
            this.initSwitchRobot(item, type)
          },5)
        }
      }
      
    },
// 初始化已开启的状态判断,如果开启一种,另一种不可开启
if((item.deviceName == '333' && item.startupstatus == '1') || (item.deviceName == '666' && item.startupstatus == '1')){
    this.swichchange = item.deviceName  // 变量存储状态
 }
// 如果全部设备开启一个了,其他不可开启
if(item.startupstatus == '1'){
   this.swichchangeAuto = item.deviceName // 变量存储状态
 }
data
{
     swichchange:null,
     swichchangeAuto:null,
     smartTag: [
        {
          id: '1',
          name: '手动',
          switchTap:'1',
          isActive: false
        },
        {
          id: '2',
          name: '自动',
          switchTap:'0',
          isActive: true
        }
      ],
}

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值