var app = angular.module('app', ["angularUtils.directives.dirPagination"]); app.controller("indexCtrl", ["$scope", "$http", "$compile", "$timeout", function ($scope, $http, $compile, $timeout) { var self = this; var s4 = new SM4Util(); self.userId = $.cookie("GlWorkPlatform-userid"); self.userName = $.cookie("GlWorkPlatform-username"); self.userCName = $.cookie("GlWorkPlatform-chineseName"); self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken"); $("#content-box").height($("body").height() - 80); var postCfg = { headers: { 'Content-Type': 'application/json', 'Authorization': "Bearer " + self.get_AccessToken } }; //获取一级类别 self.departList = []; self.getDepartData = function () { self.departList = []; var postData = {"pageno": "0", "pagesize": "0", "sectcode": ""} $http.post(apiurljs.login + "g2app/phonebook/querySectWithPage", {data: s4.encryptData_CBC(JSON.stringify(postData))}, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); res.data.forEach(function (item) { item.SECTIONNAME = item.SECTION + " (" + item.CHILDCOUNT + ") "; }) self.departList = res.data; //console.log(self.departList); }) .error(function (XMLHttpRequest, textStatus, errorThrown) { }) } self.leftActive = "newF"; //默认newF oldF以及code\ self.leftActiveName = "新的朋友"; self.direction = ""; //user or depart //用于生成导航条的数组,只用与记录组织通讯录 self.passArray = []; self.passIndex = ""; self.changeActive = function (code, cname, item) { self.passArray = []; self.passIndex = ""; self.leftActive = code; self.leftActiveName = cname; if (code == "newF" || code == "oldF") { self.direction = ""; } else { if (parseInt(item.CHILDCOUNT) == 0) { self.direction = "user"; self.passArray.push({ level: 0, type: "user", code: code, cname: cname }); self.passIndex = 0; } else { self.direction = "depart"; self.passArray.push({ level: 0, type: "depart", code: code, cname: cname }); self.passIndex = 0; } } self.getData(1); // console.log(self.passArray); // console.log(self.passIndex); } self.noDataTip = 1; self.rows = []; self.pageno = 1; self.total_count = 0; self.itemsPerPage = 8; self.pageOptions = [8, 16, 24, 32]; self.getUserAddress = function (pageno) { self.pageno = pageno; $scope.__default__currentPage = self.pageno; var postData = { "pageno": self.pageno, "pagesize": self.itemsPerPage, "userid": self.userId, "status": "", "order": "cdate" } if (self.leftActive == "newF") { postData.status = "0"; } else if (self.leftActive == "oldF") { postData.status = "1"; } $http.post(apiurljs.login + "g2app/phonebook/queryFriendWithPage", {data: s4.encryptData_CBC(JSON.stringify(postData))}, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); //console.log(res); // res.data.forEach(function (item) { // item.SECTIONNAME = item.SECTION + " (" + item.CHILDCOUNT + ") "; // }) // self.departList = res.data; //console.log(res); if (sp.isval(res.data)) { self.noDataTip = 1; self.rows = res.data; self.total_count = res.totalCount; } else { self.rows = []; self.noDataTip = 0; } }) .error(function (XMLHttpRequest, textStatus, errorThrown) { }) } self.getDepartList = function (pageno) { self.pageno = pageno; $scope.__default__currentPage = self.pageno; let nowItem = self.passArray[self.passIndex]; var postData = { "pageno": self.pageno, "pagesize": self.itemsPerPage, "sectcode": nowItem.code } $http.post(apiurljs.login + "g2app/phonebook/querySectUserinfoWithPage", {data: s4.encryptData_CBC(JSON.stringify(postData))}, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); console.log(res); if (sp.isval(res.data)) { self.noDataTip = 1; self.rows = res.data; self.total_count = res.totalCount; } else { self.rows = []; self.noDataTip = 0; } }) .error(function (XMLHttpRequest, textStatus, errorThrown) { }) } self.getUserList = function (pageno) { self.pageno = pageno; $scope.__default__currentPage = self.pageno; let nowItem = self.passArray[self.passIndex]; var postData = { "pageno": self.pageno, "pagesize": self.itemsPerPage, "sectcode": nowItem.code, "userid":self.userId } $http.post(apiurljs.login + "g2app/phonebook/queryUserinfoWithPage", {data: s4.encryptData_CBC(JSON.stringify(postData))}, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); console.log(res); if (sp.isval(res.data)) { self.noDataTip = 1; self.rows = res.data; self.total_count = res.totalCount; } else { self.rows = []; self.noDataTip = 0; } }) .error(function (XMLHttpRequest, textStatus, errorThrown) { }) } self.getData = function (pageno) { if (self.leftActive == "newF" || self.leftActive == "oldF") { self.getUserAddress(pageno); // } else { let nowItem = self.passArray[self.passIndex]; if (nowItem.type == "depart") { self.getDepartList(pageno); } else if (nowItem.type == "user") { self.direction = "user"; self.getUserList(pageno); } } } self.extendDepart = function (item) { if (parseInt(item.CHILDDPCOUNT) <= 0) { self.passArray.push({ level: 1, type: "user", code: item.CODE, cname: item.SECTION }); self.passIndex++; } else { self.passArray.push({ level: 1, type: "depart", code: item.CODE, cname: item.SECTION }); self.passIndex++; } self.getData(1); } //返回 self.goBack = function () { self.passIndex--; self.passArray = self.passArray.splice(0, self.passArray.length - 1); self.direction = "depart"; self.getData(1); } self.getDepartData(); self.getData(1); //删除朋友 self.deleteFirend = function (code) { var getDelID = code; 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 getid = $(this).attr("data-id"); sp.dialoghide(); var data = { "userid": self.userId, "useridfriend": getid } //console.log(data); $http.post(apiurljs.login + "g2app/phonebook/deleteFriend", {data: s4.encryptData_CBC(JSON.stringify(data))}, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); if (res.success) { sp.dialog("删除成功"); self.getData(self.pageno); } else { sp.dialog(res.message); } }) .error(function (XMLHttpRequest, textStatus, errorThrown) { }) }); } //编辑部门弹出曾 self.depart = { CODE: "", ADDR: "", //地址 EMAIL: "", //邮件 POSTCODE: "", //邮编 SECTION: "", //部门名 TELPHONE: "" //电话 } self.openLayerEditDepart = function (item) { self.depart.CODE = item.CODE; self.depart.ADDR = item.ADDR; self.depart.EMAIL = item.EMAIL; self.depart.POSTCODE = item.POSTCODE; self.depart.SECTION = item.SECTION; self.depart.TELPHONE = item.TELPHONE; sp.layer("#layer_editDepart"); }; self.departCancel = function () { self.depart.CODE = ""; self.depart.ADDR = ""; self.depart.EMAIL = ""; self.depart.POSTCODE = ""; self.depart.SECTION = ""; self.depart.TELPHONE = ""; sp.layerhide(); }; self.departSave = function () { var data = { "sectcode": self.depart.CODE, "addr": self.depart.ADDR, "postcode": self.depart.POSTCODE, "telphone": self.depart.TELPHONE, "email": self.depart.EMAIL } console.log(data); $http.post(apiurljs.login + "g2app/phonebook/saveSectinfo", {data: s4.encryptData_CBC(JSON.stringify(data))}, postCfg) .success(function (obj) { sp.layerhide(); var res = strToJson(s4.decryptData_CBC(obj.data)); console.log(res) if (res.success) { sp.dialog("编辑完成"); self.getData(self.pageno); } else { sp.dialog(res.message); } }) .error(function (XMLHttpRequest, textStatus, errorThrown) { }) } self.updateFriend = function (item) { var data = { "userid":item.USERID, "useridfriend":item.USERIDFRIEND, "status":"1" } $http.post(apiurljs.login + "g2app/phonebook/updateFriend", {data: s4.encryptData_CBC(JSON.stringify(data))}, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); //console.log(res) if (res.success) { sp.dialog("添加成功,请在好友列表中查看"); self.getData(self.pageno); } else { sp.dialog(res.message); } }) .error(function (XMLHttpRequest, textStatus, errorThrown) { }) } self.updateFriend2 = function (item) { var data = { "userid":self.userId, "useridfriend":item.USERID, "status":"1" } console.log(data); $http.post(apiurljs.login + "g2app/phonebook/addFriend", {data: s4.encryptData_CBC(JSON.stringify(data))}, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); console.log(res) if (res.success) { console.log(res); sp.dialog("添加成功,请在好友列表中查看"); self.getData(self.pageno); } else { sp.dialog(res.message); } }) .error(function (XMLHttpRequest, textStatus, errorThrown) { }) } self.user = { USHOWNAME:"", USERID:"", DUTYNAME:"", TELPHONE:"", EMAIL: "", ROOM: "", CELLPHONE:"" } self.openLayerEditUser = function (item) { self.user.USHOWNAME=item.USHOWNAME; self.user.USERID = item.USERID; self.user.DUTYNAME = item.DUTYNAME; self.user.TELPHONE = item.TELPHONE; self.user.EMAIL = item.EMAIL; self.user.ROOM = item.ROOM; self.user.CELLPHONE = item.CELLPHONE; sp.layer("#layer_editUser"); }; self.userCancel = function () { self.user.USHOWNAME=""; self.user.USERID = ""; self.user.DUTYNAME = ""; self.user.TELPHONE = ""; self.user.EMAIL = ""; self.user.ROOM = ""; self.user.CELLPHONE = ""; sp.layerhide(); }; self.userSave = function () { var data ={ "userid":self.user.USERID, "cellphone":self.user.CELLPHONE, "telphone":self.user.TELPHONE, "email": self.user.EMAIL, "room": self.user.ROOM } $http.post(apiurljs.login + "g2app/phonebook/saveUserinfoT", {data: s4.encryptData_CBC(JSON.stringify(data))}, postCfg) .success(function (obj) { sp.layerhide(); var res = strToJson(s4.decryptData_CBC(obj.data)); if (res.success) { sp.dialog("编辑完成"); self.getData(self.pageno); } else { sp.dialog(res.message); } }) .error(function (XMLHttpRequest, textStatus, errorThrown) { }) } }]);