345 lines
13 KiB
JavaScript
345 lines
13 KiB
JavaScript
var example = null;
|
||
var pers = null;
|
||
layui.use(['layer', 'form'], function () {
|
||
var layer = layui.layer;
|
||
var form = layui.form;
|
||
getOrg(form);
|
||
var orgId = $("#orgId").val();
|
||
getPro(form, orgId);
|
||
form.on('select(orgId)', function (data) {
|
||
getPro(form, data.value);
|
||
});
|
||
init();
|
||
pers = checkPermission();
|
||
$("#searchBt").click(function () {
|
||
example.ajax.reload();
|
||
});
|
||
});
|
||
|
||
|
||
|
||
function init() {
|
||
example =
|
||
$('#dt-table').DataTable({
|
||
"sort": false,
|
||
"searching": false,
|
||
"processing": true, //加载数据时显示进度状态
|
||
"serverSide": true,
|
||
//表头固定
|
||
"fixedHeader": true,
|
||
"scrollX": "500px",
|
||
"scrollY": "650px",
|
||
"scrollCollapse": true,
|
||
"language": {
|
||
"url": "../../../js/plugin/datatables/Chinese.lang"
|
||
},
|
||
"ajax": {
|
||
"url": smz_ht_url + "/project",
|
||
"type": "get",
|
||
"data": function (d) {
|
||
d.companyId = $("#orgId").val();
|
||
d.proId = $("#proId").val();
|
||
d.status = $("#status").find("option:selected").text();
|
||
},
|
||
"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);
|
||
}
|
||
}
|
||
},
|
||
"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>>",
|
||
"columns": [
|
||
{
|
||
"width":"3%",
|
||
"data": null,
|
||
"bSortable": false,
|
||
render: function (data, type, full, meta) {
|
||
console.log(full);
|
||
var node = '';
|
||
var checkedStatus = data['checkedStatus'];
|
||
node = '<input class="checkall" name="checked" value=\"' + full.id + ',' + full.name + '\" type="checkbox"/>';
|
||
if (checkedStatus == 1) {
|
||
node = '<input class="checkall" name="checked" checked="checked" value=\"' + full.id + ',' + full.name + '\" type="checkbox"/>';
|
||
}
|
||
return node;
|
||
}
|
||
},
|
||
{
|
||
width: '4%',
|
||
data: function (row, type, set, meta) {
|
||
var c = meta.settings._iDisplayStart + meta.row + 1;
|
||
return c;
|
||
}
|
||
},
|
||
{"data": "orgName","width":"15%"},
|
||
{"data": "name","width":"15%"},
|
||
{"data": "proType","width":"10%"},
|
||
{"data": "voltageLevel","width":"8%"},
|
||
{"data": "status","width":"8%"},
|
||
|
||
|
||
|
||
{
|
||
"data": "",
|
||
"width":"10%",
|
||
"defaultContent": "",
|
||
"orderable": false,
|
||
"render": function (data, type, row) {
|
||
var isPush = row['isPush'];
|
||
var html = '';
|
||
if(isPush == '0'){
|
||
html += '<span style="color:#F5A547">未推送</span>';
|
||
}
|
||
if(isPush == '1'){
|
||
html += '<span style="color:#89BD32">成功</span>';
|
||
}
|
||
if(isPush == '2'){
|
||
html += '<span style="color:#DB2642">失败</span>';
|
||
}
|
||
return html;
|
||
}
|
||
},
|
||
{"data": "pushTime","width":"8%"},
|
||
{
|
||
"data": "",
|
||
"width":"10%",
|
||
"defaultContent": "",
|
||
"orderable": false,
|
||
"render": function (data, type, row) {
|
||
var proId = row['id'];
|
||
var html = '';
|
||
html += buttonView(proId, "", pers);
|
||
html += buttonPush(proId, "", pers);
|
||
return html;
|
||
}
|
||
}
|
||
|
||
],
|
||
"order": [[0, "desc"], [1, "asc"]] //在栏目列上显示排序功能
|
||
});
|
||
}
|
||
|
||
|
||
// 详情按钮
|
||
function buttonView(id, permission, pers) {
|
||
if (permission != "") {
|
||
if ($.inArray(permission, pers) < 0) {
|
||
return "";
|
||
}
|
||
}
|
||
var btn = $("<button class='layui-btn layui-btn-xs' title='详情' onclick='view(\"" + id + "\")'>详情</button>");
|
||
return btn.prop("outerHTML");
|
||
}
|
||
/**
|
||
* 查看
|
||
* */
|
||
function view(id) {
|
||
$.ajax({
|
||
type: 'POST',
|
||
contentType: "application/x-www-form-urlencoded",
|
||
url: smz_ht_url + '/project/getProjectById',
|
||
data: {"id": id},
|
||
dataType: 'json',
|
||
success: function (data) {
|
||
var height = '750px';
|
||
var width = '1650px';
|
||
var index = layer.open({
|
||
title: ['查看', 'color:#3B70A1;background-color:#E8ECEB;font-size:20px'],
|
||
type: 2,
|
||
content: 'ProManagerPushFormView.html',
|
||
area: [width, height],
|
||
maxmin: false,
|
||
btn: ['关闭'],
|
||
success: function (layero, index) {
|
||
var myIframe = window[layero.find('iframe')[0]['name']];
|
||
myIframe.setData(data); //aaa()为子页面的方法
|
||
myIframe.setDisable(); //aaa()为子页面的方法
|
||
},
|
||
});
|
||
}
|
||
})
|
||
}
|
||
|
||
// 推送
|
||
function buttonPush(proId, permission, pers) {
|
||
if (permission != "") {
|
||
if ($.inArray(permission, pers) < 0) {
|
||
return "";
|
||
}
|
||
}
|
||
var btn = $("<button class='layui-btn layui-btn-xs' title='推送' onclick='pushView(\"" + proId + "\")'>推送</button>");
|
||
return btn.prop("outerHTML");
|
||
}
|
||
|
||
/**
|
||
* 推送
|
||
* */
|
||
function pushView(proId) {
|
||
$.ajax({
|
||
type: 'POST',
|
||
data: {
|
||
proId: proId
|
||
},
|
||
contentType: "application/x-www-form-urlencoded",
|
||
url: smz_ht_url + '/projectPush/selectProjectPush',
|
||
dataType: 'json',
|
||
success: function (data) {
|
||
console.log(data);
|
||
if(data.obj.indexOf("推送状态为:成功") != -1){
|
||
var index = layer.confirm(data.obj, {
|
||
closeBtn: 0,
|
||
btn: ['取消'] //按钮
|
||
}, function(){
|
||
layer.close(index);
|
||
});
|
||
example.ajax.reload();
|
||
}
|
||
if(data.obj.indexOf("推送状态为:失败") != -1 || data.obj == '暂无数据'){
|
||
var index = layer.confirm(data.obj, {
|
||
closeBtn: 0,
|
||
btn: ['确定'] //按钮
|
||
}, function(){
|
||
layer.close(index);
|
||
});
|
||
example.ajax.reload();
|
||
}
|
||
}
|
||
})
|
||
}
|
||
|
||
function batchPush(){
|
||
var proId = [];
|
||
var proName = [];
|
||
var success = '';//批量推送成功信息
|
||
var error = '';//批量推送失败信息
|
||
var oTable = $('#dt-table').dataTable();
|
||
var rowcollection = oTable.$(".checkall:checked", {"page": "all"});
|
||
rowcollection.each(function (index, elem) {
|
||
var checkbox_value = $(elem).val();
|
||
proId.push(checkbox_value.split(',')[0]);
|
||
proName.push(checkbox_value.split(',')[1]);
|
||
});
|
||
if (proId.length == 0) {
|
||
return layer.msg("请勾选要批量推胸的数据", {icon: 2, time: 2000});
|
||
}
|
||
for(var i = 0;i < proId.length;i++){
|
||
$.ajax({
|
||
type: 'POST',
|
||
async:false,
|
||
data: {
|
||
proId: proId[i]
|
||
},
|
||
contentType: "application/x-www-form-urlencoded",
|
||
url: smz_ht_url + '/projectPush/selectProjectPush',
|
||
dataType: 'json',
|
||
success: function (data) {
|
||
if(data.obj.indexOf("推送状态为:成功") != -1){
|
||
success += '<br/>工程ID为:<span style="font-weight: 600">'+ proId[i] +'</span>,工程名称为:<span style="font-weight: 600">'+ proName[i] +'</span>的工程推送成功;'
|
||
}
|
||
if(data.obj.indexOf("推送状态为:失败") != -1 || data.obj == '暂无数据'){
|
||
error += '<br/>工程ID为:<span style="font-weight: 600">'+ proId[i] +'</span>,工程名称为:<span style="font-weight: 600">'+ proName[i] +'</span>的工程推送失败;'
|
||
}
|
||
}
|
||
})
|
||
}
|
||
var index = layer.confirm('<span style="color: #89BD32">成功:</span>' + success + '<br/><span style="color: #DB2642">失败:</span>' + error, {
|
||
closeBtn: 0,
|
||
btn: ['确定'] //按钮
|
||
}, function(){
|
||
layer.close(index);
|
||
});
|
||
example.ajax.reload();
|
||
}
|
||
/**
|
||
* 获取分公司
|
||
* */
|
||
function getCompanys(orgId) {
|
||
$("#orgId").empty();
|
||
$.ajax({
|
||
type: 'POST',
|
||
url: smz_ht_url + '/project/getCompanys',
|
||
data: {},
|
||
dataType: 'json',
|
||
success: function (data) {
|
||
var str = '<option selected value="">请选择分公司</option>';
|
||
if (data.length > 0) {
|
||
for (var i = 0; i < data.length; i++) {
|
||
if (orgId == data[i].id) {
|
||
str += '<option selected value=\'' + data[i].id + '\'>' + data[i].name + '</option>';
|
||
} else {
|
||
str += '<option value=\'' + data[i].id + '\'>' + data[i].name + '</option>';
|
||
}
|
||
}
|
||
}
|
||
$("#orgId").append(str);
|
||
layui.form.render('select'); //这里就是我们要渲染的地方了
|
||
}
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 获取工程
|
||
* */
|
||
function getProject(orgId) {
|
||
$("#proId").empty();
|
||
$.ajax({
|
||
type: 'POST',
|
||
url: smz_ht_url + '/balls/getPros',
|
||
data: {
|
||
"comId": orgId,
|
||
},
|
||
dataType: 'json',
|
||
success: function (data) {
|
||
var str = '<option selected value="">请选择工程</option>';
|
||
if (data.length > 0) {
|
||
for (var i = 0; i < data.length; i++) {
|
||
str += '<option value=\'' + data[i].id + '\'>' + data[i].name + '</option>';
|
||
}
|
||
}
|
||
$("#proId").append(str);
|
||
layui.form.render('select'); //这里就是我们要渲染的地方了
|
||
}
|
||
})
|
||
} |