{field: 'state', title: '状态', width: 85, templet: function (data) {
if (data.state == 0) {
return '<div> <input type="checkbox" checked="" name="codeSwitch" lay-skin="switch" id="open" lay-filter="switchTest" switchId=' + data.userId + '' +
' lay-text="启用|已禁用" value=' + data.state + '></div>';
}
return '<div> <input type="checkbox" lay-skin="switch" name="codeSwitch" switchId=' + data.userId + ' lay-filter="switchTest"' +
'lay-text="启用|已禁用" value=' + data.state + '></div>';
}
}
实现操作js代码如下:
/**
* 监听开关 状态 操作
*/
form.on('switch(switchTest)', function (data) {
/**
* 禁用标签
* 状态 赋值为 1
*/
var layerIndex = layer.load(3);
if ((this.checked ? 'true' : 'false') == 'false') {
$.ajax({
url: '/users/delete',
data: {
state: 1,
userId: data.elem.getAttribute("switchId")
},
type: 'PUT', //HTTP请求类型
success: function (data) {
console.log(data);
$.message({
message: "禁用用户",
type: 'success',
showClose: true
});
}, error: function () {
$.message({
message: "boom..",
type: 'error',
showClose: true
});
}
})
} else {
/**
* 启动标签
* 状态 赋值为 0
*/
$.ajax({
url: '/users/delete',
data: {
state: 0,
userId: data.elem.getAttribute("switchId")
},
type: 'PUT',
success: function (data) {
console.log(data);
$.message({
message: "启动用户",
type: 'success',
showClose: true
});
}, error: function () {
$.message({
message: "boom..",
type: 'error',
showClose: true
});
}
})
}
layer.close(layerIndex);
});
本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!