layui ajax请求确认,LayUI switch 开关ajax请求后更改状态

LayUI switch 开关ajax请求后更改状态

@if ($item['shop_status'] == 1) checked @endif lay-skin="switch"

lay-filter="switch_shop_status" lay-text="开启|关闭">

layui.use(['form', 'layer'], function () {

var form = layui.form

, layer = layui.layer;

// 状态

form.on('switch(switch_shop_status)', function (data) {

var check = data.elem.checked;

var shop_status = check ? '1' : '0';

var shop_id = $(data.elem).attr('data-shop_id');

var url = "{{url('/backend/shop/update')}}";

var ajax_data = {"shop_id": shop_id, "shop_status": shop_status};

var msg = '确定' + (shop_status == 1 ? '开启' : '关闭') + '态店铺吗?';

data.elem.checked = !check;

form.render();

layer.confirm(msg, function (index) {

$.ajax({

url: url,

method: "post",

dataType: "json",

data: ajax_data,

success: function (res, textStatus, xhr) {

if (res.status === 1) {

data.elem.checked = check;

layer.msg(res.msg, {icon: 1, time: 1000});

} else {

layer.msg(res.msg, {icon: 2, time: 1000});

}

form.render();

},

error: function (xhr, textStatus, error) {

layer.msg('请求失败', {icon: 2, time: 3000});

},

});

layer.close(index);

});

});

});

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值