'use strict'; var app = angular.module('app', [ 'angularUtils.directives.dirPagination', ]); app.controller("indexCtrl", ["$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"); var postCfg = { headers: { 'Content-Type': 'application/json', 'Authorization': "Bearer " + self.get_AccessToken } }; self.UserRole = false; self.getROLE = function () { var data = { userid: self.userId }; $http.post(apiurljs.login + "g2work/datazu/queryDataUserAuth", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); for (var i = 0; i < res.data[0].auths.length; i++) { if (res.data[0].auths[i].ZID == "AA78" && res.data[0].auths[i].AUTH == 1) { self.UserRole = true; } } self.getLeftTree(); }); } self.getROLE() self.getLeftTree = function () { var data = { tablename: "SX_TONGXUNLUTREE" } $http.post(apiurljs.login + "g2app/dataabase/getTreeListAllByTablename", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); self.leftTree = res.data; self.activeNode = null; self.checkNode(self.leftTree[0], 0) self.checkNode(self.leftTree[0].C_H_I_L_D_DATA[0], 1) }) } self.addNode = function () { self.add = { "tablename": "SX_TONGXUNLUTREE", "PARENT_CNAME": "通讯录汇总", "code": "P01", "levels": item.LEVELS, "cname": "", "userid": self.userId } sp.layer('#layer_box_add') } self.LPEdit = function (obj) { self.edit = { "id": obj.ID, "tablename": "SX_TONGXUNLUTREE", "cname": obj.CNAME, "userid": self.userId } sp.layer('#layer_box_edit'); } self.btnSaveNode = function () { var data = { "id": self.edit.id, "tablename": self.edit.tablename, "setwhere": { "CNAME": self.edit.cname } } $http.post(apiurljs.login + "g2app/dataabase/setColumnsById", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); if (res.success) { sp.layerhide(); self.getLeftTree(); } else { sp.layerhide(); sp.dialog(res.message); } }) } self.checkNode = function (node, n) { if (n == 0) { node.show = !node.show; } else { self.activeNode = node; var data = { tablename: "SX_TONGXUNLU", colums: "*", order: "SORTID asc", sqlwhere: { TREECODE: node.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.list = res.data; self.editFlag = false; self.list.forEach(function (item) { item.editFlag = false; }) }) } } self.btnAdd = function () { self.addItem = { ID: 0, USHOWNAME: "", DUTYNAME: "", MOBILE: "", EMAIL: "", TEL: "", ROOM: "", FAX: "", ZIPCODE: "", TREECODE: self.activeNode.CODE } sp.layer("#addUser") } self.btnEdit = function (obj) { self.editFlag = true; obj.editFlag = true; self.editItem = { ID: obj.ID, USHOWNAME: obj.USHOWNAME, DUTYNAME: obj.DUTYNAME, //SECTNAME: obj.SECTNAME, MOBILE: obj.MOBILE, EMAIL: obj.EMAIL, TEL: obj.TEL, ROOM: obj.ROOM, FAX: obj.FAX, ZIPCODE: obj.ZIPCODE }; } self.btnSave = function (n) { if (n == 1) { var data = { tablename: "SX_TONGXUNLU", data: JSON.stringify({ USHOWNAME: self.addItem.USHOWNAME, DUTYNAME: self.addItem.DUTYNAME, MOBILE: self.addItem.MOBILE, EMAIL: self.addItem.EMAIL, TEL: self.addItem.TEL, ROOM: self.addItem.ROOM, FAX: self.addItem.FAX, ZIPCODE: self.addItem.ZIPCODE, TREECODE: self.addItem.TREECODE }) } $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)); sp.layerhide() if (res.success) { self.checkNode(self.activeNode, 1) } else { sp.dialog(res.message) } }) } else { var data = { tablename: "SX_TONGXUNLU", id: self.editItem.ID, data: JSON.stringify({ USHOWNAME: self.editItem.USHOWNAME, DUTYNAME: self.editItem.DUTYNAME, //SECTNAME: self.editItem.SECTNAME, MOBILE: self.editItem.MOBILE, EMAIL: self.editItem.EMAIL, TEL: self.editItem.TEL, ROOM: self.editItem.ROOM, FAX: self.editItem.FAX, ZIPCODE: self.editItem.ZIPCODE }) } $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.checkNode(self.activeNode, 1) } else { sp.dialog(res.message) } }) } } self.btnDelete = function (item) { var dialogHead = "温馨提示×"; var dialogBody = "
删除后不可恢复,您确认要删除吗?
"; var dialogFoot = "
"; $('.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_TONGXUNLU", 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.checkNode(self.activeNode, 1) } else { sp.dialog("删除失败,请联系管理员!"); } }); }); } self.btnSort = function (item, n) { var ids = [], sortids = []; for (var i = 0; i < self.list.length; i++) { if (self.list[i].ID == item.ID) { ids = [self.list[i + n].ID, self.list[i].ID] sortids = [self.list[i].SORTID, self.list[i + n].SORTID] } } var data = { entity: "SX_TONGXUNLU", data: sortids.map(function (item) { return { SORTID: item } }), setwhere: ids.map(function (item) { return { ID: item } }) } $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 == true) { self.checkNode(self.activeNode, 1) } }) } }])