controllers.js 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526
  1. starter.controller('DailyCtrl', function ($rootScope, $scope, $state, global, Daily, Tool) {
  2. $scope.goBack = function () {
  3. global.goBack();
  4. }
  5. global.fetch_user().then(function () {
  6. getdailydata();
  7. });
  8. $scope.toman = function () {
  9. $state.go('daily-man');
  10. }
  11. $scope.towrite = function () {
  12. $state.go('daily-edit', {
  13. 'flag': 0
  14. });
  15. }
  16. $scope.totransfer = function (id) {
  17. $state.go('transfer', {
  18. module: 'daily',
  19. id: id
  20. });
  21. }
  22. $scope.doRefresh = function () {
  23. global.refresh = true;
  24. getdailydata();
  25. }
  26. $scope.loadMore = function () {
  27. if ($scope.dailys != undefined && $scope.dailys.next != null) {
  28. Tool.get($scope.dailys.next).then(function (data) {
  29. _.each(data.results, function (item) {
  30. $scope.dailys.results.push(item);
  31. });
  32. $scope.dailys.next = data.next;
  33. $scope.dailys.previous = data.previous;
  34. }).finally(function () {
  35. $scope.$broadcast('scroll.infiniteScrollComplete');
  36. $scope.loading = false;
  37. });
  38. } else {
  39. $scope.$broadcast('scroll.infiniteScrollComplete');
  40. }
  41. }
  42. $scope.moreCanBeLoaded = function () {
  43. return $scope.dailys != undefined && $scope.dailys.next != null ? true : false;
  44. }
  45. function getdailydata() {
  46. if (global.user.token != "") {
  47. if ($scope.dailys == undefined) {
  48. $scope.loading = true;
  49. }
  50. Daily.dailymf.get(function (res) {
  51. $scope.dailys = res;
  52. console.log($scope.dailys);
  53. $scope.roleid = global.user.roleid;
  54. }, function (err) {
  55. alert(JSON.stringify(err));
  56. }).$promise.finally(function () {
  57. $scope.$broadcast('scroll.refreshComplete');
  58. $scope.loading = false;
  59. });
  60. }
  61. }
  62. enter = $scope.$on("$ionicView.enter", function (event, data) {
  63. if (data.fromCache && $rootScope.commons.refresh) {
  64. $rootScope.commons.refresh = false;
  65. getdailydata();
  66. }
  67. });
  68. $scope.$on("$destroy", function () {
  69. enter = null;
  70. });
  71. })
  72. .controller('DailyReadCtrl', function ($scope, $state, $ionicSlideBoxDelegate, Daily, global, Tool) {
  73. $scope.index = 0;
  74. global.fetch_user().then(function () {
  75. getsummaryata();
  76. });
  77. $scope.select = function (index) {
  78. $ionicSlideBoxDelegate.slide(index);
  79. $scope.index = $ionicSlideBoxDelegate.currentIndex();
  80. }
  81. $scope.toMonthCount = function (item) {
  82. $state.go('daily-readMonthCount', {
  83. 'daily_dd': item.daily_date
  84. });
  85. }
  86. $scope.toDayCount = function (date) {
  87. $state.go('daily-readDay', {
  88. 'daily_dd': date
  89. })
  90. }
  91. $scope.isMonth = function (item) {
  92. var date = new Date(item.daily_date);
  93. return date.getMonth() == new Date().getMonth() ? false : true;
  94. }
  95. $scope.doRefresh = function () {
  96. global.refresh = true;
  97. getsummaryata();
  98. }
  99. $scope.loadMore = function () {
  100. if ($scope.summary != undefined && $scope.summary.next != null) {
  101. Tool.get($scope.summary.next).then(function (data) {
  102. data.results = initialize(data.results);
  103. _.each(data.results, function (value, key) {
  104. var item = _.pick($scope.summary.results, key);
  105. if (item[key]) {
  106. _.each(value, function (i) {
  107. $scope.summary.results[key].push(i);
  108. })
  109. } else {
  110. $scope.summary.results[key] = value;
  111. }
  112. });
  113. console.log($scope.summary.results);
  114. $scope.summary.next = data.next;
  115. $scope.summary.previous = data.previous;
  116. }).finally(function () {
  117. $scope.$broadcast('scroll.infiniteScrollComplete');
  118. $scope.loading = false;
  119. });
  120. } else {
  121. $scope.$broadcast('scroll.infiniteScrollComplete');
  122. }
  123. }
  124. $scope.moreCanBeLoaded = function () {
  125. return $scope.summary != undefined && $scope.summary.next != null ? true : false;
  126. }
  127. function getsummaryata() {
  128. if (global.user.token != "") {
  129. if ($scope.summary == undefined) {
  130. $scope.loading = true;
  131. }
  132. Daily.dailysummary.get(function (res) {
  133. console.log(res.results);
  134. res.results = initialize(res.results);
  135. $scope.summary = res;
  136. }, function (err) {
  137. alert(JSON.stringify(err));
  138. }).$promise.finally(function () {
  139. $scope.$broadcast('scroll.refreshComplete');
  140. $scope.loading = false;
  141. });
  142. }
  143. }
  144. function initialize(data) {
  145. _.each(data, function (item) {
  146. var date = new Date(item.daily_date);
  147. item.month = date.getFullYear() + '-' + (date.getMonth() + 1);
  148. });
  149. return _.groupBy(data, 'month');
  150. }
  151. })
  152. .controller('DailyDetailsCtrl', function ($rootScope, $scope, $state, $ionicPopover, $ionicPopup, $ionicHistory, global, Daily, showPopup) {
  153. $scope.id = $state.params['id'];
  154. $scope.cssstyle = true;
  155. $scope.comments = {};
  156. $scope.reads = {};
  157. $scope.data = {
  158. daily_mf: $scope.id,
  159. comment: null
  160. }
  161. var view = $ionicHistory.backView();
  162. $scope.popup = {
  163. isPopup: false
  164. }
  165. global.fetch_user().then(function () {
  166. if (view) {
  167. $scope.loading = true;
  168. $scope.daily = Daily.daily;
  169. Daily.dailyread.get({mf_id: $scope.id}, function (data) {
  170. $scope.comments = data;
  171. $scope.loading = false;
  172. });
  173. Daily.readview.query({mf_id: $scope.id}, function (data) {
  174. $scope.reads = data;
  175. });
  176. } else {
  177. getdailydata();
  178. }
  179. });
  180. $scope.goBack = function () {
  181. global.goBack();
  182. }
  183. $ionicPopover.fromTemplateUrl('templates/detiilsmenu.html', {
  184. scope: $scope
  185. }).then(function (popover) {
  186. $scope.popover = popover;
  187. });
  188. $scope.sendComment = function () {
  189. if ($scope.data.comment != null && $scope.data.comment != "") {
  190. Daily.dailyread.save($scope.data, function (data) {
  191. $scope.comments.results.splice(0, 0, data);
  192. $scope.data.comment = null;
  193. })
  194. }
  195. }
  196. $scope.popupMessageOpthins = function (id, usrid) {
  197. if (usrid == global.user.usrid) {
  198. $scope.popup.optionsPopup = $ionicPopup.show({
  199. template: '<div class="center" style="height:20px;width:100%;line-height:20px;margin-top:10px;" rj-close-back-drop><h4>用户操作</h4></div>',
  200. scope: $scope,
  201. buttons: [{
  202. text: '删除',
  203. type: 'button-positive',
  204. onTap: function (e) {
  205. Daily.dailyread.delete({id: id}, function () {
  206. var comment = _.find($scope.comments.results, function (item) {
  207. if (item.id === parseInt(id))
  208. return item;
  209. });
  210. if (comment != undefined)
  211. $scope.comments.results.splice($scope.comments.results.indexOf(comment), 1);
  212. });
  213. }
  214. }]
  215. });
  216. $scope.popup.isPopup = true;
  217. }
  218. }
  219. $scope.transfer = function () {
  220. $scope.popover.hide();
  221. $state.go('transfer', {
  222. module: 'daily',
  223. id: $scope.id
  224. });
  225. }
  226. $scope.remove = function () {
  227. $scope.popover.hide();
  228. showPopup.confirm('是否删除该汇报?', '是', '否').then(function (res) {
  229. if (res) {
  230. Daily.dailymf.delete({id: $scope.id}, function () {
  231. $rootScope.commons.refresh = true;
  232. $ionicHistory.goBack();
  233. });
  234. }
  235. });
  236. }
  237. $scope.edit = function () {
  238. $scope.popover.hide();
  239. $state.go('daily-edit', {
  240. 'flag': $scope.id
  241. })
  242. }
  243. $scope.doRefresh = function () {
  244. global.refresh = true;
  245. getdailydata();
  246. }
  247. $scope.loadMore = function () {
  248. if ($scope.comments != undefined && $scope.comments.next != null) {
  249. Tool.get($scope.comments.next).then(function (data) {
  250. _.each(data.comments, function (item) {
  251. $scope.comments.results.push(item);
  252. });
  253. $scope.comments.next = data.next;
  254. $scope.comments.previous = data.previous;
  255. }).finally(function () {
  256. $scope.$broadcast('scroll.infiniteScrollComplete');
  257. $scope.loading = false;
  258. });
  259. } else {
  260. $scope.$broadcast('scroll.infiniteScrollComplete');
  261. }
  262. }
  263. $scope.moreCanBeLoaded = function () {
  264. return $scope.comments != undefined && $scope.comments.next != null ? true : false;
  265. }
  266. function getdailydata() {
  267. if ($scope.daily == undefined) {
  268. $scope.loading = true;
  269. }
  270. Daily.dailymf.get({id: $scope.id}, function (res) {
  271. Daily.daily = _.clone(res);
  272. $scope.daily = res;
  273. }, function (err) {
  274. alert(JSON.stringify(err));
  275. }).$promise.finally(function () {
  276. $scope.$broadcast('scroll.refreshComplete');
  277. $scope.loading = false;
  278. });
  279. Daily.dailyread.get({mf_id: $scope.id}, function (data) {
  280. $scope.comments = data;
  281. });
  282. Daily.readview.query({mf_id: $scope.id}, function (data) {
  283. $scope.reads = data;
  284. });
  285. }
  286. enter = $scope.$on('$ionicView.enter', function (event, data) {
  287. if (data.fromCache && $rootScope.commons.refresh) {
  288. if (view == null)
  289. $rootScope.commons.refresh = false;
  290. getdailydata();
  291. }
  292. });
  293. $scope.$on("$destroy", function () {
  294. enter = null;
  295. $scope.popover.remove();
  296. })
  297. })
  298. .controller('DailyPermissionCtrl', function ($rootScope, $scope, $ionicPopover, $state, global, Daily) {
  299. var deletes = {C: [], D: [], U: []};
  300. global.fetch_user().then(function () {
  301. getpermissiondata();
  302. });
  303. $ionicPopover.fromTemplateUrl('templates/add.html', {
  304. scope: $scope
  305. }).then(function (popover) {
  306. $scope.popover = popover;
  307. });
  308. $scope.isshowdelete = {
  309. showDelete: false
  310. }
  311. $scope.displayremove = function () {
  312. $scope.isshowdelete.showDelete = !$scope.isshowdelete.showDelete;
  313. $scope.popover.hide();
  314. }
  315. $scope.ok = function () {
  316. $scope.popover.hide();
  317. if (deletes.D.length > 0) {
  318. deletes.D = deletes.D.join(',');
  319. Daily.dailypermission.patch(deletes, function () {
  320. deletes.D = [];
  321. });
  322. }
  323. $scope.isshowdelete.showDelete = false;
  324. }
  325. $scope.toadd = function () {
  326. $scope.popover.hide();
  327. $state.go('additem');
  328. }
  329. $scope.remove = function (item) {
  330. _.each(item.permissions, function (permission) {
  331. deletes.D.push(permission.id);
  332. });
  333. $scope.userlist.results.splice(_.indexOf($scope.userlist.results, item), 1);
  334. }
  335. $scope.toSelectDeptOrItem = function (item) {
  336. Daily.permissionUser = _.clone(item);
  337. $state.go('selectdeptoritem', {
  338. "id": item.user_id
  339. });
  340. }
  341. $scope.doRefresh = function () {
  342. global.refresh = true;
  343. getpermissiondata();
  344. }
  345. $scope.loadMore = function () {
  346. if ($scope.userlist != undefined && $scope.userlist.next != null) {
  347. Tool.get($scope.userlist.next).then(function (data) {
  348. _.each(data.results, function (item) {
  349. $scope.userlist.results.push(item);
  350. });
  351. $scope.userlist.next = data.next;
  352. $scope.userlist.previous = data.previous;
  353. }).finally(function () {
  354. $scope.$broadcast('scroll.infiniteScrollComplete');
  355. $scope.loading = false;
  356. });
  357. } else {
  358. $scope.$broadcast('scroll.infiniteScrollComplete');
  359. }
  360. }
  361. $scope.moreCanBeLoaded = function () {
  362. return $scope.userlist != undefined && $scope.userlist.next != null ? true : false;
  363. }
  364. function getpermissiondata() {
  365. if (global.user.token != "") {
  366. if ($scope.userlist == undefined) {
  367. $scope.loading = true;
  368. }
  369. Daily.dailypermission.get(function (res) {
  370. $scope.userlist = res;
  371. Daily.permissionUsers = res.results;
  372. }, function (err) {
  373. alert(JSON.stringify(err));
  374. }).$promise.finally(function () {
  375. $scope.$broadcast('scroll.refreshComplete');
  376. $scope.loading = false;
  377. });
  378. }
  379. }
  380. enter = $scope.$on('$ionicView.enter', function (event, data) {
  381. if (data.fromCache && $rootScope.commons.refresh) {
  382. $rootScope.commons.refresh = false;
  383. getpermissiondata();
  384. }
  385. });
  386. $scope.$on('$destroy', function () {
  387. enter = null;
  388. $scope.popover.remove();
  389. })
  390. })
  391. .controller('SelectDeptOrItemCtrl', function ($rootScope, $scope, $state, $stateParams, $ionicHistory, Daily, Dept, showPopup, Tool) {
  392. var userId = $stateParams.id;
  393. $scope.cancel = function () {
  394. $ionicHistory.goBack();
  395. }
  396. $scope.leftbtn = [{
  397. text: '取消',
  398. click: 'cancel'
  399. }, {
  400. text: '上一层',
  401. click: 'up'
  402. }];
  403. $scope.index = 0;
  404. $scope.deptlst = [];
  405. $scope.emplst = [];
  406. $scope.deptid = null;
  407. $scope.selecteditems = Tool.cloneObj(Daily.permissionUser);
  408. var selecteditems_old = [];
  409. _.each($scope.selecteditems.depts, function (dept) {
  410. selecteditems_old.push(dept.permission);
  411. });
  412. _.each($scope.selecteditems.users, function (user) {
  413. selecteditems_old.push(user.permission);
  414. });
  415. var patchs = {C: [], D: [], U: []};
  416. $scope.selectcount = '';
  417. $scope.isUp = false;
  418. $scope.loading = true;
  419. Dept.getDep().then(function (data) {
  420. d = _.find(data, function (dept) {
  421. return dept.parent == null;
  422. });
  423. data = _.filter(data, function (item) {
  424. return item.level == 1;
  425. });
  426. $scope.deptlst = data;
  427. setdeptrighticon($scope.deptlst);
  428. getemp(d.id);
  429. $scope.loading = false;
  430. });
  431. $scope.tochilddept = function (dept) {
  432. getChildDept(dept.id);
  433. }
  434. function getemp(id, childdepts) {
  435. Dept.getEmp(id).then(function (data) {
  436. $scope.emplst = data;
  437. setitem();
  438. });
  439. }
  440. function getChildDept(did) {
  441. Dept.getEmp(did).then(function (data) {
  442. $scope.emplst = data;
  443. $scope.deptlst = Dept.getChildDept(did);
  444. setdeptrighticon($scope.deptlst);
  445. setitem();
  446. deptid = did;
  447. if (did == 1) {
  448. $scope.index = 0;
  449. } else {
  450. $scope.index = 1;
  451. }
  452. });
  453. }
  454. function setitem() {
  455. _.each($scope.deptlst, function (cd) {
  456. cd.selected = false;
  457. _.each($scope.selecteditems.depts, function (dept) {
  458. if (cd.id == dept.id)
  459. cd.selected = true;
  460. });
  461. cd.isShow = Dept.getChildDept(cd.id).length == 0 ? false : true;
  462. });
  463. _.each($scope.emplst, function (e) {
  464. e.selected = false;
  465. _.each($scope.selecteditems.users, function (user) {
  466. if (e.user_id == user.user_id)
  467. e.selected = true;
  468. });
  469. });
  470. }
  471. function setdeptrighticon(deptlst) {
  472. _.each(deptlst, function (d) {
  473. d.isShow = Dept.getChildDept(d.id).length == 0 ? false : true;
  474. })
  475. }
  476. $scope.up = function () {
  477. var dept = _.find(Dept.all(), function (d) {
  478. return d.id == parseInt(deptid);
  479. });
  480. getChildDept(dept.parent);
  481. }
  482. $scope.change = function (selitem, op) {
  483. var type = op == 'd' ? true : false;
  484. if (op == 'd') {
  485. setSelectItem(selitem, type, $scope.selecteditems.depts);
  486. } else {
  487. setSelectItem(selitem, type, $scope.selecteditems.users);
  488. }
  489. if ($scope.selecteditems.all) {
  490. $scope.selecteditems.all = false;
  491. if ($scope.selecteditems.permissions.length == 1 && $scope.selecteditems.permissions[0].flag == 0) {
  492. patchs.D = $scope.selecteditems.permissions[0].id.toString();
  493. }
  494. }
  495. }
  496. function setSelectItem(selectItem, type, array) {
  497. if (selectItem.selected) {
  498. selectItem.permission = {
  499. 'user_id': userId,
  500. 'flag': type ? 1 : 2,
  501. 'value': type ? selectItem.id : selectItem.user_id
  502. };
  503. array.push(selectItem);
  504. } else {
  505. var item = _.find(array, function (item) {
  506. return type ? item.id == selectItem.id : item.user_id == selectItem.user_id;
  507. });
  508. array.splice(_.indexOf(array, item), 1);
  509. }
  510. }
  511. $scope.ok = function () {
  512. selecteditems = [];
  513. _.each($scope.selecteditems.depts, function (dept) {
  514. selecteditems.push(dept.permission);
  515. });
  516. _.each($scope.selecteditems.users, function (user) {
  517. selecteditems.push(user.permission);
  518. });
  519. rst = _.diff(selecteditems, selecteditems_old);
  520. if (patchs.D.length > 0) {
  521. if (rst.D.length > 0) {
  522. rst.D = rst.D + ',' + patchs.D;
  523. } else {
  524. rst.D = patchs.D;
  525. }
  526. }
  527. if (rst.C.length > 0 || rst.U.length > 0 || rst.D.length > 0) {
  528. showPopup.showLoading(1, '正在提交');
  529. Daily.dailypermission.patch(rst, function () {
  530. $rootScope.commons.refresh = true;
  531. showPopup.hideLoading();
  532. $ionicHistory.goBack();
  533. })
  534. } else {
  535. $ionicHistory.goBack();
  536. }
  537. }
  538. $scope.selectAll = function () {
  539. if ($scope.selecteditems.all) {
  540. if ($scope.selecteditems.permissions.length == 1 && $scope.selecteditems.permissions[0].flag == 0) {
  541. $ionicHistory.goBack();
  542. } else {
  543. showPopup.showLoading(1, '正在提交');
  544. var data = {C: [], D: [], U: []};
  545. data.C.push({
  546. 'user_id': userId,
  547. 'flag': 0,
  548. 'value': 0
  549. });
  550. data.D = _.map($scope.selecteditems.permissions, function (permission) {
  551. return permission.id;
  552. }).join(',');
  553. Daily.dailypermission.patch(data, function () {
  554. $rootScope.commons.refresh = true;
  555. showPopup.hideLoading();
  556. $ionicHistory.goBack();
  557. })
  558. }
  559. }
  560. }
  561. })
  562. .controller('DailyTemplateCtrl', function ($rootScope, $scope, $state, Daily, global) {
  563. $scope.gosetmoban = function (template) {
  564. Daily.currentTemplate = template;
  565. $state.go('daily-templateEdit', {
  566. "id": template.id
  567. });
  568. }
  569. global.fetch_user().then(function () {
  570. gettemplatedata();
  571. });
  572. $scope.doRefresh = function () {
  573. global.refresh = true;
  574. gettemplatedata();
  575. }
  576. $scope.loadMore = function () {
  577. if ($scope.templates != undefined && $scope.templates.next != null) {
  578. Tool.get($scope.templates.next).then(function (data) {
  579. _.each(data.results, function (item) {
  580. $scope.templates.results.push(item);
  581. });
  582. $scope.templates.next = data.next;
  583. $scope.templates.previous = data.previous;
  584. }).finally(function () {
  585. $scope.$broadcast('scroll.infiniteScrollComplete');
  586. $scope.loading = false;
  587. });
  588. } else {
  589. $scope.$broadcast('scroll.infiniteScrollComplete');
  590. }
  591. }
  592. $scope.moreCanBeLoaded = function () {
  593. return $scope.templates != undefined && $scope.templates.next != null ? true : false;
  594. }
  595. function gettemplatedata() {
  596. if (global.user.token != "") {
  597. if ($scope.templates == undefined) {
  598. $scope.loading = true;
  599. }
  600. Daily.template.get(function (res) {
  601. $scope.templates = res;
  602. }, function (err) {
  603. alert(JSON.stringify(err));
  604. }).$promise.finally(function () {
  605. $scope.$broadcast('scroll.refreshComplete');
  606. $scope.loading = false;
  607. });
  608. }
  609. }
  610. enter = $scope.$on('$ionicView.enter', function (event, data) {
  611. if (data.fromCache && $rootScope.commons.refresh) {
  612. $rootScope.commons.refresh = false;
  613. gettemplatedata();
  614. }
  615. });
  616. $scope.$on("$destroy", function () {
  617. enter = null;
  618. });
  619. })
  620. .controller('DailyTemplateScopeCtrl', function ($rootScope, $scope, $stateParams, $ionicHistory, $state, Dept, Daily) {
  621. $scope.leftbtn = [{
  622. text: '取消',
  623. click: 'cancel'
  624. }, {
  625. text: '上一层',
  626. click: 'up'
  627. }];
  628. $scope.isNew = $stateParams.id == -1;
  629. // Daily.templateData = {items: [], depts: []}
  630. $scope.deptsAll = [];
  631. $scope.index = 0;
  632. $scope.actived = false;
  633. $scope.cancel = function () {
  634. $ionicHistory.goBack();
  635. }
  636. $scope.depts = [];
  637. if (!$scope.isNew) {
  638. $scope.selecteddepts = _.map(Daily.templateData.depts, function (dept) {
  639. return {'id': dept.dept_id, 'depname': dept.dept_name}
  640. });
  641. } else {
  642. $scope.selecteddepts = []
  643. }
  644. $scope.selecteddepts_old = _.map($scope.selecteddepts, _.clone)
  645. $scope.selectdeptcount = '';
  646. $scope.showupbtn = false;
  647. var resourcedept = [];
  648. $scope.isUp = false;
  649. $scope.loading = true;
  650. function setdept(data) {
  651. $scope.depts = data;
  652. }
  653. Dept.getDep().then(function (data) {
  654. $scope.deptsAll = data;
  655. Daily.templatedept.get(function (res) {
  656. _.each($scope.deptsAll, function (dept) {
  657. dept.selected = _.find($scope.selecteddepts, function (d) {
  658. return d.id == dept.id && !$scope.isNew;
  659. }) == undefined ? false : true; //selected the existing dept
  660. if (!dept.selected) {
  661. dept.isdisabled = _.find(res.results, function (d) {
  662. return d.dept_id == dept.id;
  663. }) == undefined ? false : true;//部门是否已设置模板
  664. }
  665. dept.isshow = Dept.getChildDept(dept.id).length > 0;
  666. });
  667. $scope.loading = false;
  668. });
  669. depts_lvl_1 = _.filter($scope.deptsAll, function (item) {
  670. return item.level == 1;
  671. });
  672. setdept(depts_lvl_1);
  673. });
  674. $scope.change = function (dept) {
  675. if (dept.selected) {
  676. $scope.selecteddepts.push(dept);
  677. Daily.templateDepts.push(dept);
  678. } else {
  679. $scope.selecteddepts.splice(_.indexOf($scope.selecteddepts, dept), 1);
  680. Daily.templateDepts.splice(_.indexOf(Daily.templateDepts, dept), 1);
  681. }
  682. }
  683. $scope.ok = function () {
  684. depts = _.pluck($scope.selecteddepts, 'depname');
  685. dept_names = depts.join(',');
  686. dept_ids = _.pluck($scope.selecteddepts, 'id');
  687. if ($scope.isNew) {
  688. Daily.template.save({'name': dept_names, 'dept_ids': dept_ids}, function (dept) {
  689. $rootScope.commons.refresh = true;
  690. $state.go('custom-form', {id: dept.id});
  691. })
  692. } else {
  693. Daily.template.update({'id': $stateParams.id, 'name': dept_names, 'dept_ids': dept_ids}, function (dept) {
  694. $rootScope.commons.refresh = true;
  695. $ionicHistory.goBack();
  696. })
  697. }
  698. }
  699. var activedept = {};
  700. $scope.tochilddept = function (dept) {
  701. activedept = dept;
  702. if (dept.isshow) {
  703. getChildDept(dept);
  704. } else {
  705. activedept.selected = !activedept.selected;
  706. $scope.change(activedept);
  707. }
  708. }
  709. function getChildDept(dept) {
  710. var childdepts = Dept.getChildDept(dept.id);
  711. $scope.index = dept.level < 1 ? 0 : 1;
  712. if (childdepts.length > 0) {
  713. setdept(childdepts);
  714. }
  715. }
  716. $scope.up = function () {
  717. dept = _.find($scope.deptsAll, function (dept) {
  718. return dept.id == activedept.parent;
  719. });
  720. getChildDept(dept);
  721. activedept = dept
  722. }
  723. })
  724. .controller('DailyTemplateEditCtrl', function ($rootScope, $scope, $ionicHistory, $state, $stateParams, global, Dept, Daily, showPopup) {
  725. Daily.templateId = $stateParams.id;
  726. $scope.cancel = function () {
  727. $ionicHistory.goBack();
  728. }
  729. global.fetch_user().then(function (data) {
  730. gettemplatedata();
  731. });
  732. $scope.delete = function () {
  733. showPopup.confirm('是否删除该日报模板?', '是', '否').then(function (res) {
  734. if (res) {
  735. Daily.template.delete({id: $stateParams.id}, function () {
  736. $rootScope.commons.refresh = true;
  737. $ionicHistory.goBack();
  738. });
  739. }
  740. });
  741. }
  742. $scope.defineform = function () {
  743. $state.go('custom-form', {
  744. id: $stateParams.id
  745. });
  746. }
  747. $scope.toSetDept = function () {
  748. $state.go('daily-templateScope', {
  749. "id": $stateParams.id
  750. });
  751. }
  752. function gettemplatedata() {
  753. if (global.user.token != "") {
  754. Daily.template.get({'id': Daily.templateId}, function (res) {
  755. $scope.template = res;
  756. Daily.templateData = res;
  757. }, function (err) {
  758. alert(JSON.stringify(err));
  759. });
  760. }
  761. }
  762. enter = $scope.$on('$ionicView.enter', function (event, data) {
  763. if (data.fromCache && $rootScope.commons.refresh)
  764. gettemplatedata();
  765. });
  766. $scope.$on("$destroy", function () {
  767. enter = null;
  768. });
  769. })
  770. .controller('FormFieldTypeCtrl', function ($scope, $state, $ionicHistory, global, showPopup, Daily) {
  771. $scope.template_field = {};
  772. $scope.index = $state.params['id'];
  773. $scope.isNew = $scope.index == -1;
  774. $scope.showadd = false;
  775. $scope.template_field.required = false;
  776. $scope.selecttexts = [{text: ""}];
  777. $scope.template_field_active = {};
  778. if (!$scope.isNew && Daily.templateData.items[$scope.index]) {
  779. $scope.template_field = Daily.templateData.items[$scope.index];
  780. }
  781. watch = $scope.$watch('template_field', function (n, o) {
  782. if (n == o)
  783. return;
  784. $scope.template_field.isModified = true; //TODO:check
  785. }, true);
  786. global.fetch_user().then(function () {
  787. Daily.templatefield.get(function (res) {
  788. $scope.template_fields = res.results;
  789. if ($scope.isNew) {
  790. if ($scope.template_fields.length > 1) {
  791. $scope.template_field_active = $scope.template_fields[1]
  792. }
  793. } else {
  794. $scope.template_field_active = _.find($scope.template_fields, function (r_field) {
  795. return r_field.id == $scope.template_field.daily_template_field_id;
  796. })
  797. }
  798. if ($scope.template_field && $scope.template_field.extra)
  799. $scope.selecttexts = JSON.parse($scope.template_field.extra)
  800. })
  801. });
  802. $scope.back = function () {
  803. $ionicHistory.goBack();
  804. }
  805. $scope.add = function () {
  806. $scope.selecttexts.push({text: ""});
  807. }
  808. $scope.change = function (item) {
  809. $scope.template_field_active = item;
  810. }
  811. $scope.ok = function () {
  812. if ($scope.template_field.name == '' || $scope.template_field.name == undefined) {
  813. showPopup.PopupWindow(0, '名称不能为空!', false);
  814. return;
  815. }
  816. if ($scope.template_field.showlist)
  817. if ($scope.selecttexts.length == 0) {
  818. showPopup.PopupWindow(0, '请添加选项!', false);
  819. return;
  820. } else {
  821. $scope.template_field.extra = $scope.selecttexts;
  822. }
  823. exists = _.find(Daily.templateData.items, function (f) {
  824. return f.name == $scope.template_field.name && f != $scope.template_field;
  825. });
  826. if (exists) {
  827. showPopup.PopupWindow(0, '名称不能重复!', false);
  828. return;
  829. }
  830. if ($scope.template_field_active) {
  831. $scope.template_field.daily_template_field_id = $scope.template_field_active.id;
  832. $scope.template_field.t__type = $scope.template_field_active.type;
  833. }
  834. d = _.filter($scope.selecttexts, function (item) {
  835. return item.text != "";
  836. });
  837. if (d.length > 0) {
  838. $scope.template_field.extra = JSON.stringify(d)
  839. }
  840. if ($scope.isNew) {
  841. $scope.template_field.daily_template_id = Daily.templateId;
  842. Daily.templateData.items.push($scope.template_field);
  843. }
  844. $ionicHistory.goBack();
  845. }
  846. $scope.delete = function () {
  847. Daily.templateData.items.splice($scope.index, 1);
  848. $ionicHistory.goBack();
  849. }
  850. $scope.remove = function (index) {
  851. $scope.selecttexts.splice(index, 1);
  852. }
  853. $scope.$on("$destroy", function () {
  854. watch();
  855. })
  856. })
  857. .controller('CustomFormCtrl', function ($rootScope, $scope, $ionicHistory, $state, global, Daily, showPopup, Tool) {
  858. $scope.fieldItems = [];
  859. $scope.fieldItems_old = [];
  860. $scope.mobanitems = null;
  861. $scope.addmobanitems = null;
  862. Daily.templateId = $state.params['id'];
  863. $scope.isNew = Daily.templateId == -1;
  864. global.fetch_user().then(function (data) {
  865. Daily.templateitem.get({'daily_template_id': Daily.templateId}, function (res) {
  866. Daily.templateData.items = res.results;
  867. $scope.fieldItems = Daily.templateData.items;
  868. $scope.fieldItems_old = _.map($scope.fieldItems, _.clone);
  869. })
  870. });
  871. $scope.ok = function () {
  872. if (Daily.templateData.items.length == 0) {
  873. showPopup.PopupWindow(0, '请添加字段!', false);
  874. return;
  875. }
  876. showPopup.showLoading(1, '正在上传');
  877. Daily.templateData.description = Daily.get_description();
  878. Daily.template.update({'id': Daily.templateId, 'description': Daily.templateData.description});
  879. var fieldItems = _.map($scope.fieldItems, function (item) {
  880. return _.omit(item, 't__type');
  881. });
  882. rst = _.diff(fieldItems, $scope.fieldItems_old);
  883. Daily.templateitem.patch(rst, function () {
  884. $rootScope.commons.refresh = true;
  885. Tool.removeBackView('daily-templateScope');
  886. showPopup.hideLoading();
  887. $ionicHistory.goBack();
  888. });
  889. }
  890. $scope.cancel = function () {
  891. Daily.templateData.items = [];
  892. Tool.removeBackView('daily-templateScope');
  893. $ionicHistory.goBack();
  894. }
  895. $rootScope.commons.fun = $scope.cancel;
  896. $scope.tohref = function (item) {
  897. var index = _.indexOf(Daily.templateData.items, item);
  898. return '#/fieldtype/' + index;
  899. }
  900. $scope.preview = function () {
  901. Daily.previewData = {
  902. 'daily_tfs': Daily.templateData.items
  903. }
  904. $state.go('daily-edit', {
  905. 'flag': -1
  906. });
  907. }
  908. })
  909. .controller('AddItemCtrl', function ($rootScope, $scope, $state, $ionicHistory, Dept, Daily, showPopup) {
  910. $scope.isUp = false;
  911. $scope.leftbtn = [{
  912. text: '取消',
  913. click: 'cancel'
  914. }, {
  915. text: '上一层',
  916. click: 'up'
  917. }];
  918. $scope.index = 0;
  919. $scope.deptlst = [];
  920. $scope.emplst = [];
  921. $scope.selectedemplst = [];
  922. var deptid = 0;
  923. $scope.selectcount = '';
  924. Dept.getDep().then(function (data) {
  925. d = _.find(data, function (dept) {
  926. return dept.parent == null;
  927. });
  928. data = _.filter(data, function (item) {
  929. return item.level == 1;
  930. });
  931. $scope.deptlst = data;
  932. setdeptrighticon($scope.deptlst);
  933. getemp(d.id);
  934. });
  935. $scope.changedept = function (dept) {
  936. getdept_emp(dept.id);
  937. }
  938. $scope.change = function (emp) {
  939. if (emp.selected) {
  940. $scope.selectedemplst.push(emp);
  941. } else {
  942. $scope.selectedemplst.splice(_.indexOf($scope.selectedemplst, emp), 1);
  943. }
  944. }
  945. $scope.cancel = function () {
  946. $ionicHistory.goBack();
  947. }
  948. $scope.up = function () {
  949. var dept = _.find(Dept.all(), function (d) {
  950. return d.id == parseInt(deptid);
  951. });
  952. getdept_emp(dept.parent);
  953. }
  954. $scope.ok = function () {
  955. showPopup.showLoading(1, '提交中');
  956. var data = [];
  957. _.each($scope.selectedemplst, function (item) {
  958. data.push({'user': item.user_id, 'flag': 0, 'value': 0});
  959. });
  960. Daily.dailypermission.save(data, function () {
  961. $rootScope.commons.refresh = true;
  962. showPopup.hideLoading();
  963. $ionicHistory.goBack();
  964. });
  965. }
  966. function getdept_emp(did) {
  967. Dept.getEmp(did).then(function (data) {
  968. $scope.emplst = data;
  969. $scope.deptlst = Dept.getChildDept(did);
  970. setdeptrighticon($scope.deptlst);
  971. setitem();
  972. deptid = did;
  973. if (did == 1) {
  974. $scope.index = 0;
  975. } else {
  976. $scope.index = 1;
  977. }
  978. });
  979. }
  980. function getemp(id) {
  981. Dept.getEmp(id).then(function (data) {
  982. $scope.emplst = data;
  983. setitem();
  984. });
  985. }
  986. function setitem() {
  987. _.each($scope.emplst, function (e) {
  988. e.selected = false;
  989. e.disabled = false;
  990. _.each(Daily.permissionUsers, function (p) {
  991. if (p.user_id == parseInt(e.user_id)) {
  992. e.disabled = true;
  993. e.selected = true;
  994. }
  995. });
  996. _.each($scope.selectedemplst, function (e1) {
  997. if (e1.user_id == e.user_id) {
  998. e.selected = true;
  999. }
  1000. });
  1001. });
  1002. }
  1003. function setdeptrighticon(deptlst) {
  1004. _.each(deptlst, function (d) {
  1005. d.isShow = Dept.getChildDept(d.id).length == 0 ? false : true;
  1006. })
  1007. }
  1008. })
  1009. .controller('DailyEditCtrl', function ($rootScope, $scope, $stateParams, $state, $ionicHistory, $q, global, ImageManage, showPopup, Daily, Tool) {
  1010. $scope.flag = $stateParams.flag;
  1011. $scope.change = 1;
  1012. $scope.index = 14;
  1013. $scope.coke = 11;
  1014. $scope.image_list = [];
  1015. $scope.deleteimage_list = [];
  1016. $scope.popup = {
  1017. isPopup: false
  1018. };
  1019. var isModified = false;
  1020. $scope.changeDate = function (id) {
  1021. $scope.index = id;
  1022. $scope.change = 15 - id;
  1023. $scope.closeModal();
  1024. }
  1025. global.fetch_user().then(function () {
  1026. if ($scope.flag == 0) {
  1027. Daily.templatedept.get(function (td) {
  1028. dept = _.find(td.results, function (d) {
  1029. return d.dept_id == global.user.deptno;
  1030. });
  1031. Daily.templateitem.get({'daily_template_id': dept.daily_template_id}, function (res) {
  1032. Daily.templateData.items = res.results;
  1033. _.each(Daily.templateData.items, function (item) {
  1034. item.daily_template_item = item.id
  1035. });
  1036. Daily.previewData = {
  1037. 'daily_tfs': res.results
  1038. };
  1039. $scope.item = Daily.previewData;
  1040. $scope.item.files = [];
  1041. })
  1042. });
  1043. $scope.newDate = Daily.getDate();
  1044. } else if ($scope.flag == -1) {
  1045. $scope.item = Daily.previewData;
  1046. $scope.item.files = [];
  1047. $scope.newDate = Daily.getDate();
  1048. } else {
  1049. $scope.item = Tool.cloneObj(Daily.daily);
  1050. }
  1051. });
  1052. $scope.goBack = function () {
  1053. if ($scope.flag == 0) {
  1054. back = _.find($scope.item.daily_tfs, function (item) {
  1055. return item.text !== undefined && item.text != '';
  1056. });
  1057. showConfirm(isModified, '是否退出写日报?');
  1058. } else if ($scope.flag > 0) {
  1059. showConfirm(isModified, '是否放弃当前编辑?');
  1060. } else {
  1061. $ionicHistory.goBack();
  1062. }
  1063. }
  1064. $scope.addDaily = function () {
  1065. if (Daily.checkDaily($scope.item.daily_tfs)) {
  1066. showPopup.showLoading(1, '正在提交');
  1067. if ($scope.flag == 0) {
  1068. date = $scope.newDate[$scope.change].day;
  1069. Daily.dailymf.save({'daily_dd': date}, function (res) {
  1070. var id = res.id;
  1071. data = _.map($scope.item.daily_tfs, function (it) {
  1072. return _.extend(_.pick(it, 'text', 'daily_template_item'), {'daily_mf': id});
  1073. });
  1074. Daily.dailytf.save(data, function (res) {
  1075. $rootScope.commons.refresh = true;
  1076. var imagefiles = [];
  1077. _.each($scope.item.files, function (image) {
  1078. if (!image.id)
  1079. imagefiles.push(image.file_full_path);
  1080. });
  1081. if (imagefiles.length > 0) {
  1082. postimg(imagefiles, id);
  1083. } else {
  1084. showPopup.hideLoading();
  1085. $ionicHistory.goBack();
  1086. }
  1087. });
  1088. });
  1089. } else if ($scope.flag > 0) {
  1090. if (isModified) {
  1091. data = _.map($scope.item.daily_tfs, function (it) {
  1092. return _.pick(it, 'id', 'text', 'daily_template_item', 'daily_mf')
  1093. });
  1094. Daily.dailytf.update(data, function (res) {
  1095. $rootScope.commons.refresh = true;
  1096. _.each($scope.deleteimage_list, function (file) {
  1097. Daily.dailyfile.delete({id: file});
  1098. });
  1099. var imagefiles = [];
  1100. _.each($scope.item.files, function (image) {
  1101. if (!image.id)
  1102. imagefiles.push(image.file_full_path);
  1103. });
  1104. if (imagefiles.length > 0) {
  1105. postimg(imagefiles, $scope.flag);
  1106. } else {
  1107. showPopup.hideLoading();
  1108. $ionicHistory.goBack();
  1109. }
  1110. });
  1111. } else {
  1112. showPopup.hideLoading();
  1113. $ionicHistory.goBack();
  1114. }
  1115. } else {
  1116. showPopup.hideLoading();
  1117. $ionicHistory.goBack();
  1118. }
  1119. }
  1120. }
  1121. showPopup.modalTemplate('templates/modal-selectDate.html', 'slide-in-right', $scope).then(function (modal) {
  1122. $scope.select_date_modal = modal;
  1123. });
  1124. $scope.showModal = function () {
  1125. $scope.select_date_modal.show();
  1126. $rootScope.commons.modal = $scope.select_date_modal;
  1127. }
  1128. $scope.closeModal = function (rst) {
  1129. $rootScope.commons.modal.hide();
  1130. }
  1131. $scope.shouBigImage = function (imageName) { //传递一个参数(图片的URl)
  1132. $scope.Url = imageName; //$scope定义一个变量Url,这里会在大图出现后再次点击隐藏大图使用
  1133. $rootScope.commons.bigImage = true; //显示大图
  1134. }
  1135. $rootScope.commons.bigImage = false; //初始默认大图是隐藏的
  1136. $scope.hideBigImage = function () {
  1137. $rootScope.commons.bigImage = false;
  1138. }
  1139. $scope.deleteimage = function () {
  1140. var img = _.find($scope.item.files, function (image) {
  1141. return image.file_full_path == $scope.Url;
  1142. });
  1143. if (img) {
  1144. $scope.item.files.splice(_.indexOf($scope.item.files, img), 1);
  1145. if (img.id)
  1146. $scope.deleteimage_list.push(img.id);
  1147. }
  1148. $rootScope.commons.bigImage = false;
  1149. }
  1150. $scope.addphoto = function () {
  1151. $scope.popup.optionsPopup = showPopup.showSelectImgPopup(Camera, ImagePicker, $scope);
  1152. $scope.popup.isPopup = true;
  1153. }
  1154. if ($scope.flag > 0) {
  1155. watch = $scope.$watch('item', function (n, o) {
  1156. if (n == o)
  1157. return;
  1158. isModified = true;
  1159. }, true);
  1160. }
  1161. $scope.$on("$destroy", function () {
  1162. if ($rootScope.commons.modal)
  1163. $rootScope.commons.modal = null;
  1164. $scope.select_date_modal.remove();
  1165. if ($scope.flag > 0) {
  1166. watch();
  1167. }
  1168. });
  1169. function ImagePicker() { //打开相册
  1170. $scope.popup.optionsPopup.close();
  1171. ImageManage.ImagePicker_getPictures(10).then(function (data) {
  1172. _.each(data, function (imageUrl) {
  1173. $scope.item.files.push({
  1174. "file_thumbnail_path": imageUrl,
  1175. "file_full_path": imageUrl
  1176. });
  1177. });
  1178. });
  1179. }
  1180. function Camera() {
  1181. $scope.popup.optionsPopup.close();
  1182. ImageManage.Camera_getPicture().then(function (result) {
  1183. $scope.item.files.push({
  1184. "file_thumbnail_path": result,
  1185. "file_full_path": result
  1186. });
  1187. });
  1188. }
  1189. function postimg(imgfiles, id) {
  1190. ImageManage.uploadImage(imgfiles, 'daily', id, 'dailyfile').then(function (res) {
  1191. $q.all(res).then(function (data) {
  1192. showPopup.hideLoading();
  1193. $ionicHistory.goBack();
  1194. })
  1195. }, function (err) {
  1196. alert(JSON.stringify(error));
  1197. showPopup.PopupWindow(0, 'upload image fail');
  1198. })
  1199. }
  1200. function showConfirm(flag, content) {
  1201. if (flag) {
  1202. showPopup.confirm(content, '是', '否').then(function (res) {
  1203. if (res)
  1204. $ionicHistory.goBack();
  1205. });
  1206. } else {
  1207. $ionicHistory.goBack();
  1208. }
  1209. }
  1210. })
  1211. .controller('DailyReadMonthCountCtrl', function ($rootScope, $scope, $state, global, Daily, showPopup) {
  1212. var daily_dd = $state.params['daily_dd'];
  1213. var date = new Date(daily_dd);
  1214. $scope.year = date.getFullYear();
  1215. $scope.month = date.getMonth() + 1;
  1216. global.fetch_user().then(function () {
  1217. if (global.user.token != "") {
  1218. Daily.mouthsummary.get({'daily_dd': daily_dd}, function (res) {
  1219. $scope.monthView = res;
  1220. }, function (err) {
  1221. alert(JSON.stringify(err));
  1222. });
  1223. Daily.dailydeptview.query(function (res) {
  1224. $scope.index = res[0].id;
  1225. if (res[0].id == 1 && res[0].parent == null)
  1226. res[0].depname = '全体成员';
  1227. $scope.depts = res;
  1228. })
  1229. }
  1230. });
  1231. $scope.changeindex = function (dept) {
  1232. $scope.index = dept.id;
  1233. var data = {'dept': dept.id, 'daily_dd': daily_dd};
  1234. if (dept.parent == null)
  1235. data = _.omit(data, 'dept');
  1236. Daily.mouthsummary.get(data, function (res) {
  1237. $scope.monthView = res;
  1238. $scope.closeModal();
  1239. })
  1240. }
  1241. showPopup.modalTemplate('templates/modal-selectdept.html', 'slide-in-right', $scope).then(function (modal) {
  1242. $scope.select_dept_modal = modal;
  1243. });
  1244. $scope.showModal = function () {
  1245. $scope.select_dept_modal.show();
  1246. $rootScope.commons.modal = $scope.select_dept_modal;
  1247. }
  1248. $scope.closeModal = function (rst) {
  1249. $rootScope.commons.modal.hide();
  1250. }
  1251. $scope.$on("$destroy", function () {
  1252. if ($rootScope.commons.modal)
  1253. $rootScope.commons.moda = null;
  1254. $scope.select_dept_modal.remove();
  1255. })
  1256. })
  1257. .controller('DailyReadDayCtrl', function ($rootScope, $scope, $state, global, Daily, Tool) {
  1258. var daily_dd = $state.params['daily_dd'];
  1259. var date = new Date(daily_dd);
  1260. $scope.month = date.getMonth() + 1;
  1261. $scope.day = date.getDate();
  1262. global.fetch_user().then(function () {
  1263. getdailydata();
  1264. });
  1265. $scope.totransfer = function (id) {
  1266. $state.go('transfer', {
  1267. module: 'daily',
  1268. id: id
  1269. });
  1270. }
  1271. $scope.lookCount = function () {
  1272. $state.go('daily-readDayCount', {
  1273. 'daily_dd': daily_dd
  1274. });
  1275. }
  1276. $scope.shouBigImage = function (imageName, event) { //传递一个参数(图片的URl)
  1277. $scope.Url = imageName; //$scope定义一个变量Url,这里会在大图出现后再次点击隐藏大图使用
  1278. $rootScope.commons.bigImage = true; //显示大图
  1279. event.stopPropagation();
  1280. }
  1281. $rootScope.commons.bigImage = false; //初始默认大图是隐藏的
  1282. $scope.hideBigImage = function () {
  1283. $rootScope.commons.bigImage = false;
  1284. }
  1285. $scope.doRefresh = function () {
  1286. global.refresh = true;
  1287. getdailydata();
  1288. }
  1289. $scope.loadMore = function () {
  1290. if ($scope.dailys != undefined && $scope.dailys.next != null) {
  1291. Tool.get($scope.dailys.next).then(function (data) {
  1292. _.each(data.results, function (item) {
  1293. $scope.dailys.results.push(item);
  1294. });
  1295. $scope.dailys.next = data.next;
  1296. $scope.dailys.previous = data.previous;
  1297. }).finally(function () {
  1298. $scope.$broadcast('scroll.infiniteScrollComplete');
  1299. $scope.loading = false;
  1300. });
  1301. } else {
  1302. $scope.$broadcast('scroll.infiniteScrollComplete');
  1303. }
  1304. }
  1305. $scope.moreCanBeLoaded = function () {
  1306. return $scope.dailys != undefined && $scope.dailys.next != null ? true : false;
  1307. }
  1308. function getdailydata() {
  1309. if (global.user.token != "") {
  1310. if ($scope.dailys == undefined) {
  1311. $scope.loading = true;
  1312. }
  1313. Daily.dailyview.get({'daily_dd': daily_dd}, function (res) {
  1314. $scope.dailys = res;
  1315. }, function (err) {
  1316. alert(JSON.stringify(err));
  1317. }).$promise.finally(function () {
  1318. $scope.$broadcast('scroll.refreshComplete');
  1319. $scope.loading = false;
  1320. });
  1321. }
  1322. }
  1323. })
  1324. .controller('DailyReadDayCountCtrl', function ($scope, $state, global, Daily) {
  1325. var daily_dd = $state.params['daily_dd'];
  1326. var date = new Date(daily_dd);
  1327. $scope.year = date.getFullYear();
  1328. $scope.month = date.getMonth() + 1;
  1329. $scope.day = date.getDate();
  1330. global.fetch_user().then(function () {
  1331. if (global.user.token != "") {
  1332. Daily.todaysummary.get({'daily_dd': daily_dd}, function (res) {
  1333. console.log(res);
  1334. $scope.toDayView = res;
  1335. }, function (err) {
  1336. alert(JSON.stringify(err));
  1337. });
  1338. }
  1339. });
  1340. $scope.lookDeptCount = function (flag, users, dept, isSubmit) {
  1341. if (isSubmit != 0) {
  1342. Daily.toDayViewUsers = users;
  1343. $state.go('daily-readDayDeptCount', {
  1344. 'flag': flag,
  1345. 'daily_dd': daily_dd,
  1346. 'dept': dept
  1347. });
  1348. }
  1349. }
  1350. })
  1351. .controller('DailyReadDayDeptCountCtrl', function ($scope, $state, Daily) {
  1352. var daily_dd = $state.params['daily_dd'];
  1353. $scope.flag = $state.params['flag'];
  1354. $scope.dept = $state.params['dept'];
  1355. var date = new Date(daily_dd);
  1356. $scope.year = date.getFullYear();
  1357. $scope.month = date.getMonth() + 1;
  1358. $scope.day = date.getDate();
  1359. $scope.users = Daily.toDayViewUsers;
  1360. });