controllers.js 48 KB

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