'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");
var postCfg = {
headers: {
'Content-Type': 'application/json',
'Authorization': "Bearer " + self.get_AccessToken
}
}
self.type = sp.getUrlName("type") == "" ? 1 : sp.getUrlName("type");
self.changeType = function (n) {
if (self.type == n) {
return;
} else {
self.type = n;
self.getData(1, self.type)
}
}
self.CrossPage = window.parent.CrossPage;
self.loading = false;
self.noDataTip = 1;//没有数据时赋变量为0,先默认为1
self.listTotal1 = [];
self.listTotal2 = [];
self.list = [];
self.pageno = 1;
self.total_count = 0;
//self.itemsPerPage = 10;
self.pageOptions = [10, 20, 30, 40];
self.search = JSON.parse($.cookie("danganList2-search"));
//1为已提交、2为退回、3为合并提交、4为合并草稿、5为封装、6为已整理提交
self.getData = function (pageno, type) {
if (self.search == null) {
self.search = {
starttime: "",
endtime: "",
title: "",
archyear: sp.currentYear(),
mijiqixian: "10年",
itemsPerPage: 10
}
}
$.cookie("danganList2-search", JSON.stringify(self.search), { path: '/', expires: 1 });
self.loading = true;
self.pageno = pageno;
$scope.__default__currentPage = self.pageno; //设置页面样式在第几页
self.list = [];
var functionName = type == 1 ? "queryDataByColumnsWithPage" : "queryZLDataWithPage";
var data = {
tablename: "DOCELEMENT_ZL",
sqlwhere: type == 1 ? {
DPCODE: self.userDpCode,
MIJIQIXIAN: self.search.mijiqixian,
ARCHYEAR: self.search.archyear
} : {
MODELMARK: "1",
DPCODE: self.userDpCode,
MIJIQIXIAN: self.search.mijiqixian,
ARCHYEAR: self.search.archyear
},
sqlinwhere: type == 1 ? {
LOCKSTATUS: "'0','" + self.userId + "'",
sendstatus: "1"
} : {
LOCKSTATUS: "'0','" + self.userId + "'",
sendstatus: "3,4"
},
title: self.search.title,
order: type == 1 ? "JIANHAO" : "SENDDATE desc",
pageno: self.pageno,
pagesize: self.search.itemsPerPage
}
if (type == 1) {
data.columns = "ID,WENHAO,ROUTEINFOID,DOCUMENTTYPE,DOCTITLE,FLOWID,TO_CHAR(FINISHEDDATE,'YYYY-mm-dd hh24:mi:ss') AS FINISHEDDATE,SENDSTATUS,DOCISSUEDNUM,ARCHYEAR,JIANHAO,ARCHCODE,MIJIQIXIAN,ORGANIZATIONMA"
}
$http.post(apiurljs.login + "g2app/DangAn/" + functionName, { 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.listChecked = false;
self.total_count = res.totalCount;
if (QCHB(self.list, self["listTotal" + self.type], "ID").length > 0) {
self["listTotal" + self.type] = self["listTotal" + self.type].concat(QCHB(self.list, self["listTotal" + self.type], "ID"))
}
var checkedNum = 0;
$.each(self.list, function (index, item) {
item.checked = false;
item.STATUS = item.SENDSTATUS == 1 ? "未整理" : item.SENDSTATUS == 3 ? "已合并" : "未合并";
$.each(self["listTotal" + self.type], function (index1, item1) {
if (item.ID == item1.ID) {
item.checked = item1.checked;
}
})
if (item.checked == true) {
checkedNum++
}
})
if (checkedNum == self.list.length) {
self.listChecked = true;
}
}
})
}
self.changeListCheck = function () {
$.each(self.list, function (index, item) {
item.checked = self.listChecked;
$.each(self["listTotal" + self.type], function (index1, item1) {
if (item1.ID == item.ID) {
item1.checked = item.checked;
}
})
})
}
self.changeCheck = function (item, n) {
item.checked = n == 1 ? item.checked : !item.checked;
$.each(self["listTotal" + self.type], function (index1, item1) {
if (item1.ID == item.ID) {
item1.checked = item.checked;
}
})
event.stopPropagation()
}
self.load = function () {
if (self.get_lastReturnPageno == undefined || self.get_lastReturnPageno == null || self.get_lastReturnPageno == "") {
self.getData(self.pageno, self.type);
} else {
$timeout(function () {
self.getData(parseInt(self.get_lastReturnPageno), self.type);
}, 1)
}
}
self.getDP = function () {
var data = {
userid: self.userId
}
$http.post(apiurljs.login + "g2app/richang/queryDpInfo", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
.success(function (obj) {
var res = strToJson(s4.decryptData_CBC(obj.data));
self.userDpName = res.data.length == 0 ? "" : res.data[0].SECTION;
self.userDpCode = res.data.length == 0 ? "" : res.data[0].CODE;
self.getORGANIZATIONMA();
})
}
self.getORGANIZATIONMA = function () {
self.ORGANIZATIONMA = []
var data = {
tablename: "SYS_SECT",
colums: "*",
order: "SORTID",
sqlwhere: "",
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.ORGANIZATIONMA = res.data;
self.load();
})
}
self.getDP();
self.refresh = function () {
self.CrossPage.type = null;
self.getData(self.pageno, self.type);
}
///查询-打开弹出层
self.openSearchLayer = function () {
if (self.search == null) {
self.search = {
starttime: "",
endtime: "",
title: "",
archyear: sp.currentYear(),
mijiqixian: "10年",
itemsPerPage: 10
}
}
sp.layer("#search");
}
self.btnSubmit = function () {
var itemlist = [], flag = true;
self["listTotal" + self.type].forEach(function (item) {
if (item.checked == true) {
if (item.SENDSTATUS != 3) {
flag = false;
sp.dialog("请勾选状态为已合并的案件!");
return;
} else {
if (item.ARCHCODE == "" || item.ARCHCODE == null) {
flag = false;
sp.dialog("档号不能为空,请先进行档号整理!")
return;
} else {
itemlist.push(item.ROUTEINFOID);
}
}
}
})
if (!flag) {
return
}
if (itemlist.length == 0) {
sp.dialog("请勾选需要提交的案件!");
return;
}
var dialogHead = "温馨提示×";
var dialogBody = "
您确认要提交所勾选的案件吗?
";
var dialogFoot = "";
$('.sp-dialog').html(dialogHead + dialogBody + dialogFoot);
sp.openCenter(".sp-dialog");
$('.sp-closeDialog').click(function (event) {
sp.dialoghide();
event.preventDefault();
event.stopPropagation();
});
$("#upDataTrue").click(function () {
sp.dialoghide();
var data = {
routeinfoid: itemlist.join(","),
tablename: "DOCELEMENT_ZL",
sqlwhere: {
SENDSTATUS: "6",
LOCKSTATUS: "0",
SENDDATE: sp.getLocalDate()
}
}
$http.post(apiurljs.login + "g2app/DangAn/setColumns", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
.success(function (obj) {
var res = strToJson(s4.decryptData_CBC(obj.data));
if (res.success) {
sp.dialog("提交成功!");
self.getData(1, self.type);
self["listTotal" + self.type] = self["listTotal" + self.type].filter(function (item) {
return itemlist.every(function (item1) {
return item.ROUTEINFOID != item1;
})
})
$timeout(function () {
sp.dialoghide();
}, 1000)
} else {
sp.dialog(res.message)
}
})
})
}
self.list1 = [];
self.pailie = function (n) {
var data = {
tablename: "DOCELEMENT_ZL",
colums: "*",
sqlwhere: {
MIJIQIXIAN: self.search.mijiqixian//n == 3 ? "永久" : n == 2 ? "30年" : "10年"
},
sqlinwhere: {
LOCKSTATUS: "'0','" + self.userId + "'",
sendstatus: "1"
} ,
sqllikewhere: "",
order: "JIANHAO"
}
$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));
if (res.data == null || res.data == undefined || res.data == "") {
if (n == 0) {
sp.dialog("暂无数据!")
return
} else {
self.list1 = [];
}
}
self.list1 = res.data;
self.jianhaoList = res.data.map(function (item) { return item.JIANHAO });
$("#table_tbody").sortable({
cursor: "move",
stop: function (event, ui) {
var index = 1;
$("#table_tbody").children().each(function (x) {
$(this).attr("index", index)
$(this).children().eq(0).html(index)
index++
})
}
}).disableSelection();
if (n == 0) {
$(".Item").removeClass("Choose").eq(0).addClass("Choose")
sp.layer("#pailie", 1)
} else {
$(".Item").removeClass("Choose").eq(n - 1).addClass("Choose")
}
})
}
self.closePai = function () {
var IDS = [], JIANHAOS = [];
self.list1.forEach(function (item) {
$("#table_tbody").children().each(function (index) {
if ($(this).attr("data-col") == item.ID) {
IDS.push({ ID: item.ID })
var MIJIQIXIAN = item.MIJIQIXIAN == "10年" ? "D10" : item.MIJIQIXIAN == "30年" ? "D30" : "Y";
var ORGANIZATIONMA = self.ORGANIZATIONMA.filter(function (item1) {
if (item1.CODE == item.ORGANIZATIONMA) {
return item1
}
})[0].INSTCODE
JIANHAOS.push({ JIANHAO: index + 1, ARCHCODE: "X154-WS・" + item.ARCHYEAR + "-" + MIJIQIXIAN + "-" + ORGANIZATIONMA + "-" + JIANHAO(index + 1) })
}
})
})
var data = {
entity: "DOCELEMENT_ZL",
data: JIANHAOS,
setwhere: IDS
}
$http.post(apiurljs.login + "g2app/Data/UpdataByWhereList", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
.success(function (obj) {
var res = strToJson(s4.decryptData_CBC(obj.data));
if (res.success == true) {
self.getData(1, 1);
sp.closeCenter("#pailie")
}
})
}
self.Top = function (obj, n) {
for (var i = 0; i < n; i++) {
self.list1[i].JIANHAO = self.list1[i].JIANHAO * 1 + 1;
}
obj.JIANHAO = 1;
self.list1.sort(function (a, b) {
return a.JIANHAO - b.JIANHAO;
})
}
self.Up = function (obj, n) {
obj.JIANHAO--
self.list1[n - 1].JIANHAO++
self.list1.sort(function (a, b) {
return a.JIANHAO - b.JIANHAO;
})
}
self.Down = function (obj, n) {
obj.JIANHAO++
self.list1[n + 1].JIANHAO--
self.list1.sort(function (a, b) {
return a.JIANHAO - b.JIANHAO;
})
}
self.Bottom = function (obj, n) {
for (var i = n; i < self.list.length; i++) {
self.list1[i].JIANHAO = self.list1[i].JIANHAO * 1 - 1;
}
obj.JIANHAO = self.list1.length;
self.list1.sort(function (a, b) {
return a.JIANHAO - b.JIANHAO;
})
}
self.danghao = function () {
var list = [];
self["listTotal" + self.type].forEach(function (item) {
if (item.checked == true) {
list.push(item)
}
})
if (list.length == 0) {
sp.dialog("请选择要生成档号的案件!");
return;
} else {
var ids = [], title = [], archcode = [];
list.forEach(function (item) {
if (item.ARCHCODE != "" && item.ARCHCODE != null) {
title.push(item.DOCTITLE)
} else {
ids.push({ ID: item.ID })
var MIJIQIXIAN = item.MIJIQIXIAN == "10年" ? "D10" : item.MIJIQIXIAN == "30年" ? "D30" : "Y";
var ORGANIZATIONMA = self.ORGANIZATIONMA.filter(function (item1) {
if (item1.CODE == item.ORGANIZATIONMA) {
return item1
}
})[0].INSTCODE
archcode.push({ id: item.ID, data: { ARCHCODE: "X154-WS・" + (item.ARCHYEAR == null ? sp.currentYear() : item.ARCHYEAR) + "-" + MIJIQIXIAN + "-" + ORGANIZATIONMA + "-" + JIANHAO(item.JIANHAO) } })
}
})
//if (title.length == list.length) {
// sp.dialog(title.join(",") + "已有档号!")
// $timeout(function () {
// sp.dialoghide()
// }, 1500)
// return
//}
var data = {
entity: "DOCELEMENT_ZL",
data: archcode,
columns: "ID,ARCHCODE",
order: "ID"
//setwhere: ids
}
$http.post(apiurljs.login + "g2app/DangAn/UpdataDangHaoBackData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
.success(function (obj) {
var res = strToJson(s4.decryptData_CBC(obj.data));
console.log(res)
if (res.success) {
self.list.forEach(function (item) {
res.data.forEach(function (item1) {
if (item.ID == item1.ID) {
item.ARCHCODE = item1.ARCHCODE;
}
})
})
if (title.length == 0) {
sp.dialog("档号生成成功")
$timeout(function () {
sp.dialoghide()
}, 1500)
} else {
sp.dialog(title.join(",") + "已有档号,其他档号生成成功!")
$timeout(function () {
sp.dialoghide()
}, 1500)
}
} else {
sp.dialog(res.message)
}
})
}
}
self.gdz = function () {
var list = [];
self["listTotal" + self.type].forEach(function (item) {
if (item.checked == true) {
list.push(item)
}
})
if (list.length == 0) {
sp.dialog("请选择要生成归档章的案件!");
return;
} else {
}
}
self.hebing = function () {
var itemlist = [];
self["listTotal" + self.type].forEach(function (item) {
if (item.checked == true) {
itemlist.push({ ID: item.ID, NAME: item.DOCTITLE, ROUTEINFOID: item.ROUTEINFOID })
}
})
if (itemlist.length == 0) {
sp.dialog("请选择要合并的案件!");
return;
}
var dialogHead = "温馨提示×";
var dialogBody = "您确认要合并这些内容吗?
";
var dialogFoot = "";
$('.sp-dialog').html(dialogHead + dialogBody + dialogFoot);
sp.openCenter(".sp-dialog");
$('.sp-closeDialog').click(function (event) {
sp.dialoghide();
event.preventDefault();
event.stopPropagation();
});
$("#upDataTrue").click(function () {
sp.dialoghide();
var data = {
routeinfoid: itemlist.map(function (item) { return item.ROUTEINFOID }).join(","),
status: self.userId//"1"
}
$http.post(apiurljs.login + "g2app/DangAn/setLockStatus", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
.success(function (obj) {
var res = strToJson(s4.decryptData_CBC(obj.data));
if (res.success) {
$.cookie("hebing-itemlist", JSON.stringify(itemlist), { path: '/', expires: 1 });
window.location.href = "hebing.html?lastReturn=list2&lastReturnPageno=" + self.pageno
} else {
sp.dialog(res.message)
}
})
})
}
//编辑已合并的草稿件
self.hbEdti = function (item) {
var data = {
routeinfoid: item.MERGEID,
status: self.userId//"1"
}
$http.post(apiurljs.login + "g2app/DangAn/setLockStatus", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
.success(function (obj) {
var res = strToJson(s4.decryptData_CBC(obj.data));
sp.dialoghide();
if (res.success) {
$.cookie("hebingedt-itemlist", JSON.stringify({ MERGEID: item.MERGEID, ROUTEINFOID: item.ROUTEINFOID }), { path: '/', expires: 1 });
window.location.href = "hebingedt.html?lastReturn=list2&lastReturnPageno=" + self.pageno
} else {
sp.dialog(res.message)
}
})
event.stopPropagation()
}
self.toHref = function (html, item, type) {
window.location.href = html + ".html?id=" + item.ID + "&routeinfoid=" + item.ROUTEINFOID + "&lastReturn=list2&lastReturnPageno=" + self.pageno + "&type=" + type;
event.stopPropagation()
}
self.btnSearch = function () {
self.getData(1, self.type)
sp.layerhide()
}
self.closeSeach = function () {
self.search.title = "";
self.search.archyear = sp.currentYear();
self.search.mijiqixian = "10年";
sp.layerhide();
$.cookie("danganList2-search", null, { path: '/', expires: -1 });
self.getData(1, self.type)
};
self.btnReturn = function (n, ID) {
if (n == 1) {
self.back = {
ID: ID,
opinion: "",
}
sp.layer("#backopinion");
} else {
if (self.back.opinion == "") {
sp.dialog("退回意见不能为空!");
return;
}
sp.layerhide();
var data = {
routeinfoid: self.back.ID,
userid: self.userId,
username: self.userName,
backopinion: self.back.opinion
}
$http.post(apiurljs.login + "g2app/DangAn/BackData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
.success(function (obj) {
var res = strToJson(s4.decryptData_CBC(obj.data));
if (res.success == true) {
self.getData(1, self.type)
}
})
}
event.stopPropagation()
}
self.Delete = function (routeinfoid) {
var dialogHead = "温馨提示×";
var dialogBody = "您确认要删除此记录吗?
";
var dialogFoot = "";
$('.sp-dialog').html(dialogHead + dialogBody + dialogFoot);
sp.openCenter(".sp-dialog");
$('.sp-closeDialog').click(function (event) {
sp.dialoghide();
event.preventDefault();
event.stopPropagation();
});
$("#upDataTrue").click(function () {
sp.dialoghide();
var data = {
routeinfoid: routeinfoid
}
$http.post(apiurljs.login + "g2app/DangAn/deleteBuHuoData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
.success(function (obj) {
var res = strToJson(s4.decryptData_CBC(obj.data));
if (res.success) {
self.getData(self.pageno, self.type);
}
})
})
}
//头部下滚冻结
$(function () {
//页面高度撑满
setTimeout(function () {
if ($(".ibox-content").height() < $(window).height() - 31) {
$(".ibox-content").css("height", $(window).height() - 31)
}
}, 1)
})
}])
function QCHB(arr1, arr2, filed) {
return arr1.filter(function (item) {
return arr2.every(function (item1) {
return item[filed] != item1[filed];
})
})
}
function JIANHAO(n) {
if (n < 10) {
return "000" + n;
} else if (n > 10 && n < 100) {
return "00" + n;
} else if (n > 100 && n < 1000) {
return "0" + n;
} else {
return n
}
}