templet: function (d) { if (d.status == 1) { return '<input type="checkbox" name="status" checked lay-filter="status" lay-skin="switch" lay-text="启用|停用" id=' + d.id + '>' } else if (d.status == 0) { return '<input type="checkbox" name="status" lay-filter="status" lay-skin="switch" lay-text="启用|停用" id=' + d.id + '>' } }
form.on('switch', function (data) { var status = 0; var id = data.elem["id"]; if (data.elem.checked) { status = 1; } var param = {}; param.id = id; param.status = status; var reqObj = JSON.stringify(param); var access_token = localStorage.getItem("super_token"); $.ajax({ type: "PUT", url: setter.domain + '/system/user/change-status', contentType: "application/json", data: reqObj, dataType: "json", headers: { "token": access_token }, success: function (res) { layer.msg("操作成功"); }, error: function (XMLHttpRequest, textStatus, errorThrown) { layer.msg("操作失败"); console.log(XMLHttpRequest); console.log(textStatus); console.log(errorThrown); } }); });