list.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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.search = {
  27. CNAME: ""
  28. }
  29. self.getData = function (pageno) {
  30. self.pageno = pageno;
  31. $scope.__default__currentPage = self.pageno;
  32. let postData = {
  33. tablename: "SX_SJGLB",
  34. pagesize: self.itemsPerPage,
  35. pageno: self.pageno,
  36. colums: "ID,SORTID,CNAME,TEL,CARDTYPE",
  37. order: "ID",
  38. sqlwhere: {},
  39. sqlorwhere: "",
  40. sqlinwhere: "",
  41. sqllikewhere: {
  42. CNAME: self.search.CNAME,
  43. }
  44. }
  45. $http.post(apiurljs.login + "g2app/dataabase/queryDataByColWithPage", { data: s4.encryptData_CBC(JSON.stringify(postData)) }, postCfg)
  46. .success(function (res) {
  47. var res = strToJson(s4.decryptData_CBC(res.data));
  48. if (sp.isval(res.data)) {
  49. self.noDataTip = 1;
  50. self.rows = res.data;
  51. self.total_count = res.totalCount;
  52. } else {
  53. self.rows = [];
  54. self.noDataTip = 0;
  55. }
  56. }).error(function (err) {
  57. sp.dialog(JSON.stringify(err));
  58. });
  59. }
  60. self.getData(1);
  61. //弹出筛选框
  62. self.openSearchLayer = function () {
  63. sp.layer("#layer_search");
  64. }
  65. self.doSearch = function () {
  66. sp.closeCenter('.sp-layer');
  67. self.pageno = 1; // 初始化 当前页为 1
  68. self.getData(self.pageno);
  69. }
  70. //新增数据
  71. self.insertData = [];
  72. self.opneInsertLayer = function () {
  73. self.insertData = [];
  74. sp.layer('#layer_insert');
  75. }
  76. self.addItemData = function () {
  77. self.insertData.push({
  78. CNAME: "",
  79. TEL: "",
  80. CARDTYPE: ""
  81. });
  82. }
  83. self.deleteItem = function (index) {
  84. self.insertData.splice(index, 1);
  85. }
  86. self.saveInsertData = function () {
  87. if (spngvld.submit("#layer_insert")) {
  88. var postData = {
  89. "tablename": "SX_SJGLB",
  90. "data": []
  91. }
  92. self.insertData.forEach(function (item) {
  93. postData.data.push({
  94. CNAME: item.CNAME,
  95. TEL: item.TEL,
  96. CARDTYPE: item.CARDTYPE,
  97. CUSERID: self.userId,
  98. CDATE: sp.getLocalDate()
  99. });
  100. });
  101. $http.post(apiurljs.login + "g2app/dataabase/insertDataList", { data: s4.encryptData_CBC(JSON.stringify(postData)) }, postCfg)
  102. .success(function (obj) {
  103. sp.closeCenter('.sp-layer');
  104. var res = strToJson(s4.decryptData_CBC(obj.data));
  105. if (res.success) {
  106. self.getData(1);
  107. } else {
  108. sp.dialog(res.message);
  109. }
  110. })
  111. .error(function (XMLHttpRequest, textStatus, errorThrown) {
  112. })
  113. }
  114. }
  115. self.deleteData = function ($item) {
  116. var getDelID = $item.ID;
  117. var dialogHead = "<span class=\"sp-dialog-head\"><span class=\"sp-dialog-tip\">温馨提示</span><span class=\"sp-dialog-close sp-closeDialog\" title=\"关闭\">×</span></span>";
  118. var dialogBody = "<div class=\"sp-dialog-body\">删除后不可恢复,您确认要删除吗?</div>";
  119. 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>";
  120. $('.sp-dialog').html(dialogHead + dialogBody + dialogFoot);
  121. sp.openCenter(".sp-dialog");
  122. ///取消按钮
  123. $('.sp-closeDialog').click(function (event) {
  124. sp.closeCenter(".sp-dialog");
  125. event.preventDefault();
  126. event.stopPropagation();
  127. });
  128. //post消息的id
  129. $("#delDataTrue").click(function () {
  130. var getid = $(this).attr("data-id");
  131. sp.dialoghide();
  132. var data = { "id": $item.ID, "tablename": "SX_SJGLB" }
  133. //console.log(data);
  134. $http.post(apiurljs.login + "g2app/richang/delDataById", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  135. .success(function (obj) {
  136. var res = strToJson(s4.decryptData_CBC(obj.data));
  137. if (res.success) {
  138. self.getData(1);
  139. } else {
  140. sp.dialog(res.message);
  141. }
  142. })
  143. .error(function (XMLHttpRequest, textStatus, errorThrown) {
  144. })
  145. });
  146. }
  147. self.itemObj = {
  148. ID: "",
  149. CNAME: "",
  150. TEL: "",
  151. CARDTYPE: ""
  152. }
  153. self.itemDataEdit = function ($item) {
  154. self.itemObj.ID = $item.ID;
  155. self.itemObj.CNAME = $item.CNAME;
  156. self.itemObj.TEL = $item.TEL;
  157. self.itemObj.CARDTYPE = $item.CARDTYPE;
  158. sp.layer('#layer_edit');
  159. };
  160. self.editBtn = function () {
  161. if (spngvld.submit("#layer_edit")) {
  162. var postData = {
  163. "entity": "SX_SJGLB",
  164. "data": {
  165. CNAME: self.itemObj.CNAME,
  166. TEL: self.itemObj.TEL,
  167. CARDTYPE: self.itemObj.CARDTYPE
  168. },
  169. "setwhere": " WHERE id=" + self.itemObj.ID + ""
  170. }
  171. $http.post(apiurljs.login + "g2app/dataabase/UpdataBySql", { data: s4.encryptData_CBC(JSON.stringify(postData)) }, postCfg)
  172. .success(function (obj) {
  173. sp.closeCenter('.sp-layer');
  174. var res = strToJson(s4.decryptData_CBC(obj.data));
  175. if (res.success) {
  176. self.getData(1);
  177. } else {
  178. sp.dialog(res.message);
  179. }
  180. })
  181. .error(function (XMLHttpRequest, textStatus, errorThrown) {
  182. })
  183. } else {
  184. }
  185. }
  186. }])