'use strict'; var app = angular.module('app', [ 'angularUtils.directives.dirPagination' ]); app.controller("listCtrl", ["$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.dateParam = sp.getUrlName("date"); var postCfg = { headers: { 'Content-Type': 'application/json', 'Authorization': "Bearer " + self.get_AccessToken } } self.leftTree = [{ CNAME: "政策文件", CODE: "ZCWJ" }, { CNAME: "两清单", CHILDREN: [{ CNAME: "委党委", show: false, CHILDREN: [], TYPE: 1 }, { CNAME: "班子成员", show: false, CHILDREN: [], TYPE: 2 }, { CNAME: "市管单位", show: false, CHILDREN: [], TYPE: 3 }, { CNAME: "直属单位", show: false, CHILDREN: [], TYPE: 4 }] }, { CNAME: "报告", CHILDREN: [{ CNAME: "委党委", show: false, TYPE: 0 }, { CNAME: "班子成员", show: false, CHILDREN: [], TYPE: 2 }, { CNAME: "市管单位", show: false, CHILDREN: [], TYPE: 3 }, { CNAME: "直属单位", show: false, CHILDREN: [], TYPE: 4 }] } ] self.checkNode = function (NODE) { NODE.show = !NODE.show; self.activeNode = NODE; if (self.activeNode.TYPE > 0) { if (self.activeNode.TYPE == 1 && NODE.CHILDREN.length == 0) { var data = { unitid: "AA01" } $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)); res.data.forEach(function (item) { if (item.CODE != "AA0136") { NODE.CHILDREN.push({ CNAME: item.SECTION, CODE: item.CODE }) } }) }) } else if (self.activeNode.TYPE == 2 && NODE.CHILDREN.length == 0) { var data = { zid: "AA19", levels: "0" } $http.post(apiurljs.login + "g2work/datazu/queryDataUser", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); res.data.forEach(function (item) { item.users.forEach(function (item1) { if (item1.auth == 1) { NODE.CHILDREN.push({ CNAME: item1.ushowname, CODE: item1.userid }) } }) }) }) } else if (self.activeNode.TYPE == 3 && NODE.CHILDREN.length == 0) { var data = { unitid: "AA02" } $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)); res.data.forEach(function (item) { if (item.CODE == "AA0216" || item.CODE == "AA0201") { NODE.CHILDREN.push({ CNAME: item.SECTION, CODE: item.CODE }) } }) }) } else if (self.activeNode.TYPE == 4 && NODE.CHILDREN.length == 0) { var data = { unitid: "AA02" } $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)); res.data.forEach(function (item) { if (item.CODE != "AA0216" && item.CODE != "AA0201") { NODE.CHILDREN.push({ CNAME: item.SECTION, CODE: item.CODE }) } }) }) } } else { if (!self.activeNode.CHILDREN) { self.getFiles(self.activeNode) } } } self.filesList = []; self.getFiles = function (obj) { var data = { tablename: "FILE_ATTACH", colums: "*", order: "ID asc", sqlwhere: { ATTACHTYPE: obj.CODE }, 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.filesList = res.data }) } self.type = 2; self.searchDWMC = ""; self.searchYear = sp.currentYear() * 1; self.years = [sp.currentYear() * 1 - 2, sp.currentYear() * 1 - 1, sp.currentYear() * 1, sp.currentYear() * 1 + 1, sp.currentYear() * 1 + 2] self.getType = function () { var data = { userid: self.userId } $http.post(apiurljs.login + "g2app/dataabase/queryDPParentName", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); for (var i in res.data[0]) { if (res.data[0][i][0].PARENT_DATA.length > 0) { self.type = res.data[0][i][0].PARENT_DATA[0].SECTION != "直属单位" ? 1 : 2; } else { self.type = 1; } } 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.userDpCode = res.data.length == 0 ? "" : res.data[0].CODE; self.userDpName = res.data.length == 0 ? "" : res.data[0].SECTION; self.getData(); }) } self.getData = function () { var sqlwhere = ["AND NF='" + self.searchYear + "' and GLBMCODE='" + self.userDpCode + "'"] if (self.searchDWMC != "") { sqlwhere.push("and DWMC like '%" + self.searchDWMC + "%'") } var data = { pageno: 0, pagesize: 0, tztablename: "SX_CYZDXMTZ", tzcolums: "ID,XMMC,WCSX", colums: "ID", order: "ID", sqlwhere: sqlwhere.join(" "), childtopnum: "", childcolumns: "ID,BH,WCQK,SJWCSJ", childorder: "sortid" } $http.post(apiurljs.login + "g2app/xinxifabu/queryXXFBDataWithChildAndAttach", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); self.list = res.data; console.log(self.list) }) } self.getType() self.openLayer = function () { self.searchDWMC = ""; self.searchYear = sp.currentYear() * 1; sp.layer("#Search") } self.doSearch = function () { self.getData() sp.layerhide() } self.initSearch = function () { self.searchYear = sp.currentYear() * 1; self.searchDWMC = ""; self.getData() sp.layerhide() } self.Detail = function (obj,n) { self.detail = obj; var data = { pageno: 1, pagesize: 1, tztablename: "SX_CYZDXMTZ", tzcolums: "ID,XMMC,WCSX", colums: "ID", order: "ID", sqlwhere: "AND ID='" + obj.ID + "'", childtopnum: "", childcolumns: "ID,BH,WCQK,SJWCSJ", childorder: " sortid" } $http.post(apiurljs.login + "g2app/xinxifabu/queryXXFBDataWithChildAndAttach", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); //self.rwList = res.data[0].CHILD; if (res.data[0].data.length > 0) { self.rwList_CHILD = true; self.rwList = res.data[0].data[0].CHILD; } else { self.rwList_CHILD = false; self.rwList = res.data[0].data; } self.addFlag = false; self.editFlag = false; self.rwList.forEach(function (item) { item.SJWCSJ = sp.format(item.SJWCSJ) item.editFlag = false; }) if (n == 0) { sp.layer("#Detail") } }) } self.addItem = function () { if (self.editFlag == true || self.addFlag == true) { return } self.addFlag = true; self.add = { ID: 0, BH: self.rwList.length == 0 ? 1 : self.rwList[self.rwList.length - 1].BH * 1 + 1, WCQK: "", SJWCSJ: "" } } self.editItem = function (obj) { if (self.addFlag == true) { return } self.editFlag = true; obj.editFlag = true; self.edit = { ID: obj.ID, WCQK: obj.WCQK, SJWCSJ: obj.SJWCSJ } } self.saveItem = function (object) { if (object.ID == 0) { if (self.rwList_CHILD == false) { var data = { id: 0, tablename: "SX_CYZD", data: { PID: self.detail.ID }, childtablename: "SX_CYZD_01", childdata: [{ BH: object.BH, WCQK: object.WCQK, SJWCSJ: object.SJWCSJ }] } $http.post(apiurljs.login + "g2app/dataabase/SaveDataAndChildData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); if (res.success) { self.Detail(self.detail, 1); self.getData() } else { sp.dialog(res.message) } }) } else { var data = { tablename: "SX_CYZD", colums: "ID,PID", order: "ID desc", sqlwhere: { PID: self.detail.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)); var data1 = { tablename: "SX_CYZD_01", id: 0, data: JSON.stringify({ PID: res.data[0].ID, BH: object.BH, WCQK: object.WCQK, SJWCSJ: object.SJWCSJ }) } $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.success) { self.Detail(self.detail, 1); self.getData() } else { sp.dialog(res1.message) } }) }) } } else { var data = { tablename: "SX_CYZD_01", id: object.ID, data: JSON.stringify({ WCQK: object.WCQK, SJWCSJ: object.SJWCSJ }) } $http.post(apiurljs.login + "g2app/dataabase/upFormData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); if (res.success) { self.Detail(self.detail, 1); self.getData() } else { sp.dialog(res.message) } }) } } self.deleteItem = function (obj) { var data = { tablename: "SX_CYZD_01", 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)); sp.dialoghide(); if (res.success) { self.Detail(self.detail, 1); self.getData() } else { sp.dialog("删除失败,请联系管理员!"); } }); } self.upload = function (obj, n) { $('#fileupload' + n).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=FILE_ATTACH,routeinfoid=" + obj.ID + ",ATTACHTYPE=" + self.detail.XMMC)); }, add: function (e, data) { self.uploading = true; data.submit(); }, // 上传完成后的执行逻辑 done: function (e, data) { self.uploading = false; self.Detail(self.detail, 1); self.getData() } }) } self.download = function (obj) { window.open(apiurljs.login + "g2work/files/" + obj.FILEURL.slice(7)) } self.deleteFile = function (obj) { var data = { tablename: "FILE_ATTACH", 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)); sp.dialoghide(); if (res.success) { self.Detail(self.detail, 1); self.getData() } else { sp.dialog("删除失败,请联系管理员!"); } }); } self.upload1 = function () { $('#fileupload_1').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=FILE_ATTACH,routeinfoid=" + self.activeNode.CODE + ",ATTACHTYPE=" + self.activeNode.CODE)); }, add: function (e, data) { self.uploading = true; data.submit(); }, // 上传完成后的执行逻辑 done: function (e, data) { self.getFiles(self.activeNode) } }) } self.deleteFile1 = function (obj) { var data = { tablename: "FILE_ATTACH", 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)); sp.dialoghide(); if (res.success) { self.getFiles(self.activeNode) } else { sp.dialog("删除失败,请联系管理员!"); } }); } }])