hn_cloud_web/smz-web/js/work/push/attendancePush.js

395 lines
15 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;
$(function () {
layui.use(['layer', 'laydate', 'form'], function () {
var layer = layui.layer;
var laydate = layui.laydate;
var form = layui.form;
getOrg(form);
var orgId = $("#orgId").val();
getPro(form, orgId);
form.on('select(orgId)', function (data) {
getPro(form, data.value);
});
pers = checkPermission();
init();
var minListDate = $('#hidMinListDate').val();//最小可选时间1990-02-01
var maxListDate = $('#hidMaxListDate').val();//最大可选时间2200-12-31
$('#startTime').val(getNowTime());
$('#endTime').val(getNowTime());
var begin = "#startTime", end = "#endTime";//开始时间选择框、结束时间选择框:文本框
var endChange = function (val, date) {
if (date && date.year)
begindate.config.max = {
year: date.year,
month: date.month - 1,//必须减1才是正确值
date: date.date,
hours: date.hours,
minutes: date.minutes,
seconds: date.seconds
};
else {
var dateInit = new Date(maxListDate.replace(/-/g, "/"));
begindate.config.max = {
year: dateInit.getFullYear(),
month: dateInit.getMonth(),
date: dateInit.getDate(),
hours: dateInit.getHours(),
minutes: dateInit.getMinutes(),
seconds: dateInit.getSeconds()
};
}
};
var beginChange = function (val, date) {
if (date && date.year)
enddate.config.min = {
year: date.year,
month: date.month - 1,
date: date.date,
hours: date.hours,
minutes: date.minutes,
seconds: date.seconds
};
else {
var dateInit = new Date(minListDate.replace(/-/g, "/"));
enddate.config.min = {
year: dateInit.getFullYear(),
month: dateInit.getMonth(),
date: dateInit.getDate(),
hours: dateInit.getHours(),
minutes: dateInit.getMinutes(),
seconds: dateInit.getSeconds()
};
}
};
var enddate = laydate.render({
elem: end,
format: 'yyyy-MM-dd',
min: minListDate,
max: maxListDate,
done: endChange
});
var begindate = laydate.render({
elem: begin,
format: 'yyyy-MM-dd',
min: minListDate,
max: maxListDate,
done: beginChange
});
$("#searchBt").click(function () {
var startTime = $("#startTime").val();
var endTime = $("#endTime").val();
var dateStart = new Date(startTime);
var dateEnd = new Date(endTime);
var difValue = (dateEnd - dateStart) / (1000 * 60 * 60 * 24);
if ((startTime == '' && endTime != '') || (startTime != '' && endTime == '')) {
return top.layer.msg('时间填写不完整', {
icon: 2,
time: 2000 //2秒关闭如果不配置默认是3秒
});
}
var startDateTemp = startTime.split("-");
var endDateTemp = endTime.split("-");
var allStartDate = new Date(startDateTemp[0], startDateTemp[1], startDateTemp[2]);
var allEndDate = new Date(endDateTemp[0], endDateTemp[1], endDateTemp[2]);
if (allStartDate.getTime() > allEndDate.getTime()) {
return top.layer.msg('时间选择不合理,请重新选择', {
icon: 2,
time: 2000 //2秒关闭如果不配置默认是3秒
});
}
example.ajax.reload();
});
$("#checkall").change(function () {
if ($(this).is(':checked')) {
$('input[name="checked"]').each(function () {
$(this).prop("checked", true);
});
} else {
$('input[name="checked"]').each(function () {
$(this).prop("checked", false);
});
}
});
});
})
function init() {
example =
$('#dt-table').DataTable({
"sort": false,
"searching": false,
"processing": true, //加载数据时显示进度状态
"serverSide": true,
"language": {
"url": contentPath + "/js/plugin/datatables/Chinese.lang"
},
"ajax": {
"url": ctxPath + "/attendancePush",
"type": "get",
"data": function (d) {
d.orgId = $("#orgId").val();
d.proId = $("#proId").val();
d.isPush = $("#isPush").val();
d.keyWord = $("#keyWord").val();
d.startTime = $("#startTime").val();
d.endTime = $("#endTime").val();
},
"error": function (xhr, textStatus, errorThrown) {
var msg = xhr.responseText;
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 = ctxPath + '/login.html';
});
} else if (code == 403) {
console.log("未授权:" + message);
layer.msg('未授权');
} else if (code == 500) {
console.log('系统错误:' + message);
}
}
},
"drawCallback": function() {
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) {
// var node = '';
// var checkedStatus = data['checkedStatus'];
// node = '<input class="checkall" name="checked" value=\"' + full.idNumber + ',' + full.currentDay + '\" type="checkbox"/>';
// if (checkedStatus == 1) {
// node = '<input class="checkall" name="checked" checked="checked" value=\"' + full.idNumber + ',' + full.currentDay + '\" type="checkbox"/>';
// }
// return node;
// }
// },
{
width: '5%',
data: function (row, type, set, meta) {
var c = meta.settings._iDisplayStart + meta.row + 1;
return c;
}
},
{"data": "name",width: '6%'},
{"data": "idNumber",width: '8%'},
{"data": "orgName",width: '10%'},
{"data": "proName",width: '10%'},
{"data": "currentDay",width: '10%'},
{"data": "counts",width: '10%'},
{
"data": "",
"defaultContent": "",width: '5%',
"orderable": false,
"render": function (data, type, row) {
var isPush = row['isPush'];
var html = '';
if (isPush == '未推送') {
html += '<span style="color:#f7a00a;">未推送</span>';
} else if (isPush == '推送成功') {
html += '<span style="color:green">推送成功</span>';
} else if (isPush == '推送失败') {
html += '<span style="color:red">推送失败</span>';
}else{
html += '<span style="color:red"></span>';
}
return html;
}
},
{"data": "pushTime",width: '5%'},
{
"data": "",
"defaultContent": "",width: '5%',
"orderable": false,
"render": function (data, type, row) {
var currentDay = row['currentDay'];
var idNumber = row['idNumber'];
var html = '';
html += buttonView(idNumber,currentDay,"", pers);
return html;
}
},
],
"order": [[0, "desc"], [1, "asc"]] //在栏目列上显示排序功能
});
}
/**
* 单个信息推送
* */
function onePush(idNumber,currentDay) {
$.ajax({
type: 'post',
url: ctxPath + '/attPush/selectAttendancePush',
data: {
idCard:idNumber,
currentDay:currentDay
},
dataType: 'json',
success: function (data) {
layer.msg(data.obj);
example.ajax.reload();
}
})
}
// 详情按钮
function buttonView(idNumber,currentDay, permission, pers) {
if (permission != "") {
if ($.inArray(permission, pers) < 0) {
return "";
}
}
var btn = $("<button class='layui-btn layui-btn-xs' title='推送' onclick='onePush(\"" + idNumber + "\",\"" + currentDay + "\")'>推送</button>");
return btn.prop("outerHTML");
}
// 批量推送
// function pushAll() {
// var idNumber = [];
// var currentDay = [];
// var oTable = $('#dt-table').dataTable();
// var rowcollection = oTable.$(".checkall:checked", {"page": "all"});
// rowcollection.each(function (index, elem) {
// var checkbox_value = $(elem).val();
// var strArr = checkbox_value.split(",");
// idNumber.push(strArr[0]);
// currentDay.push(strArr[1]);
// });
// if (idNumber.length == 0) {
// return layer.msg("请勾选要批量推送的数据", {icon: 2, time: 2000});
// }else{
// $.ajax({
// type: 'post',
// url: ctxPath + '/attendancePush/',
// traditional:true,
// data: {
// idNumberList:idNumber,
// currentDayList:currentDay
// },
// dataType: 'json',
// success: function (data) {
// }
// })
// }
// }
/**
* 获得当前时间 yyyy-MM-dd
* @returns {string}
*/
function getNowTime() {
var time = new Date();
var year = time.getFullYear();
var month = time.getMonth() + 1 >= 10 ? time.getMonth() + 1 : '0' + (time.getMonth() + 1);
var day = time.getDate() >= 10 ? time.getDate() : '0' + time.getDate();
return year + "-" + month + "-" + day;
}
/**
* 获取当月第一天
* @returns {string}
*/
function getCurrentMonthFirst() {
var date = new Date();
date.setDate(1);
var year = date.getFullYear();
var month = date.getMonth() + 1 > 10 ? date.getMonth() + 1 : '0' + (date.getMonth() + 1);
var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
return year + "-" + month + "-" + day;
}
/**
* 获取分公司
* */
function getCompanys(orgId) {
$("#orgId").empty();
$.ajax({
type: 'POST',
url: ctxPath + '/WorkRecord/getCompanys',
data: {},
dataType: 'json',
success: function (data) {
if(data.length>0){
var str = '<option selected value="">请选择分公司</option>';
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: ctxPath + '/WorkRecord/getProject',
data: {
"comId":orgId,
},
dataType: 'json',
success: function (data) {
if(data.length>0){
var str = '<option selected value="">请选择工程</option>';
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'); //这里就是我们要渲染的地方了
}
}
})
}