workRecord.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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 = "workList.html?lastReturnPageno=" + self.get_lastReturnPageno
  14. self.deviceType = localStorage.getItem("tjJxtGoldenlinkWork-deviceType");
  15. self.read = sp.getUrlName("read");
  16. var postCfg = {
  17. headers: {
  18. 'Content-Type': 'application/json',
  19. 'Authorization': "Bearer " + self.get_AccessToken
  20. }
  21. };
  22. var weeks = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"]
  23. self.beforeUpload = function () {
  24. if (self.data.ID == 0) {
  25. var data = {
  26. tablename: "SX_ZHIBANGZRZ",
  27. data: {
  28. GLRQ: self.data.GLRQ,
  29. XINGQI: self.data.XINGQI,
  30. TIANQI: self.data.TIANQI,
  31. QIWEN: self.data.QIWEN,
  32. DBLDZW: self.data.DBLDZW,
  33. ZBYBB: self.data.ZBYBB,
  34. ZBYYB: self.data.ZBYYB,
  35. ZBJL: self.data.ZBJL,
  36. USERID: self.userId,
  37. CDATE: sp.getLocalDate()
  38. }
  39. }
  40. $http.post(apiurljs.login + "g2app/dataabase/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.success) {
  44. self.get_id = res.data;
  45. self.upload()
  46. $timeout(function () {
  47. sp.dialoghide();
  48. }, 1000)
  49. } else {
  50. sp.dialog(res.message);
  51. }
  52. })
  53. } else {
  54. self.upload()
  55. }
  56. }
  57. self.upload = function () {
  58. var acceptFileTypes = /(jpg|png)$/i
  59. $('#fileupload').fileupload({
  60. url: apiurljs.login + 'g2app/abase/saveUploadFileName',
  61. dataType: 'json',
  62. beforeSend: function (xhr, data) {
  63. xhr.setRequestHeader("Authorization", "Bearer " + self.get_AccessToken);
  64. xhr.setRequestHeader("File-Argument", s4.encryptData_CBC("tablename=SX_ZHIBANGZRZ,column=ATTACHLIST,routeinfoid=" + self.get_id + ",loaded=" + data.loaded + ",total=" + data.total));
  65. },
  66. add: function (e, data) {
  67. var num = 0;
  68. //文件类型判断
  69. $.each(data.originalFiles, function (index, item) {
  70. if (item['type'] != null && item['type'] != undefined && !acceptFileTypes.test(item['name'])) {
  71. sp.dialog("您好,请上传JPG、PNG格式的文件!");
  72. return;
  73. } else {
  74. num++
  75. }
  76. })
  77. if (num == data.originalFiles.length) {
  78. data.submit();
  79. }
  80. },
  81. // 上传完成后的执行逻辑
  82. done: function (e, data) {
  83. var arrayFile = strToJson(s4.decryptData_CBC(data.result.data).slice(0, s4.decryptData_CBC(data.result.data).lastIndexOf("}") + 1))
  84. self.arrayFile = arrayFile.data;
  85. self.arrayFile.forEach(function (item) {
  86. item.FILEURL1 = $sce.trustAsResourceUrl(apiurljs.login + "g2work" + item.FILEURL)
  87. })
  88. $scope.$apply();//绑定数据局部刷新
  89. }
  90. })
  91. $timeout(function () {
  92. $("#fileupload").trigger("click")
  93. }, 1)
  94. }
  95. self.getDBLD = function () {
  96. var data = {
  97. tablename: "SX_ZHIBANRYGL",
  98. colums: "*",
  99. order: "ID",
  100. sqlwhere: { "MANMARK": "C01" },
  101. sqlorwhere: "",
  102. sqlinwhere: "",
  103. sqllikewhere: ""
  104. }
  105. $http.post(apiurljs.login + "g2app/dataabase/queryDataByCol", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  106. .success(function (obj) {
  107. var res = strToJson(s4.decryptData_CBC(obj.data));
  108. self.DBLD = res.data;
  109. self.getData()
  110. })
  111. }
  112. self.getDBLD()
  113. //获取数据
  114. self.getData = function () {
  115. if (self.get_id == 0) {
  116. self.data = {
  117. ID: 0,
  118. GLRQ: sp.format(sp.getLocalDate()),
  119. XINGQI: weeks[new Date(sp.getLocalDate()).getDay()],
  120. TIANQI: "",
  121. QIWEN: "",
  122. DBLDZW: "",
  123. ZBYBB: "",
  124. ZBYYB: "",
  125. ZBJL: ""
  126. }
  127. self.arrayFile = [];
  128. } else {
  129. var data = {
  130. tablename: "SX_ZHIBANGZRZ",
  131. colums: "*",
  132. order: "ID desc",
  133. sqlwhere: { ID: self.get_id },
  134. sqlinwhere: "",
  135. sqllikewhere: ""
  136. }
  137. $http.post(apiurljs.login + "g2app/dataabase/queryDataByCol", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  138. .success(function (obj) {
  139. var res = strToJson(s4.decryptData_CBC(obj.data));
  140. self.data = {
  141. ID: res.data[0].ID,
  142. GLRQ: res.data[0].GLRQ ? sp.format(res.data[0].GLRQ) : sp.format(sp.getLocalDate()),
  143. XINGQI: res.data[0].XINGQI ? res.data[0].XINGQI : weeks[new Date(sp.getLocalDate()).getDay()],
  144. TIANQI: res.data[0].TIANQI ? res.data[0].TIANQI : "",
  145. QIWEN: res.data[0].QIWEN ? res.data[0].QIWEN : "",
  146. DBLDZW: res.data[0].DBLDZW ? res.data[0].DBLDZW : "",
  147. ZBYBB: res.data[0].ZBYBB ? res.data[0].ZBYBB : "",
  148. ZBYYB: res.data[0].ZBYYB ? res.data[0].ZBYYB : "",
  149. ZBJL: res.data[0].ZBJL ? res.data[0].ZBJL : "",
  150. };
  151. if (res.data[0].ATTACHLIST) {
  152. self.arrayFile = JSON.parse(res.data[0].ATTACHLIST)
  153. self.arrayFile.forEach(function (item) {
  154. item.FILEURL1 = $sce.trustAsResourceUrl(apiurljs.login + "g2work" + item.FILEURL)
  155. })
  156. console.log(self.arrayFile)
  157. } else {
  158. self.arrayFile = [];
  159. }
  160. })
  161. }
  162. }
  163. self.seePic = function (obj) {
  164. self.seePicUrl = obj.FILEURL1
  165. $('.sp-bgMask').fadeIn(200);
  166. $(".sp-bgMask").bind("click", function () {
  167. $(this).fadeOut(200);
  168. if ($("#seePic").is(":visible")) { //若对话框显示则淡出
  169. $("#seePic").fadeOut(200);
  170. }
  171. });
  172. $timeout(function () {
  173. sp.setCenter("#seePic")
  174. }, 1)
  175. }
  176. //删除附件
  177. self.deleteFile = function (item) {
  178. var data = {
  179. tablename: "SX_ZHIBANGZRZ",
  180. column: "ATTACHLIST",
  181. routeinfoid: self.get_id,
  182. fileid: item.FILEID,
  183. filenames: item.FILEOLDNAME
  184. }
  185. $http.post(apiurljs.login + "g2app/abase/deleteUploadFileName", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  186. .success(function (obj) {
  187. var res = strToJson(s4.decryptData_CBC(obj.data));
  188. if (res.success == true) {
  189. self.arrayFile = res.data;
  190. self.arrayFile.forEach(function (item) {
  191. item.FILEURL1 = $sce.trustAsResourceUrl(apiurljs.login + "g2work" + item.FILEURL)
  192. })
  193. } else {
  194. sp.dialog(res.message)
  195. }
  196. })
  197. }
  198. self.changeDate = function () {
  199. self.data.XINGQI = weeks[new Date(self.data.GLRQ).getDay()]
  200. }
  201. //保存提交
  202. self.btnSave = function (n) {
  203. if (self.get_id == 0) {
  204. var data = {
  205. tablename: "SX_ZHIBANGZRZ",
  206. data: {
  207. GLRQ: self.data.GLRQ,
  208. XINGQI: self.data.XINGQI,
  209. TIANQI: self.data.TIANQI,
  210. QIWEN: self.data.QIWEN,
  211. DBLDZW: self.data.DBLDZW,
  212. ZBYBB: self.data.ZBYBB,
  213. ZBYYB: self.data.ZBYYB,
  214. ZBJL: self.data.ZBJL,
  215. USERID: self.userId,
  216. CDATE: sp.getLocalDate()
  217. }
  218. }
  219. $http.post(apiurljs.login + "g2app/dataabase/insertFormData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  220. .success(function (obj) {
  221. var res = strToJson(s4.decryptData_CBC(obj.data));
  222. if (res.success) {
  223. sp.dialog("保存成功!");
  224. self.get_id = res.data;
  225. self.getData();
  226. $timeout(function () {
  227. sp.dialoghide();
  228. }, 1000)
  229. } else {
  230. sp.dialog(res.message);
  231. }
  232. })
  233. } else {
  234. var data = {
  235. id: self.data.ID,
  236. tablename: "SX_ZHIBANGZRZ",
  237. data: {
  238. GLRQ: self.data.GLRQ,
  239. XINGQI: self.data.XINGQI,
  240. TIANQI: self.data.TIANQI,
  241. QIWEN: self.data.QIWEN,
  242. DBLDZW: self.data.DBLDZW,
  243. ZBYBB: self.data.ZBYBB,
  244. ZBYYB: self.data.ZBYYB,
  245. ZBJL: self.data.ZBJL,
  246. }
  247. }
  248. $http.post(apiurljs.login + "g2app/dataabase/upFormData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  249. .success(function (obj) {
  250. var res = strToJson(s4.decryptData_CBC(obj.data));
  251. if (res.success) {
  252. sp.dialog("保存成功!");
  253. self.getData();
  254. $timeout(function () {
  255. sp.dialoghide();
  256. }, 1000)
  257. } else {
  258. sp.dialog(res.message);
  259. }
  260. })
  261. }
  262. }
  263. //头部下滚冻结
  264. $(function () {
  265. $(".sp-page-center").css("max-height", $(window).height() - 58).css("height", $(window).height() - 58)
  266. //页面高度撑满
  267. setTimeout(function () {
  268. if ($(".ibox-content").height() < $(window).height() - 31) {
  269. $(".ibox-content").css("height", $(window).height() - 31)
  270. }
  271. }, 1)
  272. })
  273. }])