// 完成按钮
onNavigationBarButtonTap() {
if (!this.addData.every((item) => item.name !== '')) {
uni.showToast({
title: '指令名称不能为空!',
icon: 'none',
duration: 2000
})
} else if (!this.addData.every((item) => item.device_key !== '')) {
uni.showToast({
title: '请选择设备!',
icon: 'none',
duration: 2000
})
} else if (!this.addData.every((item) => item.switch_key !== '')) {
uni.showToast({
title: '请选择开关!',
icon: 'none',
duration: 2000
})
} else {
for (var i = 0; i < this.addData.length; i++) {
if (this.addData[i].state === true) {
this.addData[i].state = 1
} else if (this.addData[i].state === false) {
this.addData[i].state = 0
}
this.keys.push({
name: this.addData[i].name,
detail_id: this.addData[i].switch_key,
scenes_id: this.scenesid,
state: this.addData[i].state
})
}
// 发送添加指令的请求
this.request({
data: this.keys,
method: 'post',
url: this.common.geturl('/instruction/insert'),
header: {
'content-type': 'application/json',
},
dataType: 'json',
success: (result) => {
console.log(result)
if (result.code == 200) {
setTimeout(() => {
uni.switchTab({
url: '../scene',
success: () => {
uni.$emit('update', {
msg: '页面更新'
})
}
})
}, 1000)
}
},
fail: (err) => {
console.log(JSON.stringify(err))
}
})
}
},
批量注册、添加、修改表单项不能为空
最新推荐文章于 2021-07-19 18:00:14 发布