hn_cloud_web/smz-web/js/work/smallSubManagement/smallSubPermission.js

177 lines
6.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var example = null;
var pers = null;
layui.use(['layer','form'], function () {
var layer = layui.layer;
var form = layui.form;
form.render();
form.verify();
pers = checkPermission();
init();
$("#searchBt").click(function () {
example.ajax.reload();
});
});
//重置
$("#resetBt").click(function () {
$("#subName").val("");
example.ajax.reload();
});
//查询
function init() {
example =
$('#dt-table').DataTable({
"searching": false,
"processing": true, //加载数据时显示进度状态
"serverSide": true,
"pagingType": "full_numbers", //首页|尾页
"language": {
"url": "../../../js/plugin/datatables/Chinese.lang"
},
"ajax": {
"url": smz_ht_url + "/smallSubPermission/getSmallSubPermissionList",
"type": "post",
"data": function (d) {
d.subName = $("#subName").val();
},
"error": function (xhr, textStatus, errorThrown) {
var msg = xhr.responseText;
console.log(msg);
var response = JSON.parse(msg);
var code = response.code;
var message = response.message;
if (code == 400) {
layer.msg(message);
} else if (code == 401) {
localStorage.removeItem("token");
layer.msg("token过期请先登录", {shift: -1, time: 1000}, function () {
location.href = smz_ht_url + '/login.html';
});
} else if (code == 403) {
console.log("未授权:" + message);
layer.msg('未授权');
} else if (code == 500) {
console.log('系统错误:' + message);
}
}
},
"lengthMenu": [ [10, 20, 50], [10, 20, 50] ], // 设置每页显示数据量选项
"drawCallback": function() {
// alert( '表格重绘了' );
var thisDataTable = $('#dt-table').DataTable();
$(".pagination").append("<li>" +
"<a class='paginate_button' style='padding:4px;' href='#' tabindex='0'>到 <input style='margin:0px;width:40px;' id='changePage'> 页</a>" +
"<a class='paginate_button' style='margin-bottom:1px' href='#' tabindex='0' id='dataTable-btn'>确认</a></li>");
//点击按钮跳转指定页数
$('#dataTable-btn').click(function (e) {
if ($("#changePage").val() && $("#changePage").val() > 0) {
var redirectpage = $("#changePage").val() - 1;
} else {
var redirectpage = 0;
}
thisDataTable.page(redirectpage).draw( 'page' );
});
//敲击回车键跳转指定页数
$("#changePage").keypress(function (e) {
if(event.keyCode==13){
if ($("#changePage").val() && $("#changePage").val() > 0) {
var redirectpage = $("#changePage").val() - 1;
} else {
var redirectpage = 0;
}
thisDataTable.page(redirectpage).draw( 'page' );
}
});
},
"dom": "<'dt-toolbar'r>t<'dt-toolbar-footer'<'col-sm-4 col-xs-4 hidden-xs'i><'col-xs-8 col-sm-8' p v>><'dt-table-length'l>",
"columns": [
{
"width": "5%",
"orderable": false,
data: function (row, type, set, meta) {
var c = meta.settings._iDisplayStart + meta.row + 1;
return c;
}
},
{"data": "subName", "defaultContent": ""},
{
"data": "",
"defaultContent": "",
"orderable": false,
"render": function (data, type, row) {
var subId = row['subId'];
var html = '';
html += buttonUnbindView(subId, "", pers);
return html;
}
},
],
"order": [[1, "desc"]] //在栏目列上显示排序功能
});
}
//添加数据
function insertSubPermission() {
localStorage.setItem("smallSubId", '-1');
let index = layer.open({
title: ['新增', 'color:#3B70A1;background-color:#E8ECEB;font-size:20px'],
type: 2,
content: 'smallSubPermissionForm.html',
area: ['75%', '75%'],
maxmin: false,
btn: ['确定','关闭'],
yes: function (index, layero) {
// 获取弹出层中的form表单元素
var formSubmit = layer.getChildFrame('form', index);
var submited = formSubmit.find('button')[0];
// 触发点击事件,会对表单进行验证,验证成功则提交表单,失败则返回错误信息
// var myIframe = window[layero.find('iframe')[0]['name']];
// myIframe.selectCheck(); //aaa()为子页面的方法
submited.click();
example.ajax.reload(); // 刷新页面
},
});
// layer.close(index);
}
// 解绑按钮
function buttonUnbindView(subId, permission, pers){
if(permission != ""){
if ($.inArray(permission, pers) < 0) {
return "";
}
}
var btn = $("<button class='layui-btn layui-btn-xs' title='解绑' onclick='unbindView(\""+subId+"\")' style='background-color: transparent;color: #009688;'>解绑</button>");
return btn.prop("outerHTML");
}
/**
* 解绑小包干
* */
function unbindView(subId) {
layer.confirm("<strong>是否确定解绑?</strong><br>存在未结束的班组小包干合同禁止解绑。",function () {
$.ajax({
type: 'post',
url: smz_ht_url + '/smallSubPermission/unbindSmallSubPermissionById',
data: {subId:subId},
dataType: 'json',
success: function (data) {
if (data.res === 1) {
layer.alert('解绑成功', {icon: 1});
example.ajax.reload(); // 刷新页面
} else {
layer.alert(data.resMsg, {icon: 2});
example.ajax.reload(); // 刷新页面
}
}
})
})
}