formedit.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. 'use strict';
  2. var app = angular.module('app', [
  3. ]);
  4. app.controller("formeditCtrl", ["$scope", "$http", "$timeout", "$sce", function ($scope, $http, $timeout, $sce) {
  5. var self = this;
  6. var s4 = new SM4Util();
  7. self.userId = $.cookie("GlWorkPlatform-userid");
  8. self.userName = $.cookie("GlWorkPlatform-chineseName");
  9. self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken");
  10. self.get_id = sp.getUrlName("id");
  11. self.get_lastReturnPageno = sp.getUrlName("lastReturnPageno");
  12. self.get_lastReturnPage = sp.getUrlName("lastReturnPage");
  13. self.return = "../list.html?lastReturnPageno=" + self.get_lastReturnPageno + "&type=2"
  14. self.deviceType = localStorage.getItem("tjJxtGoldenlinkWork-deviceType");
  15. var postCfg = {
  16. headers: {
  17. 'Content-Type': 'application/json',
  18. 'Authorization': "Bearer " + self.get_AccessToken
  19. }
  20. };
  21. self.FormTitle = $.cookie("GlWorkPlatform-SYSNAME");
  22. self.getEditData = function () {
  23. if (self.get_id != 0) {
  24. var data = {
  25. tablename: "SX_HYSGLB",
  26. colums: "*",
  27. order: "ID",
  28. sqlwhere: { ID: self.get_id },
  29. sqlinwhere: "",
  30. sqllikewhere: ""
  31. }
  32. $http.post(apiurljs.login + "g2app/dataabase/queryDataByCol", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  33. .success(function (obj) {
  34. var res = strToJson(s4.decryptData_CBC(obj.data));
  35. self.data = {
  36. ID: self.get_id,
  37. HYSMC: res.data[0].HYSMC,
  38. KRNRS: res.data[0].KRNRS,
  39. SB: res.data[0].SB,
  40. WZ: res.data[0].WZ,
  41. GLY: res.data[0].GLY,
  42. ZT: res.data[0].ZT,
  43. BZ: res.data[0].BZ
  44. }
  45. })
  46. } else {
  47. self.data = {
  48. ID: 0,
  49. HYSMC: "",
  50. KRNRS: "",
  51. SB: "",
  52. WZ: "",
  53. GLY: "",
  54. ZT: "正常",
  55. BZ: ""
  56. }
  57. }
  58. }
  59. self.getEditData()
  60. self.btnSave = function () {
  61. if (self.get_id == 0) {
  62. var data = {
  63. tablename: "SX_HYSGLB",
  64. data: {
  65. HYSMC: self.data.HYSMC,
  66. KRNRS: self.data.KRNRS,
  67. SB: self.data.SB,
  68. WZ: self.data.WZ,
  69. GLY: self.data.GLY,
  70. ZT: self.data.ZT,
  71. BZ: self.data.BZ
  72. }
  73. }
  74. $http.post(apiurljs.login + "g2app/dataabase/insertFormData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  75. .success(function (obj) {
  76. var res = strToJson(s4.decryptData_CBC(obj.data));
  77. if (res.success) {
  78. sp.dialog("保存成功!");
  79. self.get_id = res.data;
  80. self.getEditData();
  81. $timeout(function () {
  82. sp.dialoghide();
  83. }, 1000)
  84. } else {
  85. sp.dialog(res.message);
  86. }
  87. })
  88. } else {
  89. var data = {
  90. id: self.get_id,
  91. tablename: "SX_HYSGLB",
  92. data: {
  93. HYSMC: self.data.HYSMC,
  94. KRNRS: self.data.KRNRS,
  95. SB: self.data.SB,
  96. WZ: self.data.WZ,
  97. GLY: self.data.GLY,
  98. ZT: self.data.ZT,
  99. BZ: self.data.BZ
  100. }
  101. }
  102. $http.post(apiurljs.login + "g2app/dataabase/upFormData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  103. .success(function (obj) {
  104. var res = strToJson(s4.decryptData_CBC(obj.data));
  105. if (res.success) {
  106. sp.dialog("保存成功!");
  107. self.getEditData();
  108. $timeout(function () {
  109. sp.dialoghide();
  110. }, 1000)
  111. } else {
  112. sp.dialog(res.message);
  113. }
  114. })
  115. }
  116. }
  117. }])