taizhang.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. 'use strict';
  2. var app = angular.module('app', [
  3. 'angularUtils.directives.dirPagination'
  4. ]);
  5. app.controller("listCtrl", ["$scope", "$http", "$timeout", "$sce", function ($scope, $http, $timeout, $sce) {
  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.dateParam = sp.getUrlName("date");
  12. var postCfg = {
  13. headers: {
  14. 'Content-Type': 'application/json',
  15. 'Authorization': "Bearer " + self.get_AccessToken
  16. }
  17. }
  18. self.searchYear = sp.currentYear() * 1;
  19. self.searchDWMC = "";
  20. self.impYear = sp.currentYear() * 1;
  21. self.years = [sp.currentYear() * 1 - 2, sp.currentYear() * 1 - 1, sp.currentYear() * 1, sp.currentYear() * 1 + 1, sp.currentYear() * 1 + 2]
  22. self.getDWLX = function () {
  23. var data = {
  24. tablename: "CODE_DWLX",
  25. colums: "ID,CODE,CNAME",
  26. order: "SORTID desc",
  27. sqlwhere: "",
  28. sqlinwhere: "",
  29. sqllikewhere: ""
  30. }
  31. $http.post(apiurljs.login + "g2app/dataabase/queryDataByCol", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  32. .success(function (obj) {
  33. var res = strToJson(s4.decryptData_CBC(obj.data));
  34. self.DWLX = res.data;
  35. self.getDP()
  36. })
  37. }
  38. self.getDP = function () {
  39. var data = {
  40. userid: self.userId
  41. }
  42. $http.post(apiurljs.login + "g2app/richang/queryDpInfo", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  43. .success(function (obj) {
  44. var res = strToJson(s4.decryptData_CBC(obj.data));
  45. self.userDpCode = res.data.length == 0 ? "" : res.data[0].CODE;
  46. self.userDpName = res.data.length == 0 ? "" : res.data[0].SECTION;
  47. self.getData();
  48. })
  49. }
  50. self.getData = function () {
  51. var data = {
  52. tablename: "SX_CYZDXMTZ",
  53. colums: "*",
  54. order: "SORTID",
  55. sqlwhere: { NF: self.searchYear },
  56. sqlinwhere: "",
  57. sqllikewhere: { DWMC: self.searchDWMC }
  58. }
  59. $http.post(apiurljs.login + "g2app/dataabase/queryDataByCol", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  60. .success(function (obj) {
  61. var res = strToJson(s4.decryptData_CBC(obj.data));
  62. self.list = res.data;
  63. self.addFlag = false;
  64. self.editFlag = false;
  65. console.log(res.data.map(function (item) { return { GLBM: item.GLBM, GLBMCODE: item.GLBMCODE } }))
  66. self.list.forEach(function (item) {
  67. item.editFlag = false;
  68. self.DWLX.forEach(function (item1) {
  69. if (item.DWLX == item1.CODE) {
  70. item.DWLX1 = item1.CNAME;
  71. }
  72. })
  73. })
  74. self.getDpList()
  75. })
  76. }
  77. self.getDWLX()
  78. //n=-1下移,n=1上移
  79. self.sortItem = function (index, n) {
  80. var ids = [{ ID: self.list[index].ID }, { ID: self.list[index + n].ID }], sortids = [{ SORTID: self.list[index + n].SORTID }, { SORTID: self.list[index].SORTID }];
  81. var data = {
  82. entity: "SX_CYZDXMTZ",
  83. data: sortids,
  84. setwhere: ids
  85. }
  86. $http.post(apiurljs.login + "g2app/Data/UpdataByWhereList", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  87. .success(function (obj) {
  88. var res = strToJson(s4.decryptData_CBC(obj.data));
  89. if (res.success == true) {
  90. self.getData();
  91. }
  92. })
  93. }
  94. self.getDpList = function () {
  95. var data = {
  96. unitid: "AA"
  97. }
  98. $http.post(apiurljs.login + "g2app/dataabase/querySectByCode", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  99. .success(function (obj) {
  100. var res = strToJson(s4.decryptData_CBC(obj.data));
  101. self.dpList = [];
  102. res.data.forEach(function (item) {
  103. if (item.CHILD_DATA.length == 0) {
  104. self.dpList.push(item)
  105. } else {
  106. item.CHILD_DATA.forEach(function (item1) {
  107. if (item1.CHILD_DATA.length == 0) {
  108. self.dpList.push(item1)
  109. } else {
  110. item1.CHILD_DATA.forEach(function (item2) {
  111. if (item2.CHILD_DATA.length == 0) {
  112. self.dpList.push(item2)
  113. }
  114. })
  115. }
  116. })
  117. }
  118. })
  119. self.dpList.forEach(function (item) {
  120. item.checked = false;
  121. })
  122. })
  123. }
  124. self.openDpList = function (str) {
  125. self.filed = str;
  126. sp.layer("#DpList")
  127. $("#DpList .sp-page").eq(0).scrollTop(0);
  128. }
  129. self.checkDpItem = function (obj) {
  130. $.each(self.dpList, function (index, item) {
  131. item.checked = false;
  132. })
  133. obj.checked = !obj.checked;
  134. self.submitDpList(1)
  135. }
  136. self.submitDpList = function (n) {
  137. $.each(self.dpList, function (index, item) {
  138. if (item.checked == true) {
  139. self[self.filed].GLBM = item.SECTION
  140. self[self.filed].GLBMCODE = item.CODE;
  141. }
  142. })
  143. if (n == 0) {
  144. sp.layerhide();
  145. }
  146. }
  147. self.openLayer = function () {
  148. self.searchYear = sp.currentYear() * 1;
  149. self.searchDWMC = "";
  150. sp.layer("#Search")
  151. }
  152. self.doSearch = function () {
  153. self.getData()
  154. sp.layerhide()
  155. }
  156. self.initSearch = function () {
  157. self.searchYear = sp.currentYear() * 1;
  158. self.searchDWMC = "";
  159. self.getData()
  160. sp.layerhide()
  161. }
  162. self.addItem = function () {
  163. if (self.editFlag == true) {
  164. sp.dialog("请先保存或取消编辑!")
  165. return
  166. }
  167. if (self.addFlag == true) {
  168. return
  169. }
  170. self.addFlag = true;
  171. self.add = {
  172. ID: 0,
  173. DWLX: self.DWLX[0].CODE,
  174. DWMC: "",
  175. GLBM: "",
  176. GLBMCODE: "",
  177. XMMC: "",
  178. WCSX: ""
  179. }
  180. }
  181. self.editItem = function (obj) {
  182. if (self.addFlag == true) {
  183. sp.dialog("请先保存或取消添加!")
  184. return
  185. }
  186. self.editFlag = true;
  187. obj.editFlag = true;
  188. self.edit = {
  189. ID: obj.ID,
  190. DWLX: obj.DWLX,
  191. DWMC: obj.DWMC,
  192. GLBM: obj.GLBM,
  193. GLBMCODE: obj.GLBMCODE,
  194. XMMC: obj.XMMC,
  195. WCSX: obj.WCSX
  196. }
  197. }
  198. self.saveItem = function (obj) {
  199. if (obj.ID == 0) {
  200. var data = {
  201. tablename: "SX_CYZDXMTZ",
  202. data: JSON.stringify({
  203. DWLX: obj.DWLX,
  204. DWMC: obj.DWMC,
  205. GLBM: obj.GLBM,
  206. GLBMCODE: obj.GLBMCODE,
  207. XMMC: obj.XMMC,
  208. WCSX: obj.WCSX,
  209. NF: self.searchYear,
  210. CUSERID: self.userId,
  211. CJRBMID: self.userDpCode,
  212. CDATE: sp.getLocalDate()
  213. })
  214. }
  215. $http.post(apiurljs.login + "g2app/dataabase/insertFormData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  216. .success(function (obj) {
  217. var res = strToJson(s4.decryptData_CBC(obj.data));
  218. if (res.success) {
  219. self.getData();
  220. } else {
  221. sp.dialog(res.message)
  222. }
  223. })
  224. } else {
  225. var data = {
  226. tablename: "SX_CYZDXMTZ",
  227. id: obj.ID,
  228. data: JSON.stringify({
  229. DWLX: obj.DWLX,
  230. DWMC: obj.DWMC,
  231. GLBM: obj.GLBM,
  232. GLBMCODE: obj.GLBMCODE,
  233. XMMC: obj.XMMC,
  234. WCSX: obj.WCSX
  235. })
  236. }
  237. $http.post(apiurljs.login + "g2app/dataabase/upFormData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  238. .success(function (obj) {
  239. var res = strToJson(s4.decryptData_CBC(obj.data));
  240. if (res.success) {
  241. self.getData();
  242. } else {
  243. sp.dialog(res.message)
  244. }
  245. })
  246. }
  247. }
  248. self.deleteItem = function (obj) {
  249. var dialogHead = "<span class=\"sp-dialog-head\"><span class=\"sp-dialog-tip\">温馨提示</span><span class=\"sp-dialog-close sp-closeDialog\" title=\"关闭\">×</span></span>";
  250. var dialogBody = "<div class=\"sp-dialog-body\">删除后不可恢复,您确认要删除吗?</div>";
  251. var dialogFoot = "<div class=\"sp-dialog-foot\"><input id='delDataTrue' type='button' value='确 认' class='sp-dialog-btnTrue' /><input type='button' value='取 消' class='sp-dialog-btnCancle sp-closeDialog' /></div>";
  252. $('.sp-dialog').html(dialogHead + dialogBody + dialogFoot);
  253. sp.openCenter(".sp-dialog");
  254. ///取消按钮
  255. $('.sp-closeDialog').click(function (event) {
  256. sp.closeCenter(".sp-dialog");
  257. event.preventDefault();
  258. event.stopPropagation();
  259. });
  260. //post消息的id
  261. $("#delDataTrue").click(function () {
  262. var data = {
  263. tablename: "SX_CYZDXMTZ",
  264. id: obj.ID
  265. };
  266. $http.post(apiurljs.login + "g2app/dataabase/delDataById", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  267. .success(function (obj) {
  268. var res = strToJson(s4.decryptData_CBC(obj.data));
  269. sp.dialoghide();
  270. if (res.success) {
  271. self.getData();
  272. } else {
  273. sp.dialog("删除失败,请联系管理员!");
  274. }
  275. });
  276. });
  277. }
  278. self.upload_sign = function () {
  279. $('#fileupload-sign').fileupload({
  280. url: apiurljs.login + 'g2app/dataabase/impExecl_ByParam',
  281. dataType: 'json',
  282. beforeSend: function (xhr, data) {
  283. xhr.setRequestHeader("Authorization", "Bearer " + self.get_AccessToken);
  284. xhr.setRequestHeader("File-Argument", s4.encryptData_CBC("tablename=SX_CYZDXMTZ,columnsname=DWLX|DWMC|GLBM|XMMC|WCSX,startrow=1,othercol=CJRBMID,cyear=" + self.impYear));
  285. },
  286. add: function (e, data) {
  287. self.uploading = true;
  288. data.submit();
  289. },
  290. // 上传完成后的执行逻辑
  291. done: function (e, data) {
  292. self.uploading = false;
  293. self.getData()
  294. sp.layerhide()
  295. }
  296. })
  297. }
  298. }])