123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424 |
- 'use strict';
- var app = angular.module('app', [
- 'angularUtils.directives.dirPagination'
- ]);
- app.controller("taizhangCtrl", ["$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.loading = false;
- self.search = JSON.parse($.cookie("GlWorkPlatform-yzaptz")) || { DATE1: sp.getWeekNumber(new Date()).begin, DATE2: sp.getWeekNumber(new Date()).end };
- self.getSORTID = function () {
- var data = {
- userid: self.userId
- }
- $http.post(apiurljs.login + "g2app/richang/queryLDSortid", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
- .success(function (obj) {
- var res = strToJson(s4.decryptData_CBC(obj.data));
- self.LDSORTID = res.data;
- self.getData()
- })
- }
- self.getData = function () {
- self.list = [];
- self.loading = false;
- var data = {
- tablename: "SX_YZAPTZ",
- colums: "*,TO_CHAR(YZAPDATE,'yyyy-mm-dd')as YZAPDATE1,TO_CHAR(CTIME,'hh24:mi')as CTIME1",
- order: "CTIME",
- sqlwhere: " and YZAPDATE BETWEEN '" + self.search.DATE1 + " 00:00:00' AND '" + self.search.DATE2 + " 23:59:59' and USERID='" + self.userId + "'"
- }
- $http.post(apiurljs.login + "g2app/dataabase/queryDataByColStr", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
- .success(function (obj) {
- var res = strToJson(s4.decryptData_CBC(obj.data));
- self.loading = false;
- self.addFlag = false;
- self.editFlag = false;
- self.addList = [];
- self.list = res.data;
- self.list.forEach(function (item) {
- item.CNAME = item.CNAME == "null" ? "" : item.CNAME
- item.ATTENDANCESCOPE = item.ATTENDANCESCOPE == "null" ? "" : item.ATTENDANCESCOPE
- item.ADDR = item.ADDR == "null" ? "" : item.ADDR
- item.TIMEPERIOD1 = item.TIMEPERIOD;
- item.CTIME2 = item.CTIME1;
- item.CNAME1 = item.CNAME;
- item.ATTENDANCESCOPE1 = item.ATTENDANCESCOPE;
- item.ADDR1 = item.ADDR;
- })
- console.log(self.list)
- })
- }
- self.getSORTID();
- self.openLayer = function () {
- sp.layer("#Search")
- }
- self.doSearch = function () {
- sp.layerhide()
- if (self.search.DATE1 == "" || self.search.DATE2 == "") {
- sp.dialog("时间为可为空!");
- return
- }
- $.cookie("GlWorkPlatform-yzaptz", JSON.stringify(self.search), { path: '/', expires: 1 });
- self.getData();
- }
- self.cancal = function () {
- self.search = {
- DATE1: sp.getWeekNumber(new Date()).begin,
- DATE2: sp.getWeekNumber(new Date()).end
- }
- $.cookie("GlWorkPlatform-yzaptz", null, { path: '/', expires: 1 });
- self.getData();
- sp.layerhide()
- }
- self.refresh = function () {
- self.getData();
- }
- self.openInit = function () {
- self.init = {
- DATE1: sp.getWeekNumber(new Date()).begin, DATE2: sp.getWeekNumber(new Date()).end
- }
- sp.layer("#Init")
- }
- self.doInit = function () {
- var data = {
- userid: self.userId,
- routeinfoid:0,
- startdate: self.init.DATE1 + " 00:00:00",
- enddate: self.init.DATE2 + " 23:59:59"
- }
- $http.post(apiurljs.login + "g2app/richang/initYZAPTZList", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
- .success(function (obj) {
- var res = strToJson(s4.decryptData_CBC(obj.data));
- sp.layerhide();
- if (res.success) {
- self.getData();
- } else {
- sp.dialog(res.message)
- }
- })
- }
- self.addItem = function () {
- self.addFlag = true;
- self.addList.push({
- LDSORTID: self.LDSORTID,
- YZAPDATE: sp.format(sp.getLocalDate()),
- CWEEK: weeks[new Date().getDay()],
- TIMEPERIOD: "上午",
- CTIME: "09:00",
- CNAME: "",
- ATTENDANCESCOPE: "",
- ADDR: ""
- })
- $timeout(function () {
- $(".table-scroll").scrollTop($(".table-scroll").find("table").height())
- }, 1)
- }
- self.delItem = function (item) {
- var dialogHead = "<span class=\"sp-dialog-head\"><span class=\"sp-dialog-tip\">温馨提示</span><span class=\"sp-dialog-close sp-closeDialog\" title=\"关闭\">×</span></span>";
- var dialogBody = "<div class=\"sp-dialog-body\">删除后不可恢复,您确认要删除吗?</div>";
- var dialogFoot = "<div class=\"sp-dialog-foot\"><input id='delDataTrue' type='button' value='确 认' class='sp-dialog-btnTrue' /><input type='button' value='取 消' class='sp-dialog-btnCancle sp-closeDialog' /></div>";
- $('.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_YZAPTZ",
- id: item.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();
- } else {
- sp.dialog("删除失败,请联系管理员!");
- }
- });
- });
- }
- var weeks = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"]
- self.changeCtime = function (obj, n) {
- if (n == 0) {
- if (obj.CTIME >= "13:00") {
- obj.TIMEPERIOD = "下午"
- } else {
- obj.TIMEPERIOD = "上午"
- }
- } else {
- if (obj.CTIME2 >= "13:00") {
- obj.TIMEPERIOD1 = "下午"
- } else {
- obj.TIMEPERIOD1 = "上午"
- }
- }
- obj.CWEEK = weeks[new Date(obj.YZAPDATE).getDay()]
- }
- self.btnCancal = function () {
- self.addFlag = false;
- self.addList = []
- self.editFlag = false;
- self.list.forEach(function (item) {
- item.TIMEPERIOD1 = item.TIMEPERIOD;
- item.CTIME2 = item.CTIME1;
- item.CNAME1 = item.CNAME;
- item.ATTENDANCESCOPE1 = item.ATTENDANCESCOPE;
- item.ADDR1 = item.ADDR;
- })
- }
- self.btnSave = function () {
- var n1 = true, n2 = true;
- if (self.addList.length > 0) {
- n1 = false;
- var data1 = {
- tablename: "SX_YZAPTZ",
- data: []
- }
- self.addList.forEach(function (item) {
- data1.data.push({
- LDSORTID: item.LDSORTID,
- YZAPDATE: item.YZAPDATE,
- TIMEPERIOD: item.TIMEPERIOD,
- CWEEK: item.CWEEK,
- CTIME: item.YZAPDATE + " " + item.CTIME + ":00",
- CNAME: item.CNAME,
- ATTENDANCESCOPE: item.ATTENDANCESCOPE,
- ADDR: item.ADDR,
- USERNAME: self.userName,
- USERID: self.userId,
- SECTCODE: self.userDpCode,
- CDATE: sp.getLocalDate()
- })
- })
- $http.post(apiurljs.login + "g2app/dataabase/insertDataList", { data: s4.encryptData_CBC(JSON.stringify(data1)) }, postCfg)
- .success(function (obj) {
- var res = strToJson(s4.decryptData_CBC(obj.data));
- if (res.success == true) {
- n1 = true;
- if (self.list.length > 0) {
- n2 = false;
- var data2 = {
- entity: "SX_YZAPTZ",
- data: [],
- setwhere: []
- }
- self.list.forEach(function (item) {
- data2.data.push({
- TIMEPERIOD: item.TIMEPERIOD1,
- CTIME: item.YZAPDATE1 + " " + item.CTIME2 + ":00",
- CNAME: item.CNAME1,
- ATTENDANCESCOPE: item.ATTENDANCESCOPE1,
- ADDR: item.ADDR1
- })
- data2.setwhere.push({ ID: item.ID })
- })
- $http.post(apiurljs.login + "g2app/Data/UpdataByWhereList", { data: s4.encryptData_CBC(JSON.stringify(data2)) }, postCfg)
- .success(function (obj1) {
- var res1 = strToJson(s4.decryptData_CBC(obj1.data));
- if (res1.success == true) {
- n2 = true;
- if (n1 == true && n2 == true) {
- self.getData();
- sp.dialog("保存成功!");
- $timeout(function () {
- sp.dialoghide();
- }, 1500)
- }
- } else {
- sp.dialog(res1.message)
- }
- })
- } else {
- if (n1 == true && n2 == true) {
- self.getData();
- sp.dialog("保存成功!");
- $timeout(function () {
- sp.dialoghide();
- }, 1500)
- }
- }
- } else {
- sp.dialog(res.message)
- }
- })
- } else {
- n2 = false;
- var data1 = {
- entity: "SX_YZAPTZ",
- data: [],
- setwhere: []
- }
- self.list.forEach(function (item) {
- data1.data.push({
- TIMEPERIOD: item.TIMEPERIOD1,
- CTIME: item.YZAPDATE1 + " " + item.CTIME2 + ":00",
- CNAME: item.CNAME1,
- ATTENDANCESCOPE: item.ATTENDANCESCOPE1,
- ADDR: item.ADDR1
- })
- data1.setwhere.push({ ID: item.ID })
- })
- $http.post(apiurljs.login + "g2app/Data/UpdataByWhereList", { data: s4.encryptData_CBC(JSON.stringify(data1)) }, postCfg)
- .success(function (obj) {
- var res = strToJson(s4.decryptData_CBC(obj.data));
- if (res.success == true) {
- n2 = true;
- if (n1 == true && n2 == true) {
- self.getData();
- sp.dialog("保存成功!");
- $timeout(function () {
- sp.dialoghide();
- }, 1500)
- }
- } else {
- sp.dialog(res.message)
- }
- })
- }
- }
- self.printOut = function () {
- if (self.canExportExcel) {
- $('#table 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('#table'), cell, "一周安排台账")
- //设置表格的样式
- 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('数据还未加载完成,请稍等...')
- }
- }
- //头部下滚冻结
- $(function () {
- //页面高度撑满
- setTimeout(function () {
- if ($(".ibox-content").height() < $(window).height() - 31) {
- $(".ibox-content").css("height", $(window).height() - 31)
- }
- }, 1)
- })
- }])
- app.directive("repeatFinish", function () {
- return {
- link: function (scope) {
- if (scope.$last == true) {
- scope.$parent.ctl.canExportExcel = true;
- setTimeout(function () {
- $("#table").rowspan(1)
- $("#table").rowspan(0)
- }, 10);
- }
- }
- };
- });
- jQuery.fn.rowspan = function (colIdx) { //封装的一个JQuery小插件
- return this.each(function () {
- var that;
- $('tr', this).each(function (row) {
- $('td:eq(' + colIdx + ')', this).filter(':visible').each(function (col) {
- if (that != null && $(this).html() == $(that).html()) {
- var 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;
- }
- });
- });
- });
- }
|