AbutmentHomeCtrl.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. angular.module('push')
  2. .controller('AbutmentHomeCtrl', function ($scope, $timeout, $rootScope, SqliteStorageService, SynchroService, UserService, HandleService,
  3. $ionicPopup, UtilService, ConfigService, ModelService, $ionicListDelegate, HomeService, DockingService) {
  4. $scope.user = UserService.user.user;
  5. $scope.shownone = false;//是否显示无网络页面
  6. var loadflg = false;
  7. //进入云文件夹详情
  8. $scope.goSpecifyFolder = function (folder) {
  9. $scope.go('cloudFolderDetail', {folder: angular.toJson(folder)});
  10. };
  11. /*==============================以上为版本更新内容,以下为数据显示及同步内容==============================*/
  12. /*TODO--9、server数据回写*/
  13. var updateHandleData = function (res) {
  14. if (res.insertList) {
  15. // console.log("-------------------res.insertList------------------------");
  16. // console.log(res.insertList);
  17. for (key in res.insertList) {
  18. SqliteStorageService.insertBatchData(key, res.insertList[key]).then(function () {
  19. // console.log("批量insert成功");
  20. }, function () {
  21. })
  22. }
  23. }
  24. if (res.updateList) {
  25. // console.log("-------------------res.updateList------------------------");
  26. // console.log(res.updateList);
  27. for (key in res.updateList) {
  28. SqliteStorageService.updateBatchData(key, res.updateList[key]).then(function () {
  29. // console.log("批量修改成功");
  30. }, function () {
  31. })
  32. }
  33. }
  34. if (res.deleteList) {
  35. // console.log("-------------------res.deleteList------------------------");
  36. // console.log(res.deleteList);
  37. for (key in res.deleteList) {
  38. SqliteStorageService.deleteBatchData(key, res.deleteList[key]).then(function () {
  39. // console.log("批量delete成功");
  40. }, function () {
  41. })
  42. }
  43. }
  44. if (res.conninfopicture.length > 0) {
  45. // console.log("-------------------res.conninfopicture------------------------");
  46. // console.log(res.conninfopicture);
  47. angular.forEach(res.conninfopicture, function (value, index) {
  48. var del_pic_sql = "delete from conninfopicture where localinfoid = " + value.localinfoid;
  49. SqliteStorageService.deleteData(del_pic_sql).then(function () {
  50. // console.log("依据localinfoid删除图片成功");
  51. if (value.picturelist.length > 0) {
  52. SqliteStorageService.insertBatchData("conninfopicture", value.picturelist).then(function () {
  53. // console.log("批量修改图片成功");
  54. }, function () {
  55. })
  56. }
  57. }, function () {
  58. })
  59. });
  60. }
  61. if (res.conninfoperson.length > 0) {
  62. // console.log("-------------------res.conninfoperson------------------------");
  63. // console.log(res.conninfoperson);
  64. angular.forEach(res.conninfoperson, function (value, index) {
  65. var del_pic_sql = "delete from conninfoperson where localuid = " + value.localuid;
  66. SqliteStorageService.deleteData(del_pic_sql).then(function () {
  67. // console.log("依据localuid删除人员成功");
  68. if (value.personlist.length > 0) {
  69. SqliteStorageService.insertBatchData("conninfoperson", value.personlist).then(function () {
  70. // console.log("批量修改人员成功");
  71. }, function () {
  72. })
  73. }
  74. }, function () {
  75. })
  76. });
  77. }
  78. if (res.conninfotheme.length > 0) {
  79. // console.log("-------------------res.conninfotheme------------------------");
  80. // console.log(res.conninfotheme);
  81. angular.forEach(res.conninfotheme, function (value, index) {
  82. var del_pic_sql = "delete from conninfotheme where localuid = " + value.localuid;
  83. SqliteStorageService.deleteData(del_pic_sql).then(function () {
  84. // console.log("依据localuid删除主题成功");
  85. if (value.themelist.length > 0) {
  86. SqliteStorageService.insertBatchData("conninfotheme", value.themelist).then(function () {
  87. // console.log("批量修改主题成功");
  88. }, function () {
  89. })
  90. }
  91. }, function () {
  92. })
  93. });
  94. }
  95. if (res.conninfoproduct.length > 0) {
  96. // console.log("-------------------res.conninfoproduct------------------------");
  97. // console.log(res.conninfoproduct);
  98. angular.forEach(res.conninfoproduct, function (value, index) {
  99. var del_pro_sql = "delete from conninfoproduct where localuid = " + value.localuid;
  100. SqliteStorageService.deleteData(del_pro_sql).then(function () {
  101. // console.log("依据localuid删除产品成功");
  102. if (value.productlist.length > 0) {
  103. SqliteStorageService.insertBatchData("conninfoproduct", value.productlist).then(function () {
  104. // console.log("批量修改产品成功");
  105. }, function () {
  106. })
  107. }
  108. }, function () {
  109. })
  110. });
  111. }
  112. if (res.conninfoiur.length > 0) {
  113. // console.log("-------------------res.conninfoiur------------------------");
  114. // console.log(res.conninfoiur);
  115. angular.forEach(res.conninfoiur, function (value, index) {
  116. var del_iur1_sql = "delete from conninfoiur where localuid = " + value.localuid;
  117. SqliteStorageService.deleteData(del_iur1_sql).then(function () {
  118. // console.log("依据localuid删除产学研经历成功");
  119. if (value.iur1list.length > 0) {
  120. SqliteStorageService.insertBatchData("conninfoiur", value.iur1list).then(function () {
  121. // console.log("批量修改产学研经历成功");
  122. }, function () {
  123. })
  124. }
  125. }, function () {
  126. })
  127. });
  128. }
  129. if (res.conninforesearch.length > 0) {
  130. // console.log("-------------------res.conninforesearch------------------------");
  131. // console.log(res.conninforesearch);
  132. angular.forEach(res.conninforesearch, function (value, index) {
  133. var del_iur2_sql = "delete from conninforesearch where localuid = " + value.localuid;
  134. SqliteStorageService.deleteData(del_iur2_sql).then(function () {
  135. // console.log("依据localuid删除重大科研项目成功");
  136. if (value.iur2list.length > 0) {
  137. SqliteStorageService.insertBatchData("conninforesearch", value.iur2list).then(function () {
  138. // console.log("批量修改重大科研项目成功");
  139. }, function () {
  140. })
  141. }
  142. }, function () {
  143. })
  144. });
  145. }
  146. $timeout(function () {
  147. if (ConfigService.synchroflg || loadflg) {
  148. UtilService.showMess("同步完成");
  149. loadflg = false;
  150. ConfigService.synchroflg = false;
  151. }
  152. ConfigService.isedit = 0;
  153. SqliteStorageService.updateEditFlg(0);
  154. $scope.hideLoadingToast();
  155. $scope.initFolderList();
  156. }, 300);
  157. };
  158. /*TODO--8、处理server返回数据,按表划分*/
  159. var handleResponseData = function (tempresponse) {
  160. //--第一次,本地没有数据,server数据全部返回处理
  161. if (tempresponse.responsetype == 1) {
  162. if (angular.isDefined(tempresponse.folderlist) && tempresponse.folderlist.length > 0) {
  163. HandleService.handleFirstServerData(tempresponse.folderlist).then(function (res) {
  164. // console.log("处理返回数据,按表划分");
  165. // console.log(res);
  166. for (key in res) {
  167. SqliteStorageService.insertBatchData(key, res[key]).then(function (res) {
  168. // console.log("OK")
  169. }, function () {
  170. })
  171. }
  172. $timeout(function () {
  173. if (ConfigService.synchroflg || loadflg) {
  174. UtilService.showMess("同步完成");
  175. loadflg = false;
  176. ConfigService.synchroflg = false;
  177. }
  178. ConfigService.isedit = 0;
  179. SqliteStorageService.updateEditFlg(0);
  180. $scope.hideLoadingToast();
  181. $scope.initFolderList();
  182. }, 300);
  183. }, function () {
  184. $scope.hideLoadingToast();
  185. });
  186. } else {
  187. $scope.hideLoadingToast();
  188. }
  189. }
  190. //--第二及之后,本地有数据,server数据部分返回处理
  191. if (tempresponse.responsetype == 2) {
  192. HandleService.handleSecondServerData(tempresponse.folderReturnList, tempresponse.recordReturnList, tempresponse.cardReturnList).then(function (res) {
  193. // console.log("按增删改处理同步返回的数据");
  194. // console.log(res);
  195. updateHandleData(res);
  196. }, function () {
  197. $scope.hideLoadingToast();
  198. });
  199. }
  200. };
  201. /*TODO--7、同步本地数据*/
  202. var uplocalfolderlist = [];//本地查询的所有文件夹
  203. var Synchro = function (tempconninfolist, tempcardlist) {
  204. // console.log("-------------------请求同步----------------");
  205. uplocalfolderlist.sort(function (a, b) {
  206. return a.level - b.level;//置顶(level)升序
  207. });
  208. // console.log(uplocalfolderlist);
  209. // console.log(tempconninfolist);
  210. // console.log(tempcardlist);
  211. SynchroService.synchroAllData(uplocalfolderlist, tempconninfolist, tempcardlist).then(function (response) {
  212. // console.log("-------------------同步返回的数据----------------");
  213. // console.log(response);
  214. handleResponseData(response);
  215. }, function () {
  216. // $scope.hideLoadingToast();
  217. })
  218. };
  219. /*TODO--6、若有图片,同步上传图片*/
  220. var uploadImages = function (responsedata) {
  221. SynchroService.uploadImages(responsedata.conninfolist).then(function (res_conninfolist) {
  222. Synchro(res_conninfolist, responsedata.cardlist);
  223. }, function () {
  224. // $scope.hideLoadingToast();
  225. });
  226. };
  227. /*TODO--5、处理本地记录相关信息:conninfolist,cardlist*/
  228. var handleRequestData = function () {
  229. HandleService.handleRequestData(conninfolist, picturelist, cardlist, persionlist, themelist, productlist, iur1list, iur2list).then(function (response) {
  230. // console.log("-------------------记录、名片分别拼接,返回结果如下----------------");
  231. // console.log(response);
  232. if (picturelist.length > 0) {
  233. //检测本地图片是否均已上传,若未上传则去上传,否则直接去同步
  234. var count = 0;
  235. for (var i = 0; i < picturelist.length; i++) {
  236. if (picturelist[i].photo_name.indexOf("file:") != -1) {
  237. count++;
  238. break;
  239. }
  240. }
  241. if (count > 0) {
  242. uploadImages(response);
  243. } else {
  244. Synchro(response.conninfolist, response.cardlist)
  245. }
  246. } else {
  247. //无图片,直接去同步
  248. Synchro(response.conninfolist, response.cardlist)
  249. }
  250. }, function () {
  251. $scope.hideLoadingToast();
  252. });
  253. };
  254. var checknum = 1;
  255. $scope.isover = 0;//0:本地对接记录开始查询 4:查询结束
  256. var conninfolist = [];
  257. var picturelist = [];
  258. var cardlist = [];
  259. var persionlist = [];
  260. var themelist = [];
  261. var productlist = [];
  262. var iur1list = [];
  263. var iur2list = [];
  264. /*TODO--2、获取本地对接记录列表*/
  265. var getConninfoList = function () {
  266. var folderidlist = "";
  267. angular.forEach(templocalfolderlist, function (value) {
  268. if (value.localparentid == null || value.localparentid == "0") {
  269. var tempstr = "'" + value.localid + "'";
  270. folderidlist = folderidlist + tempstr + ",";
  271. }
  272. });
  273. folderidlist = folderidlist.substring(0, folderidlist.length - 1);
  274. var sql = "select * from conninfo where localclaid in (" + folderidlist + ") or creator = " + UserService.id + " order by conntime desc";
  275. SqliteStorageService.queryData(sql).then(function (response) {
  276. // console.log("获取本地对接记录列表:");
  277. // console.log(response);
  278. conninfolist = response;
  279. //计算本地文件夹下信息总数
  280. HandleService.computeFolderCounts(templocalfolderlist, conninfolist).then(function (respp) {
  281. templocalfolderlist = respp;
  282. $scope.contactflg++;
  283. }, function () {
  284. $scope.contactflg++;
  285. });
  286. //存在对接记录时,查询对接记录下各信息
  287. if (conninfolist.length > 0) {
  288. checknum++;
  289. /*--2.2、拼接对接记录localid*/
  290. var infoidlist = "";
  291. angular.forEach(conninfolist, function (value) {
  292. var tempstr = "'" + value.localid + "'";
  293. infoidlist = infoidlist + tempstr + ",";
  294. });
  295. infoidlist = infoidlist.substring(0, infoidlist.length - 1);
  296. /*--2.3、查询对接记录下名片列表*/
  297. var q_com_sql = "select * from conninfounit where localinfoid in (" + infoidlist + ")";
  298. SqliteStorageService.queryData(q_com_sql).then(function (res) {
  299. // console.log("查询本地名片信息:");
  300. // console.log(res);
  301. cardlist = res;
  302. //存在名片时,查询名片下各信息
  303. if (cardlist.length > 0) {
  304. checknum = checknum + 4;
  305. /*--2.3.1、拼接本地名片id*/
  306. var uidlist = "";
  307. angular.forEach(cardlist, function (value) {
  308. var tempstr = "'" + value.localid + "'";
  309. uidlist = uidlist + tempstr + ",";
  310. });
  311. uidlist = uidlist.substring(0, uidlist.length - 1);
  312. /*--2.3.2、查询名片下人员列表*/
  313. var q_per_sql = "select * from conninfoperson where localuid in (" + uidlist + ")";
  314. SqliteStorageService.queryData(q_per_sql).then(function (resp) {
  315. // console.log("查询本地人员信息:");
  316. // console.log(resp);
  317. persionlist = resp;
  318. $scope.isover++;
  319. }, function () {
  320. $scope.isover++;
  321. });
  322. /*--2.3.3、查询名片下主题列表*/
  323. var q_the_sql = "select * from conninfotheme where localuid in (" + uidlist + ")";
  324. SqliteStorageService.queryData(q_the_sql).then(function (resp) {
  325. // console.log("查询本地主题信息:");
  326. // console.log(resp);
  327. themelist = resp;
  328. $scope.isover++;
  329. }, function () {
  330. $scope.isover++;
  331. });
  332. //--2.3.4、查询产品信息
  333. var q_pro_sql = "select * from conninfoproduct where localuid in (" + uidlist + ")";
  334. SqliteStorageService.queryData(q_pro_sql).then(function (resp) {
  335. // console.log(resp);
  336. productlist = resp;
  337. $scope.isover++;
  338. }, function () {
  339. $scope.isover++;
  340. });
  341. //--2.3.5、查询产学研经历信息
  342. var q_iur1_sql = "select * from conninfoiur where localuid in (" + uidlist + ")";
  343. SqliteStorageService.queryData(q_iur1_sql).then(function (resp) {
  344. // console.log(resp);
  345. iur1list = resp;
  346. $scope.isover++;
  347. }, function () {
  348. $scope.isover++;
  349. });
  350. //--2.3.6、查询重大科研项目信息
  351. var q_iur2_sql = "select * from conninforesearch where localuid in (" + uidlist + ")";
  352. SqliteStorageService.queryData(q_iur2_sql).then(function (resp) {
  353. // console.log(resp);
  354. iur2list = resp;
  355. $scope.isover++;
  356. }, function () {
  357. $scope.isover++;
  358. });
  359. } else {
  360. //无名片去请求同步
  361. $scope.isover++;
  362. }
  363. }, function () {
  364. $scope.isover++;
  365. });
  366. /*--2.4、查询对接记录下图片列表*/
  367. var q_pic_sql = "select * from conninfopicture where localinfoid in (" + infoidlist + ")";
  368. SqliteStorageService.queryData(q_pic_sql).then(function (res) {
  369. // console.log("查询本地图片信息:");
  370. // console.log(res);
  371. picturelist = res;
  372. $scope.isover++;
  373. }, function () {
  374. $scope.isover++;
  375. });
  376. } else {
  377. //无对接记录(1、无需计算folder--counts,2、去请求同步)
  378. $scope.isover++;
  379. }
  380. }, function (err) {
  381. //--ERROR:对接记录请求失败,单独处理分类
  382. // console.log(err);
  383. $scope.contactflg++;
  384. });
  385. };
  386. //--监听查询是否结束
  387. $scope.$watch("isover", function (newValue) {
  388. if (newValue == checknum) {
  389. if (UtilService.checkNetWork() != "None") {
  390. /*--2.6、所有数据查询结束后,汇总处理,组装同步请求数据*/
  391. if (ConfigService.synchroflg || ConfigService.isedit == 1) {
  392. if (conninfolist.length < 1) {
  393. Synchro([], []);
  394. } else {
  395. handleRequestData();
  396. }
  397. }
  398. }
  399. checknum = 1;
  400. $scope.isover = 0;
  401. }
  402. });
  403. //初始化文件夹列表
  404. $scope.contactflg = 0;//0:本地/云文件夹开始查询 4:查询结束
  405. var templocalfolderlist = [];
  406. var tempcloudfolderlist = [];
  407. $scope.initFolderList = function () {
  408. $scope.contactflg = 0;
  409. $scope.showLoadingToast();
  410. //--查询本地文件夹
  411. var sql = "select * from conninfofolder where userid = " + UserService.id + " and isCloud = 0 and type = 1 order by updatetime desc";
  412. SqliteStorageService.queryData(sql).then(function (response) {
  413. // console.log(response);
  414. templocalfolderlist = response;
  415. uplocalfolderlist = angular.copy(response);
  416. if (response.length > 0) {
  417. getConninfoList();
  418. } else {
  419. if (ConfigService.isedit == 1) {
  420. Synchro([], []);
  421. }
  422. $scope.contactflg++;
  423. }
  424. }, function () {
  425. templocalfolderlist = [];
  426. $scope.contactflg++;
  427. });
  428. //--查询云文件夹
  429. DockingService.newGetFolderList().then(function (response) {
  430. if (UtilService.isDefined(response.folderlist)) {
  431. tempcloudfolderlist = response.folderlist;
  432. } else {
  433. tempcloudfolderlist = [];
  434. }
  435. $scope.contactflg++;
  436. }, function () {
  437. tempcloudfolderlist = [];
  438. $scope.contactflg++;
  439. })
  440. };
  441. //拼接本地与云文件夹(按sort、updatetime排序)
  442. var connectLocalAndCloud = function () {
  443. HandleService.connectLocalAndCloud(templocalfolderlist, tempcloudfolderlist).then(function (response) {
  444. $scope.folderlist = response;
  445. if ($scope.folderlist.length == 0) {
  446. $scope.shownone = true;
  447. } else {
  448. $scope.shownone = false;
  449. }
  450. ModelService.setFolderList(response);
  451. $scope.hideLoadingToast();
  452. }, function () {
  453. $scope.hideLoadingToast();
  454. })
  455. };
  456. //--监听本地与云文件夹查询是否结束
  457. $scope.$watch("contactflg", function (newValue) {
  458. if (newValue == 2) {
  459. //本地与云均无,显示缺省页
  460. if (tempcloudfolderlist.length == 0 && templocalfolderlist.length == 0) {
  461. $scope.shownone = true;
  462. $scope.folderlist = [];
  463. // Synchro([], []);
  464. $scope.hideLoadingToast();
  465. } else {
  466. //无云文件夹显示本地
  467. if (tempcloudfolderlist.length < 1) {
  468. $scope.folderlist = templocalfolderlist;
  469. ModelService.setFolderList($scope.folderlist);
  470. $scope.hideLoadingToast();
  471. }
  472. //无本地文件夹显示云
  473. if (templocalfolderlist.length < 1) {
  474. $scope.folderlist = tempcloudfolderlist;
  475. ModelService.setFolderList($scope.folderlist);
  476. $scope.hideLoadingToast();
  477. }
  478. //本地与云均有去拼接
  479. if (tempcloudfolderlist.length > 0 && templocalfolderlist.length > 0) {
  480. connectLocalAndCloud();
  481. }
  482. $scope.shownone = false;
  483. }
  484. ModelService.setLocalFolderList(templocalfolderlist);
  485. ModelService.setCloudFolderList(tempcloudfolderlist);
  486. $scope.contactflg = 0;
  487. }
  488. });
  489. //页面缓存,每次进入刷选数据
  490. $scope.$on('$ionicView.beforeEnter', function () {
  491. $scope.showMoreAction = true;
  492. $scope.initFolderList();
  493. if($scope.app){
  494. $scope.setStatusBar(1);
  495. }
  496. });
  497. //下拉刷新数据
  498. $scope.refreshData = function () {
  499. ConfigService.isedit = 1;
  500. loadflg = true;
  501. $scope.initFolderList();
  502. $scope.$broadcast('scroll.refreshComplete');
  503. var trHtml = "<div class='refresh_tip_div'>更新了" + $scope.folderlist.length + "条内容</div>";
  504. $timeout(function () {
  505. $(".calendarList-content-ul .list").prepend(trHtml);
  506. $(".refresh_tip_div").animate({width: 100 + "%"}, 150);
  507. }, 800);
  508. $timeout(function () {
  509. $(".refresh_tip_div").slideUp();
  510. }, 1200);
  511. };
  512. //新建记录
  513. $scope.addRecord = function () {
  514. if ($scope.folderlist.length < 1) {
  515. UtilService.showMess("您还没有文件夹,去新建文件夹吧");
  516. return;
  517. }
  518. ModelService.setCreateType(0);
  519. ModelService.setCheckdeFolder($scope.folderlist[0]);
  520. $scope.go('cloudAddConnInfo');
  521. };
  522. //进入分类详情,记录列表
  523. $scope.queryFolder = function (folder) {
  524. ModelService.setCheckdeFolder(folder);
  525. if (UtilService.isDefined(folder.localid)) {
  526. //本地文件夹记录列表
  527. $scope.go('conninfolist', {folder: angular.toJson(folder)});
  528. } else {
  529. //云文件夹记录列表
  530. $scope.go('cloudFolderDetail', {folder: angular.toJson(folder)});
  531. }
  532. };
  533. //展开按钮
  534. $scope.showAction = function () {
  535. $scope.showMoreAction = !$scope.showMoreAction;
  536. };
  537. //关闭按钮
  538. $scope.actionButton_three = function () {
  539. $scope.showMoreAction = !$scope.showMoreAction;
  540. };
  541. //新建文件夹
  542. $scope.buildNewFolder = function () {
  543. $scope.go("authorityCreate", {templettype: 2});
  544. };
  545. //进入设置资源库页面
  546. $scope.goAutoritySet = function (reclib) {
  547. $timeout(function () {
  548. $ionicListDelegate.closeOptionButtons();
  549. }, 10);
  550. if (UtilService.isDefined(reclib.localid)) {
  551. $scope.go("authorityLocalSet", {authoritydata: angular.toJson(reclib), type: 0, goflg: 0});
  552. } else {
  553. $scope.go("authoritySet", {
  554. reclibid: reclib.id,
  555. authorityid: reclib.authorityid,
  556. authoritycomefrom: reclib.authoritycomefrom,
  557. name: reclib.name,
  558. content: reclib.content,
  559. sort: reclib.sort,
  560. type: 0,
  561. parentid: reclib.parentid
  562. });
  563. }
  564. };
  565. //跳转工具搜索
  566. $scope.goToolsSearch = function () {
  567. $timeout(function () {
  568. $scope.go("connsearch");
  569. }, 300);
  570. }
  571. });