editConninfoCtrl.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937
  1. angular.module('push')
  2. .controller('editConninfoCtrl', function ($scope, $stateParams, $ionicActionSheet, $ionicModal, $timeout, UserService, $ionicSlideBoxDelegate,
  3. UtilService, ModelService, $ionicScrollDelegate, HandleService, SqliteStorageService, ConfigService) {
  4. var localinfoid = $stateParams.infoid;//是localinfoid
  5. $scope.folderlist = angular.copy(ModelService.getLocalFolderList());//分类列表
  6. $scope.level = 0;
  7. $scope.checkfolder = "";//被选中的文件夾id
  8. var copyrecord = {};
  9. var copyimagelist = [];
  10. //处理名片(名片下多个人员,则姓名组装-->XXX、XXX、XXX)
  11. var handleCard = function () {
  12. angular.forEach($scope.cardlist, function (value, index) {
  13. if (angular.isDefined(value.personlist) && value.personlist.length > 0) {
  14. var contactsrt = [];
  15. angular.forEach(value.personlist, function (val, ind) {
  16. contactsrt.push(val.contact);
  17. });
  18. $scope.cardlist[index].contactsrt = contactsrt.join("、");
  19. }
  20. $scope.cardlist[index].type = parseInt(value.type);
  21. });
  22. };
  23. //拼接名片下单位、人员、主题
  24. var handleConninfoDetailData = function () {
  25. HandleService.handleConninfoDetailData(tempcardlist, temppersonlist, tempthemelist, tempproductlist, tempiur1list, tempiur2list, tempyearprojectlist).then(function (response) {
  26. // console.log(response);
  27. $scope.cardlist = response;
  28. handleCard();
  29. }, function () {
  30. });
  31. //关闭监听
  32. overwatch();
  33. };
  34. //查找该记录所属本地文件夹
  35. var queryCheckFolder = function (localclaid) {
  36. var q_sql = "select * from conninfofolder where localid = '" + localclaid + "'";
  37. SqliteStorageService.queryData(q_sql).then(function (response) {
  38. // console.log(response);
  39. $scope.checkdefolder = response[0];
  40. $scope.checkfolder = $scope.checkdefolder.localid;
  41. }, function () {
  42. });
  43. angular.forEach($scope.folderlist, function (value, index) {
  44. if (value.localid == localclaid) {
  45. $scope.folderlist[index].value = true;
  46. }
  47. });
  48. };
  49. $scope.isover = 0;//0:本地对接信息开始查询 4:查询结束
  50. var tempcardlist = [];
  51. var temppersonlist = [];
  52. var tempthemelist = [];
  53. var tempproductlist = [];
  54. var tempiur1list = [];
  55. var tempiur2list = [];
  56. var tempyearprojectlist = [];
  57. //获取对接信息列表
  58. var getConninfo = function () {
  59. var sql = "select * from conninfo where creator = " + UserService.id + " and localid = " + localinfoid;
  60. SqliteStorageService.queryData(sql).then(function (response) {
  61. $scope.record = response[0];
  62. queryCheckFolder($scope.record.localclaid);
  63. //记录时间格式化
  64. var str = response[0].conntime;
  65. if (device.platform != "Android") {
  66. str = str.replace("-", "/");
  67. str = str.replace("-", "/");
  68. }
  69. $scope.record.date = new Date(str).Format("yyyy年MM月dd日 hh:mm");
  70. //记录详情格式化(HTML标签转换成文档标记)
  71. $scope.record.content = UtilService.replaceHTMLTag(response[0].content);
  72. //--查询图片信息
  73. var q_pic_sql = "select * from conninfopicture where localinfoid = " + localinfoid;
  74. SqliteStorageService.queryData(q_pic_sql).then(function (res) {
  75. // console.log(res);
  76. $scope.imagelist = res;
  77. copyimagelist = angular.copy(angular.toJson(res));
  78. }, function () {
  79. });
  80. //--查询名片信息
  81. var q_com_sql = "select * from conninfounit where localinfoid = " + localinfoid;
  82. SqliteStorageService.queryData(q_com_sql).then(function (res) {
  83. tempcardlist = res;
  84. if (tempcardlist.length > 0) {
  85. //组装名片localid list
  86. var cardlocalidstr = "";
  87. angular.forEach(tempcardlist, function (data) {
  88. var tempstr = "'" + data.localid + "'";
  89. cardlocalidstr = cardlocalidstr + tempstr + ",";
  90. });
  91. cardlocalidstr = cardlocalidstr.substring(0, cardlocalidstr.length - 1);
  92. //--查询人员信息
  93. var q_per_sql = "select * from conninfoperson where localuid in (" + cardlocalidstr + ")";
  94. SqliteStorageService.queryData(q_per_sql).then(function (resp) {
  95. temppersonlist = resp;
  96. $scope.isover++;
  97. }, function () {
  98. temppersonlist = [];
  99. $scope.isover++;
  100. });
  101. //--查询主题信息
  102. var q_the_sql = "select * from conninfotheme where localuid in (" + cardlocalidstr + ")";
  103. SqliteStorageService.queryData(q_the_sql).then(function (resp) {
  104. tempthemelist = resp;
  105. $scope.isover++;
  106. }, function () {
  107. tempthemelist = [];
  108. $scope.isover++;
  109. });
  110. //--查询产品信息
  111. var q_pro_sql = "select * from conninfoproduct where localuid in (" + cardlocalidstr + ")";
  112. SqliteStorageService.queryData(q_pro_sql).then(function (resp) {
  113. // console.log(resp);
  114. tempproductlist = resp;
  115. $scope.isover++;
  116. }, function () {
  117. tempproductlist = [];
  118. $scope.isover++;
  119. });
  120. //--查询产学研经历信息
  121. var q_iur1_sql = "select * from conninfoiur where localuid in (" + cardlocalidstr + ")";
  122. SqliteStorageService.queryData(q_iur1_sql).then(function (resp) {
  123. // console.log(resp);
  124. tempiur1list = resp;
  125. $scope.isover++;
  126. }, function () {
  127. tempiur1list = [];
  128. $scope.isover++;
  129. });
  130. //--查询重大科研项目信息
  131. var q_iur2_sql = "select * from conninforesearch where localuid in (" + cardlocalidstr + ")";
  132. SqliteStorageService.queryData(q_iur2_sql).then(function (resp) {
  133. // console.log(resp);
  134. tempiur2list = resp;
  135. $scope.isover++;
  136. }, function () {
  137. tempiur2list = [];
  138. $scope.isover++;
  139. });
  140. //--查询历年申报项目信息
  141. var q_project_sql = "select * from yearproject where localuid in (" + cardlocalidstr + ")";
  142. SqliteStorageService.queryData(q_project_sql).then(function (resp) {
  143. // console.log(resp);
  144. tempyearprojectlist = resp;
  145. $scope.isover++;
  146. }, function () {
  147. tempyearprojectlist = [];
  148. $scope.isover++;
  149. });
  150. } else {
  151. $scope.cardlist = [];
  152. }
  153. }, function () {
  154. });
  155. }, function (err) {
  156. // console.log(err);
  157. });
  158. };
  159. //监听查询是否结束
  160. var overwatch = $scope.$watch("isover", function (newValue, oldValue, scope) {
  161. if (newValue == 6) {
  162. handleConninfoDetailData();
  163. }
  164. });
  165. //编辑:数据是否已操作过
  166. if (ModelService.getIsFirstOpen() == 1) {
  167. $scope.record = ModelService.getConninfo();
  168. $scope.imagelist = ModelService.getImageList();//图片
  169. $scope.cardlist = ModelService.getCardList();
  170. handleCard();
  171. $scope.checkdefolder = ModelService.getEditCheckdeFolder();
  172. } else {
  173. getConninfo();
  174. }
  175. //分类列表页面
  176. $scope.search = {searchkey: ""};
  177. $ionicModal.fromTemplateUrl('templates/modal.html', {
  178. scope: $scope,
  179. animation: 'slide-in-up'
  180. }).then(function (modal) {
  181. $scope.modal = modal;
  182. });
  183. //关闭选择文件夹
  184. $scope.closeModel = function () {
  185. $scope.modal.hide();
  186. // angular.forEach($scope.folderlist, function (value, ind) {
  187. // if (value.value) {
  188. // $scope.checkdefolder = value;
  189. // }
  190. // });
  191. };
  192. //选择分类
  193. $scope.chooseNewUndid = function (folder, index) {
  194. angular.forEach($scope.folderlist, function (value, ind) {
  195. $scope.folderlist[ind].value = false;
  196. });
  197. $scope.folderlist[index].value = true;
  198. $scope.checkdefolder = folder;
  199. $scope.checkfolder = folder.localid;
  200. ModelService.setEditCheckdeFolder(folder);
  201. };
  202. var tempimages = [];
  203. var uploadImages = function (temprecord) {
  204. tempimages = [];
  205. var upimages = [];
  206. angular.forEach($scope.imagelist, function (data) {
  207. if (data.photo_name.indexOf("file:") != -1) {
  208. upimages.push(data.photo_name);
  209. } else {
  210. tempimages.push(data);
  211. }
  212. });
  213. if (upimages.length > 0) {
  214. UtilService.uploadFile(upimages, 0, "image/jpeg").then(function (response) {
  215. // console.log(response);
  216. angular.forEach(response, function (value, index) {
  217. if (value.status) {
  218. tempimages.push({
  219. id: 0, photo_name: value.userPhoto,
  220. original_name: value.originalPhoto,
  221. source_name: value.sourcePhoto,
  222. source_size: value.source_size
  223. });
  224. } else {
  225. tempimages.push({
  226. id: 0,
  227. photo_name: $scope.imagelist[index].photo_name,
  228. original_name: $scope.imagelist[index].original_name,
  229. source_name: $scope.imagelist[index].source_name,
  230. source_size: 0
  231. });
  232. }
  233. });
  234. $timeout(function () {
  235. saveInformation(temprecord);
  236. }, 100);
  237. }, function () {
  238. tempimages = angular.copy($scope.imagelist);
  239. saveInformation(temprecord);
  240. })
  241. } else {
  242. tempimages = angular.copy($scope.imagelist);
  243. saveInformation(temprecord);
  244. }
  245. };
  246. var checknum = 1;
  247. $scope.addisover = 0;
  248. var imagelist = [];
  249. var saveInformation = function (temprecord) {
  250. //名片(单位、人员、主题)数据生成
  251. var insertcardlist = [];//插入名片列表
  252. var updatecardlist = [];//更新名片列表
  253. var personlist = [];//人员列表
  254. var themelist = [];//主题列表
  255. var productlist = [];//产品列表
  256. var iur1list = [];//产学研经历列表
  257. var iur2list = [];//重大科研项目列表
  258. var yearprojectlist = [];//历年申报项目表
  259. var dellocaluidstr = "";
  260. try {
  261. var conninfodate = UtilService.formatDate();
  262. //对接信息数据修改
  263. temprecord.localclaid = $scope.checkdefolder.localid;//本地分类id
  264. temprecord.claid = $scope.checkdefolder.id;//server分类id
  265. if (temprecord.synchrotype != 1) {
  266. temprecord.synchrotype = 2;
  267. temprecord.updatetime = conninfodate.formattime;//修改时间
  268. }
  269. if (!UtilService.isDefined(temprecord.defaultFlag) && temprecord.defaultFlag != 1) {
  270. temprecord.defaultFlag = 0;
  271. }
  272. //图片列表数据生成
  273. imagelist = tempimages.length > 0 ? tempimages : $scope.imagelist;
  274. angular.forEach(imagelist, function (value, index) {
  275. var templocalinfoid = parseInt(temprecord.localid);
  276. imagelist[index].localid = templocalinfoid + index + "";
  277. imagelist[index].localinfoid = temprecord.localid;
  278. imagelist[index].id = 0;
  279. imagelist[index].infoid = temprecord.id;
  280. });
  281. /*------------------------------------------------------------*/
  282. var tempdatelocalid = conninfodate.timestamp;
  283. var date = new Date();
  284. angular.forEach($scope.cardlist, function (value, index) {
  285. //insert 0:新增名片 其他:名片已插入数据库
  286. if (value.isinsert == 0) {
  287. date.setSeconds(date.getSeconds() + index);
  288. //新增的名片初始化一些数据
  289. var tempcardobj = angular.copy(value);
  290. tempcardobj.localid = tempdatelocalid + index + "";
  291. tempcardobj.localinfoid = temprecord.localid;
  292. tempcardobj.id = 0;
  293. tempcardobj.infoid = temprecord.id;
  294. tempcardobj.synchrotype = 1;
  295. tempcardobj.creator = UserService.id;
  296. tempcardobj.creatorcomefrom = ConfigService.comefrom;
  297. tempcardobj.createtime = date.Format("yyyy-MM-dd hh:mm:ss");
  298. tempcardobj.updatetime = date.Format("yyyy-MM-dd hh:mm:ss");
  299. insertcardlist.push(tempcardobj);
  300. //新增的人员初始化一些数据
  301. angular.forEach(value.personlist, function (data, ind) {
  302. var tempperson = data;
  303. tempperson.localid = tempdatelocalid + ind + "";
  304. tempperson.localuid = tempcardobj.localid;
  305. tempperson.id = 0;
  306. tempperson.uid = 0;
  307. personlist.push(tempperson);
  308. });
  309. //新增的主题初始化一些数据
  310. angular.forEach(value.themelist, function (data, ind) {
  311. var temtheme = data;
  312. temtheme.localid = tempdatelocalid + ind + "";
  313. temtheme.localuid = tempcardobj.localid;
  314. temtheme.id = 0;
  315. temtheme.uid = 0;
  316. themelist.push(temtheme);
  317. });
  318. //新增的产品数据生成
  319. angular.forEach(value.productlist, function (data, ind) {
  320. var temproduct = data;
  321. temproduct.localid = tempdatelocalid + ind + "";
  322. temproduct.localuid = tempcardobj.localid;
  323. temproduct.id = 0;
  324. temproduct.uid = 0;
  325. temproduct.infoid = temprecord.id;
  326. productlist.push(temproduct);
  327. });
  328. //新增的产学研经历数据生成
  329. angular.forEach(value.iur1list, function (data, ind) {
  330. var temiur1 = data;
  331. temiur1.localid = tempdatelocalid + ind + "";
  332. temiur1.localuid = tempcardobj.localid;
  333. temiur1.id = 0;
  334. temiur1.uid = 0;
  335. temiur1.infoid = temprecord.id;
  336. iur1list.push(temiur1);
  337. });
  338. //新增的重大科研项数据生成
  339. angular.forEach(value.iur2list, function (data, ind) {
  340. var temiur2 = data;
  341. temiur2.localid = tempdatelocalid + ind + "";
  342. temiur2.localuid = tempcardobj.localid;
  343. temiur2.id = 0;
  344. temiur2.uid = 0;
  345. temiur2.infoid = temprecord.id;
  346. iur2list.push(temiur2);
  347. });
  348. //新增的重大科研项数据生成
  349. angular.forEach(value.calendarlist, function (data, ind) {
  350. var temiur2 = data;
  351. temiur2.localid = tempdatelocalid + ind + "";
  352. temiur2.localuid = tempcardobj.localid;
  353. temiur2.id = 0;
  354. temiur2.uid = 0;
  355. temiur2.infoid = temprecord.id;
  356. yearprojectlist.push(temiur2);
  357. });
  358. } else if (value.synchrotype != 0) {
  359. //组装数据库已存在的名片的localid(用于清空人员、主题,方便后续插入)
  360. if (dellocaluidstr.length == 0) {
  361. dellocaluidstr = value.localid;
  362. } else {
  363. dellocaluidstr = dellocaluidstr + "," + value.localid;
  364. }
  365. //数据库已存在名片,需要修改
  366. value.updatetime = conninfodate.formattime;
  367. updatecardlist.push(value);
  368. //人员列表处理(已存在的不动,新增的初始化数据)
  369. angular.forEach(value.personlist, function (data, ind) {
  370. var tempperson = data;
  371. if (!UtilService.isDefined(tempperson.localid)) {
  372. tempperson.localid = tempdatelocalid + ind + "";
  373. tempperson.localuid = value.localid;
  374. tempperson.id = 0;
  375. tempperson.uid = 0;
  376. }
  377. personlist.push(tempperson);
  378. });
  379. //主题列表处理(已存在的不动,新增的初始化数据)
  380. angular.forEach(value.themelist, function (data, ind) {
  381. var temtheme = data;
  382. if (!UtilService.isDefined(temtheme.localid)) {
  383. temtheme.localid = tempdatelocalid + ind + "";
  384. temtheme.localuid = value.localid;
  385. temtheme.id = 0;
  386. temtheme.uid = 0;
  387. }
  388. themelist.push(temtheme);
  389. });
  390. //产品数据生成(已存在的不动,新增的初始化数据)
  391. angular.forEach(value.productlist, function (data, ind) {
  392. var temproduct = data;
  393. if (!UtilService.isDefined(data.localid)) {
  394. temproduct.localid = tempdatelocalid + ind + "";
  395. temproduct.localuid = value.localid;
  396. temproduct.id = 0;
  397. temproduct.uid = 0;
  398. temproduct.infoid = temprecord.id;
  399. }
  400. productlist.push(temproduct);
  401. });
  402. //产学研经历数据生成(已存在的不动,新增的初始化数据)
  403. angular.forEach(value.iur1list, function (data, ind) {
  404. var temiur1 = data;
  405. if (!UtilService.isDefined(data.localid)) {
  406. temiur1.localid = tempdatelocalid + ind + "";
  407. temiur1.localuid = value.localid;
  408. temiur1.id = 0;
  409. temiur1.uid = 0;
  410. temiur1.infoid = temprecord.id;
  411. }
  412. iur1list.push(temiur1);
  413. });
  414. //重大科研项数据生成(已存在的不动,新增的初始化数据)
  415. angular.forEach(value.iur2list, function (data, ind) {
  416. var temiur2 = data;
  417. if (!UtilService.isDefined(data.localid)) {
  418. temiur2.localid = tempdatelocalid + ind + "";
  419. temiur2.localuid = value.localid;
  420. temiur2.id = 0;
  421. temiur2.uid = 0;
  422. temiur2.infoid = temprecord.id;
  423. }
  424. iur2list.push(temiur2);
  425. });
  426. //重大科研项数据生成(已存在的不动,新增的初始化数据)
  427. angular.forEach(value.calendarlist, function (data, ind) {
  428. var temiur2 = data;
  429. if (!UtilService.isDefined(data.localid)) {
  430. temiur2.localid = tempdatelocalid + ind + "";
  431. temiur2.localuid = value.localid;
  432. temiur2.id = 0;
  433. temiur2.uid = 0;
  434. temiur2.infoid = temprecord.id;
  435. }
  436. yearprojectlist.push(temiur2);
  437. });
  438. }
  439. });
  440. // console.log(temprecord);
  441. // console.log(imagelist);
  442. // console.log(insertcardlist);
  443. // console.log("-----------------------------------");
  444. // console.log(updatecardlist);
  445. // console.log(dellocaluidstr);
  446. // console.log(personlist);
  447. // console.log(themelist);
  448. // console.log(productlist);
  449. // console.log(iur1list);
  450. // console.log(iur2list);
  451. console.log(yearprojectlist);
  452. // console.log("-----------------------------------");
  453. } catch (e) {
  454. // console.log(e);
  455. $scope.hideLoadingToast();
  456. }
  457. if (imagelist.length > 0) {
  458. checknum++;
  459. }
  460. if (updatecardlist.length > 0) {
  461. checknum++;
  462. }
  463. if (insertcardlist.length > 0) {
  464. checknum++;
  465. }
  466. if (personlist.length > 0) {
  467. checknum++;
  468. }
  469. if (themelist.length > 0) {
  470. checknum++;
  471. }
  472. if (productlist.length > 0) {
  473. checknum++;
  474. }
  475. if (iur1list.length > 0) {
  476. checknum++;
  477. }
  478. if (iur2list.length > 0) {
  479. checknum++;
  480. }
  481. if (yearprojectlist.length > 0) {
  482. checknum++;
  483. }
  484. //更新记录
  485. SqliteStorageService.updateSingleData("conninfo", temprecord).then(function () {
  486. $scope.addisover++;
  487. }, function () {
  488. $scope.editstatus = 2;
  489. $scope.addisover++;
  490. });
  491. //更新图片
  492. var deletesql = "delete from conninfopicture where localinfoid = " + temprecord.localid;
  493. SqliteStorageService.deleteData(deletesql).then(function () {
  494. if (imagelist.length > 0) {
  495. SqliteStorageService.insertBatchData("conninfopicture", imagelist).then(function () {
  496. $scope.addisover++;
  497. }, function () {
  498. $scope.addisover++;
  499. });
  500. }
  501. }, function () {
  502. $scope.hideLoadingToast();
  503. });
  504. //更新名片
  505. if (updatecardlist.length > 0) {
  506. SqliteStorageService.updateBatchData("conninfounit", updatecardlist).then(function () {
  507. $scope.addisover++;
  508. }, function () {
  509. $scope.addisover++;
  510. });
  511. }
  512. //插入新名片
  513. if (insertcardlist.length > 0) {
  514. SqliteStorageService.insertBatchData("conninfounit", insertcardlist).then(function () {
  515. $scope.addisover++;
  516. }, function () {
  517. $scope.addisover++;
  518. });
  519. }
  520. //删除--插入人员
  521. var delsql1 = "delete from conninfoperson where localuid in (" + dellocaluidstr + ")";
  522. SqliteStorageService.deleteData(delsql1).then(function () {
  523. if (personlist.length > 0) {
  524. SqliteStorageService.insertBatchData("conninfoperson", personlist).then(function () {
  525. $scope.addisover++;
  526. }, function () {
  527. $scope.addisover++;
  528. });
  529. }
  530. }, function () {
  531. $scope.hideLoadingToast();
  532. });
  533. //删除--插入主题
  534. var delsql2 = "delete from conninfotheme where localuid in (" + dellocaluidstr + ")";
  535. SqliteStorageService.deleteData(delsql2).then(function () {
  536. if (themelist.length > 0) {
  537. SqliteStorageService.insertBatchData("conninfotheme", themelist).then(function () {
  538. $scope.addisover++;
  539. }, function () {
  540. $scope.addisover++;
  541. });
  542. }
  543. }, function () {
  544. $scope.hideLoadingToast();
  545. });
  546. //删除--插入产品
  547. var delsql3 = "delete from conninfoproduct where localuid in (" + dellocaluidstr + ")";
  548. SqliteStorageService.deleteData(delsql3).then(function () {
  549. if (productlist.length > 0) {
  550. SqliteStorageService.insertBatchData("conninfoproduct", productlist).then(function () {
  551. $scope.addisover++;
  552. }, function () {
  553. $scope.addisover++;
  554. });
  555. }
  556. }, function () {
  557. $scope.hideLoadingToast();
  558. });
  559. //删除--插入产学研经历
  560. var delsql4 = "delete from conninfoiur where localuid in (" + dellocaluidstr + ")";
  561. SqliteStorageService.deleteData(delsql4).then(function () {
  562. if (iur1list.length > 0) {
  563. SqliteStorageService.insertBatchData("conninfoiur", iur1list).then(function () {
  564. $scope.addisover++;
  565. }, function () {
  566. $scope.addisover++;
  567. });
  568. }
  569. }, function () {
  570. $scope.hideLoadingToast();
  571. });
  572. //删除--插入重大科研项目
  573. var delsql5 = "delete from conninforesearch where localuid in (" + dellocaluidstr + ")";
  574. SqliteStorageService.deleteData(delsql5).then(function () {
  575. if (iur2list.length > 0) {
  576. SqliteStorageService.insertBatchData("conninforesearch", iur2list).then(function () {
  577. $scope.addisover++;
  578. }, function () {
  579. $scope.addisover++;
  580. });
  581. }
  582. }, function () {
  583. $scope.hideLoadingToast();
  584. });
  585. //删除--插入历年申报项目
  586. var delsql6 = "delete from yearproject where localuid in (" + dellocaluidstr + ")";
  587. SqliteStorageService.deleteData(delsql6).then(function () {
  588. if (yearprojectlist.length > 0) {
  589. SqliteStorageService.insertBatchData("yearproject", yearprojectlist).then(function () {
  590. $scope.addisover++;
  591. }, function () {
  592. $scope.addisover++;
  593. });
  594. }
  595. }, function () {
  596. $scope.hideLoadingToast();
  597. });
  598. };
  599. $scope.immediateRelease = function () {
  600. //判断记录标题
  601. if (!UtilService.isDefined($scope.record.title)) {
  602. UtilService.showMess("标题不能为空");
  603. return;
  604. }
  605. //记录日期转化为yyyy-MM-dd HH:mm 格式
  606. var temprecord = angular.copy($scope.record);
  607. var tempstr = $("#appDateTime").val();
  608. if (UtilService.isDefined(tempstr)) {
  609. temprecord.conntime = UtilService.formatTime(tempstr);
  610. } else {
  611. temprecord.conntime = UtilService.formatTime($scope.record.date);
  612. }
  613. //记录内容转为HTML标签
  614. if (UtilService.isDefined(temprecord.content)) {
  615. temprecord.content = UtilService.replaceEnterTag(temprecord.content);
  616. }
  617. $scope.showLoadingToast();
  618. //检测网络
  619. if (UtilService.checkNetWork() != "None") {
  620. //上传图片
  621. uploadImages(temprecord);
  622. } else {
  623. //保存信息
  624. saveInformation(temprecord);
  625. }
  626. };
  627. //监听是否结束
  628. var overwatch2 = $scope.$watch("addisover", function (newValue, oldValue, scope) {
  629. if (newValue == checknum) {
  630. if ($scope.editstatus == 2) {
  631. UtilService.showMess("修改记录失败,请重试");
  632. $scope.hideLoadingToast();
  633. } else {
  634. UtilService.showMess("修改记录成功");
  635. $scope.hideLoadingToast();
  636. $timeout(function () {
  637. $scope.goback();
  638. }, 1000);
  639. ModelService.resetTempData();
  640. ConfigService.isedit = 1;
  641. SqliteStorageService.updateEditFlg(1);
  642. overwatch2();
  643. }
  644. }
  645. });
  646. //保存本页面数据
  647. var saveTempDate = function () {
  648. var tempstr = $("#appDateTime").val();
  649. if (UtilService.isDefined(tempstr)) {
  650. $scope.record.date = tempstr;
  651. }
  652. ModelService.setConninfo($scope.record);
  653. ModelService.setImageList($scope.imagelist);
  654. ModelService.setCardList($scope.cardlist);
  655. ModelService.setEditCheckdeFolder($scope.checkdefolder);
  656. ModelService.setIsFirstOpen(1);
  657. };
  658. //切换标志
  659. $scope.checkFlag = function () {
  660. $scope.record.flag = $scope.record.flag == 1 ? 0 : 1;
  661. };
  662. //显示选择框
  663. $scope.show = function () {
  664. $ionicActionSheet.show({
  665. buttons: [
  666. {text: '<a class="action-sheet-push act_f">添加照片</a>'},
  667. {text: '<a class="action-sheet-push act_m">添加名片</a>'}
  668. ],
  669. cancelText: '取消',
  670. buttonClicked: function (index) {
  671. if (index == 0) {
  672. getPictures();
  673. } else if (index == 1) {
  674. saveTempDate();
  675. $scope.go('editListCard');
  676. }
  677. return true;
  678. }
  679. });
  680. };
  681. //打开相机
  682. $scope.openCamera = function () {
  683. if ($scope.imagelist.length >= 18) {
  684. UtilService.showMess("最多选取18张图片");
  685. return;
  686. }
  687. UtilService.getPicture(1).then(function (results) {
  688. // console.log(results);
  689. $scope.imagelist.push({
  690. id: 0,
  691. photo_name: results,
  692. original_name: results,
  693. source_name: results
  694. });
  695. $scope.totalImglength = 600 * $scope.imagelist.length;
  696. $ionicScrollDelegate.$getByHandle("scrollimage").resize();
  697. }, function (err) {
  698. });
  699. };
  700. var verifyStorage = function () {
  701. window.imagePicker.verifyStorage(
  702. function (results) {
  703. if (results == "1") {
  704. getPic();
  705. }
  706. }, function (error) {
  707. }
  708. );
  709. };
  710. var getPic = function () {
  711. if ($scope.imagelist.length >= 18) {
  712. UtilService.showMess("最多选取18张图片");
  713. return;
  714. }
  715. UtilService.getPictureList(18 - $scope.imagelist.length).then(function (results) {
  716. // console.log(results);
  717. angular.forEach(results, function (value, index) {
  718. $scope.imagelist.push({id: 0, photo_name: value, original_name: value, source_name: results})
  719. });
  720. $scope.totalImglength = 600 * $scope.imagelist.length;
  721. $ionicScrollDelegate.$getByHandle("scrollimage").resize();
  722. }, function (err) {
  723. });
  724. };
  725. var getPictures = function () {
  726. if (device.platform == "Android") {
  727. verifyStorage();
  728. } else {
  729. getPic();
  730. }
  731. };
  732. //删除图片
  733. $scope.deletePhoto = function (image, index) {
  734. $scope.imagelist.splice(index, 1);
  735. };
  736. //时间选择器
  737. $(function () {
  738. var currYear = (new Date()).getFullYear();
  739. var opt = {};
  740. opt.date = {preset: 'date'};
  741. opt.datetime = {preset: 'datetime'};
  742. opt.time = {preset: 'time'};
  743. opt.default = {
  744. theme: 'android-ics light', //皮肤样式
  745. display: 'modal', //显示方式
  746. mode: 'scroller', //日期选择模式
  747. dateFormat: 'yyyy年mm月dd日',
  748. lang: 'zh',
  749. showNow: true,
  750. nowText: "今天",
  751. startYear: currYear - 50, //开始年份
  752. endYear: currYear + 10 //结束年份
  753. };
  754. var optDateTime = $.extend(opt['datetime'], opt['default']);
  755. $("#appDateTime").mobiscroll(optDateTime).datetime(optDateTime);
  756. });
  757. $scope.editBack = function () {
  758. ModelService.resetTempData();
  759. $scope.goback();
  760. };
  761. //查找分类
  762. $scope.searchClassification = function () {
  763. $timeout(function () {
  764. $(".searchClassification").css("width", "88%");
  765. $(".category_search_icon").css("left", "5%");
  766. $(".new_category_search").animate({paddingLeft: "10%"});
  767. $(".new_category_search").css("text-align", "left");
  768. $(".searchClassDelete").css("display", "inline-block");
  769. }, 100);
  770. };
  771. //取消查询
  772. $scope.searchClassDelete = function () {
  773. $(".searchClassification").css("width", "100%");
  774. $(".category_search_icon").animate({left: "39%"});
  775. $(".new_category_search").animate({paddingLeft: "0%"});
  776. $(".new_category_search").css("text-align", "center");
  777. $(".searchClassDelete").css("display", "none");
  778. $scope.search.searchkey = "";
  779. };
  780. //点击图片放大
  781. $scope.bigImage = false; //初始默认大图是隐藏的
  782. $scope.hideBigImage = function () {
  783. $timeout(function () {
  784. $scope.bigImage = false;
  785. }, 400);
  786. };
  787. $scope.shouBigImage = function (index) { //传递一个参数(图片的URl)
  788. $scope.bigImage = true; //显示大图
  789. // console.log(index);
  790. $ionicSlideBoxDelegate.update();//重绘,让图片显示出来
  791. //图片总数量
  792. setTimeout(function () {
  793. // console.log(parseInt($ionicSlideBoxDelegate.slidesCount()));
  794. // console.log(parseInt($ionicSlideBoxDelegate.currentIndex()));
  795. $ionicSlideBoxDelegate.$getByHandle('slide_detail').slide(index, -10);
  796. //获取图片
  797. var imgObj = document.getElementsByClassName('bigimage');
  798. var n;
  799. for (n = 0; n < imgObj.length; n++) {
  800. // 获取图片的原始高度和宽度
  801. var oldWid = imgObj[n].naturalWidth;
  802. var oldHei = imgObj[n].naturalHeight;
  803. var screen = document.body.offsetWidth;
  804. var screenH = window.innerHeight;
  805. // console.log(oldWid/oldHei);
  806. // console.log(screen );
  807. var cc = screen / (oldWid / oldHei);
  808. imgObj[n].style.height = cc + 'px';
  809. if (cc < screenH) {
  810. imgObj[n].style.marginTop = (screenH - cc) / 2 + 'px';
  811. // console.log("e:" + imgObj[n].style.marginTop);
  812. } else {
  813. imgObj[n].style.marginTop = 0 + 'px';
  814. // console.log((cc - screenH) + 'px')
  815. }
  816. }
  817. }, 0);
  818. };
  819. //显示更多名片部分
  820. $scope.showMoreCard = function (index) {
  821. $(".parentWrapCard").eq(index).toggle();
  822. $(".showCardWrap").eq(index).toggle();
  823. $(".changeArrowButton").eq(index).toggleClass("upArrow");
  824. };
  825. var cardDelect = function (cardindex) {
  826. if ($scope.cardlist[cardindex].isinsert == 0) {
  827. $scope.cardlist.splice(cardindex, 1);
  828. } else {
  829. $scope.cardlist[cardindex].synchrotype = 4;
  830. }
  831. };
  832. //重新编辑名片
  833. $scope.editCardContent = function (cardindex) {
  834. $ionicActionSheet.show({
  835. buttons: [
  836. {text: '<a class="action-sheet-push">编辑名片</a>'},
  837. {text: '<a class="action-sheet-push">删除名片</a>'}
  838. ],
  839. cancelText: '取消',
  840. buttonClicked: function (index) {
  841. if (index == 0) {
  842. saveTempDate();
  843. $scope.go("editListCard", {index: cardindex});
  844. } else {
  845. cardDelect(cardindex);
  846. }
  847. return true;
  848. }
  849. });
  850. };
  851. //返回上一级目录
  852. $scope.backUpperFolder = function () {
  853. ModelService.deleteSelectLevelList($scope.level);
  854. $scope.level--;
  855. if ($scope.level == 0) {
  856. $scope.folderlist = angular.copy(ModelService.getLocalFolderList());
  857. } else {
  858. var tempfolder = ModelService.getSelectLevelList()[$scope.level];
  859. queryLocalFolder(tempfolder);
  860. $scope.currentfoldername = tempfolder.name;
  861. }
  862. $scope.checkfolder = "";
  863. };
  864. //打开下一级目录
  865. $scope.openNextFolder = function (folder) {
  866. //记录本级目录
  867. var tempobj = {
  868. localid: folder.localid,
  869. id: folder.id,
  870. level: folder.level,
  871. isCloud: folder.isCloud,
  872. name: folder.name
  873. };
  874. ModelService.addSelectLevelList(tempobj);
  875. $scope.currentfoldername = folder.name;
  876. $scope.folderlist = [];
  877. $scope.level = folder.level + 1;
  878. queryLocalFolder(folder);
  879. $scope.checkfolder = "";
  880. };
  881. //查询本地子文件夹
  882. var queryLocalFolder = function (folder) {
  883. var q_sql = "select * from conninfofolder where localparentid = '" + folder.localid + "'";
  884. SqliteStorageService.queryData(q_sql).then(function (response) {
  885. // console.log(response);
  886. $scope.folderlist = response;
  887. }, function () {
  888. });
  889. };
  890. });