/// <reference path="../../../../scripts/jquery-3.6.4.js" />
/// <reference path="../../../../scripts/helper.js" />
layui.use('table', function () {
var element = layui.element,
form = layui.form,
laydate = layui.laydate,
table = layui.table;
//获取汇报人员
GetWechatUsersAll();
var startDate = objDate.GetCurrentDate();
var endDate = objDate.DateOperation();
//日期范围
laydate.render({
elem: '#P_StartTime',
value: startDate + ' - ' + endDate,
isInitValue: true,
range: true
});
laydate.render({
elem: '#P_ActualCompletionTime',
value: startDate + ' - ' + endDate,
isInitValue: true,
range: true
});
//监听select选择
form.on('select(sel_Date)', function (data) {
//console.log(data.elem); //得到select原始DOM对象
console.log(data.value); //得到被选中的值
//console.log(data.othis); //得到美化后的DOM对象
var _date = "";
switch (data.value) {
case "今天":
_date = startDate + ' - ' + endDate;
break;
case "昨天":
startDate = objDate.DateOperation("", "-");
endDate = objDate.GetCurrentDate();
_date = startDate + ' - ' + endDate;
break;
case "最近7天":
startDate = objDate.DateOperation("", "-", "", "7");
endDate = objDate.GetCurrentDate();
_date = startDate + ' - ' + endDate;
break;
case "最近30天":
startDate = objDate.DateOperation("", "-", "", "30");
endDate = objDate.GetCurrentDate();
_date = startDate + ' - ' + endDate;
break;
case "这个月":
startDate = objDate.GetMonthFirstDay();
endDate = objDate.GetMonthLastDay();
_date = startDate + ' - ' + endDate;
break;
default:
}
$("#txt_Date").val(_date);
});
//方法级渲染
table.render({
elem: '#LAY_table_user',
toolbar: '#toolbarDemo', // true 开启头部工具栏,并为其绑定左侧模板
method: 'post',
defaultToolbar: [''],
title: '用户数据表'
, url: "/Administration/UserInfo/GetPageListForSQL"
//, url: "/api/RepairRecord/GetPageListForSQL"
,
cols: [
[
{ type: 'numbers' },
{ type: 'checkbox' },
{ field: 'Id', title: 'Id', width: 100, sort: true, hide: true },
{
field: 'JobNumber', title: '工号', width: 100, sort: true
},
{
field: 'UserName', title: '姓名', width: 100, sort: true
},
{
field: 'Sex', title: '性别', width: 100, sort: true
},
{
field: 'IsEnable', title: '启用', width: 80,
templet: function (d) {
return d.IsEnable == 1 ? "是" : "否";
}
},
{
field: 'Phone', title: '手机', width: 120, sort: true
},
{
field: 'Email', title: '邮箱', width: 220, sort: true
},
{
field: 'RoleName', title: '角色', width: 200, sort: true
}
,
{
field: 'PositionName', title: '职务', width: 120, sort: true
},
{
field: 'ClassGroupName', title: '班组', width: 200, sort: true
}
, {
field: 'RouteName', title: '线路', width: 200, sort: true
}
]
],
id: 'testReload',
page: true,
height: 'full-100' //高度最大化减去差值
, limits: [10, 20, 30, 50, 100, 200, 500, 1000, 2000]
, limit: 20 //每页默认显示的数量
});
//监听头部工具栏事件
table.on('toolbar(table_user)', function (obj) {
var checkStatus = table.checkStatus(obj.config.id);
var data = checkStatus.data;
//console.log(data);
switch (obj.event) {
case 'add':
//window.location.href = "/Administration/UserInfo/Edit";
//window.parent.MenuNavTab("D0101" + rowdata.ID + "", "/Administration/WechatUsers/Edit?ID=" + rowdata.ID + "", "编辑用户角色");
layer.open({
type: 2,
title: '新增用户',
maxmin: true,
shadeClose: false, //点击遮罩关闭层
area: ['700px', '620px'],
content: '/Administration/UserInfo/Edit',
end: function () {
active["reload"].call(this)
}
});
break;
case 'delete':
if (data.length == 0) {
layer.msg('未选中行!');
return false;
}
layer.confirm('确定要删除这' + data.length + '条数据库吗?', function (index) {
layer.close(index);
//console.log(index);
var Ids = [];
for (var item in data) {
var Id = data[item].Id;
Ids.push({ Id: Id });
}
//删除操作
console.log(Ids);
LogicDeleteBatch(Ids);
});
break;
case 'export':
//layer.msg('导出');
Export();
break;
};
});
//监听行双击事件
table.on('rowDouble(table_user)', function (obj) {
if (!IsEdit) {
layer.msg('您无此编辑权限!');
return;
}
var rowdata = obj.data;
//window.location.href = "/Administration/WechatUsers/Edit?ID=" + rowdata.ID + "";
//window.parent.MenuNavTab("D0101" + rowdata.ID + "", "/Administration/WechatUsers/Edit?ID=" + rowdata.ID + "", "编辑用户角色");
layer.open({
type: 2,
title: '编辑用户',
maxmin: true,
shadeClose: false, //点击遮罩关闭层
area: ['700px', '620px'],
content: '/Administration/UserInfo/Edit?Id=' + rowdata.Id + '',
end: function () {
active["reload"].call(this)
}
});
});
var $Lay = layui.$,
active = {
reload: function () {
var _P_Engineer = $('#P_Engineer').val()
//执行重载
table.reload('testReload', {
page: {
curr: 1 //重新从第 1 页开始
},
where: {
UserName: _P_Engineer
}
}, 'data');
}
};
//点击按钮
$('#btn_search').on('click', function () {
var type = $(this).data('type');
console.log(type);
active[type] ? active[type].call(this) : '';
console.log(type);
});
//获取所有成员
function GetWechatUsersAll() {
$("#P_Engineer").empty();
$.post("/WechatUsers/GetWechatUsers", { DepartmentId: "5" }, function (data) {
var html = '<option value="">所有人</option>';
$.each(data, function (i, v) {
html += '<option value="' + v.UserName + '">' + v.UserName + '</option>';
});
$("#P_Engineer").append(html);
form.render();
});
}
//批量删除
function LogicDeleteBatch(parameter) {
console.log(parameter);
console.log(JSON.stringify(parameter));
$.ajax({
type: "Post",
contentType: "application/json",
url: "/Administration/UserInfo/LogicDeleteBatch",
data: JSON.stringify(parameter),
success: function (data) {
console.log("成功", data);
//执行重载
table.reload('testReload', {
page: {
curr: 1 //重新从第 1 页开始
},
where: {
}
}, 'data');
}
});
}
//条件伸缩开关
$("#ConditionSwitch").click(function () {
/*右侧条件面板样式 以位置伸缩*/
if ($(".Condition-Content").css('right') != "0px") {
$(".Condition-Panel").animate({
right: 0
}, "slow");
$(".Condition-Content").animate({
right: 0
}, "slow");
$(".Condition-Icon").attr("src", "Icon/收缩.png");
} else {
$(".Condition-Panel").animate({
right: '-460px'
}, "slow");
$(".Condition-Content").animate({
right: '-460px'
}, "slow");
$(".Condition-Icon").attr("src", "Icon/筛选.png");
}
});
});
//右侧条件面板
function ConditionPanel() {
var _height = $(".layui-body").height();
$(".Condition-Content").css({
height: _height
});
}
//导出
function Export() {
var _ReportTo = $('#sel_ReportTo').val();
var _CreateTime = $('#txt_Date').val();
var _StartTime = _CreateTime.split(" - ")[0];
var _EndTime = _CreateTime.split(" - ")[1];
console.log(_ReportTo);
if (!objValidate.NotNull(_ReportTo)) {
layer.msg('请选择汇报人!');
return;
}
var parameter = {
WechatId: _ReportTo,
StartTime: _StartTime,
EndTime: _EndTime
};
$.post("/Administration/Home/Export", parameter, function (data) {
console.log(data);
if (data == 0) {
return;
}
var JsonData = $.parseJSON(data);
console.log(JsonData.File);
console.log(JsonData.RelativePath);
window.open("https://report.all-iot.net" + JsonData.RelativePath);
});
//$.post("/Administration/Home/TemplateExcle", null, function (data) {
//});
}