detail.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. 'use strict';
  2. var app = angular.module('app', [
  3. ]);
  4. app.controller("detailCtrl", ["$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.userCName = $.cookie("GlWorkPlatform-chineseName");
  10. self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken");
  11. self.get_lastReturnPageno = sp.getUrlName("lastReturnPageno");
  12. self.get_id = sp.getUrlName("id");
  13. self.return = "list.html?lastReturnPageno=" + self.get_lastReturnPageno
  14. var postCfg = {
  15. headers: {
  16. 'Content-Type': 'application/json',
  17. 'Authorization': "Bearer " + self.get_AccessToken
  18. }
  19. };
  20. //上传附件
  21. self.beforeUpload = function () {
  22. if (self.data.ID == 0) {
  23. var data = {
  24. tablename: "SX_SJPSWJTZ",
  25. data: {
  26. LWDW: self.data.LWDW,
  27. WJMC: self.data.WJMC,
  28. SJPS: self.data.SJPS,
  29. QPSJ: self.data.QPSJ,
  30. BLJD: self.data.BLJD,
  31. DBTX: self.data.DBTX,
  32. DBTXTIME: self.data.DBTXTIME,
  33. REMARK: self.data.REMARK,
  34. FLOWROUTEINFOID: "",
  35. USERID: self.userId,
  36. SECTCODE: self.userDpCode,
  37. CDATE: sp.getLocalDate()
  38. }
  39. }
  40. $http.post(apiurljs.login + "g2app/DangJian/insertFormData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  41. .success(function (obj) {
  42. var res = strToJson(s4.decryptData_CBC(obj.data));
  43. if (res.code == 0) {
  44. self.get_id = res.data;
  45. self.getData();
  46. self.upload()
  47. } else {
  48. sp.dialog(res.message)
  49. }
  50. })
  51. } else {
  52. self.upload()
  53. }
  54. }
  55. self.upload = function () {
  56. $('#fileupload').fileupload({
  57. url: apiurljs.login + 'g2app/abase/saveUploadFileName',
  58. dataType: 'json',
  59. beforeSend: function (xhr, data) {
  60. xhr.setRequestHeader("Authorization", "Bearer " + self.get_AccessToken);
  61. xhr.setRequestHeader("File-Argument", s4.encryptData_CBC("tablename=SX_SJPSWJTZ,column=FILEATTACH,id=" + self.get_id + ",routeinfoid=" + self.get_id + ",loaded=" + data.loaded + ",total=" + data.total));
  62. },
  63. // 上传完成后的执行逻辑
  64. done: function (e, data) {
  65. var arrayFile = strToJson(s4.decryptData_CBC(data.result.data).slice(0, s4.decryptData_CBC(data.result.data).lastIndexOf("}") + 1))
  66. self.arrayFile = arrayFile.data;
  67. $scope.$apply();//绑定数据局部刷新
  68. }
  69. })
  70. $timeout(function () {
  71. $("#fileupload").trigger("click")
  72. }, 1)
  73. }
  74. self.getDP = function () {
  75. var data = {
  76. userid: self.userId
  77. }
  78. $http.post(apiurljs.login + "g2app/richang/queryDpInfo", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  79. .success(function (obj) {
  80. var res = strToJson(s4.decryptData_CBC(obj.data));
  81. self.userDpName = res.data.length == 0 ? "" : res.data[0].SECTION;
  82. self.userDpCode = res.data.length == 0 ? "" : res.data[0].CODE;
  83. self.getData();
  84. })
  85. }
  86. self.getData = function () {
  87. if (self.get_id == 0) {
  88. self.data = {
  89. ID: 0,
  90. LWDW: "",
  91. WJMC: "",
  92. SJPS: "",
  93. QPSJ: sp.format(sp.getLocalDate()),
  94. BLJD: "",
  95. DBTX: "",
  96. DBTXTIME: sp.format(sp.getLocalDate()),
  97. REMARK: ""
  98. }
  99. self.arrayFile = [];
  100. } else {
  101. var data = {
  102. tablename: "SX_SJPSWJTZ",
  103. colums: "*",
  104. order: "ID",
  105. sqlwhere: {
  106. ID: self.get_id
  107. },
  108. sqlorwhere: "",
  109. sqlinwhere: "",
  110. sqllikewhere: ""
  111. }
  112. $http.post(apiurljs.login + "g2app/dataabase/queryDataByCol", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  113. .success(function (obj) {
  114. var res = strToJson(s4.decryptData_CBC(obj.data));
  115. self.data = {
  116. ID: res.data[0].ID,
  117. LWDW: res.data[0].LWDW ? res.data[0].LWDW : "",
  118. WJMC: res.data[0].WJMC ? res.data[0].WJMC : "",
  119. SJPS: res.data[0].SJPS ? res.data[0].SJPS : "",
  120. QPSJ: res.data[0].QPSJ ? sp.format(res.data[0].QPSJ) : sp.format(sp.getLocalDate()),
  121. BLJD: res.data[0].BLJD ? res.data[0].BLJD : "",
  122. DBTX: res.data[0].DBTX ? res.data[0].DBTX : "",
  123. DBTXTIME: res.data[0].DBTXTIME ? sp.format(res.data[0].DBTXTIME) : sp.format(sp.getLocalDate()),
  124. REMARK: res.data[0].REMARK ? res.data[0].REMARK : ""
  125. }
  126. if (res.data[0].FILEATTACH && res.data[0].FILEATTACH != "") {
  127. self.arrayFile = JSON.parse(res.data[0].FILEATTACH);
  128. }
  129. })
  130. }
  131. }
  132. self.getDP()
  133. self.btnSave = function () {
  134. if (self.data.ID == 0) {
  135. var data = {
  136. tablename: "SX_SJPSWJTZ",
  137. data: {
  138. LWDW: self.data.LWDW,
  139. WJMC: self.data.WJMC,
  140. SJPS: self.data.SJPS,
  141. QPSJ: self.data.QPSJ,
  142. BLJD: self.data.BLJD,
  143. DBTX: self.data.DBTX,
  144. DBTXTIME: self.data.DBTXTIME,
  145. REMARK: self.data.REMARK,
  146. FLOWROUTEINFOID: "",
  147. USERID: self.userId,
  148. SECTCODE: self.userDpCode,
  149. CDATE: sp.getLocalDate()
  150. }
  151. }
  152. $http.post(apiurljs.login + "g2app/dataabase/insertFormData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  153. .success(function (obj) {
  154. var res = strToJson(s4.decryptData_CBC(obj.data));
  155. if (res.success) {
  156. sp.dialog("保存成功!");
  157. self.get_id = res.data;
  158. self.getData();
  159. $timeout(function () {
  160. sp.dialoghide();
  161. }, 1000)
  162. } else {
  163. sp.dialog(res.message);
  164. }
  165. })
  166. } else {
  167. var data = {
  168. id: self.data.ID,
  169. tablename: "SX_SJPSWJTZ",
  170. data: {
  171. LWDW: self.data.LWDW,
  172. WJMC: self.data.WJMC,
  173. SJPS: self.data.SJPS,
  174. QPSJ: self.data.QPSJ,
  175. BLJD: self.data.BLJD,
  176. DBTX: self.data.DBTX,
  177. DBTXTIME: self.data.DBTXTIME,
  178. REMARK: self.data.REMARK,
  179. }
  180. }
  181. $http.post(apiurljs.login + "g2app/dataabase/upFormData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  182. .success(function (obj) {
  183. var res = strToJson(s4.decryptData_CBC(obj.data));
  184. if (res.success) {
  185. sp.dialog("保存成功!");
  186. self.getData();
  187. $timeout(function () {
  188. sp.dialoghide();
  189. }, 1000)
  190. } else {
  191. sp.dialog(res.message);
  192. }
  193. })
  194. }
  195. }
  196. }])