//触发排序函数时 调用ajax
$.ajax({
url: '/add/···',//路径
type: "POST",
data: {
"page": 1,
"rows": 999999,
"userId": id
},
success: function (data) {
layer.closeAll("loading");
if (data.code == 200) {
let list = data.list;
if (list.length < 2) {
layer.msg("选中层级无排序数据", {icon: 2});
return false;
}
//str就是弹框要显示的可以排序的表格
let str = "<table id='sort_table'style='width: 220px;margin: 10px;'>";
for (let i = 0; i < list.length; i++) {
str += "<tr><td width='60%'>" + list[i].title +
"</td><td width='40%' style='text-align: center'>" +
"<button type=\"button\" id=\"" + list[i].id + "\" class=\"layui-btn layui-btn-primary layui-btn-xs upup\">上</button>" +
"<button type=\"button\" class=\"layui-btn layui-btn-primary layui-btn-xs downdown\">下</button>" +
"</td></tr>";
}
str += "</table>";
let layer_open = layer.open({
type: 1,
title: false,
area: '250px',
offset: '100px',
move: false,
btn: ['保存', '取消'],
success: function (layero, index) {
$(".upup").click(function () {
let btn = $(this);
let tr = btn.parent("td").parent("tr");
let pretr = tr.prev("tr");
if (pretr.length == 1) {
pretr.before(tr);
tr.fadeOut().fadeIn();
} else {
layer.msg("不能再往上了", {icon: 2});
}
});
$(".downdown").click(function () {
let btn = $(this);
let tr = btn.parent("td").parent("tr");
let nexttr = tr.next("tr");
if (nexttr.length == 1) {
nexttr.after(tr);
tr.fadeOut().fadeIn();
} else {
layer.msg("不能再往下了", {icon: 2});
}
});
},
yes: function (index, layero) {
let idlist = "";
$(".upup").each(function () {
idlist=idlist+","+$(this).attr("id");
});
layer.load(1);
$.ajax({
url: 'add/'+idlist.substr(1),
type: "post",
dataType: "json",
data: {
token: getToken(),
},
success: function (data) {
if (data.code == 200) {
layer.msg("操作成功!", {icon: 1});
setTimeout(function () {
layer.close(layer_open);
layer.closeAll("loading");
}, 1500);
reBuildTree();//保存后重新渲染好友分组的数据
}else {
layer.closeAll("loading");
layer.alert(data.msg, {icon: 2});
}
},
error: function () {
layer.closeAll("loading");
layer.msg(data.msg, {icon: 2});
}
});
},
btn2: function (index, layero) {
//点击取消按钮
layer.close(layer_open);
},
content: str,
});
} else if (data.code == 401) {
setTimeout(function () {
parent.doLogin();
}, 1500);
} else {
layer.msg(data.msg, {icon: 2});
}
},
error: function (data) {
layer.closeAll("loading");
layer.msg(data.msg, {icon: 2});
}
});
向上prev(),before();向下next(),after()通过<table>表格中的tr进行排序
最新推荐文章于 2022-06-01 15:57:13 发布