controllers.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. starter.controller('SigninReportCtrl', function ($scope, $state, $rootScope, showPopup, global, Tool, SigninReport) {
  2. $scope.loading = true;
  3. global.fetch_user().then(function () {
  4. $scope.get_data(4);
  5. });
  6. var beforeEnter = $scope.$on('$ionicView.beforeEnter', function () {
  7. showPopup.modalTemplate('templates/modal-filter.html', 'slide-in-right', $scope).then(function (modal) {
  8. $rootScope.commons.modal = modal;
  9. });
  10. });
  11. $scope.seedetail = function (item) {
  12. SigninReport.filter.trs_dd = item.trs_dd;
  13. SigninReport.filter.choice_date = $scope.acitve_date.key;
  14. $state.go('tab.signinreportdetail');
  15. };
  16. $scope.date_list = [
  17. {"value": "上季", "key": 7},
  18. {"value": "本季", "key": 6},
  19. {"value": "上月", "key": 5},
  20. {"value": "本月", "key": 4},
  21. {"value": "上周", "key": 3},
  22. {"value": "本周", "key": 2},
  23. {"value": "当日", "key": 1}
  24. ].reverse();
  25. $scope.acitve_date = $scope.date_list[3];
  26. $scope.change = function (item) {
  27. if ($scope.acitve_date.value == item.value) {
  28. $rootScope.commons.modal.hide();
  29. return;
  30. }
  31. $scope.acitve_date = item;
  32. $scope.loading = true;
  33. $scope.get_data(item.key);
  34. $rootScope.commons.modal.hide();
  35. console.log(JSON.stringify(item));
  36. };
  37. $scope.get_data = function (key) {
  38. SigninReport.report.query({"choice_date": $scope.acitve_date.key, "cz_list": ""}, function (data) {
  39. SigninReport.reportdata = angular.copy(data);
  40. get_results(data);
  41. }, function (err) {
  42. alert(JSON.stringify(err))
  43. }).$promise.finally(function (f) {
  44. $scope.loading = false;
  45. $scope.$broadcast('scroll.refreshComplete');
  46. })
  47. };
  48. function get_results(data) {
  49. var date_list = _.uniq(_.map(data, function (item) {
  50. item.daystr = Tool.getTranslateByKey("weekdays", new Date(item.trs_dd).getDay());
  51. item.date = item.trs_dd.substr(0, 7);
  52. return item.trs_dd.substr(0, 7);
  53. }));
  54. $scope.report = _.map(date_list, function (date) {
  55. return {"date": new Date(date), "items": _.filter(data, {"date": date})}
  56. });
  57. console.log($scope.report)
  58. }
  59. })
  60. .controller('SigninReportDetailCtrl', function ($scope, $state, $rootScope, $ionicHistory, showPopup, global, Tool, SigninReport) {
  61. global.fetch_user().then(function (data) {
  62. $scope.report = _.find(SigninReport.reportdata, {"trs_dd": SigninReport.filter.trs_dd});
  63. });
  64. $scope.goBack = function () {
  65. $ionicHistory.goBack()
  66. };
  67. })
  68. .controller('SigninReportDetailMoreCtrl', function ($scope, $state, $rootScope, $ionicHistory, showPopup, global, SigninReport, Tool) {
  69. global.fetch_user().then(function (data) {
  70. $scope.report = _.find(SigninReport.reportdata, {"trs_dd": SigninReport.filter.trs_dd});
  71. SigninReport.item.get(function (res) {
  72. $scope.items = res;
  73. })
  74. });
  75. $scope.openModal = function () {
  76. $rootScope.commons.modal.show();
  77. };
  78. showPopup.modalTemplate('templates/modal-items.html', 'slide-in-right', $scope).then(function (modal) {
  79. $rootScope.commons.modal = modal;
  80. });
  81. $scope.ok = function () {
  82. $rootScope.commons.modal.hide();
  83. $scope.loading = true;
  84. SigninReport.report.query({"choice_date": SigninReport.filter.choice_date, "cz_list": _.pluck(_.filter($scope.items.Data, {"selected": true}), "no").join(',')}, function (data) {
  85. SigninReport.reportdata = angular.copy(data);
  86. get_results(data);
  87. }, function (err) {
  88. alert(JSON.stringify(err))
  89. }).$promise.finally(function (f) {
  90. $scope.loading = false;
  91. })
  92. };
  93. $scope.loadMore = function () {
  94. Tool.get_nextpage($scope.items.next).then(function (res) {
  95. var old_data = angular.copy($scope.items.Data);
  96. $scope.items = res.Data;
  97. $scope.items.Data = old_data.concat(res.data.Data);
  98. }).finally(function (f) {
  99. $scope.$broadcast('scroll.infiniteScrollComplete');
  100. })
  101. };
  102. $scope.goBack = function () {
  103. $ionicHistory.goBack()
  104. };
  105. function set_item() {
  106. }
  107. })