wastepaperCtrl.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. angular.module('push')
  2. .controller('wastepaperCtrl', function ($scope, $ionicActionSheet, $ionicPopup, DockingService, UtilService, SqliteStorageService, HandleService, UserService) {
  3. if($scope.app){
  4. $scope.setStatusBar(0);
  5. }
  6. var status = true;
  7. var handleConninfoDataByDate = function (templist1, templist2) {
  8. HandleService.handleConninfoDataByDate(templist1, templist2, "was").then(function (response) {
  9. // console.log("按日期处理本地对接数据完成");
  10. $scope.recordList = response.conninfolist;
  11. }, function () {
  12. })
  13. };
  14. var tempconninfolist = [];
  15. //对接信息列表初始化
  16. var getConninfoList = function () {
  17. var sql = "select * from conninfo where status = 1 and creator = " + UserService.id + " order by conntime desc";
  18. SqliteStorageService.queryData(sql).then(function (response) {
  19. // console.log(response);
  20. tempconninfolist = response;
  21. //拼接记录id
  22. var infoidlist = "";
  23. angular.forEach(response, function (value) {
  24. var tempstr = "'" + value.localid + "'";
  25. infoidlist = infoidlist + tempstr + ",";
  26. });
  27. infoidlist = infoidlist.substring(0, infoidlist.length - 1);
  28. //--查询图片信息
  29. var q_pic_sql = "select * from conninfopicture where localinfoid in (" + infoidlist + ")";
  30. SqliteStorageService.queryData(q_pic_sql).then(function (res) {
  31. // console.log(res);
  32. handleConninfoDataByDate(response, res);
  33. }, function () {
  34. });
  35. }, function () {
  36. });
  37. };
  38. getConninfoList();
  39. $scope.AllRemove = function () {
  40. // 显示记录操作表
  41. $ionicActionSheet.show({
  42. buttons: [
  43. {text: '还原记录'},
  44. {text: '<span class="ionicAction_span">清空记录</span>'}
  45. ],
  46. cancelText: '取消',
  47. buttonClicked: function (index) {
  48. if (index == 0) {
  49. $(".wastepaperDiv").css("padding-left", "15%");
  50. $("#collect-bottom").css("display", "block");
  51. status = false;
  52. } else if (index == 1) {
  53. $ionicPopup.show({
  54. template: "<p style='text-align: center;'>确定永久删除废纸篓所有记录</p>",
  55. title: "清空废纸篓",
  56. scope: $scope,
  57. buttons: [
  58. {text: "取消"},
  59. {
  60. text: '<span class="ionicAction_span">删除</span>',
  61. type: "button-positive",
  62. onTap: function (e) {
  63. deleteAll();
  64. }
  65. }
  66. ]
  67. })
  68. }
  69. return true;
  70. }
  71. });
  72. };
  73. //跳转详情检测
  74. $scope.checkStatus = function (record, rec, index) {
  75. if (status) {
  76. goRecordDetail(rec)
  77. } else {
  78. selectRecord(record, rec, index)
  79. }
  80. };
  81. var goRecordDetail = function (record) {
  82. $scope.go("Dockingdetails", {infoid: record.localid});
  83. };
  84. //编辑列表
  85. var selectRecord = function (record, rec, index) {
  86. var ii = $scope.recordList.indexOf(record);
  87. $scope.recordList[ii].reclist[index].value = !$scope.recordList[ii].reclist[index].value;
  88. countInfoidList();
  89. };
  90. var restorelist = [];
  91. $scope.selectNum = 0;
  92. //组装选中的infoid
  93. var countInfoidList = function () {
  94. restorelist = [];
  95. angular.forEach($scope.recordList, function (record, index) {
  96. angular.forEach(record.reclist, function (rec, ind) {
  97. if (rec.value) {
  98. restorelist.push(rec);
  99. }
  100. });
  101. });
  102. $scope.selectNum = restorelist.length;
  103. };
  104. //批量更新
  105. var updateBatchData = function (tablename, datalist) {
  106. SqliteStorageService.updateBatchData(tablename, datalist).then(function () {
  107. // console.log("回写成功");
  108. }, function () {
  109. });
  110. };
  111. //批量删除
  112. var deleteBatchData = function (tablename, datalist) {
  113. SqliteStorageService.deleteBatchData(tablename, datalist).then(function () {
  114. // console.log("批量delete成功");
  115. }, function () {
  116. })
  117. };
  118. var batchSynchConninfo = function (templist) {
  119. DockingService.singleSync(2, templist).then(function (res) {
  120. // console.log("还原/删除记录--批量同步成功");
  121. // console.log(res);
  122. if (angular.isDefined(res.recordReturnList) && res.recordReturnList.length > 0) {
  123. var tempconnlist_del = [];
  124. var tempconnlist_up = [];
  125. angular.forEach(res.recordReturnList, function (value, index) {
  126. var tconn = {};
  127. tconn.localid = value.localid;
  128. tconn.id = value.id;
  129. if (value.synchrotype == 4) {
  130. tempconnlist_del.push(tconn);
  131. } else {
  132. tconn.synchrotype = 0;
  133. tempconnlist_up.push(tconn);
  134. }
  135. });
  136. deleteBatchData("conninfo", tempconnlist_del);
  137. updateBatchData("conninfo", tempconnlist_up);
  138. }
  139. SqliteStorageService.updateEditFlg(1);
  140. }, function () {
  141. SqliteStorageService.updateEditFlg(1);
  142. });
  143. };
  144. var batchSynchCard = function (templist) {
  145. DockingService.singleSync(3, templist).then(function (res) {
  146. // console.log("删除名片--名片同步成功");
  147. // console.log(res);
  148. if (angular.isDefined(res.cardReturnList) && res.cardReturnList.length > 0) {
  149. var tempunitlist_del = [];
  150. angular.forEach(res.cardReturnList, function (value, index) {
  151. var tunit = {};
  152. tunit.localid = value.localid;
  153. tunit.id = value.id;
  154. tunit.infoid = value.infoid;
  155. tempunitlist_del.push(tunit);
  156. });
  157. deleteBatchData("conninfounit", tempunitlist_del);
  158. var localuid = "";
  159. angular.forEach(templist, function (data, ind) {
  160. localuid = localuid + "'" + data.localid + "'" + ",";
  161. });
  162. localuid = localuid.substring(0, localuid.length - 1);
  163. var del_per_sql = "delete from conninfoperson where localuid in (" + localuid + ")";
  164. SqliteStorageService.queryData(del_per_sql);
  165. var del_the_sql = "delete from conninfotheme where localuid in (" + localuid + ")";
  166. SqliteStorageService.queryData(del_the_sql);
  167. }
  168. }, function () {
  169. });
  170. };
  171. var handleConninfoAndPicture = function (conninfolist, picturelist) {
  172. angular.forEach(conninfolist, function (value, index) {
  173. //图片拼接
  174. var templist1 = [];
  175. angular.forEach(picturelist, function (data, ind) {
  176. if (value.localid == data.localinfoid) {
  177. templist1.push(data);
  178. }
  179. });
  180. conninfolist[index].picture = templist1;
  181. });
  182. //批量同步记录
  183. batchSynchConninfo(conninfolist);
  184. };
  185. //还原
  186. $scope.restore = function () {
  187. var templist = [];
  188. var infoidlist = "";
  189. angular.forEach(restorelist, function (value, index) {
  190. var tempdate = UtilService.formatDate();
  191. var tempobj = angular.copy(value);
  192. tempobj.status = 2;
  193. tempobj.cloudfolder = "";
  194. tempobj.updatetime = tempdate.formattime;
  195. if (UtilService.isDefined(value.id)) {
  196. tempobj.synchrotype = 2;
  197. } else {
  198. tempobj.synchrotype = 1;
  199. }
  200. templist.push(tempobj);
  201. var tempstr = "'" + value.localid + "'";
  202. infoidlist = infoidlist + tempstr + ",";
  203. });
  204. infoidlist = infoidlist.substring(0, infoidlist.length - 1);
  205. SqliteStorageService.updateBatchData("conninfo", templist).then(function (res) {
  206. //--查询图片信息
  207. var q_pic_sql = "select * from conninfopicture where localinfoid in (" + infoidlist + ")";
  208. SqliteStorageService.queryData(q_pic_sql).then(function (res) {
  209. // console.log("查询图片。。。");
  210. // console.log(res);
  211. handleConninfoAndPicture(templist, res);
  212. }, function () {
  213. SqliteStorageService.updateEditFlg(1);
  214. });
  215. UtilService.showMess("还原记录成功");
  216. getConninfoList();
  217. $scope.cancel();
  218. HandleService.changeflg = true;
  219. }, function () {
  220. SqliteStorageService.updateEditFlg(1);
  221. });
  222. };
  223. //取消
  224. $scope.cancel = function () {
  225. status = true;
  226. $(".wastepaperDiv").css("padding-left", "0%");
  227. $("#collect-bottom").css("display", "none");
  228. };
  229. //清空
  230. var deleteAll = function () {
  231. var templist = [];
  232. var localinfoidstr = "";
  233. angular.forEach(tempconninfolist, function (value, index) {
  234. var tempdate = UtilService.formatDate();
  235. var tempobj = angular.copy(value);
  236. tempobj.synchrotype = 4;
  237. tempobj.status = 3;
  238. tempobj.cloudfolder = "";
  239. tempobj.updatetime = tempdate.formattime;
  240. templist.push(tempobj);
  241. //组装名片localid list
  242. localinfoidstr = localinfoidstr + "'" + value.localid + "'" + ",";
  243. });
  244. localinfoidstr = localinfoidstr.substring(0, localinfoidstr.length - 1);
  245. SqliteStorageService.updateBatchData("conninfo", templist).then(function (res) {
  246. //批量同步记录
  247. batchSynchConninfo(templist);
  248. //--查询名片信息
  249. var q_com_sql = "select * from conninfounit where localinfoid in (" + localinfoidstr + ")";
  250. SqliteStorageService.queryData(q_com_sql).then(function (res) {
  251. // console.log(res);
  252. var tempcardlist = [];
  253. var tempdate2 = UtilService.formatDate();
  254. angular.forEach(res, function (data) {
  255. var tempobj2 = angular.copy(data);
  256. tempobj2.localid = data.localid;
  257. tempobj2.synchrotype = 4;
  258. tempobj2.updatetime = tempdate2.formattime;
  259. tempcardlist.push(tempobj2);
  260. });
  261. SqliteStorageService.updateBatchData("conninfounit", tempcardlist).then(function (res) {
  262. batchSynchCard(tempcardlist);
  263. UtilService.showMess("清空记录成功");
  264. }, function () {
  265. });
  266. });
  267. getConninfoList();
  268. HandleService.changeflg = true;
  269. SqliteStorageService.updateEditFlg(1);
  270. }, function () {
  271. });
  272. };
  273. });