'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.pageform = sp.getUrlName("pageform");
self.tablename = "SX_TFNZZGZB"
var postCfg = {
headers: {
'Content-Type': 'application/json',
'Authorization': "Bearer " + self.get_AccessToken
}
}
self.getCARDID = function () {
var postData = { "userid": self.userId };
$http.post(apiurljs.login + "g2work/user/queryUserinfoAddress", JSON.stringify(postData), postCfg)
.success(function (obj) {
var res = strToJson(s4.decryptData_CBC(obj.data));
if (res.success) {
self.CARDID = res.data.CARDID///身份证号码
if (self.CARDID == "" || self.CARDID == null || self.CARDID == undefined) {
sp.dialog("请先去个人资料-通讯录信息中补全身份证号信息!现在就去")
} else {
self.getHead()
}
}
})
};
self.getHead = function () {
var data = {
tablename: self.tablename,
order: "sortid"
}
$http.post(apiurljs.login + "g2app/richang/queryColumnsData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
.success(function (obj) {
var res = strToJson(s4.decryptData_CBC(obj.data))
self.thead = [];
$.each(res.data, function (index, item) {
if (item.code != "ID" && item.code != "ROUTEINFOID" &&
item.code != "SORTID" && item.code != "APPCODE" &&
item.code != "CTIME" && item.code != "RYSF" && item.code != "RYFL" && item.code != "SFZHM" && item.code != "CJGZSJ" && item.code != "ZW") {
self.thead.push({ code: item.code, cname: item.cname, ckind: item.ckind })
}
})
self.date = sp.currentYear() + "-" + formate(sp.currentMonth())
self.getData()
})
}
self.getCARDID();
self.changeDate = function () {
if (self.date > sp.currentYear() + "-" + formate(sp.currentMonth())) {
$timeout(function () { self.date = sp.currentYear() + "-" + formate(sp.currentMonth()) },1)
}
}
self.changeTB = function (tablename) {
if (self.tablename == tablename) {
return;
} else {
self.tablename = tablename;
self.getHead()
}
}
self.noDataTip = 1;//没有数据时赋变量为0,先默认为1
self.getData = function () {
self.list = [];
if (self.tablename == "SX_TFWZZGZB") {
var data = {
ffny: self.date,
sfzhm: self.CARDID,
xm: self.userName
}
$http.post(apiurljs.login + "g2app/richang/querytfwzzgzbData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
.success(function (obj) {
var res = strToJson(s4.decryptData_CBC(obj.data));
self.canExportExcel = true;
if (res.data == null || res.data == undefined || res.data == "") {
self.noDataTip = 0;
} else {
self.noDataTip = 1;
res.data.forEach(function (item) {
item.DATA.forEach(function (item1) {
self.list.push(item1)
})
});
self.list.forEach(function (item) {
self.thead.forEach(function (item1) {
if (item1.ckind == "datetime") {
item[item1.code] = item[item1.code] ? sp.minsToDate("yyyy-MM", item[item1.code]) : "";
}
if (item.NAMETYPE == "合计") {
item.XM = "合计";
}
})
})
}
})
} else {
var data = {
tablename: self.tablename,
colums: "*",
order: "ID",
sqlwhere: { XM: self.userName, SFZHM: self.CARDID },
sqlorwhere: "",
sqlinwhere: "",
sqllikewhere: { FFNY: self.date }
};
$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.canExportExcel = true;
if (res.data == null || res.data == undefined || res.data == "") {
self.noDataTip = 0;
} else {
self.noDataTip = 1;
self.list = res.data;
self.list.forEach(function (item) {
self.thead.forEach(function (item1) {
if (item1.ckind == "datetime") {
item[item1.code] = sp.format(item[item1.code]).slice(0, 10)
}
})
})
}
})
}
}
self.YINHANG = function () {
self.yhList = [];
var data = {
cname: "SX_TFWZZGZB",
ffny: self.date,
xm: self.userName
}
$http.post(apiurljs.login + "g2app/richang/queryTFWDataToMan", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
.success(function (obj) {
var res = strToJson(s4.decryptData_CBC(obj.data))
self.yhList = res.data;
sp.layer("#YINHANG")
})
}
self.downloadYH = function () {
var title = "统发外个人工资银行表格"
if (self.canExportExcel) {
$('#yh td').attr('t', 's')
var defaultCellStyle = {
font: {
name: 'Times New Roman',
sz: 12,
color: {
rgb: "000000"
},
bold: false, italic: false,
underline: false
},
alignment: {
vertical: "center",
horizontal: "center", indent: 0, wrapText: true
},
border: {
top: {
style: "thin",
color: {
rgb: "000000"
}
},
right: {
style: "thin",
color: {
rgb: "000000"
}
},
bottom: {
style: "thin",
color: {
rgb: "000000"
}
},
left: {
style: "thin",
color: {
rgb: "000000"
}
}
}
};
var cell = { defaultCellStyle: defaultCellStyle };
var wb = XLSX.utils.table_to_book_addtitle(document.querySelector('#yh'), cell, title)
//设置表格的样式
var wbout = XLSX.write(wb, {
bookType: 'xlsx',
bookSST: false,
type: 'binary',
cellStyles: true,
defaultCellStyle: defaultCellStyle,
showGridLines: false
});
var s2ab = function (s) {
var buf = new ArrayBuffer(s.length);
var view = new Uint8Array(buf);
for (var i = 0; i !== s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
return buf;
};
try {
saveAs(new Blob([s2ab(wbout)], { type: 'application/octet-stream' }), '统发外个人工资银行表格.xlsx')
} catch (e) { if (typeof console !== 'undefined') console.log(e, wbout) }
return wbout
} else {
sp.dialog('数据还未加载完成,请稍等...')
}
}
self.printOut = function () {
var title = self.date.split("-")[0] + "年" + self.date.split("-")[1] + "月" + (self.tablename == "SX_TFNZZGZB" ? "统发内工资单" : "统发外工资单");
if (self.canExportExcel) {
$('#printOut td').attr('t', 's')
var defaultCellStyle = {
font: {
name: 'Times New Roman',
sz: 12,
color: {
rgb: "000000"
},
bold: false, italic: false,
underline: false
},
alignment: {
vertical: "center",
horizontal: "center", indent: 0, wrapText: true
},
border: {
top: {
style: "thin",
color: {
rgb: "000000"
}
},
right: {
style: "thin",
color: {
rgb: "000000"
}
},
bottom: {
style: "thin",
color: {
rgb: "000000"
}
},
left: {
style: "thin",
color: {
rgb: "000000"
}
}
}
};
var cell = { defaultCellStyle: defaultCellStyle };
var wb = XLSX.utils.table_to_book_addtitle(document.querySelector('#printOut'), cell, title)
//设置表格的样式
var wbout = XLSX.write(wb, {
bookType: 'xlsx',
bookSST: false,
type: 'binary',
cellStyles: true,
defaultCellStyle: defaultCellStyle,
showGridLines: false
});
var s2ab = function (s) {
var buf = new ArrayBuffer(s.length);
var view = new Uint8Array(buf);
for (var i = 0; i !== s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
return buf;
};
try {
saveAs(new Blob([s2ab(wbout)], { type: 'application/octet-stream' }), title + '.xlsx')
} catch (e) { if (typeof console !== 'undefined') console.log(e, wbout) }
return wbout
} else {
sp.dialog('数据还未加载完成,请稍等...')
}
}
}])
function formate(d){
return d > 9 ? d : "0" + d
}
function goUrl() {
window.top.sp.addTabNav('asetNewPersonalData', '个人资料', 'tpk/_asetnew/personalData_phone.html')
sp.dialoghide()
}