caipan_shop_admin/public/static/manager/js/role.js

153 lines
4.9 KiB
JavaScript
Executable File
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

layui.use(['jquery', 'laytpl', 'table', 'form', 'miniTab'], function () {
let $ = layui.jquery,
form = layui.form,
table = layui.table,
layer = layui.layer,
miniTab = layui.miniTab;
let modifyUrl = '/manager/role/modify';
/**** index begin ***/
//index页面
if ($('.location-index-page').length > 0) {
miniTab.listen();
// 渲染表格
let listUrl = $('#table-container').data('url');
let insTb = table.render({
elem: '#table-container',
toolbar: '#toolbar-tpl',
defaultToolbar: [],
url: listUrl,
method: 'post',
request: {
pageName: 'page',
limitName: 'size',
},
parseData: function (res) {
return {
"code": res.code, //解析接口状态
"msg": res.msg, //解析提示文本
"count": res.data.total, //解析数据长度
"data": res.data.list //解析数据列表
};
},
page: true,
cols: [[
{type: 'checkbox'},
{field: 'title', minWidth: 200, title: '标题'},
{field: 'sort', align: 'center', title: '排序', edit: 'text'},
{templet: '#row-status', field: 'status', align: 'center', title: '状态'},
{templet: '#row-operate', align: 'center', title: '操作'}
]],
done: function () {
}
});
Tools.setInsTb(insTb)
//监听单元格编辑
table.on('edit(table-container)', function (obj) {
$.post(modifyUrl, {id: obj.data.id, field: obj.field, value: obj.value}, function (res) {
layer.msg(res.msg)
if (res.code === 0) {
insTb.reload();
}
})
});
//监听状态改变
form.on('switch(changeStatus)', function (obj) {
// layer.tips(this.value + ' ' + this.name + ''+ obj.elem.checked, obj.othis);
let val = obj.elem.checked ? 1 : 0;
$.post(modifyUrl, {id: this.value, field: this.name, value: val}, function (res) {
layer.msg(res.msg)
if (res.code === 0) {
setTimeout(function () {
insTb.reload();
}, 1000)
}
})
});
//监听工具条 注意区别toolbar和tool toolbar是表头上的工具条 tool是行中的工具条
table.on('toolbar(table-container)', function (obj) {
let layEvent = obj.event;
if (layEvent === 'del') {
let checkStatus = table.checkStatus('table-container');
if (checkStatus.data.length <= 0) {
layer.msg('请先选择数据');
return false;
}
let selected = checkStatus.data;
let ids = [];
let url = $($(this).context).data('href')
$.each(selected, function (index, val) {
ids.push(val.id);
})
del(url, ids);
return false;
}
if (layEvent === 'refresh') {
insTb.reload();
return false;
}
if (layEvent === 'add') {
let url = $($(this).context).data('href')
let title = $($(this).context).data('title')
openLayer(url, title);
return false;
}
});
//删除
function del(url, ids) {
let index = layer.confirm('确认删除吗?', {
btn: ['确认', '取消'], //按钮
title: '操作提示',
}, function () {
$.post(url, {ids: ids}, function (res) {
layer.msg(res.msg)
if (res.code === 0) {
insTb.reload();
}
})
}, function () {
layer.close(index)
return false;
});
}
//监听工具条
table.on('tool(table-container)', function (obj) {
let data = obj.data;
let layEvent = obj.event;
let url = $($(this).context).data('href');
let title = $($(this).context).data('title');
if (layEvent === 'del') {
let ids = [data.id];
del(url, ids);
return false;
}
if (layEvent === 'edit') {
openLayer(url, title);
return false;
}
if (layEvent === 'auth') {
openLayer(url, title);
return false;
}
});
}
/*** index end ***/
if ($('.location-rule-page').length > 0) {
}
});