zbUserList.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. 'use strict';
  2. var app = angular.module('app', [
  3. 'angularUtils.directives.dirPagination'
  4. ]);
  5. app.controller("indexCtrl", ["$scope", "$http", "$timeout", function ($scope, $http, $timeout) {
  6. var self = this;
  7. var s4 = new SM4Util();
  8. self.userId = $.cookie("GlWorkPlatform-userid");
  9. self.userName = $.cookie("GlWorkPlatform-chineseName");
  10. self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken");
  11. self.get_lastReturnPageno = sp.getUrlName("lastReturnPageno");
  12. self.get_type = sp.getUrlName("type");
  13. var postCfg = {
  14. headers: {
  15. 'Content-Type': 'application/json',
  16. 'Authorization': "Bearer " + self.get_AccessToken
  17. }
  18. }
  19. //根据选择的底稿目录获取当前目录下的文件
  20. self.noDataTip = 1;
  21. self.rows = [];
  22. self.pageno = 1;
  23. self.total_count = 0;
  24. self.itemsPerPage = 10;
  25. self.pageOptions = [10, 15, 20, 25, 30];
  26. self.type = 1;
  27. self.search = {
  28. CNAME: "",
  29. ZHIWU: ""
  30. }
  31. self.getData = function (pageno) {
  32. self.pageno = pageno;
  33. $scope.__default__currentPage = self.pageno;
  34. var postData = {
  35. tablename: "SX_ZHIBANRYGL",
  36. pagesize: self.itemsPerPage,
  37. pageno: self.pageno,
  38. colums: "*",
  39. order: "SORTID",
  40. sqlwhere: { MANMARK: self.type == 1 ? "C01" : self.type == 2 ? "C02" : "C03" },
  41. sqlorwhere: "",
  42. sqlinwhere: "",
  43. sqllikewhere: {
  44. CNAME: self.search.CNAME,
  45. ZHIWU: self.search.ZHIWU
  46. }
  47. }
  48. $http.post(apiurljs.login + "g2app/dataabase/queryDataByColWithPage", { data: s4.encryptData_CBC(JSON.stringify(postData)) }, postCfg)
  49. .success(function (res) {
  50. var res = strToJson(s4.decryptData_CBC(res.data));
  51. if (sp.isval(res.data)) {
  52. self.noDataTip = 1;
  53. self.rows = res.data;
  54. self.total_count = res.totalCount;
  55. } else {
  56. self.rows = [];
  57. self.noDataTip = 0;
  58. }
  59. }).error(function (err) {
  60. sp.dialog(JSON.stringify(err));
  61. });
  62. }
  63. self.getData(1);
  64. //弹出筛选框
  65. self.openSearchLayer = function () {
  66. sp.layer("#layer_search");
  67. }
  68. self.doSearch = function () {
  69. sp.closeCenter('.sp-layer');
  70. self.pageno = 1; // 初始化 当前页为 1
  71. self.getData(self.pageno);
  72. }
  73. //新增数据
  74. self.insertData = [];
  75. self.opneInsertLayer = function () {
  76. self.insertData = [];
  77. sp.layer('#layer_insert');
  78. }
  79. self.addItemData = function () {
  80. if (self.type == 1) {
  81. self.insertData.push({
  82. CNAME: "",
  83. SEX: "",
  84. ZHIWU: "",
  85. TEL: "",
  86. MOBILEPHONE: ""
  87. });
  88. } else {
  89. self.insertData.push({
  90. CNAME: "",
  91. SEX: "",
  92. ZHIWU: "",
  93. DPNAME: "",
  94. REMARK: ""
  95. });
  96. }
  97. }
  98. self.deleteItem = function (index) {
  99. self.insertData.splice(index, 1);
  100. }
  101. self.saveInsertData = function () {
  102. if (spngvld.submit("#layer_insert")) {
  103. var postData = {
  104. "tablename": "SX_ZHIBANRYGL",
  105. "data": []
  106. }
  107. if (self.type == 1) {
  108. self.insertData.forEach(function (item) {
  109. postData.data.push({
  110. CNAME: item.CNAME,
  111. SEX: item.SEX,
  112. ZHIWU: item.ZHIWU,
  113. TEL: item.TEL,
  114. MOBILEPHONE: item.MOBILEPHONE,
  115. MANMARK: "C01",
  116. CUSERID: self.userId,
  117. CDATE: sp.getLocalDate()
  118. });
  119. });
  120. } else {
  121. self.insertData.forEach(function (item) {
  122. postData.data.push({
  123. CNAME: item.CNAME,
  124. SEX: item.SEX,
  125. ZHIWU: item.ZHIWU,
  126. DPNAME: item.DPNAME,
  127. REMARK: item.REMARK,
  128. MANMARK: self.type == 2 ? "C02" : "C03",
  129. CUSERID: self.userId,
  130. CDATE: sp.getLocalDate()
  131. });
  132. });
  133. }
  134. $http.post(apiurljs.login + "g2app/dataabase/insertDataList", { data: s4.encryptData_CBC(JSON.stringify(postData)) }, postCfg)
  135. .success(function (obj) {
  136. sp.closeCenter('.sp-layer');
  137. var res = strToJson(s4.decryptData_CBC(obj.data));
  138. if (res.success) {
  139. self.getData(1);
  140. } else {
  141. sp.dialog(res.message);
  142. }
  143. })
  144. .error(function (XMLHttpRequest, textStatus, errorThrown) {
  145. })
  146. }
  147. }
  148. self.deleteData = function ($item) {
  149. var getDelID = $item.ID;
  150. var dialogHead = "<span class=\"sp-dialog-head\"><span class=\"sp-dialog-tip\">温馨提示</span><span class=\"sp-dialog-close sp-closeDialog\" title=\"关闭\">×</span></span>";
  151. var dialogBody = "<div class=\"sp-dialog-body\">删除后不可恢复,您确认要删除吗?</div>";
  152. 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>";
  153. $('.sp-dialog').html(dialogHead + dialogBody + dialogFoot);
  154. sp.openCenter(".sp-dialog");
  155. ///取消按钮
  156. $('.sp-closeDialog').click(function (event) {
  157. sp.closeCenter(".sp-dialog");
  158. event.preventDefault();
  159. event.stopPropagation();
  160. });
  161. //post消息的id
  162. $("#delDataTrue").click(function () {
  163. var getid = $(this).attr("data-id");
  164. sp.dialoghide();
  165. var data = { "id": $item.ID, "tablename": "SX_ZHIBANRYGL" }
  166. //console.log(data);
  167. $http.post(apiurljs.login + "g2app/richang/delDataById", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  168. .success(function (obj) {
  169. var res = strToJson(s4.decryptData_CBC(obj.data));
  170. if (res.success) {
  171. self.getData(1);
  172. } else {
  173. sp.dialog(res.message);
  174. }
  175. })
  176. .error(function (XMLHttpRequest, textStatus, errorThrown) {
  177. })
  178. });
  179. }
  180. self.itemObj = {
  181. ID: "",
  182. CNAME: "",
  183. SEX: "",
  184. ZHIWU: ""
  185. }
  186. self.itemDataEdit = function ($item) {
  187. self.itemObj.ID = $item.ID;
  188. self.itemObj.CNAME = $item.CNAME;
  189. self.itemObj.SEX = $item.SEX;
  190. self.itemObj.ZHIWU = $item.ZHIWU;
  191. if (self.type == 1) {
  192. self.itemObj.TEL = $item.TEL;
  193. self.itemObj.MOBILEPHONE = $item.MOBILEPHONE;
  194. } else {
  195. self.itemObj.DPNAME = $item.DPNAME;
  196. self.itemObj.REMARK = $item.REMARK;
  197. }
  198. sp.layer('#layer_edit');
  199. };
  200. self.editBtn = function () {
  201. if (spngvld.submit("#layer_edit")) {
  202. var postData = {
  203. "entity": "SX_ZHIBANRYGL",
  204. "data": {
  205. CNAME: self.itemObj.CNAME,
  206. SEX: self.itemObj.SEX,
  207. ZHIWU: self.itemObj.ZHIWU
  208. },
  209. "setwhere": " WHERE id=" + self.itemObj.ID + ""
  210. }
  211. if (self.type == 1) {
  212. postData.data.TEL = self.itemObj.TEL;
  213. postData.data.MOBILEPHONE = self.itemObj.MOBILEPHONE;
  214. } else {
  215. postData.data.DPNAME = self.itemObj.DPNAME;
  216. postData.data.REMARK = self.itemObj.REMARK;
  217. }
  218. $http.post(apiurljs.login + "g2app/dataabase/UpdataBySql", { data: s4.encryptData_CBC(JSON.stringify(postData)) }, postCfg)
  219. .success(function (obj) {
  220. sp.closeCenter('.sp-layer');
  221. var res = strToJson(s4.decryptData_CBC(obj.data));
  222. if (res.success) {
  223. self.getData(1);
  224. } else {
  225. sp.dialog(res.message);
  226. }
  227. })
  228. .error(function (XMLHttpRequest, textStatus, errorThrown) {
  229. })
  230. } else {
  231. }
  232. }
  233. self.openSortLayer = function () {
  234. var postData = {
  235. tablename: "SX_ZHIBANRYGL",
  236. colums: "*",
  237. order: "SORTID",
  238. sqlwhere: { MANMARK: self.type == 1 ? "C01" : self.type == 2 ? "C02" : "C03" },
  239. sqlorwhere: "",
  240. sqlinwhere: "",
  241. sqllikewhere: ""
  242. }
  243. $http.post(apiurljs.login + "g2app/dataabase/queryDataByCol", { data: s4.encryptData_CBC(JSON.stringify(postData)) }, postCfg)
  244. .success(function (res) {
  245. var res = strToJson(s4.decryptData_CBC(res.data));
  246. self.sortList = res.data;
  247. $("#sortList tbody").sortable({
  248. cursor: "move",
  249. stop: function (event, ui) {
  250. var index = 1;
  251. $("#sortList tbody").children().each(function (x) {
  252. $(this).attr("index", index)
  253. $(this).children().eq(0).html(index)
  254. index++
  255. })
  256. }
  257. }).disableSelection();
  258. sp.layer("#sortWin")
  259. })
  260. }
  261. self.btnSortBtn = function () {
  262. var IDS = [], SORTIDS = [];
  263. self.sortList.forEach(function (item) {
  264. $("#sortList tbody").children().each(function (index) {
  265. if ($(this).attr("data-col") == item.ID) {
  266. IDS.push({ ID: item.ID })
  267. SORTIDS.push({ SORTID: index + 1 })
  268. }
  269. })
  270. })
  271. var data = {
  272. entity: "SX_ZHIBANRYGL",
  273. data: SORTIDS,
  274. setwhere: IDS
  275. }
  276. $http.post(apiurljs.login + "g2app/Data/UpdataByWhereList", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  277. .success(function (obj) {
  278. var res = strToJson(s4.decryptData_CBC(obj.data));
  279. if (res.success == true) {
  280. self.getData(1);
  281. sp.closeCenter("#sortWin")
  282. }
  283. })
  284. }
  285. }])