LayUI switch 开关监听 数据 绑定数值 选择后禁用掉 默认值改为0,1
最近要写一个 LayUI switch 开关监听,0是接单,1是已接单
效果图
在表格里面加的,因为要实时更新数据
, {
width: 100,
field: 'run_status',
title: '接单状态',
fixed: 'right',
templet: '#switchTpl'
}
html代码 d.receive_tag == 1就禁用
<script type="text/html" id="switchTpl">
<input type="checkbox" name="isShow" value="{{d.code}}" lay-skin="switch" lay-text="接单|已接单" lay-filter="isShow" {{ d.receive_tag == 1 ? '' : 'checked' }} {{ d.receive_tag == 1 ? 'disabled' : '' }}>
</script>
js代码
//switch 开关监听接单
layui.use(['form'], function () {
var form = layui.form;
form.on('switch(isShow)',function (data) {
var code = this.value;
var llo = layer.load(2,{shade:[0.001,'#fff']}); //layer.load() - 加载层
$.ajax({
url:接口,
type: "get",
//contentType: "application/json",
headers: {
'access_token': layui.data('layuiAdmin').access_token},
data: {code: code}, // 参数
success: function(data) {
layer.close(llo); //layer.close(index) - 关闭特定层
if (data.code == 0) {
layer.alert('接单成功', {
icon: 1,
title: '提示'
}, function(i) {
layer.close(i);
})
}
},
error: function(xhr) {
layer.close(llo); //关闭特定层
layer.msg('系统错误,请联系管理员');
}
});
layer.close(llo);
});
});