'use strict';
var app = angular.module('app', [
'angularUtils.directives.dirPagination'
]);
app.controller("listCtrl", ["$scope", "$http", "$timeout", function ($scope, $http, $timeout) {
var self = this;
var s4 = new SM4Util();
self.userId = $.cookie("GlWorkPlatform-userid");
self.userName = $.cookie("GlWorkPlatform-chineseName");
self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken");
self.get_lastReturnPageno = sp.getUrlName("lastReturnPageno");
self.get_type = sp.getUrlName("type");
var postCfg = {
headers: {
'Content-Type': 'application/json',
'Authorization': "Bearer " + self.get_AccessToken
}
}
self.type = self.get_type != "" ? self.get_type : "1";
self.loading = false;
self.noDataTip = 1;//没有数据时赋变量为0,先默认为1
self.pageno = 1;
self.total_count = 0;
self.itemsPerPage = 10;
self.pageOptions = [10, 20, 30, 40];
self.Status = "";
self.getData = function (pageno) {
self.list = [];
self.loading = false;
self.pageno = pageno;
$scope.__default__currentPage = self.pageno; //设置页面样式在第几页
var data = {
tablename: "SX_HYSGLB",
pagesize: self.itemsPerPage,
pageno: self.pageno,
colums: "*",
order: "SORTID",
sqlwhere: { ZT: self.Status },
sqlorwhere: "",
sqlinwhere: "",
sqllikewhere: ""
};
$http.post(apiurljs.login + "g2app/dataabase/queryDataByColWithPage", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
.success(function (obj) {
var res = strToJson(s4.decryptData_CBC(obj.data));
self.loading = false;
if (res.data == null || res.data == undefined || res.data == "") {
self.noDataTip = 0;
} else {
self.noDataTip = 1;
self.list = res.data;
self.total_count = res.totalCount;
}
})
}
self.load = function () {
if (self.get_lastReturnPageno == undefined || self.get_lastReturnPageno == null || self.get_lastReturnPageno == "") {
self.getData(self.pageno);
} else {
$timeout(function () {
self.getData(self.get_lastReturnPageno);
}, 1)
}
}
self.wuye = false;
self.getROLE = function () {
var data = {
userid: self.userId
};
$http.post(apiurljs.login + "g2work/datazu/queryDataUserAuth", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
.success(function (obj) {
var res = strToJson(s4.decryptData_CBC(obj.data));
res.data[0].auths.forEach(function (item) {
if (item.ZID == "AA36" && item.AUTH == "1") {
self.wuye = true;
self.load()
}
})
});
}
self.getROLE()
self.refresh = function () {
self.getData(self.pageno);
}
self.changeType = function (str) {
if (self.type == str) {
return;
} else {
self.type = str;
self.getData(1)
}
}
self.btnEdit = function (id) {
window.location.href = "huiyi/formedit.html?id=" + id + "&lastReturnPageno=" + self.pageno;
}
self.btnDel = function (id) {
var dialogHead = "温馨提示×";
var dialogBody = "
删除后不可恢复,您确认要删除吗?
";
var dialogFoot = "";
$('.sp-dialog').html(dialogHead + dialogBody + dialogFoot);
sp.openCenter(".sp-dialog");
///取消按钮
$('.sp-closeDialog').click(function (event) {
sp.closeCenter(".sp-dialog");
event.preventDefault();
event.stopPropagation();
});
//post消息的id
$("#delDataTrue").click(function () {
var data = {
tablename: "SX_HYSGLB",
id: id
};
$http.post(apiurljs.login + "g2app/dataabase/delDataById", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
.success(function (obj) {
var res = strToJson(s4.decryptData_CBC(obj.data));
sp.dialoghide();
if (res.success) {
self.getData(self.pageno);
} else {
sp.dialog("删除失败,请联系管理员!");
}
});
});
}
//生成当天起,一共7天数据
self.searchDay = sp.format(sp.getLocalDate())
//自动生成列数据
self.getRoom = function () {
self.week = []
sp.getWeekNumber(new Date(self.searchDay)).dateString.split(",").forEach(function (item) {
self.week.push({ date: item, time: "08:00" }, { date: item, time: "09:00" }, { date: item, time: "10:00" }, { date: item, time: "11:00" }, { date: item, time: "12:00" }, { date: item, time: "13:00" }, { date: item, time: "14:00" }, { date: item, time: "15:00" }, { date: item, time: "16:00" }, { date: item, time: "17:00" }, { date: item, time: "18:00" })
})
var data = {
tablename: "SX_HYSGLB",
colums: "*",
order: "ID",
sqlwhere: { ZT: "正常" },
sqlorwhere: "",
sqlinwhere: "",
sqllikewhere: ""
};
$http.post(apiurljs.login + "g2app/dataabase/queryDataByCol", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
.success(function (obj) {
var res = strToJson(s4.decryptData_CBC(obj.data));
self.huiyiRoom = [];
res.data.forEach(function (item) {
self.huiyiRoom.push({ name: item.HYSMC, fjh: item.WZ })
})
self.getApplication()
})
}
self.getRoom()
//使用情况数据,status:1为已结束,2为进行中,3为已预订,4为已取消
self.getApplication = function () {
self.application = [];
var data = {
userid: self.userId,
sdate: sp.dateCount(0) + " 08:00:00",
edate: sp.dateCount(6) + " 23:00:00"
}
$http.post(apiurljs.login + "g2app/huiwu/queryDataHuiwuStatus", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
.success(function (obj) {
var res = strToJson(s4.decryptData_CBC(obj.data));
res.data.forEach(function (item) {
self.application.push({
id: item.ID,
routeinfoid: item.ROUTEINFOID,
date: sp.datefmt("M-dd", item.KSSJ).replace("-", "."),
start: sp.datefmt("HH:mm", item.KSSJ),
end: sp.datefmt("HH:mm", item.JSSJ),
fjh: item.HYS,
dpname: item.CBBM,
username: item.SQR,
status: item.SFSH == "已审核" ? 4 : getStatus(sp.datefmt("MM-dd HH-mm", item.KSSJ), sp.datefmt("MM-dd HH-mm", item.JSSJ)),
title: item.HYMC,
lxfs: item.LXFS
})
})
self.application.forEach(function (item, index) {
item.msg = item.start + "—" + item.end + " " + "
" + item.dpname + " " + item.username + "
" + item.lxfs;
item.msg1 = item.start + "—" + item.end + " " + " " + item.dpname + " " + item.username + " " + item.lxfs;
item.show = true;
item.showRoom = false;
item.showDate = false;
item.style = {
"background-color": "",
"text-align": "center",
"color": "white",
"font-size": "14px",
"font-weight": 600,
"padding": "0 10px",
"position": "absolute",
"left": 0,
"top": 0,
"width": 200,
"height": 0,
}
item.style["background-color"] = getColor(item.status);
self.huiyiRoom.forEach(function (item1, index1) {
if (item.fjh == item1.name) {
item.style.left = index1 * 200 + 200;
item.showRoom = true;
}
})
self.week.forEach(function (item1, index1) {
var n1 = 0, n2 = 0, n3 = 0, n4 = 0;
if ((item.date.split(".")[0] < 10 ? "0" + item.date : item.date) == item1.date) {
if (item.start.slice(0, 2) == item1.time.slice(0, 2)) {
n1 = index1 * 50;
n2 = 50 - item.start.slice(3) * 1 / 60 * 50;
item.style.top = n1 + n2;
}
item.style.height = (item.end.slice(0, 2) * 1 - item.start.slice(0, 2) * 1) * 50 + (item.end.slice(3) * 1 - item.start.slice(3) * 1) / 60 * 50;
item.showDate = true;
}
})
//item.style.padding = (item.style.height - 36) / 2 + "px 0";
item.show = item.showRoom == true && item.showDate == true
})
console.log(res.data)
console.log(self.application)
console.log(self.huiyiRoom)
})
}
self.cancelHY = function (item) {
var dialogHead = "温馨提示×";
var dialogBody = "您确认要取消吗?
";
var dialogFoot = "";
$('.sp-dialog').html(dialogHead + dialogBody + dialogFoot);
sp.openCenter(".sp-dialog");
///取消按钮
$('.sp-closeDialog').click(function (event) {
sp.closeCenter(".sp-dialog");
event.preventDefault();
event.stopPropagation();
});
//post消息的id
$("#delDataTrue").click(function () {
var data = {
tablename: "SX_HYSQBZHWY",
id: item.id,
data: {
KSSJ: null,
JSSJ: null
}
}
$http.post(apiurljs.login + "g2app/dataabase/upFormData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
.success(function (obj) {
var res = strToJson(s4.decryptData_CBC(obj.data));
if (res.success) {
var data1 = {
routeinfoid: item.routeinfoid,
userid: self.userId
}
$http.post(apiurljs.login + "g2work/routeinfo/removeDraftToCacheByRouteinfoid", { data: s4.encryptData_CBC(JSON.stringify(data1)) }, postCfg)
.success(function (obj1) {
var res1 = strToJson(s4.decryptData_CBC(obj1.data));
sp.dialoghide();
if (res1.success == true) {
self.getApplication()
} else {
sp.dialog(res1.message)
}
})
} else {
sp.dialoghide();
$timeout(function () {
sp.dialog(res.message);
},500)
}
})
});
}
//头部下滚冻结
$(function () {
//页面高度撑满
setTimeout(function () {
if ($(".ibox-content").height() < $(window).height() - 32) {
$(".ibox-content").css("height", $(window).height() - 32)
}
}, 1)
$(".huiyi-table").parent().css("max-height", $(window).height() - 130)
})
}])
app.directive("repeatFinish", function () {
return {
link: function (scope) {
if (scope.$last == true) {
setTimeout(function () {
$(".sp-table").rowspan(0)
}, 10);
}
}
};
});
app.filter('trustHtml', function ($sce) {
return function (input) {
return $sce.trustAsHtml(input.replace(/\n/g, '
').replace(/\s/g, ' '));
};
});
function getStatus(time1,time2) {
var ctime = sp.datefmt("MM-dd HH:mm", sp.getLocalDate());
if (ctime <= time1) {
return 3
} else if (ctime >= time1 && ctime <= time2) {
return 2
} else if (ctime >= time2) {
return 1
}
}
function getColor(n) {
var color = "";
switch (n) {
case 1: color = "#CCCCCC"; break;
case 2: color = "#00CC66"; break;
case 3: color = "#0099FF"; break;
case 4: color = "#CC0000"; break;
}
return color;
}
function scrollTable() {
$(".thead").scrollLeft($(".tbody").scrollLeft())
}
jQuery.fn.rowspan = function (colIdx) { //封装的一个JQuery小插件
return this.each(function () {
var that, rowspan;
$('tr', this).each(function (row) {
$('td:eq(' + colIdx + ')', this).filter(':visible').each(function (col) {
if (that != null && $(this).html() == $(that).html()) {
rowspan = $(that).attr("rowSpan");
if (rowspan == undefined) {
$(that).attr("rowSpan", 1);
rowspan = $(that).attr("rowSpan");
}
rowspan = Number(rowspan) + 1;
$(that).attr("rowSpan", rowspan);
$(this).remove();
} else {
that = this;
}
});
});
});
}