index.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1.  var app = angular.module('app', ["angularUtils.directives.dirPagination"]);
  2. app.controller("indexCtrl", ["$scope", "$http", "$compile", "$timeout", function ($scope, $http, $compile, $timeout) {
  3. var self = this;
  4. var s4 = new SM4Util();
  5. self.userId = $.cookie("GlWorkPlatform-userid");
  6. self.userName = $.cookie("GlWorkPlatform-username");
  7. self.userCName = $.cookie("GlWorkPlatform-chineseName");
  8. self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken");
  9. $("#content-box").height($("body").height() - 80);
  10. var postCfg = {
  11. headers: {
  12. 'Content-Type': 'application/json',
  13. 'Authorization': "Bearer " + self.get_AccessToken
  14. }
  15. };
  16. //获取一级类别
  17. self.departList = [];
  18. self.getDepartData = function () {
  19. self.departList = [];
  20. var postData = {"pageno": "0", "pagesize": "0", "sectcode": ""}
  21. $http.post(apiurljs.login + "g2app/phonebook/querySectWithPage", {data: s4.encryptData_CBC(JSON.stringify(postData))}, postCfg)
  22. .success(function (obj) {
  23. var res = strToJson(s4.decryptData_CBC(obj.data));
  24. res.data.forEach(function (item) {
  25. item.SECTIONNAME = item.SECTION + " (" + item.CHILDCOUNT + ") ";
  26. })
  27. self.departList = res.data;
  28. //console.log(self.departList);
  29. })
  30. .error(function (XMLHttpRequest, textStatus, errorThrown) {
  31. })
  32. }
  33. self.leftActive = "newF"; //默认newF oldF以及code\
  34. self.leftActiveName = "新的朋友";
  35. self.direction = ""; //user or depart
  36. //用于生成导航条的数组,只用与记录组织通讯录
  37. self.passArray = [];
  38. self.passIndex = "";
  39. self.changeActive = function (code, cname, item) {
  40. self.passArray = [];
  41. self.passIndex = "";
  42. self.leftActive = code;
  43. self.leftActiveName = cname;
  44. if (code == "newF" || code == "oldF") {
  45. self.direction = "";
  46. } else {
  47. if (parseInt(item.CHILDCOUNT) == 0) {
  48. self.direction = "user";
  49. self.passArray.push({
  50. level: 0,
  51. type: "user",
  52. code: code,
  53. cname: cname
  54. });
  55. self.passIndex = 0;
  56. } else {
  57. self.direction = "depart";
  58. self.passArray.push({
  59. level: 0,
  60. type: "depart",
  61. code: code,
  62. cname: cname
  63. });
  64. self.passIndex = 0;
  65. }
  66. }
  67. self.getData(1);
  68. // console.log(self.passArray);
  69. // console.log(self.passIndex);
  70. }
  71. self.noDataTip = 1;
  72. self.rows = [];
  73. self.pageno = 1;
  74. self.total_count = 0;
  75. self.itemsPerPage = 8;
  76. self.pageOptions = [8, 16, 24, 32];
  77. self.getUserAddress = function (pageno) {
  78. self.pageno = pageno;
  79. $scope.__default__currentPage = self.pageno;
  80. var postData = {
  81. "pageno": self.pageno,
  82. "pagesize": self.itemsPerPage,
  83. "userid": self.userId,
  84. "status": "",
  85. "order": "cdate"
  86. }
  87. if (self.leftActive == "newF") {
  88. postData.status = "0";
  89. } else if (self.leftActive == "oldF") {
  90. postData.status = "1";
  91. }
  92. $http.post(apiurljs.login + "g2app/phonebook/queryFriendWithPage", {data: s4.encryptData_CBC(JSON.stringify(postData))}, postCfg)
  93. .success(function (obj) {
  94. var res = strToJson(s4.decryptData_CBC(obj.data));
  95. //console.log(res);
  96. // res.data.forEach(function (item) {
  97. // item.SECTIONNAME = item.SECTION + " (" + item.CHILDCOUNT + ") ";
  98. // })
  99. // self.departList = res.data;
  100. //console.log(res);
  101. if (sp.isval(res.data)) {
  102. self.noDataTip = 1;
  103. self.rows = res.data;
  104. self.total_count = res.totalCount;
  105. } else {
  106. self.rows = [];
  107. self.noDataTip = 0;
  108. }
  109. })
  110. .error(function (XMLHttpRequest, textStatus, errorThrown) {
  111. })
  112. }
  113. self.getDepartList = function (pageno) {
  114. self.pageno = pageno;
  115. $scope.__default__currentPage = self.pageno;
  116. let nowItem = self.passArray[self.passIndex];
  117. var postData = {
  118. "pageno": self.pageno,
  119. "pagesize": self.itemsPerPage,
  120. "sectcode": nowItem.code
  121. }
  122. $http.post(apiurljs.login + "g2app/phonebook/querySectUserinfoWithPage", {data: s4.encryptData_CBC(JSON.stringify(postData))}, postCfg)
  123. .success(function (obj) {
  124. var res = strToJson(s4.decryptData_CBC(obj.data));
  125. console.log(res);
  126. if (sp.isval(res.data)) {
  127. self.noDataTip = 1;
  128. self.rows = res.data;
  129. self.total_count = res.totalCount;
  130. } else {
  131. self.rows = [];
  132. self.noDataTip = 0;
  133. }
  134. })
  135. .error(function (XMLHttpRequest, textStatus, errorThrown) {
  136. })
  137. }
  138. self.getUserList = function (pageno) {
  139. self.pageno = pageno;
  140. $scope.__default__currentPage = self.pageno;
  141. let nowItem = self.passArray[self.passIndex];
  142. var postData = {
  143. "pageno": self.pageno,
  144. "pagesize": self.itemsPerPage,
  145. "sectcode": nowItem.code,
  146. "userid":self.userId
  147. }
  148. $http.post(apiurljs.login + "g2app/phonebook/queryUserinfoWithPage", {data: s4.encryptData_CBC(JSON.stringify(postData))}, postCfg)
  149. .success(function (obj) {
  150. var res = strToJson(s4.decryptData_CBC(obj.data));
  151. console.log(res);
  152. if (sp.isval(res.data)) {
  153. self.noDataTip = 1;
  154. self.rows = res.data;
  155. self.total_count = res.totalCount;
  156. } else {
  157. self.rows = [];
  158. self.noDataTip = 0;
  159. }
  160. })
  161. .error(function (XMLHttpRequest, textStatus, errorThrown) {
  162. })
  163. }
  164. self.getData = function (pageno) {
  165. if (self.leftActive == "newF" || self.leftActive == "oldF") {
  166. self.getUserAddress(pageno); //
  167. } else {
  168. let nowItem = self.passArray[self.passIndex];
  169. if (nowItem.type == "depart") {
  170. self.getDepartList(pageno);
  171. } else if (nowItem.type == "user") {
  172. self.direction = "user";
  173. self.getUserList(pageno);
  174. }
  175. }
  176. }
  177. self.extendDepart = function (item) {
  178. if (parseInt(item.CHILDDPCOUNT) <= 0) {
  179. self.passArray.push({
  180. level: 1,
  181. type: "user",
  182. code: item.CODE,
  183. cname: item.SECTION
  184. });
  185. self.passIndex++;
  186. } else {
  187. self.passArray.push({
  188. level: 1,
  189. type: "depart",
  190. code: item.CODE,
  191. cname: item.SECTION
  192. });
  193. self.passIndex++;
  194. }
  195. self.getData(1);
  196. }
  197. //返回
  198. self.goBack = function () {
  199. self.passIndex--;
  200. self.passArray = self.passArray.splice(0, self.passArray.length - 1);
  201. self.direction = "depart";
  202. self.getData(1);
  203. }
  204. self.getDepartData();
  205. self.getData(1);
  206. //删除朋友
  207. self.deleteFirend = function (code) {
  208. var getDelID = code;
  209. var dialogHead = "<span class=\"sp-dialog-head\"><span class=\"sp-dialog-tip\">温馨提示</span><span class=\"sp-dialog-close sp-closeDialog\" title=\"关闭\">×</span></span>";
  210. var dialogBody = "<div class=\"sp-dialog-body\">删除后不可恢复,您确认要删除吗?</div>";
  211. var dialogFoot = "<div class=\"sp-dialog-foot\"><input data-id=" + getDelID + " id='delDataTrue' type='button' value='确 认' class='sp-dialog-btnTrue' /><input type='button' value='取 消' class='sp-dialog-btnCancle sp-closeDialog' /></div>";
  212. $('.sp-dialog').html(dialogHead + dialogBody + dialogFoot);
  213. sp.openCenter(".sp-dialog");
  214. ///取消按钮
  215. $('.sp-closeDialog').click(function (event) {
  216. sp.closeCenter(".sp-dialog");
  217. event.preventDefault();
  218. event.stopPropagation();
  219. });
  220. //post消息的id
  221. $("#delDataTrue").click(function () {
  222. var getid = $(this).attr("data-id");
  223. sp.dialoghide();
  224. var data = {
  225. "userid": self.userId,
  226. "useridfriend": getid
  227. }
  228. //console.log(data);
  229. $http.post(apiurljs.login + "g2app/phonebook/deleteFriend", {data: s4.encryptData_CBC(JSON.stringify(data))}, postCfg)
  230. .success(function (obj) {
  231. var res = strToJson(s4.decryptData_CBC(obj.data));
  232. if (res.success) {
  233. sp.dialog("删除成功");
  234. self.getData(self.pageno);
  235. } else {
  236. sp.dialog(res.message);
  237. }
  238. })
  239. .error(function (XMLHttpRequest, textStatus, errorThrown) {
  240. })
  241. });
  242. }
  243. //编辑部门弹出曾
  244. self.depart = {
  245. CODE: "",
  246. ADDR: "", //地址
  247. EMAIL: "", //邮件
  248. POSTCODE: "", //邮编
  249. SECTION: "", //部门名
  250. TELPHONE: "" //电话
  251. }
  252. self.openLayerEditDepart = function (item) {
  253. self.depart.CODE = item.CODE;
  254. self.depart.ADDR = item.ADDR;
  255. self.depart.EMAIL = item.EMAIL;
  256. self.depart.POSTCODE = item.POSTCODE;
  257. self.depart.SECTION = item.SECTION;
  258. self.depart.TELPHONE = item.TELPHONE;
  259. sp.layer("#layer_editDepart");
  260. };
  261. self.departCancel = function () {
  262. self.depart.CODE = "";
  263. self.depart.ADDR = "";
  264. self.depart.EMAIL = "";
  265. self.depart.POSTCODE = "";
  266. self.depart.SECTION = "";
  267. self.depart.TELPHONE = "";
  268. sp.layerhide();
  269. };
  270. self.departSave = function () {
  271. var data = {
  272. "sectcode": self.depart.CODE,
  273. "addr": self.depart.ADDR,
  274. "postcode": self.depart.POSTCODE,
  275. "telphone": self.depart.TELPHONE,
  276. "email": self.depart.EMAIL
  277. }
  278. console.log(data);
  279. $http.post(apiurljs.login + "g2app/phonebook/saveSectinfo", {data: s4.encryptData_CBC(JSON.stringify(data))}, postCfg)
  280. .success(function (obj) {
  281. sp.layerhide();
  282. var res = strToJson(s4.decryptData_CBC(obj.data));
  283. console.log(res)
  284. if (res.success) {
  285. sp.dialog("编辑完成");
  286. self.getData(self.pageno);
  287. } else {
  288. sp.dialog(res.message);
  289. }
  290. })
  291. .error(function (XMLHttpRequest, textStatus, errorThrown) {
  292. })
  293. }
  294. self.updateFriend = function (item) {
  295. var data = {
  296. "userid":item.USERID,
  297. "useridfriend":item.USERIDFRIEND,
  298. "status":"1"
  299. }
  300. $http.post(apiurljs.login + "g2app/phonebook/updateFriend", {data: s4.encryptData_CBC(JSON.stringify(data))}, postCfg)
  301. .success(function (obj) {
  302. var res = strToJson(s4.decryptData_CBC(obj.data));
  303. //console.log(res)
  304. if (res.success) {
  305. sp.dialog("添加成功,请在好友列表中查看");
  306. self.getData(self.pageno);
  307. } else {
  308. sp.dialog(res.message);
  309. }
  310. })
  311. .error(function (XMLHttpRequest, textStatus, errorThrown) {
  312. })
  313. }
  314. self.updateFriend2 = function (item) {
  315. var data = {
  316. "userid":self.userId,
  317. "useridfriend":item.USERID,
  318. "status":"1"
  319. }
  320. console.log(data);
  321. $http.post(apiurljs.login + "g2app/phonebook/addFriend", {data: s4.encryptData_CBC(JSON.stringify(data))}, postCfg)
  322. .success(function (obj) {
  323. var res = strToJson(s4.decryptData_CBC(obj.data));
  324. console.log(res)
  325. if (res.success) {
  326. console.log(res);
  327. sp.dialog("添加成功,请在好友列表中查看");
  328. self.getData(self.pageno);
  329. } else {
  330. sp.dialog(res.message);
  331. }
  332. })
  333. .error(function (XMLHttpRequest, textStatus, errorThrown) {
  334. })
  335. }
  336. self.user = {
  337. USHOWNAME:"",
  338. USERID:"",
  339. DUTYNAME:"",
  340. TELPHONE:"",
  341. EMAIL: "",
  342. ROOM: "",
  343. CELLPHONE:""
  344. }
  345. self.openLayerEditUser = function (item) {
  346. self.user.USHOWNAME=item.USHOWNAME;
  347. self.user.USERID = item.USERID;
  348. self.user.DUTYNAME = item.DUTYNAME;
  349. self.user.TELPHONE = item.TELPHONE;
  350. self.user.EMAIL = item.EMAIL;
  351. self.user.ROOM = item.ROOM;
  352. self.user.CELLPHONE = item.CELLPHONE;
  353. sp.layer("#layer_editUser");
  354. };
  355. self.userCancel = function () {
  356. self.user.USHOWNAME="";
  357. self.user.USERID = "";
  358. self.user.DUTYNAME = "";
  359. self.user.TELPHONE = "";
  360. self.user.EMAIL = "";
  361. self.user.ROOM = "";
  362. self.user.CELLPHONE = "";
  363. sp.layerhide();
  364. };
  365. self.userSave = function () {
  366. var data ={
  367. "userid":self.user.USERID,
  368. "cellphone":self.user.CELLPHONE,
  369. "telphone":self.user.TELPHONE,
  370. "email": self.user.EMAIL,
  371. "room": self.user.ROOM
  372. }
  373. $http.post(apiurljs.login + "g2app/phonebook/saveUserinfoT", {data: s4.encryptData_CBC(JSON.stringify(data))}, postCfg)
  374. .success(function (obj) {
  375. sp.layerhide();
  376. var res = strToJson(s4.decryptData_CBC(obj.data));
  377. if (res.success) {
  378. sp.dialog("编辑完成");
  379. self.getData(self.pageno);
  380. } else {
  381. sp.dialog(res.message);
  382. }
  383. })
  384. .error(function (XMLHttpRequest, textStatus, errorThrown) {
  385. })
  386. }
  387. }]);