chooseShareFolderCtrl.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. angular.module('push')
  2. .controller('chooseShareFolderCtrl', function ($scope, $ionicPopup, $timeout, $stateParams, ModelService, DockingService, SqliteStorageService,
  3. HandleService, ConfigService, UserService, UtilService, AuthorityService) {
  4. if($scope.app){
  5. $scope.setStatusBar(0);
  6. }
  7. $scope.search = {searchkey: ""};
  8. var chereslist = angular.fromJson($stateParams.chereslist);
  9. var folderid = $stateParams.folderid;//被选择的记录所在文件夹ID
  10. var isCloud = $stateParams.isCloud;//区别本地与云
  11. $scope.level = 0;
  12. //第一次进入显示一级目录
  13. $scope.folderlist = angular.copy(ModelService.getFolderList());
  14. ModelService.setSelectLevelList([]);//清空已打开目录
  15. $scope.checkfolder = "";//被选中的文件夾id
  16. var checkfoldertype = -1;//被选中的文件夾类型
  17. //剔除被选择的记录所在文件夹
  18. var deleteFolderOfConnindo = function () {
  19. angular.forEach($scope.folderlist, function (value, index) {
  20. if (isCloud == 0) {
  21. if (value.localid == folderid) {
  22. $scope.folderlist.splice(index, 1);
  23. }
  24. } else if (isCloud == 1) {
  25. if (value.id == folderid) {
  26. $scope.folderlist.splice(index, 1);
  27. }
  28. }
  29. });
  30. };
  31. deleteFolderOfConnindo();
  32. //返回上一级目录
  33. $scope.backUpperFolder = function () {
  34. ModelService.deleteSelectLevelList($scope.level);
  35. $scope.level--;
  36. if ($scope.level == 0) {
  37. $scope.folderlist = angular.copy(ModelService.getFolderList());
  38. } else {
  39. var tempfolder = ModelService.getSelectLevelList()[$scope.level];
  40. if (tempfolder.isCloud == 0) {
  41. queryLocalFolder(tempfolder);
  42. } else {
  43. queryCloudFolder(tempfolder);
  44. }
  45. $scope.currentfoldername = tempfolder.name;
  46. }
  47. $scope.checkfolder = "";
  48. };
  49. //打开下一级目录
  50. $scope.openNextFolder = function (folder) {
  51. //记录本级目录
  52. var tempobj = {
  53. localid: folder.localid,
  54. id: folder.id,
  55. level: folder.level,
  56. isCloud: folder.isCloud,
  57. name: folder.name
  58. };
  59. ModelService.addSelectLevelList(tempobj);
  60. $scope.currentfoldername = folder.name;
  61. $scope.folderlist = [];
  62. $scope.level = folder.level + 1;
  63. if (folder.isCloud == 0) {
  64. queryLocalFolder(folder);
  65. } else {
  66. queryCloudFolder(folder);
  67. }
  68. $scope.checkfolder = "";
  69. };
  70. //查询本地子文件夹
  71. var queryLocalFolder = function (folder) {
  72. var q_sql = "select * from conninfofolder where localparentid = '" + folder.localid + "'";
  73. SqliteStorageService.queryData(q_sql).then(function (response) {
  74. // console.log(response);
  75. $scope.folderlist = response;
  76. deleteFolderOfConnindo();
  77. }, function () {
  78. });
  79. };
  80. //查询云子文件夹
  81. var queryCloudFolder = function (folder) {
  82. DockingService.newGetConnInfoList(folder.id, folder.level, 1).then(function (response) {
  83. // console.log(response);
  84. $scope.folderlist = response.connFolderlist;
  85. deleteFolderOfConnindo();
  86. }, function () {
  87. })
  88. };
  89. //筛选文件夹
  90. $scope.chooseFolder = function (folder, index) {
  91. angular.forEach($scope.folderlist, function (value, ind) {
  92. $scope.folderlist[ind].value = false;
  93. });
  94. if (folder.isCloud == 0) {
  95. $scope.checkfolder = folder.localid;
  96. checkfoldertype = 0;
  97. }
  98. if (folder.isCloud == 1) {
  99. $scope.checkfolder = folder.id + "";
  100. checkfoldertype = 1;
  101. }
  102. $scope.folderlist[index].value = true;
  103. /*//本地文件夹选择
  104. if (reclib.isCloud == 0) {
  105. var localindex = chooselocalfolderidlist.indexOf(reclib.localid);
  106. if (localindex == -1) {
  107. chooselocalfolderidlist.push(reclib.localid);
  108. } else {
  109. chooselocalfolderidlist.splice(localindex, 1);
  110. }
  111. }
  112. console.log(chooselocalfolderidlist);
  113. //云文件夹选择
  114. if (reclib.isCloud == 1) {
  115. var cloudindex = choosecloudfolderidlist.indexOf(reclib.id);
  116. if (cloudindex == -1) {
  117. choosecloudfolderidlist.push(reclib.id);
  118. } else {
  119. choosecloudfolderidlist.splice(cloudindex, 1);
  120. }
  121. }
  122. console.log(choosecloudfolderidlist);
  123. checklength();*/
  124. };
  125. //检测选中文件夹总数
  126. /*var checklength = function () {
  127. if (choosecloudfolderidlist.length > 0 || chooselocalfolderidlist.length > 0) {
  128. $scope.blue = "toolReleaseButton_blue";
  129. } else {
  130. $scope.blue = "";
  131. }
  132. };*/
  133. //复制记录至文件夹
  134. var clickflg = 0;
  135. $scope.copyRecordToFolder = function () {
  136. //未选中文件夹则不操作
  137. if ($scope.checkfolder.length <= 0) {
  138. return;
  139. }
  140. if (clickflg != 0) {
  141. return;
  142. }
  143. clickflg = 1;
  144. //选中记录为本地记录
  145. if (isCloud == 0) {
  146. getLocalConinfoDetail();
  147. }
  148. //选中记录为云记录
  149. if (isCloud == 1) {
  150. getCloudConinfoDetail();
  151. }
  152. $timeout(function () {
  153. clickflg = 0;
  154. }, 2500);
  155. };
  156. $scope.queryisover = 0;//0:本地对接信息开始查询 4:查询结束
  157. var conninfo = {};
  158. var picturelist = [];
  159. var cardlist = [];
  160. var personlist = [];
  161. var themelist = [];
  162. var tempproductlist = [];
  163. var tempiur1list = [];
  164. var tempiur2list = [];
  165. var tempyearprojectlist = [];
  166. //取本地记录信息
  167. var getLocalConinfoDetail = function () {
  168. var sql = "select * from conninfo where creator = " + UserService.id + " and localid = " + chereslist[0];
  169. SqliteStorageService.queryData(sql).then(function (response) {
  170. // console.log(response);
  171. conninfo = response[0];
  172. //--查询图片信息
  173. var q_pic_sql = "select * from conninfopicture where localinfoid = " + chereslist[0];
  174. SqliteStorageService.queryData(q_pic_sql).then(function (res) {
  175. // console.log(res);
  176. picturelist = res;
  177. }, function () {
  178. });
  179. //--查询名片信息
  180. var q_com_sql = "select * from conninfounit where localinfoid = " + chereslist[0];
  181. SqliteStorageService.queryData(q_com_sql).then(function (res) {
  182. // console.log(res);
  183. cardlist = res;
  184. if (cardlist.length > 0) {
  185. //组装名片localid list
  186. var cardlocalidstr = "";
  187. angular.forEach(cardlist, function (data) {
  188. var tempstr = "'" + data.localid + "'";
  189. cardlocalidstr = cardlocalidstr + tempstr + ",";
  190. });
  191. cardlocalidstr = cardlocalidstr.substring(0, cardlocalidstr.length - 1);
  192. //--查询人员信息
  193. var q_per_sql = "select * from conninfoperson where localuid in (" + cardlocalidstr + ")";
  194. SqliteStorageService.queryData(q_per_sql).then(function (resp) {
  195. // console.log(resp);
  196. personlist = resp;
  197. $scope.queryisover++;
  198. }, function () {
  199. personlist = [];
  200. $scope.queryisover++;
  201. });
  202. //--查询主题信息
  203. var q_the_sql = "select * from conninfotheme where localuid in (" + cardlocalidstr + ")";
  204. SqliteStorageService.queryData(q_the_sql).then(function (resp) {
  205. // console.log(resp);
  206. themelist = resp;
  207. $scope.queryisover++;
  208. }, function () {
  209. themelist = [];
  210. $scope.queryisover++;
  211. });
  212. //--查询产品信息
  213. var q_pro_sql = "select * from conninfoproduct where localuid in (" + cardlocalidstr + ")";
  214. SqliteStorageService.queryData(q_pro_sql).then(function (resp) {
  215. // console.log(resp);
  216. tempproductlist = resp;
  217. $scope.queryisover++;
  218. }, function () {
  219. tempproductlist = [];
  220. $scope.queryisover++;
  221. });
  222. //--查询产学研经历信息
  223. var q_iur1_sql = "select * from conninfoiur where localuid in (" + cardlocalidstr + ")";
  224. SqliteStorageService.queryData(q_iur1_sql).then(function (resp) {
  225. // console.log(resp);
  226. tempiur1list = resp;
  227. $scope.queryisover++;
  228. }, function () {
  229. tempiur1list = [];
  230. $scope.queryisover++;
  231. });
  232. //--查询重大科研项目信息
  233. var q_iur2_sql = "select * from conninforesearch where localuid in (" + cardlocalidstr + ")";
  234. SqliteStorageService.queryData(q_iur2_sql).then(function (resp) {
  235. // console.log(resp);
  236. tempiur2list = resp;
  237. $scope.queryisover++;
  238. }, function () {
  239. tempiur2list = [];
  240. $scope.queryisover++;
  241. });
  242. //--查询历年申报项目信息
  243. var q_project_sql = "select * from yearproject where localuid in (" + cardlocalidstr + ")";
  244. SqliteStorageService.queryData(q_project_sql).then(function (resp) {
  245. // console.log(resp);
  246. tempyearprojectlist = resp;
  247. $scope.isover++;
  248. }, function () {
  249. tempyearprojectlist = [];
  250. $scope.isover++;
  251. });
  252. } else {
  253. $scope.queryisover = 6;
  254. }
  255. }, function () {
  256. $scope.queryisover = 6;
  257. });
  258. }, function (err) {
  259. // console.log(err);
  260. });
  261. };
  262. //监听本地记录查询是否结束
  263. var overwatch1 = $scope.$watch("queryisover", function (newValue, oldValue, scope) {
  264. if (newValue == 6) {
  265. HandleService.handleConninfoDetailData(cardlist, personlist, themelist, tempproductlist, tempiur1list, tempiur2list, tempyearprojectlist).then(function (response) {
  266. // console.log(response);
  267. cardlist = response;
  268. //本地有文件夹选中操作-->
  269. if (checkfoldertype == 0) {
  270. saveConninfoToLocal();
  271. }
  272. //云有文件夹选中操作-->
  273. if (checkfoldertype == 1) {
  274. if (UserService.viplevel == 1) {
  275. AuthorityService.isHasEnoughCount(3).then(function (response) {
  276. if (response.isHasEnoughCount == 1) {
  277. newCreateConninfo();
  278. } else {
  279. UtilService.showMess("本月新建记录次数已用完");
  280. $scope.hideLoadingToast();
  281. }
  282. }, function () {
  283. UtilService.showMess("网络不给力,请重试");
  284. $scope.hideLoadingToast();
  285. });
  286. } else {
  287. newCreateConninfo();
  288. }
  289. }
  290. }, function () {
  291. });
  292. }
  293. });
  294. //取云记录信息
  295. var getCloudConinfoDetail = function () {
  296. DockingService.newGetConnInfoDetails(chereslist[0]).then(function (response) {
  297. // console.log(response);
  298. conninfo = response;
  299. picturelist = response.picture;
  300. cardlist = response.unit;
  301. // console.log(conninfo);
  302. // console.log(picturelist);
  303. // console.log(cardlist);
  304. //本地有文件夹选中操作-->
  305. if (checkfoldertype == 0) {
  306. saveConninfoToLocal();
  307. }
  308. //云有文件夹选中操作-->
  309. if (checkfoldertype == 1) {
  310. if (UserService.viplevel == 1) {
  311. AuthorityService.isHasEnoughCount(3).then(function (response) {
  312. if (response.isHasEnoughCount == 1) {
  313. copyConnInfo();
  314. } else {
  315. UtilService.showMess("本月新建记录次数已用完");
  316. $scope.hideLoadingToast();
  317. }
  318. }, function () {
  319. UtilService.showMess("网络不给力,请重试");
  320. $scope.hideLoadingToast();
  321. });
  322. } else {
  323. copyConnInfo();
  324. }
  325. }
  326. }, function () {
  327. });
  328. };
  329. var checknum = 1;
  330. $scope.addisover = 0;
  331. var saveConninfoToLocal = function () {
  332. try {
  333. var conninfodate = UtilService.formatDate();
  334. var conninfodatelocalid = conninfodate.timestamp;
  335. //对接信息数据生成
  336. conninfo.localid = conninfodatelocalid + "";
  337. conninfo.localclaid = $scope.checkfolder;
  338. conninfo.id = 0;
  339. conninfo.claid = 0;
  340. conninfo.creator = UserService.id;
  341. conninfo.synchrotype = 1;
  342. conninfo.createtime = conninfodate.formattime;
  343. conninfo.updatetime = conninfodate.formattime;
  344. conninfo.creatorcomefrom = ConfigService.comefrom;
  345. //图片列表数据生成
  346. if (picturelist.length > 0) {
  347. checknum++;
  348. }
  349. angular.forEach(picturelist, function (value, index) {
  350. picturelist[index].localid = conninfodatelocalid + index + "";
  351. picturelist[index].localinfoid = conninfodatelocalid + "";
  352. picturelist[index].infoid = conninfo.id;
  353. picturelist[index].id = 0;
  354. });
  355. //名片(单位)数据生成
  356. if (cardlist.length > 0) {
  357. checknum++;
  358. }
  359. var personlist = [];
  360. var themelist = [];
  361. var productlist = [];
  362. var iur1list = [];
  363. var iur2list = [];
  364. var calendarlist = [];
  365. var date = new Date();
  366. angular.forEach(cardlist, function (value, index) {
  367. var tempcardlocalid = conninfodatelocalid + index;
  368. date.setSeconds(date.getSeconds() + index);
  369. cardlist[index].localid = tempcardlocalid + "";
  370. cardlist[index].localinfoid = conninfodatelocalid + "";
  371. cardlist[index].id = 0;
  372. cardlist[index].infoid = conninfo.id;
  373. cardlist[index].creator = UserService.id;
  374. cardlist[index].synchrotype = 1;
  375. cardlist[index].creatorcomefrom = ConfigService.comefrom;
  376. cardlist[index].createtime = date.Format("yyyy-MM-dd hh:mm:ss");
  377. cardlist[index].updatetime = date.Format("yyyy-MM-dd hh:mm:ss");
  378. //人员数据生成
  379. angular.forEach(value.personlist, function (value1, ind) {
  380. var tempperson = value1;
  381. tempperson.localid = tempcardlocalid + ind + "";
  382. tempperson.localuid = tempcardlocalid + "";
  383. tempperson.id = 0;
  384. tempperson.uid = 0;
  385. tempperson.infoid = conninfo.id;
  386. personlist.push(tempperson);
  387. });
  388. //主题数据生成
  389. angular.forEach(value.themelist, function (value2, ind) {
  390. var temtheme = value2;
  391. temtheme.localid = tempcardlocalid + ind + "";
  392. temtheme.localuid = tempcardlocalid + "";
  393. temtheme.id = 0;
  394. temtheme.uid = 0;
  395. temtheme.infoid = conninfo.id;
  396. themelist.push(temtheme);
  397. });
  398. //产品数据生成
  399. angular.forEach(value.productlist, function (value3, ind) {
  400. var temproduct = value3;
  401. temproduct.localid = tempcardlocalid + ind + "";
  402. temproduct.localuid = tempcardlocalid + "";
  403. temproduct.id = 0;
  404. temproduct.uid = 0;
  405. temproduct.infoid = conninfo.id;
  406. productlist.push(temproduct);
  407. });
  408. //产学研经历数据生成
  409. angular.forEach(value.iur1list, function (value4, ind) {
  410. var temiur1 = value4;
  411. temiur1.localid = tempcardlocalid + ind + "";
  412. temiur1.localuid = tempcardlocalid + "";
  413. temiur1.id = 0;
  414. temiur1.uid = 0;
  415. temiur1.infoid = conninfo.id;
  416. iur1list.push(temiur1);
  417. });
  418. //重大科研项数据生成
  419. angular.forEach(value.iur2list, function (value5, ind) {
  420. var temiur2 = value5;
  421. temiur2.localid = tempcardlocalid + ind + "";
  422. temiur2.localuid = tempcardlocalid + "";
  423. temiur2.id = 0;
  424. temiur2.uid = 0;
  425. temiur2.infoid = conninfo.id;
  426. iur2list.push(temiur2);
  427. });
  428. //历年申报项目数据生成
  429. angular.forEach(value.calendarlist, function (value2, ind) {
  430. var tempproject = value2;
  431. tempproject.localid = tempcardlocalid + ind + "";
  432. tempproject.localuid = tempcardlocalid + "";
  433. tempproject.id = 0;
  434. tempproject.uid = 0;
  435. tempproject.infoid = conninfo.id;
  436. calendarlist.push(tempproject);
  437. });
  438. });
  439. if (personlist.length > 0) {
  440. checknum++;
  441. }
  442. if (themelist.length > 0) {
  443. checknum++;
  444. }
  445. if (productlist.length > 0) {
  446. checknum++;
  447. }
  448. if (iur1list.length > 0) {
  449. checknum++;
  450. }
  451. if (iur2list.length > 0) {
  452. checknum++;
  453. }
  454. if (calendarlist.length > 0) {
  455. checknum++;
  456. }
  457. // console.log("===========================================");
  458. // console.log(conninfo);
  459. // console.log(picturelist);
  460. // console.log(cardlist);
  461. // console.log(personlist);
  462. // console.log(themelist);
  463. // console.log("===========================================");
  464. } catch (e) {
  465. $scope.hideLoadingToast();
  466. }
  467. SqliteStorageService.insertSingleData("conninfo", conninfo).then(function () {
  468. $scope.addisover++;
  469. var tempobj = {
  470. localid: $scope.checkfolder,
  471. updatetime: conninfodate.formattime
  472. };
  473. SqliteStorageService.updateSingleData("conninfofolder", tempobj);
  474. }, function () {
  475. $scope.hideLoadingToast();
  476. });
  477. if (picturelist.length > 0) {
  478. SqliteStorageService.insertBatchData("conninfopicture", picturelist).then(function () {
  479. $scope.addisover++;
  480. }, function () {
  481. $scope.hideLoadingToast();
  482. });
  483. }
  484. if (cardlist.length > 0) {
  485. SqliteStorageService.insertBatchData("conninfounit", cardlist).then(function () {
  486. $scope.addisover++;
  487. }, function () {
  488. $scope.hideLoadingToast();
  489. });
  490. }
  491. if (personlist.length > 0) {
  492. SqliteStorageService.insertBatchData("conninfoperson", personlist).then(function () {
  493. $scope.addisover++;
  494. }, function () {
  495. $scope.hideLoadingToast();
  496. });
  497. }
  498. if (themelist.length > 0) {
  499. SqliteStorageService.insertBatchData("conninfotheme", themelist).then(function () {
  500. $scope.addisover++;
  501. }, function () {
  502. $scope.hideLoadingToast();
  503. });
  504. }
  505. if (productlist.length > 0) {
  506. SqliteStorageService.insertBatchData("conninfoproduct", productlist).then(function () {
  507. $scope.addisover++;
  508. }, function () {
  509. $scope.hideLoadingToast();
  510. });
  511. }
  512. if (iur1list.length > 0) {
  513. SqliteStorageService.insertBatchData("conninfoiur", iur1list).then(function () {
  514. $scope.addisover++;
  515. }, function () {
  516. $scope.hideLoadingToast();
  517. });
  518. }
  519. if (iur2list.length > 0) {
  520. SqliteStorageService.insertBatchData("conninforesearch", iur2list).then(function () {
  521. $scope.addisover++;
  522. }, function () {
  523. $scope.hideLoadingToast();
  524. });
  525. }
  526. if (calendarlist.length > 0) {
  527. SqliteStorageService.insertBatchData("yearproject", calendarlist).then(function () {
  528. $scope.addisover++;
  529. }, function () {
  530. $scope.hideLoadingToast();
  531. });
  532. }
  533. };
  534. //监听本地记录新增是否结束(云到本地、本地到本地)
  535. var overwatch2 = $scope.$watch("addisover", function (newValue, oldValue, scope) {
  536. if (newValue == checknum) {
  537. UtilService.showMess("复制成功");
  538. $timeout(function () {
  539. $scope.goback();
  540. }, 1000);
  541. ConfigService.isedit = 1;
  542. SqliteStorageService.updateEditFlg(1);
  543. }
  544. });
  545. //本地到云复制
  546. var newCreateConninfo = function () {
  547. conninfo.conntime = conninfo.conntime.substring(0, 16);
  548. conninfo.claid = $scope.checkfolder;
  549. DockingService.newCreateConninfo(conninfo, picturelist, cardlist).then(function () {
  550. UtilService.showMess("复制成功");
  551. if (UserService.viplevel == 1) {
  552. $scope.deductUserMemberCount(3);
  553. }
  554. $timeout(function () {
  555. $scope.goback();
  556. }, 1000);
  557. }, function () {
  558. })
  559. };
  560. //云到云复制
  561. var copyConnInfo = function () {
  562. DockingService.copyConnInfo(1, folderid, $scope.checkfolder, chereslist[0]).then(function () {
  563. UtilService.showMess("复制成功");
  564. if (UserService.viplevel == 1) {
  565. $scope.deductUserMemberCount(3);
  566. }
  567. $timeout(function () {
  568. $scope.goback();
  569. }, 1000);
  570. }, function () {
  571. })
  572. };
  573. //离开页面关闭监听
  574. $scope.$on('$ionicView.beforeLeave', function () {
  575. overwatch1();
  576. overwatch2();
  577. });
  578. });