'use strict'; var app = angular.module('app', [ ]); app.controller("formeditCtrl", ["$scope", "$http", "$timeout", "$sce", function ($scope, $http, $timeout, $sce) { 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.routeinfoid = sp.getUrlName("routeinfoid"); self.id = sp.getUrlName("id"); self.deviceType = localStorage.getItem("tjJxtGoldenlinkWork-deviceType"); self.lastReturn = sp.getUrlName("lastReturn") self.info = JSON.parse($.cookie("GlWorkPlatform-gdsp")) self.guidangList = [] self.show = 1; var postCfg = { headers: { 'Content-Type': 'application/json', 'Authorization': "Bearer " + self.get_AccessToken } }; self.goBack = function () { window.location.href = "ygdlist.html?lastReturnPageno=" + sp.getUrlName("lastReturnPageno") } //初始化右上角按钮 self.buttonList = [] self.readonly = { LC: false, BT: false, WH: false, GDCS: false, GDRY: false, CSYJ: false, BZ: false } 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].INSTCODE; self.userDpId = res.data.length == 0 ? "" : res.data[0].INSTCODEID; console.log(res.data[0]) self.getGDBM(); }) } self.getDP() self.getGDBM = function () { var data = { unitid: "AA" } $http.post(apiurljs.login + "g2app/dataabase/queryDanganSectByCode", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); self.GDBM = res.data; if (self.id == 0) { self.getWENHAO(); } else { self.getData(); } }) } self.getWENHAO = function () { var data = { routeinfoid: self.routeinfoid, flowid:self.info.FLOWID } $http.post(apiurljs.login + "g2app/DangAn/queryDataByRouteinfoid", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); if (res.data.length > 0) { self.WENHAO = res.data[0].WENHAO; } else { self.WENHAO = ""; } self.getNGRQ(); }) } self.getNGRQ = function () { var data = { tablename: self.info.TABLENAME, colums: "*", order: "ID", sqlwhere: { ROUTEINFOID: self.routeinfoid }, 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)); if (res.data.length > 0) { switch (self.info.TABLENAME) { case "SW_LDPSCBD": self.NGRQ = res.data[0].LWRQ; break;//领导批示 case "SW_ZJWWJCBD": self.NGRQ = res.data[0].LWRQ; break;//一般收文 case "FW_ZB": self.NGRQ = res.data[0].NGSJ; break;//专报 case "FW_GFXWJXGMRBM": self.NGRQ = res.data[0].NGRQ; break;//规范性文件 case "FW_SPJ": self.NGRQ = res.data[0].NGSJ; break;//审批件 case "FW_WFH": self.NGRQ = res.data[0].NGSJ; break;//委发函 case "FW_ZSWSXW": self.NGRQ = res.data[0].RGRQ; break;//正式文-上行文 case "FW_ZSWPXXW": self.NGRQ = res.data[0].RGRQ; break;//正式文-平、下行文 case "SX_QBD": self.NGRQ = res.data[0].RQ; break;//签报 } } self.getData(); }) } self.getLSH = function () { var data = { tablename: "DA_YGD", colums: "*", order: "ITEM_NO desc", sqlwhere: { YEAR_CODE: self.data.YEAR_CODE, FILING_DEPT: self.data.FILING_DEPT, RETENTION_PERIOD: self.data.RETENTION_PERIOD }, 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)); if (res.data.length > 0) { self.data.ITEM_NO = res.data[0].ITEM_NO * 1 + 1; } else { self.data.ITEM_NO = 1 } self.setDangHao(); }) } self.setDangHao = function () { if (self.data.ITEM_NO == 0 || self.data.ITEM_NO == "" || self.data.ITEM_NO == null) { self.data.ITEM_NO = 1 } if (self.data.ITEM_NO.toString().indexOf(".") > -1) { self.data.ITEM_NO = parseInt(self.data.ITEM_NO.toString().slice(0, self.data.ITEM_NO.toString().indexOf("."))) } self.data.OFFICE_ARCHIVAL_CODE = "X154-WS·" + self.data.YEAR_CODE + "-" + self.data.RETENTION_PERIOD + "-" + self.userDpCode + "-" + (self.data.ITEM_NO >= 1000 ? self.data.ITEM_NO : self.data.ITEM_NO >= 100 ? "0" + self.data.ITEM_NO : self.data.ITEM_NO >= 10 ? "00" + self.data.ITEM_NO : "000" + self.data.ITEM_NO); } self.getITEMNO = function (cyear,deptcode,period) { var data = { cyear: cyear, deptcode:deptcode, period:period } $http.post(apiurljs.login + "g2app/DangAn/queryDataByRouteinfoid", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); if (res.data.length > 0) { self.WENHAO = res.data[0].WENHAO; self.WENRQ = res.data[0].WENRQ; } else { self.WENHAO = ""; self.WENRQ = ""; } self.getData(); }) } //获取数据 self.getData = function () { var data = { tablename: "DA_YGD", colums: "*", order: "ID", sqlwhere: { GLROUTEINFOID: self.routeinfoid }, sqlinwhere: "", sqllikewhere: "" } if (self.lastReturn == "list") { data.sqlwhere = { ID: sp.getUrlName("ID") } } $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[0]) { self.data = { ID: res.data[0].ID, FONDS_CODE: res.data[0].FONDS_CODE, SERIES_CODE: res.data[0].SERIES_CODE, FILE_CODE: res.data[0].FILE_CODE, TITLE_PROPER: res.data[0].TITLE_PROPER, DATE_OF_CREATION: sp.format(res.data[0].DATE_OF_CREATION), OA_ID: res.data[0].OA_ID, OFFICE_ARCHIVAL_CODE: res.data[0].OFFICE_ARCHIVAL_CODE, AUTHOR: res.data[0].AUTHOR, AMOUNT_OF_PAGES: res.data[0].AMOUNT_OF_PAGES, YEAR_CODE: res.data[0].YEAR_CODE, ITEM_NO: parseInt(res.data[0].ITEM_NO), ITEM_COUNT: res.data[0].ITEM_COUNT, RETENTION_PERIOD: res.data[0].RETENTION_PERIOD, FILING_DEPT: res.data[0].FILING_DEPT, FILING_DEPTID: res.data[0].FILING_DEPTID, FILING_DEPTCODE: res.data[0].FILING_DEPTCODE, FILENAME: res.data[0].FILENAME, ZHANGTOP: res.data[0].ZHANGTOP, ZHANGLEFT: res.data[0].ZHANGLEFT, ZHANGTOP1: res.data[0].ZHANGTOP, ZHANGLEFT1: res.data[0].ZHANGLEFT, GLROUTEINFOID: res.data[0].GLROUTEINFOID, STATUS: res.data[0].STATUS } } else { self.data = { ID: 0, FONDS_CODE: "X154", SERIES_CODE: "WS", FILE_CODE: self.WENHAO, TITLE_PROPER: self.info.TITLE, DATE_OF_CREATION: sp.format(self.NGRQ), OA_ID: "", OFFICE_ARCHIVAL_CODE:"", AUTHOR:"天津市住房和城乡建设委员会", AMOUNT_OF_PAGES:"", YEAR_CODE: sp.currentYear(), ITEM_NO: "", ITEM_COUNT:"1", RETENTION_PERIOD:"D10", FILING_DEPT: self.userDpName, FILING_DEPTID: self.userDpId, FILING_DEPTCODE: self.userDpCode, FILENAME: "", ZHANGTOP: "430", ZHANGLEFT: "750", ZHANGTOP1: "430", ZHANGLEFT1: "750", GLROUTEINFOID: self.routeinfoid, CDATE: sp.getLocalDate(), STATUS:0 } self.getLSH() } console.log(self.data) self.gdzFlag = self.data.ZHANGTOP!=-1 self.data.STATUS1 = self.data.STATUS == 0 ? "档案已创建" : self.data.STATUS == 1 ? "已发送档案系统" : "档案系统退回"; self.getYGD() }) } self.getYGD = function () { var data = { routeinfoid: self.routeinfoid, converttype: "3" } if (self.lastReturn == "list") { data.routeinfoid = self.data.GLROUTEINFOID } $http.post(apiurljs.login + "g2app/DangAn/queryYJYGDWenJianList",{ data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); self.fileList = res.data[0].DATA; self.getGDFile(); }) } self.getGDFile = function () { var data = { tablename: "DA_YJYGDFILEATTACH", colums: "*", order: "SORTID", sqlwhere: { ROUTEINFOID: self.data.ID }, 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)); res.data.forEach(function (item) { if (item.ATTACHTYPE == "YJYGDGDZ_PDF") { self.seeFiles(item, 1) } //if (item.ATTACHTYPE == "YJYGDMERGE_PDF") { // self.seeFiles(item, 1) //} }) self.guidangList = res.data.filter(function (item) { return item.ATTACHTYPE == "" }); self.fileList.forEach(function (item) { var n = 0; self.guidangList.forEach(function (item1) { if (item.WENJIANMING == item1.FILENAMES) { item.show = false; n++ } }) if (n == 0) { item.show = true; } }) $("#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(); }) } //保存提交 self.btnSave = function () { if (spngvld.submit(".formedit")) { var data = { tablename: "DA_YGD", id: self.data.ID, data: { FONDS_CODE: self.data.FONDS_CODE, SERIES_CODE: self.data.SERIES_CODE, FILE_CODE: self.data.FILE_CODE, TITLE_PROPER: self.data.TITLE_PROPER, DATE_OF_CREATION: self.data.DATE_OF_CREATION, OA_ID: self.data.OA_ID, OFFICE_ARCHIVAL_CODE: self.data.OFFICE_ARCHIVAL_CODE == "" ? danghao(self.data) : self.data.OFFICE_ARCHIVAL_CODE, AUTHOR: self.data.AUTHOR, AMOUNT_OF_PAGES: self.data.AMOUNT_OF_PAGES, YEAR_CODE: self.data.YEAR_CODE, ITEM_NO: self.data.ITEM_NO, ITEM_COUNT: self.data.ITEM_COUNT, RETENTION_PERIOD: self.data.RETENTION_PERIOD, FILING_DEPT: self.data.FILING_DEPT, FILING_DEPTID: self.data.FILING_DEPTID, FILING_DEPTCODE: self.data.FILING_DEPTCODE, FILENAME: self.data.FILENAME, ZHANGTOP: self.data.ZHANGTOP, ZHANGLEFT: self.data.ZHANGLEFT, GLROUTEINFOID: self.data.GLROUTEINFOID, CDATE: self.data.CDATE, STATUS: self.data.STATUS } } console.log(data) $http.post(apiurljs.login + "g2app/dataabase/saveChildData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); if (res.code == 0) { self.id = res.data.ID; self.getData() self.show = 2; } else { sp.dialog(res.message) } }) } } self.addFile = function (obj) { var data = { tablename: "DA_YJYGDFILEATTACH", data: { FILENAMES: obj.WENJIANMING, FILEOLDNAME: obj.WENJIANMING, FILEEXT: obj.PREFIX, FILESIZE: "", FILEDATE: obj.RIQI, FILEID: "", FILEURL: obj.URL, FILETBURL: "", ATTACHTYPE: "", FILECDATE: "", CONVERTID: "", FILEPAGE: obj.YESHU, ROUTEINFOID: self.data.ID } } $http.post(apiurljs.login + "g2app/dataabase/insertFormData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); if (res.success) { self.getYGD(); } else { sp.dialog(res.message); } }) } self.delFile = function (obj) { var data = { tablename: "DA_YJYGDFILEATTACH", id: obj.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)); if (res.success) { self.getYGD(); } else { sp.dialog(res.message); } }); } self.sortUp = function (num) { var IDS = [{ ID: self.guidangList[num].ID }, { ID: self.guidangList[num - 1].ID }] var SORTIDS = [{ SORTID: self.guidangList[num - 1].SORTID }, { SORTID: self.guidangList[num].SORTID }] var data = { entity: "DA_YJYGDFILEATTACH", data: SORTIDS, 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) { self.getGDFile(); } else { sp.dialog(res.message); } }) } self.sortDown = function (num) { var IDS = [{ ID: self.guidangList[num].ID }, { ID: self.guidangList[num + 1].ID }] var SORTIDS = [{ SORTID: self.guidangList[num + 1].SORTID }, { SORTID: self.guidangList[num].SORTID }] var data = { entity: "DA_YJYGDFILEATTACH", data: SORTIDS, 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) { self.getGDFile(); } else { sp.dialog(res.message); } }) } self.uploading = false; self.upload = function () { //var uploadformat = strToJson(s4.decryptData_CBC(apiurljs.uploadformat)).data.map(function (item) { // return item.CNAME //}) $('#fileupload').fileupload({ url: apiurljs.login + 'g2app/abase/uploadFileWithForm', dataType: 'json', beforeSend: function (xhr, data) { xhr.setRequestHeader("Authorization", "Bearer " + self.get_AccessToken); xhr.setRequestHeader("File-Argument", s4.encryptData_CBC("tablename=DA_YJYGDFILEATTACH,routeinfoid=" + self.data.ID)); }, add: function (e, data) { var num = 0; //var acceptFileTypes = eval('/(' + uploadformat.join("|") + ')$/i') var acceptFileTypes = eval('/(pdf)$/i') //文件类型判断 $.each(data.originalFiles, function (index, item) { if (item['type'].length > 0 && !acceptFileTypes.test(item['name'])) { //sp.dialog("您好,请上传" + uploadformat.join("/") + "格式的文件!"); sp.dialog("您好,请上传pdf格式的文件!"); return; } else { num++ } }) if (num == data.originalFiles.length) { self.uploading = true; data.submit(); $scope.$apply(); } }, // 上传完成后的执行逻辑 done: function (e, data) { self.uploading = false; self.getGDFile() } }) } self.changeGDZ = function () { if (self.gdzFlag == false) { self.data.ZHANGTOP = -1 self.data.ZHANGLEFT = -1 } else { if (self.data.ZHANGTOP = -1) { self.data.ZHANGTOP = self.data.ZHANGTOP1 self.data.ZHANGLEFT = self.data.ZHANGLEFT1 } } } self.btnSaveFiles = function () { var IDS = [], SORTIDS = []; self.guidangList.forEach(function (item) { $("#table_tbody").children().each(function (index) { if ($(this).attr("data-col") == item.ID) { IDS.push({ ID: item.ID }) SORTIDS.push({ SORTID: self.guidangList[$(this).attr("index") - 1].SORTID }) } }) }) var data = { entity: "DA_YJYGDFILEATTACH", data: SORTIDS, 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) { self.getGDFile(); } else { sp.dialog(res.message); } }) } self.MergeByFile = function () { var data1 = { tablename: "DA_YGD", id: self.data.ID, data: { ZHANGTOP: self.data.ZHANGTOP, ZHANGLEFT: self.data.ZHANGLEFT } } $http.post(apiurljs.login + "g2app/dataabase/saveChildData", { data: s4.encryptData_CBC(JSON.stringify(data1)) }, postCfg) .success(function (obj1) { var res1 = strToJson(s4.decryptData_CBC(obj1.data)); if (res1.code == 0) { var data = { files: [], converttype: 3, routeinfoid: self.data.ID, gdzdata: ['全宗号', '年度', '件号', "X154", self.data.YEAR_CODE, self.data.ITEM_NO, '机构', '保管期限', '页数', self.data.FILING_DEPT, self.data.RETENTION_PERIOD, self.data.AMOUNT_OF_PAGES], marginLeft: 755,//self.data.ZHANGLEFT, marginBottom: 440//self.data.ZHANGTOP } self.guidangList.forEach(function (item) { data.files.push({ fileurl: item.FILEURL }) }) $http.post(apiurljs.login + "g2app/DangAn/queryYJYGDMergeByFile", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); self.seeFiles(res.data.DATA, 1) self.show = 3; }) } else { sp.dialog(res1.message) } }) } self.send = function () { var data = { id: self.data.ID } $http.post(apiurljs.login + "g2app/DangAn/sendYJYGDXMLData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { if (res.code == 0) { self.getData() } else { sp.dialog(res.message) } }) } // 查看文件 self.seeFiles = function (obj,n) { var set_convertType = 0; if (n == 3) { obj.FILEURL = obj.URL; obj.FILEEXT = obj.PREFIX; } if (obj.FILEEXT == "doc") { set_convertType = 0; } else if (obj.FILEEXT == "pdf") { set_convertType = 20; } else if (obj.FILEEXT == "ofd") { set_convertType = 570; } else { set_convertType = 0; } let postData = { convertType: set_convertType, isSignature: 1, fileUrl: apiurljs.login + "g2work/files2/inline/" + obj.FILEURL.slice(7) }; var postCfg_transfer = { headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, transformRequest: function (data) { return $.param(data); } }; $http.post(apiurljs.login.split("glwork/")[0] + "fcscloud/composite/httpfile", postData, postCfg_transfer) .success(function (res) { if (res.errorcode === 0) { if (n == 1) { $("#filesId").attr("src", res.data.viewUrl) } else { window.open(res.data.viewUrl) } } else { sp.dialog(res.message); } }); } //头部下滚冻结 $(function () { $(".sp-page-center").css("max-height", $(window).height() - 58).css("height", $(window).height() - 58) //页面高度撑满 setTimeout(function () { if ($(".ibox-content").height() < $(window).height() - 31) { $(".ibox-content").css("height", $(window).height() - 31) } }, 1) }) }])