'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.info = JSON.parse($.cookie("GlWorkPlatform-gdsp")) self.guidangList = [] var postCfg = { headers: { 'Content-Type': 'application/json', 'Authorization': "Bearer " + self.get_AccessToken } }; self.FormTitle = $.cookie("GlWorkPlatform-SYSNAME"); //初始化右上角按钮 self.buttonList = [] self.readonly = { LC: false, BT: false, WH: false, GDCS: false, GDRY: false, CSYJ: false, BZ: false } self.getDpList = function () { var data = { unitid: "AA" } $http.post(apiurljs.login + "g2app/dataabase/querySectByCode", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); self.dpList = []; res.data.forEach(function (item) { if (item.CHILD_DATA.length == 0) { self.dpList.push(item) } else { item.CHILD_DATA.forEach(function (item1) { if (item1.CHILD_DATA.length == 0) { self.dpList.push(item1) } else { item1.CHILD_DATA.forEach(function (item2) { if (item2.CHILD_DATA.length == 0) { self.dpList.push(item2) } }) } }) } }) self.dpList.forEach(function (item) { item.checked = false; }) self.DpList = { GDCS: JSON.parse(JSON.stringify(self.dpList)) } self.AllCheckedDp = {}; self.DpLength = {}; self.selectDpList = {}; self.getUserList() }) } self.getDpList() self.getUserList = function () { $http.post(apiurljs.login + "g2app/dataabase/getDpList", { data: s4.encryptData_CBC("") }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); self.userList = res.data; self.userList.forEach(function (item) { item.checked = false; item.USER.forEach(function (item1) { item1.checked = false; item1.USHOWNAME1 = item1.USHOWNAME.length > 3 ? item1.USHOWNAME.slice(0, 3) + "..." : item1.USHOWNAME; item1.USHOWNAME2 = item1.USHOWNAME.length > 10 ? item1.USHOWNAME.slice(0, 10) + "..." : item1.USHOWNAME }) }) self.UserList = { GDRY: JSON.parse(JSON.stringify(self.userList)) }; self.AllChecked = {}; self.UserLength = {}; self.selectList = {}; self.getDP() }) } 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.getGDBM(); }) } 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.routeinfoid == 0) { self.getWENHAO(); } else { self.getData(); } }) } self.getWENHAO = function () { var data = { routeinfoid: self.info.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.getData(); }) } //获取数据 self.getData = function () { var data = { tablename: "DA_DAYUGUIDANG", colums: "*", order: "ID", sqlwhere: { ID: self.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)); if (res.data[0]) { self.data = { ID: res.data[0].ID, LC: res.data[0].LC, BT: res.data[0].BT, WH: res.data[0].WH, GDCS: res.data[0].GDCS, GDRY: res.data[0].GDRY, BZ: res.data[0].BZ, ARCHYEAR: res.data[0].ARCHYEAR, ORGANIZATIONMA: res.data[0].ORGANIZATIONMA, WENHAO: res.data[0].WENHAO, MIJIQIXIAN: res.data[0].MIJIQIXIAN, DANGANML: res.data[0].DANGANML, DOCUMENTTYPE: res.data[0].DOCUMENTTYPE, DOCTITLE: res.data[0].DOCTITLE, ZRZ: res.data[0].ZRZ, DOCISSUEDDATE: sp.format(res.data[0].DOCISSUEDDATE), JIANHAO: res.data[0].JIANHAO, YESHU: res.data[0].YESHU, BEIZHU: res.data[0].BEIZHU, ARCHCODE: res.data[0].ARCHCODE, DAROUTEINFOID: res.data[0].DAROUTEINFOID, DPNAME: res.data[0].DPNAME, DPCODE: res.data[0].DPCODE, MOBANNAME: res.data[0].MOBANNAME, TABLENAME: res.data[0].TABLENAME } } else { self.data = { ID: 0, LC: self.info.FLOWNAME, BT: self.info.TITLE, WH: self.WENHAO, GDCS: self.userDpName, GDRY: self.userName, BZ: "", ARCHYEAR: sp.currentYear(), ORGANIZATIONMA: self.userDpCode, WENHAO: self.WENHAO, MIJIQIXIAN: "10年", DANGANML: "文书", DOCUMENTTYPE: self.info.FLOWNAME, DOCTITLE: self.info.TITLE, ZRZ: "", DOCISSUEDDATE: sp.format(sp.getLocalDate()), JIANHAO: 1, YESHU: "", BEIZHU: "", ARCHCODE: "", DAROUTEINFOID: self.info.ROUTEINFOID, DPNAME: self.userDpName, DPCODE: self.userDpCode, MOBANNAME: self.info.MOBANNAME, TABLENAME: self.info.TABLENAME } } $scope.data = self.data; var n = {}, all = {}; for (var i in self.UserList) { self.AllChecked[i] = false; self.UserLength[i] = 0; self.selectList[i] = [] n[i] = []; all[i] = 0; $.each(self.UserList[i], function (index, item) { n[i].push(0) $.each(item.USER, function (index1, item1) { self.UserLength[i]++ if (self.data.GDRY.indexOf(item1.USHOWNAME) != -1 && i == "GDRY") { n[i][index]++; item1.checked = true; self.selectList[i].push(item1); } }) if (n[i][index] == item.USER.length && n[i][index] != 0) { item.checked = true; all[i]++; } else { item.checked == false; } }) if (all[i] == self.UserList[i].length) { self.AllChecked[i] = true; } else { self.AllChecked[i] = false; } } for (var i in self.DpList) { self.AllCheckedDp[i] = false; self.DpLength[i] = 0; self.selectDpList[i] = [] all[i] = 0; $.each(self.DpList[i], function (index, item) { self.DpLength[i]++ if (self.data.GDCS.indexOf(item.SECTION) != -1 && i == "GDCS") { all[i]++; item.checked = true; self.selectDpList[i].push(item); } }) if (all[i] == self.DpList[i].length) { self.AllCheckedDp[i] = true; } else { self.AllCheckedDp[i] = false; } } }) } self.openDpList = function (str) { self.filed = str; sp.layer("#DpList") $("#DpList .sp-page").eq(0).scrollTop(0); } self.checkAllDp = function () { self.AllCheckedDp[self.filed] = !self.AllCheckedDp[self.filed]; $.each(self.DpList[self.filed], function (index, item) { item.checked = self.AllCheckedDp[self.filed]; }) self.submitDpList(1) } self.checkDpItem = function (item) { item.checked = !item.checked; var n = 0; $.each(self.DpList[self.filed], function (index, item) { if (item.checked == true) { n++ } }) if (n == self.DpList[self.filed].length) { self.AllCheckedDp[self.filed] = true; } else { self.AllCheckedDp[self.filed] = false; } self.submitDpList(1) } self.submitDpList = function (n) { var AllCheckedLength1 = 0; self.selectDpList[self.filed] = []; $.each(self.DpList[self.filed], function (index, item) { if (item.checked == true) { AllCheckedLength1++; self.selectDpList[self.filed].push(item) } }) self.data[self.filed] = self.selectDpList[self.filed].map(function (item) { return item.SECTION }).join(",") self.AllCheckedDp[self.filed] = AllCheckedLength1 == self.DpLength[self.filed]; if (n == 0) { sp.layerhide(); } } self.openUserList = function (str) { self.filed = str; sp.layer("#userList") $("#userList .sp-page").eq(0).scrollTop(0); } self.checkAllUser = function () { self.AllChecked[self.filed] = !self.AllChecked[self.filed]; $.each(self.UserList[self.filed], function (index, item) { item.checked = self.AllChecked[self.filed]; $.each(item.USER, function (index1, item1) { item1.checked = self.AllChecked[self.filed]; }) }) self.submitUserList(1) } self.checkUserItem = function (item) { item.checked = !item.checked; $.each(item.USER, function (index, item1) { item1.checked = item.checked; }) var n = 0; $.each(self.UserList[self.filed], function (index, item) { if (item.checked == true) { n++ } }) if (n == self.UserList[self.filed].length) { self.AllChecked[self.filed] = true; } else { self.AllChecked[self.filed] = false; } self.submitUserList(1) } self.checkUser = function (item) { item.checked = !item.checked; var n = [], all = 0; $.each(self.UserList[self.filed], function (x, y) { n.push(0); $.each(y.USER, function (x1, y1) { if (y1.checked == true) { n[x]++ } }) if (n[x] == y.USER.length && n[x] != 0) { y.checked = true; all++ } else { y.checked = false; } }) if (all == self.UserList[self.filed].length) { self.AllChecked[self.filed] = true; } else { self.AllChecked[self.filed] = false; } self.submitUserList(1) } self.submitUserList = function (n) { var AllCheckedLength = 0; self.selectList[self.filed] = []; $.each(self.UserList[self.filed], function (index, item) { $.each(item.USER, function (index1, item1) { if (item1.checked == true) { AllCheckedLength++; self.selectList[self.filed].push(item1) } }) }) self.data[self.filed] = self.selectList[self.filed].map(function (item) { return item.USHOWNAME }).join(",") if (self.data[self.filed + "ID"] != undefined) { self.data[self.filed + "ID"] = self.selectList[self.filed].map(function (item) { return item.USERID }).join(",") } self.AllChecked[self.filed] = AllCheckedLength == self.UserLength[self.filed]; if (n == 0) { sp.layerhide(); } } //保存提交 self.btnSave = function (n) { var data = { tablename: "DA_DAYUGUIDANG", id: self.data.ID, data: { LC: self.data.LC, BT: self.data.BT, WH: self.data.WH, GDCS: self.data.GDCS, GDRY: self.data.GDRY, BZ: self.data.BZ, ARCHYEAR: self.data.ARCHYEAR, ORGANIZATIONMA: self.data.ORGANIZATIONMA, WENHAO: self.data.WENHAO, MIJIQIXIAN: self.data.MIJIQIXIAN, DANGANML: self.data.DANGANML, DOCUMENTTYPE: self.data.DOCUMENTTYPE, DOCTITLE: self.data.DOCTITLE, ZRZ: self.data.ZRZ, DOCISSUEDDATE: self.data.DOCISSUEDDATE, JIANHAO: self.data.JIANHAO, YESHU: self.data.YESHU, BEIZHU: self.data.BEIZHU, ARCHCODE: self.data.ARCHCODE, DAROUTEINFOID: self.data.DAROUTEINFOID, DPNAME: self.data.DPNAME, DPCODE: self.data.DPCODE, MOBANNAME: self.data.MOBANNAME, TABLENAME: self.data.TABLENAME } } $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() } else { sp.dialog(res.message) } }) } // 更新数据 self.updateBtn=function(){ console.log("更新---") } // 生成归档目录 self.createGuidang = function () { var data = { routeinfoid: self.routeinfoid, } $http.post(apiurljs.login + "g2app/DangAn/YJYGDMULU", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); if (res.code == 0) { self.guidangList = res.data; } else { sp.dialog(res.message) } }) } // 查看文件 self.searchFiles = function (obj) { var set_convertType = 0; if (obj.PREFIX == "doc") { set_convertType = 0; } else if (obj.PREFIX == "pdf") { set_convertType = 20; } else if (obj.PREFIX == "ofd") { set_convertType = 570; } else { set_convertType = 0; } let postData = { convertType: set_convertType, isSignature: 1, fileUrl: apiurljs.login + "g2work/files2/inline/" + obj.URL.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) { $("#filesId").attr("src", 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) }) }]) var parentData = {} function getData() { parentData = angular.element(document.getElementById("app")).scope().data return parentData }