controllers.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962
  1. starter.controller('NoticeCtrl', function ($rootScope, $scope, $state, $ionicHistory, _, global, Member, Notice, Tool) {
  2. var beoreenter = $scope.$on("$ionicView.beforeEnter", function () {
  3. global.fetch_user().then(function () {
  4. Notice.getCreateUsrsState().then(function (data) {
  5. $scope.createstate = data.state;
  6. });
  7. getnoticedata();
  8. $scope.roleid = global.user.roleid;
  9. }, function (err) {
  10. alert(JSON.stringify(err));
  11. $scope.loading = false;
  12. });
  13. Notice.getsavedata = Notice.getstructdata();
  14. Member.selectedemplst = [];
  15. $ionicHistory.clearHistory(); //清除所有的view
  16. });
  17. $scope.$on("$destroy", function () {
  18. beoreenter = null;
  19. });
  20. $scope.goBack = function () {
  21. global.goBack();
  22. };
  23. $scope.todetails = function (id) {
  24. $state.go('notice-details', {
  25. id: id
  26. });
  27. };
  28. $scope.toper = function () {
  29. $state.go('power-set');
  30. };
  31. $scope.toadd = function () {
  32. Member.resourcemember = [];
  33. Member.selectedemplst = [];
  34. Member.showall = true;
  35. Member.showgroup = true;
  36. Member.titlename = "选择通知的成员";
  37. Member.routename = "postnotice";
  38. Member.routeparams = {
  39. "id": -1
  40. };
  41. $state.go('selectmember');
  42. };
  43. $scope.doRefresh = function () {
  44. getnoticedata();
  45. }
  46. $scope.loadMore = function () {
  47. if ($scope.Notice != undefined && $scope.Notice.next != null) {
  48. Notice.getNext($scope.Notice.next).then(function (data) {
  49. console.log(data);
  50. _.each(data.results, function (item) {
  51. $scope.Notice.results.push(item);
  52. })
  53. $scope.Notice.next = data.next;
  54. $scope.Notice.previous = data.previous;
  55. }).finally(function () {
  56. $scope.$broadcast('scroll.infiniteScrollComplete');
  57. });
  58. } else {
  59. $scope.$broadcast('scroll.infiniteScrollComplete');
  60. }
  61. }
  62. $scope.moreCanBeLoaded = function () {
  63. return $scope.Notice != undefined && $scope.Notice.next != null ? true : false;
  64. };
  65. function getnoticedata() {
  66. if (global.user.token != "") {
  67. if ($scope.Notice == undefined) $scope.loading = true;
  68. Notice.getReceive().then(function (data) {
  69. data.results = _.sortBy(data.results, 'create_dd').reverse();
  70. $scope.Notice = data;
  71. console.log($scope.Notice);
  72. }, function (err) {
  73. alert(JSON.stringify(err));
  74. }).finally(function () {
  75. $scope.$broadcast('scroll.refreshComplete');
  76. $scope.loading = false;
  77. });
  78. }
  79. }
  80. })
  81. .controller('NoticeDetailsCtrl', function ($rootScope, $scope, $state, $ionicSlideBoxDelegate, $ionicPopover, $ionicPopup, _, global, showPopup, Notice, General) {
  82. $scope.id = $state.params['id'];
  83. $scope.isScopeShow = false;
  84. $scope.activeIndex = 0;
  85. $scope.data = {
  86. notice_id: $scope.id,
  87. content: null
  88. };
  89. var isChange = false;
  90. $scope.goBack = function () {
  91. global.goBack();
  92. };
  93. $scope.change = function (index) {
  94. $scope.activeIndex = index;
  95. $ionicSlideBoxDelegate.slide(index);
  96. };
  97. $scope.lockSlide = function () {
  98. $ionicSlideBoxDelegate.enableSlide(false);
  99. };
  100. $scope.changeIndex = function (index) {
  101. if (!isChange) {
  102. isChange = true;
  103. }
  104. if ($scope.details.vote_selecttype == 1) {
  105. $scope.selectIndex = index;
  106. } else {
  107. var flag = false;
  108. _.each($scope.selectIndex, function (item) {
  109. if (item == index) {
  110. $scope.selectIndex.splice($scope.selectIndex.indexOf(item), 1);
  111. flag = true;
  112. }
  113. })
  114. if (!flag) {
  115. $scope.selectIndex.push(index);
  116. }
  117. }
  118. }
  119. $scope.result = function () {
  120. // type 0 admin 1 usr
  121. var type = null;
  122. if ($scope.isAdmin) {
  123. type = 0;
  124. } else {
  125. type = 1;
  126. }
  127. $scope.popover.hide();
  128. $state.go('notice-result', {
  129. id: $scope.id,
  130. type: type
  131. });
  132. }
  133. $scope.transfer = function (id) {
  134. $scope.popover.hide();
  135. }
  136. $scope.deleteNotice = function () {
  137. $scope.popover.hide();
  138. showPopup.confirm("是否删除改公告?", '是', '否').then(function (res) {
  139. if (res) {
  140. Notice.delete_NoticeMf($scope.id).then(function (data) {
  141. $state.go('notice');
  142. }, function (error) {
  143. alert('delete noticemf error:' + JSON.stringify(error))
  144. })
  145. }
  146. });
  147. }
  148. $scope.sendComment = function () {
  149. if ($scope.data.content != null && $scope.data.content != "") {
  150. $scope.data.create_dd = new Date();
  151. General.postComment($scope.data, 'notice').then(function (data) {
  152. $scope.data.content = null;
  153. });
  154. }
  155. }
  156. $scope.popupMessageOpthins = function (id, usrid) {
  157. if (usrid == global.user.usrid) {
  158. $scope.popup.optionsPopup = $ionicPopup.show({
  159. template: '<div class="center" style="height:20px;width:100%;line-height:20px;margin-top:10px;" rj-close-back-drop><h4>用户操作</h4></div>',
  160. scope: $scope,
  161. buttons: [{
  162. text: '删除',
  163. type: 'button-positive',
  164. onTap: function (e) {
  165. General.deleteComment(id, 'notice');
  166. }
  167. }]
  168. });
  169. $scope.popup.isPopup = true;
  170. } else {
  171. //todo:对其进行回复
  172. }
  173. };
  174. $scope.giveUp = function (type) {
  175. // type 0:投票 1:反馈
  176. var title = ['是否放弃投票?', '是否放弃反馈?']
  177. showPopup.confirm(title[type], '是', '否').then(function (res) {
  178. if (res) {
  179. postGiveUp(type);
  180. }
  181. })
  182. };
  183. $scope.postVote = function () {
  184. if (isChange) {
  185. var data = {
  186. vote_selectindex: ''
  187. };
  188. $scope.usr_select_index = $scope.selectIndex;
  189. if ($scope.details.vote_selecttype == 0) {
  190. for (var i = 0; i < $scope.selectIndex.length; i++) {
  191. if (i == $scope.selectIndex.length - 1) {
  192. data.vote_selectindex += $scope.selectIndex[i];
  193. } else {
  194. data.vote_selectindex += $scope.selectIndex[i] + ';';
  195. }
  196. }
  197. } else {
  198. data.vote_selectindex = $scope.selectIndex;
  199. }
  200. postRecordData(data);
  201. }
  202. }
  203. $scope.showbackpopup = function () {
  204. $scope.backData = {
  205. content: null
  206. };
  207. var backpopup = $ionicPopup.show({
  208. template: '<div class="popup-edit-comp" ><input type="text" ng-model="backData.content" ><label ></label></div>',
  209. title: '<div><h5>请输入反馈内容</h5></div>',
  210. scope: $scope,
  211. buttons: [{
  212. text: '取消',
  213. onTap: function () {
  214. return false;
  215. }
  216. }, {
  217. text: '<b>提交</b>',
  218. type: 'button-positive',
  219. onTap: function (e) {
  220. if (!$scope.backData.content) {
  221. e.preventDefault();
  222. } else {
  223. return true;
  224. }
  225. }
  226. }]
  227. }).then(function (res) {
  228. if (res) {
  229. postBackContent();
  230. }
  231. });
  232. };
  233. $scope.edit = function () {
  234. $scope.popover.hide();
  235. $state.go("postnotice", {
  236. "id": $scope.id
  237. })
  238. }
  239. $ionicPopover.fromTemplateUrl('templates/detiilsmenu.html', {
  240. scope: $scope,
  241. }).then(function (popover) {
  242. $scope.popover = popover;
  243. });
  244. $scope.shouBigImage = function (imageName, event) {
  245. if (event != undefined) {
  246. event.stopPropagation();
  247. }
  248. $scope.Url = imageName;
  249. $rootScope.commons.bigImage = true;
  250. };
  251. $scope.doRefresh = function () {
  252. getDetails();
  253. };
  254. function postBackContent() {
  255. postRecordData({
  256. back_content: $scope.backData.content
  257. });
  258. }
  259. function postGiveUp(type) {
  260. // type 0 投票 1 反馈
  261. var data = {};
  262. if (type == 0) {
  263. data.vote_giveup = 1
  264. } else if (type == 1) {
  265. data.back_giveup = 1
  266. }
  267. postRecordData(data);
  268. }
  269. function postRecordData(data) {
  270. data.notice_id = $scope.id;
  271. data.user_id = global.user.usrid;
  272. Notice.postRecord(data).then(function (data) {
  273. $scope.record = data;
  274. })
  275. }
  276. function getDetails() {
  277. if ($scope.details == undefined) {
  278. $scope.loading = true;
  279. }
  280. Notice.getDetails($scope.id).then(function (data) {
  281. $scope.details = data;
  282. if ($scope.details.user == global.user.usrid) {
  283. $scope.isAdmin = true;
  284. }
  285. if ($scope.details.vote_enddd != null) {
  286. $scope.details.vote_enddd = new Date($scope.details.vote_enddd)
  287. }
  288. if ($scope.details.back_enddd != null) {
  289. $scope.details.back_enddd = new Date($scope.details.back_enddd)
  290. }
  291. $scope.datetime = new Date();
  292. if ($scope.details.vote_selectdata != null) {
  293. $scope.selectData = $scope.details.vote_selectdata.split(';');
  294. }
  295. if ($scope.details.vote_selecttype == 1) {
  296. $scope.selectIndex = 0;
  297. } else if ($scope.details.vote_selecttype == 0) {
  298. $scope.selectIndex = [];
  299. }
  300. Notice.getRecord($scope.id).then(function (data) {
  301. $scope.record = data;
  302. if ($scope.record != null) {
  303. if ($scope.record.vote_selectindex != null) {
  304. $scope.usr_select_index = $scope.record.vote_selectindex.split(';');
  305. }
  306. }
  307. $scope.loading = false;
  308. });
  309. General.getComment($scope.id, 'notice').then(function (data) {
  310. $scope.commentData = data.reverse();
  311. });
  312. General.getRead($scope.id, 'notice').then(function (data) {
  313. $scope.readData = data.reverse();
  314. });
  315. General.getRead($scope.id, 'notice', 'unreads').then(function (data) {
  316. $scope.unreadData = data.reverse();
  317. });
  318. }).finally(function () {
  319. $scope.$broadcast('scroll.refreshComplete');
  320. });
  321. }
  322. var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
  323. if (global.user.token == "") {
  324. global.fetch_user().then(function () {
  325. getDetails();
  326. }, function (err) {
  327. $scope.loading = false;
  328. alert(JSON.stringify(err));
  329. });
  330. } else {
  331. getDetails();
  332. }
  333. $scope.popup = {
  334. isPopup: false
  335. };
  336. });
  337. $scope.$on("$destroy", function () {
  338. $scope.popover.remove();
  339. beforeEnter = null;
  340. $rootScope.commons.bigImage = false;
  341. })
  342. })
  343. .controller('PowerSetCtrl', function ($rootScope, $scope, $state, $timeout, $location, $ionicScrollDelegate, $ionicPopover, _, global, Dept, Member, Notice) {
  344. $ionicPopover.fromTemplateUrl('templates/add.html', {
  345. scope: $scope
  346. }).then(function (popover) {
  347. $scope.popover = popover;
  348. });
  349. var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
  350. $scope.sortchars = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '#'];
  351. if (Member.selectedemplst.length > 0) {
  352. var add_usrs = _.pluck(Member.selectedemplst, 'user_id');
  353. // alert("add_usrs data:"+JSOM.stringify(add_usrs));
  354. Notice.post_NoticeCreateUsrs(add_usrs).then(function (data) {
  355. getCreateUsrs();
  356. }, function (error) {
  357. console.log(error);
  358. })
  359. } else {
  360. getCreateUsrs();
  361. }
  362. Member.cancelroutename = '';
  363. Member.cancelrouteparams = {};
  364. });
  365. $scope.$on("$destroy", function () {
  366. $scope.popover.remove();
  367. beforeEnter = null;
  368. });
  369. $scope.isshowdelete = {
  370. showDelete: false
  371. };
  372. $scope.sortchar = 'A';
  373. $scope.Isshowmiddle = false;
  374. $scope.sortByChar = function (char, id) {
  375. $scope.sortchar = char;
  376. $scope.Isshowmiddle = true;
  377. $location.hash(id);
  378. $ionicScrollDelegate.anchorScroll();
  379. $timeout(function () {
  380. $scope.Isshowmiddle = false;
  381. }, 200);
  382. };
  383. $scope.displayremove = function () {
  384. $scope.isshowdelete.showDelete = !$scope.isshowdelete.showDelete;
  385. $scope.popover.hide();
  386. };
  387. $scope.ok = function () {
  388. $scope.popover.hide();
  389. $scope.isshowdelete.showDelete = false;
  390. if (delete_data.length > 0) {
  391. Notice.delete_NoticeCreateUsrs(delete_data);
  392. for (var i = 0; i < $scope.empdata.length; i++) {
  393. _.each(delete_data, function (d) {
  394. if (d == $scope.empdata[i].id) {
  395. $scope.empdata.splice(i, 1)
  396. }
  397. })
  398. }
  399. }
  400. };
  401. $scope.toadd = function () {
  402. Member.resourcemember = [];
  403. Member.selectedemplst = [];
  404. Member.disabled = true;
  405. Member.resourcemember = $scope.empdata;
  406. Member.showall = false;
  407. Member.showgroup = false;
  408. Member.titlename = "选择成员";
  409. Member.routename = "";
  410. $scope.popover.hide();
  411. $state.go('selectmember');
  412. };
  413. var delete_data = [];
  414. $scope.removeItem = function (id, _char) {
  415. delete_data.push(id);
  416. for (var i = 0; i < $scope.resultdata.length; i++) {
  417. if ($scope.resultdata[i].sortchar == _char) {
  418. for (var j = 0; j < $scope.resultdata[i].persons.length; j++) {
  419. if ($scope.resultdata[i].persons[j].nid == id) {
  420. $scope.resultdata[i].persons.splice(j, 1);
  421. if ($scope.resultdata[i].persons.length == 0) {
  422. $scope.resultdata.splice(i, 1)
  423. }
  424. break;
  425. }
  426. }
  427. break;
  428. }
  429. }
  430. };
  431. function getCreateUsrs() {
  432. if ($scope.resultdata == undefined) {
  433. $scope.loading = true;
  434. }
  435. Notice.getCreateUsrs().then(function (data) {
  436. $scope.loading = false;
  437. $scope.empdata = data;
  438. $scope.resultdata = [];
  439. var chars = _.map($scope.empdata, function (emp) {
  440. var char = pinyin.getCamelChars(emp.name).toUpperCase().charAt(0);
  441. return _.contains($scope.sortchars, char) ? char : '#';
  442. });
  443. chars = _.sortBy(_.uniq(chars));
  444. for (var i = 0; i < chars.length; i++) {
  445. var d = {
  446. "sortchar": chars[i],
  447. "persons": []
  448. };
  449. $scope.resultdata.push(d);
  450. for (var j = 0; j < $scope.empdata.length; j++) {
  451. var char = pinyin.getCamelChars($scope.empdata[j].name).toUpperCase().charAt(0);
  452. var empchar = _.contains($scope.sortchars, char) ? char : '#';
  453. if (empchar == chars[i]) {
  454. d.persons.push({
  455. "nid": $scope.empdata[j].id,
  456. "username": $scope.empdata[j].name
  457. });
  458. }
  459. }
  460. }
  461. var index = _.pluck($scope.resultdata, 'sortchar').indexOf('#');
  462. if (index >= 0) {
  463. var item = $scope.resultdata[index];
  464. $scope.resultdata.splice(index, 1);
  465. $scope.resultdata.push(item);
  466. }
  467. Member.selectedemplst = [];
  468. }, function (err) {
  469. $scope.loading = false;
  470. alert(JSON.stringify(err))
  471. });
  472. }
  473. })
  474. .controller('PostNoticeCtrl', function ($rootScope, $scope, $state, $cordovaDatePicker, $timeout, $ionicHistory, $q, $ionicScrollDelegate, _, global, ImageManage, showPopup, Notice, Member, Tool, formatFilter) {
  475. $rootScope.commons.bigImage = false;
  476. var tmday = new Date((new Date() / 1000 + 86400) * 1000);
  477. $scope.isNew = (parseInt($state.params["id"]) < 0);
  478. $scope.selectdatas = [{
  479. name: '多选',
  480. id: 0
  481. }, {
  482. name: '单选',
  483. id: 1
  484. }];
  485. var deleteimages = {};
  486. var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
  487. Tool.removeBackView('selectmember');
  488. $scope.usernames = "";
  489. if ($scope.isNew) { //add
  490. deleteimages = Notice.getsavedata.deleteimages;
  491. $scope.noticedata = Notice.getsavedata;
  492. $scope.noticedata.allid = Member.all;
  493. if (Member.dialogresult == 0) { //cancel
  494. $scope.noticedata.allid == 0 ? setreadusrs($scope.noticedata.readusrs) : $scope.usernames = "全部成员";
  495. } else {
  496. if (Member.all == 0 && Member.selectedemplst.length > 0) {
  497. $scope.noticedata.readusrs = _.map(Member.selectedemplst, function (item) {
  498. return _.pick(item, 'user_id', 'username');
  499. });
  500. setreadusrs(Member.selectedemplst);
  501. } else if (Member.all == 1) {
  502. $scope.noticedata.readusrs = [];
  503. $scope.usernames = "全部成员";
  504. }
  505. }
  506. } else { //edit
  507. deleteimages = Notice.getLoalDetails().deleteimages;
  508. $scope.noticedata = Notice.getLoalDetails();
  509. $scope.editvotedata = $scope.noticedata.selectitems;
  510. $scope.noticedata.disablededit.showadditem = (Tool.trim($scope.noticedata.vote_title).length == 0);
  511. $scope.noticedata.disablededit.showeditback = (Tool.trim($scope.noticedata.back_title).length == 0);
  512. if (Member.selectedemplst.length > 0) {
  513. $scope.noticedata.allid = Member.all;
  514. $scope.noticedata.readusrs = _.map(Member.selectedemplst, function (item) {
  515. return _.pick(item, 'user_id', 'username');
  516. });
  517. setreadusrs(Member.selectedemplst)
  518. } else {
  519. if ($scope.noticedata.allid == 1) {
  520. $scope.noticedata.readusrs = [];
  521. $scope.usernames = "全部成员";
  522. } else {
  523. setreadusrs($scope.noticedata.readusrs)
  524. }
  525. }
  526. }
  527. Member.routeparams = {};
  528. $scope.popup = {
  529. isSetPopup: false
  530. };
  531. $ionicScrollDelegate.resize();
  532. });
  533. $scope.$on("$destroy", function () {
  534. $rootScope.commons.modal = null;
  535. $rootScope.commons.fun = null;
  536. beforeEnter = null;
  537. Notice.getsavedata = Notice.getstructdata();
  538. });
  539. $scope.noticedata = [];
  540. $scope.imagePicker = function () {
  541. ImageManage.ImagePicker_getPictures(10).then(function (data) {
  542. if (data.length == 0) return;
  543. $scope.noticedata.noticefiles = $scope.noticedata.noticefiles.concat(_.map(data, function (imageUrl) {
  544. return {"file_thumbnail_path": imageUrl, "file_full_path": imageUrl};
  545. }));
  546. });
  547. };
  548. $scope.Camera = function () {
  549. ImageManage.Camera_getPicture().then(function (result) {
  550. $scope.noticedata.noticefiles.push({
  551. "file_thumbnail_path": result,
  552. "file_full_path": result
  553. });
  554. });
  555. };
  556. $scope.shouBigImage = function (imageName, event) {
  557. if (event != undefined) event.stopPropagation();
  558. $scope.Url = imageName;
  559. $rootScope.commons.bigImage = true;
  560. };
  561. $rootScope.commons.bigImage = false;
  562. $scope.hideBigImage = function () {
  563. $rootScope.commons.bigImage = false;
  564. };
  565. $scope.deleteimage = function () {
  566. for (var i = 0; i < $scope.noticedata.noticefiles.length; i++) {
  567. if ($scope.noticedata.noticefiles[i].file_full_path == $scope.Url) {
  568. if (_.has($scope.noticedata.noticefiles[i], 'id')) {
  569. deleteimages.oldimages.push($scope.noticedata.noticefiles[i]);
  570. }
  571. $scope.noticedata.noticefiles.splice(i, 1);
  572. break;
  573. }
  574. }
  575. $rootScope.commons.bigImage = false;
  576. };
  577. var tempdata = {};
  578. $scope.set_voteback = function (type, event) {
  579. type == 'vote' ? $scope.noticedata.setbtnstyle.vote = true : $scope.noticedata.setbtnstyle.back = true;
  580. tempdata = Tool.cloneObj($scope.noticedata);
  581. tempdata.selectitems = tempdata.vote_selectdata == "" ? [] : _.map(tempdata.vote_selectdata.split(';'), function (text) {
  582. return {'text': text};
  583. });
  584. showPopup.modalTemplate(formatFilter('templates/modal-{0}.html', type), 'slide-in-right', $scope).then(function (modal) {
  585. $rootScope.commons.fun = clear_change;
  586. $rootScope.commons.modal = modal;
  587. $rootScope.commons.modal.show();
  588. })
  589. };
  590. $scope.cancel = function (op) {
  591. $rootScope.commons.fun = null;
  592. if (op == 'notice') {
  593. $ionicHistory.goBack();
  594. } else {
  595. clear_change()
  596. }
  597. };
  598. function clear_change() {
  599. $scope.noticedata = Tool.cloneObj(tempdata);
  600. if (Tool.trim(tempdata.vote_title).length == 0) $scope.noticedata.setbtnstyle.vote = false;
  601. if (Tool.trim(tempdata.back_title).length == 0) $scope.noticedata.setbtnstyle.back = false;
  602. set_modal();
  603. }
  604. $scope.ok = function (op) {
  605. $rootScope.commons.fun = null;
  606. if (op == "notice") { //创建公告的首页-确定按钮
  607. if (Tool.trim($scope.noticedata.title).length == 0) {
  608. showPopup.PopupWindow(0, "标题不能为空!", false);
  609. return;
  610. }
  611. if (Tool.trim($scope.noticedata.content).length == 0) {
  612. showPopup.PopupWindow(0, "内容不能为空!", false);
  613. return;
  614. }
  615. showPopup.showLoading(1, '正在提交');
  616. $scope.noticedata.usrid = global.user.usrid;
  617. var temp_notice = Tool.cloneObj($scope.noticedata);
  618. temp_notice.readusrs = _.pluck(temp_notice.readusrs, 'user_id');
  619. if ($scope.isNew) {
  620. Notice.post_NoticeMf(temp_notice).then(function (data) {
  621. if ($scope.noticedata.noticefiles.length > 0) {
  622. postimg($scope.noticedata.noticefiles, data.id);
  623. } else {
  624. showPopup.hideLoading();
  625. $ionicHistory.goBack();
  626. $timeout(function () {
  627. $state.go("notice-details", {
  628. "id": data.id
  629. })
  630. });
  631. }
  632. }, function (error) {
  633. showPopup.hideLoading();
  634. alert('post_NoticeMf error: ' + JSON.stringify(error))
  635. });
  636. } else {
  637. temp_notice.del_files = _.pluck(deleteimages.oldimages, 'id');
  638. Notice.put_NoticeMf(temp_notice).then(function (data) {
  639. postimgs = _.filter($scope.noticedata.noticefiles, function (img) {
  640. return !_.has(img, 'id');
  641. });
  642. if (postimgs.length > 0) {
  643. postimg(postimgs, $state.params['id']);
  644. } else {
  645. showPopup.hideLoading();
  646. $ionicHistory.goBack();
  647. }
  648. }, function (error) {
  649. showPopup.hideLoading();
  650. alert("put notice error: " + JSON.stringify(error))
  651. })
  652. }
  653. } else if (op == "vote") { //添加投票模态窗口-确定按钮
  654. if (Tool.trim($scope.noticedata.vote_title).length == 0) {
  655. showPopup.PopupWindow(0, '标题不能为空!', false);
  656. return;
  657. }
  658. var items = _.filter($scope.noticedata.selectitems, function (item) {
  659. return Tool.trim(item.text).length > 0;
  660. });
  661. var resultitems = _.uniq(_.pluck(items, 'text'));
  662. if (resultitems.length < items.length) {
  663. showPopup.PopupWindow(0, '选项不能重复!', false);
  664. return;
  665. }
  666. if (resultitems.length < 2) {
  667. showPopup.PopupWindow(0, '实际投票选项不能少于2项!', false);
  668. return;
  669. }
  670. $scope.noticedata.vote_selectdata = _.pluck($scope.noticedata.selectitems, 'text').join(';');
  671. set_modal();
  672. $timeout(function () {
  673. $scope.noticedata.showvoteDelete = true;
  674. }, 1000);
  675. } else if (op == "back") {
  676. if (Tool.trim($scope.noticedata.back_title).length == 0) {
  677. showPopup.PopupWindow(0, '问题内容不能为空!', false);
  678. return;
  679. }
  680. set_modal();
  681. $timeout(function () {
  682. $scope.noticedata.showbackDelete = true;
  683. }, 1000);
  684. }
  685. };
  686. $scope.checkend_dd = function (op) {
  687. var date = null;
  688. if ($scope.isNew) {
  689. date = tmday;
  690. } else {
  691. if (op == "vote") {
  692. date = $scope.noticedata.vote_enddd == null ? tmday : $scope.noticedata.vote_enddd;
  693. } else {
  694. date = $scope.noticedata.back_enddd == null ? tmday : $scope.noticedata.vote_enddd;
  695. }
  696. }
  697. var options = {
  698. mode: 'date',
  699. date: date,
  700. androidTheme: 3
  701. };
  702. $cordovaDatePicker.show(options).then(function (date) {
  703. $timeout(function () {
  704. if (date == undefined) return;
  705. op == "vote" ? $scope.noticedata.vote_enddd = date : $scope.noticedata.back_enddd = date;
  706. });
  707. });
  708. };
  709. $scope.addItem = function () {
  710. $timeout(function () {
  711. $scope.noticedata.selectitems.push({
  712. "text": ""
  713. });
  714. });
  715. };
  716. $scope.removeItem = function (index) {
  717. $scope.noticedata.selectitems.splice(index, 1);
  718. };
  719. //todo:选择要通知的成员
  720. $scope.toselect = function () {
  721. Member.resourcemember = [];
  722. Member.showall = true;
  723. Member.showgroup = true;
  724. Member.titlename = "选择通知的成员";
  725. Member.routename = "postnotice";
  726. Member.cancelroutename = "postnotice";
  727. Member.cancelrouteparams = {
  728. "id": $state.params['id']
  729. };
  730. Member.disabled = false;
  731. if ($scope.isNew) {
  732. Member.dialogresult == 0 ? setresourcedata($scope.noticedata.readusrs) : setresourcedata(Member.selectedemplst);
  733. Member.routeparams = {
  734. "id": -1
  735. };
  736. } else {
  737. Member.selectedemplst.length == 0 ? setresourcedata($scope.noticedata.readusrs) : setresourcedata(Member.selectedemplst);
  738. Member.routeparams = {
  739. "id": $state.params['id']
  740. };
  741. }
  742. Member.selectedemplst = [];
  743. $state.go('selectmember');
  744. };
  745. $scope.delete = function (op) {
  746. if (op == "vote") {
  747. $scope.noticedata.vote_title = "";
  748. $scope.noticedata.vote_selectdata = "";
  749. $scope.noticedata.vote_selecttype = 1;
  750. $scope.noticedata.vote_enddd = tmday;
  751. $scope.noticedata.selectitems = [];
  752. $scope.noticedata.setbtnstyle.vote = false;
  753. $scope.noticedata.showvoteDelete = false;
  754. $scope.noticedata.disablededit.showadditem = true;
  755. } else {
  756. $scope.noticedata.back_title = "";
  757. $scope.noticedata.back_enddd = tmday;
  758. $scope.noticedata.setbtnstyle.back = false;
  759. $scope.noticedata.showbackDelete = false;
  760. $scope.noticedata.disablededit.showeditback = true;
  761. }
  762. set_modal();
  763. };
  764. $scope.getaddress = function () {
  765. if (window.cordovaLinker) {
  766. var local = {
  767. NAME: "",
  768. Latitude: "",
  769. Longitude: "",
  770. Distance: ""
  771. };
  772. cordovaLinker.callMap(local, function (mapdata) {
  773. $scope.noticedata.address = mapdata.NAME
  774. });
  775. }
  776. };
  777. function setresourcedata(data) {
  778. Member.resourcemember = Member.resourcemember.concat(_.map(data, function (item) {
  779. if (_.has(item, 'user__username')) item.username = item.user__username;
  780. return item
  781. }));
  782. }
  783. function setreadusrs(data) {
  784. $scope.usernames = _.map(data, function (item) {
  785. return _.has(item, 'username') ? item.username : item.user__username;
  786. }).join('、');
  787. }
  788. function postimg(imgfiles, id) {
  789. ImageManage.uploadImage(_.pluck(imgfiles, 'file_full_path'), 'notice', id, 'noticefile').then(function (res) {
  790. $q.all(res).then(function (res1) {
  791. showPopup.hideLoading();
  792. $ionicHistory.goBack();
  793. $timeout(function () {
  794. $state.go("notice-details", {
  795. "id": id
  796. })
  797. });
  798. })
  799. }, function (err) {
  800. showPopup.hideLoading();
  801. alert(JSON.stringify(error));
  802. showPopup.PopupWindow(0, 'upload image fail');
  803. })
  804. }
  805. function set_modal() {
  806. $rootScope.commons.modal.hide();
  807. $rootScope.commons.modal = null;
  808. }
  809. })
  810. .controller('NoticeResultCtrl', function ($rootScope, $scope, $state, $timeout, showPopup, Notice) {
  811. $scope.id = $state.params['id'];
  812. $scope.type = $state.params['type'];
  813. $scope.toResultDetails = function (type, index) {
  814. // type 0 未看 1 已看 2 未反馈 3 已反馈 4 放弃反馈 5 未投票 6 放弃投票 7 已投票
  815. // index 选项的下标
  816. showPopup.showLoading(1, '加载中');
  817. var data = Notice.getCountDetails();
  818. if (type == 7) {
  819. data.selectItem = $scope.selectData[index];
  820. }
  821. Notice.getUsrCount($scope.id, type, index).then(function () {
  822. $state.go('result-details', {
  823. type: type
  824. });
  825. showPopup.hideLoading();
  826. })
  827. }
  828. var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
  829. if ($scope.details == undefined) {
  830. showPopup.showLoading(1, '加载中');
  831. }
  832. Notice.getCount($scope.id).then(function (data) {
  833. $scope.countData = data;
  834. $scope.details = Notice.getLoalDetails();
  835. if ($scope.details.vote_title != null) {
  836. $scope.selectData = $scope.details.vote_selectdata.split(';');
  837. $scope.usrvotecount = 0;
  838. for (var i = 0; i < $scope.countData.votecount.length; i++) {
  839. $scope.usrvotecount += $scope.countData.votecount[i];
  840. }
  841. $scope.usrvotecount += $scope.countData.unvote;
  842. $scope.usrvotecount += $scope.countData.votegiveup;
  843. }
  844. showPopup.hideLoading();
  845. });
  846. });
  847. $scope.$on("$destroy", function () {
  848. beforeEnter = null;
  849. })
  850. })
  851. .controller('NoticePostedCtrl', function ($scope, $state, Member, Notice) {
  852. var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
  853. if ($scope.createstate == undefined)
  854. $scope.createstate = 0; //默认不显示'+'标记
  855. Notice.getCreateUsrsState().then(function (data) {
  856. $scope.createstate = data.state;
  857. });
  858. Notice.getRelease().then(function (data) {
  859. $scope.Notice = _.sortBy(data.results, 'create_dd').reverse();
  860. });
  861. Notice.getsavedata = Notice.getstructdata();
  862. Member.selectedemplst = [];
  863. });
  864. $scope.$on("$destroy", function () {
  865. beforeEnter = null;
  866. });
  867. $scope.toadd = function () {
  868. Member.resourcemember = [];
  869. Member.selectedemplst = [];
  870. Member.showall = true;
  871. Member.showgroup = true;
  872. Member.titlename = "选择通知的成员";
  873. Member.routename = "postnotice";
  874. Member.routeparams = {
  875. "id": -1
  876. };
  877. $state.go('selectmember');
  878. };
  879. $scope.todetails = function (id) {
  880. $state.go('notice-details', {
  881. id: id
  882. });
  883. };
  884. })
  885. .controller('ResultDetailsCtrl', function ($scope, $state, Notice) {
  886. $scope.type = $state.params['type'];
  887. $scope.titleArr = ['未看', '已看', '未反馈', '已反馈', '放弃反馈', '未投票', '放弃投票', '已投票'];
  888. $scope.countDetails = Notice.getCountDetails();
  889. });