formlist-detail.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. var app = angular.module('app', ["angularUtils.directives.dirPagination"]);
  2. app.controller("formlistAddCtrl", ["$scope", "$http", "$compile", "$timeout", function ($scope, $http, $compile, $timeout) {
  3. var self = this;
  4. var s4 = new SM4Util();
  5. sp.fitHeight("#formAddPart", 190);
  6. sp.fitHeight("#formTablePart", 80);
  7. self.userId = $.cookie("GlWorkPlatform-userid");
  8. self.userName = $.cookie("GlWorkPlatform-username");
  9. self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken");
  10. self.get_formid = sp.getUrlName("formid"); //获取表的id
  11. self.get_ctype = sp.getUrlName("ctype"); //获取表的类型
  12. self.get_leftActive = sp.getUrlName("leftActive");
  13. self.get_leftActiveType = sp.getUrlName("leftActiveType");
  14. self.get_formName = ""; //获取表名
  15. self.btnGoBack = function () {
  16. window.location.href = "formlist-add.html?formid=" + self.get_formid + "&ctype=" + self.get_ctype + "&leftActive=" + self.get_leftActive + "&leftActiveType=" + self.get_leftActiveType;
  17. };
  18. var postCfg = {
  19. headers: {
  20. 'Content-Type': 'application/json',
  21. 'Authorization': "Bearer " + self.get_AccessToken
  22. }
  23. };
  24. $("#table").css("height", $("body").height() - 90)
  25. self.noDataTip = 1;
  26. self.codeArray = [];
  27. self.getCodeFormData = function () {
  28. self.codeArray = [];
  29. self.get_formName = "";
  30. var postData = {
  31. formid: self.get_formid
  32. }
  33. $http.post(apiurljs.login + "g2work/form/queryDataItem", { data: s4.encryptData_CBC(JSON.stringify(postData)) }, postCfg).success(function (obj) {
  34. var res = strToJson(s4.decryptData_CBC(obj.data));
  35. self.get_formName = res.data.CKEY;
  36. self.getThead()
  37. });
  38. }
  39. self.getThead = function () {
  40. var data = {
  41. tablename: self.get_formName,
  42. order: "sortid"
  43. }
  44. $http.post(apiurljs.login + "g2app/richang/queryColumnsData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  45. .success(function (obj) {
  46. var res = strToJson(s4.decryptData_CBC(obj.data))
  47. self.thead = [];
  48. $.each(res.data, function (index, item) {
  49. if (item.code != "ID" && item.code != "ROUTEINFOID") {
  50. self.thead.push({ code: item.code, cname: item.cname })
  51. }
  52. })
  53. console.log(self.thead)
  54. self.thead = self.thead.sort(function (a, b) {
  55. if (a.code < b.code) {
  56. return -1;
  57. }
  58. if (a.code > b.code) {
  59. return 1;
  60. }
  61. return 0;
  62. })
  63. self.getData()
  64. })
  65. }
  66. self.getData = function () {
  67. var sendData = {
  68. ckey: self.get_formName,
  69. routeinfoid: 0
  70. }
  71. $http.post(apiurljs.login + "g2app/abase/queryDataCode", { data: s4.encryptData_CBC(JSON.stringify(sendData)) }, postCfg)
  72. .success(function (obj) {
  73. var res = strToJson(s4.decryptData_CBC(obj.data));
  74. if (res.data[self.get_formName].length == 1 && res.data[self.get_formName][0].ID == "0") {
  75. self.noDataTip = 0;
  76. self.codeArray = [];
  77. } else {
  78. self.noDataTip = 1;
  79. self.codeArray = res.data[self.get_formName];
  80. }
  81. });
  82. }
  83. self.getCodeFormData();
  84. self.itemCode = {
  85. ID: "0",
  86. TITLE: "",
  87. list: []
  88. }
  89. self.openAddLayer = function () {
  90. self.itemCode.ID = "0";
  91. self.itemCode.TITLE = "新增数据";
  92. self.itemCode.list = [];
  93. self.thead.forEach(function (item) {
  94. if (item.code != "SORTID") {
  95. var a = {
  96. code: item.code,
  97. name: item.cname
  98. }
  99. a[item.code] = "";
  100. self.itemCode.list.push(a)
  101. }
  102. })
  103. console.log(self.itemCode)
  104. sp.layer("#layer_codeData");
  105. };
  106. self.openEditLayer = function (item) {
  107. self.itemCode.ID = item.ID;
  108. self.itemCode.TITLE = "编辑数据";
  109. self.itemCode.list = [];
  110. self.thead.forEach(function (item1) {
  111. var a = {
  112. code: item1.code,
  113. name: item1.cname
  114. }
  115. a[item1.code] = item[item1.code];
  116. self.itemCode.list.push(a)
  117. })
  118. sp.layer("#layer_codeData");
  119. };
  120. self.delCodeData = function ($item) {
  121. // var getDelID = $item.PKID;
  122. var getDelID = $item.ID;
  123. var dialogHead = "<span class=\"sp-dialog-head\"><span class=\"sp-dialog-tip\">温馨提示</span><span class=\"sp-dialog-close sp-closeDialog\" title=\"关闭\">×</span></span>";
  124. var dialogBody = "<div class=\"sp-dialog-body\">删除后不可恢复,您确认要删除吗?</div>";
  125. 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>";
  126. $('.sp-dialog').html(dialogHead + dialogBody + dialogFoot);
  127. sp.openCenter(".sp-dialog");
  128. ///取消按钮
  129. $('.sp-closeDialog').click(function (event) {
  130. sp.dialoghide();
  131. event.preventDefault();
  132. event.stopPropagation();
  133. });
  134. //post消息的id
  135. $("#delDataTrue").click(function () {
  136. var data = {
  137. ckey: self.get_formName,
  138. id: getDelID
  139. };
  140. $http.post(apiurljs.login + "g2app/abase/deleteDataCodeItem", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  141. .success(function (obj) {
  142. var res = strToJson(s4.decryptData_CBC(obj.data));
  143. if (res.success) {
  144. self.getCodeFormData();
  145. sp.dialoghide();
  146. } else {
  147. sp.dialog(res.message);
  148. }
  149. });
  150. });
  151. };
  152. self.btnDataCancel = function () {
  153. sp.layerhide();
  154. };
  155. self.btnDataSave = function () {
  156. var valueArray = [];
  157. var a = {}
  158. self.itemCode.list.forEach(function (item) {
  159. a[item.code]=item[item.code]
  160. })
  161. valueArray.push(a)
  162. var postData = {
  163. ckey: self.get_formName,
  164. id: self.itemCode.ID,
  165. data: JSON.stringify(valueArray)
  166. }
  167. $http.post(apiurljs.login + "g2app/abase/saveDataCodeItem", { data: s4.encryptData_CBC(JSON.stringify(postData)) }, postCfg)
  168. .success(function (obj) {
  169. var res = strToJson(s4.decryptData_CBC(obj.data));
  170. sp.layerhide();
  171. if (res.success) {
  172. self.getCodeFormData();
  173. } else {
  174. sp.dialog(res.message);
  175. }
  176. });
  177. }
  178. }]);