sendMessageCtrl.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. angular.module('push')
  2. .controller('sendMessageCtrl', function ($scope, $ionicPopup, ResourceLibraryService, $stateParams, CommentService, UtilService, $timeout, CommonService,$ionicHistory,UserService,$ionicLoading) {
  3. $scope.sixresourcelist = [];
  4. $scope.job = $stateParams.job;
  5. $scope.resrole = $stateParams.resrole;
  6. angular.forEach($scope.job.items, function (val) {
  7. if (val.selected) {
  8. $scope.rolename = val.name;
  9. }
  10. })
  11. $scope.esIdList = [];
  12. angular.forEach($stateParams.resourcelist, function (val) {
  13. $scope.esIdList.push(val.unique);
  14. })
  15. console.log($scope.esIdList, $scope.rolename)
  16. // ResourceLibraryService.getResourceListByESList($scope.esIdList, $scope.rolename).then(function (res) {
  17. ResourceLibraryService.getResourceListByESList($scope.esIdList, '全部').then(function (res) {
  18. if (res.code == 3350) {
  19. console.log(res)
  20. $scope.sendPeopleNum = 0;
  21. $scope.datalist = res.data;
  22. angular.forEach($scope.datalist, function(val1){
  23. angular.forEach(val1.userInfoList, function(val2){
  24. if(val2.tel){
  25. $scope.sendPeopleNum ++;
  26. }
  27. })
  28. })
  29. angular.forEach($scope.datalist, function(val, index){
  30. if(index < 6){
  31. $scope.sixresourcelist.push(val);
  32. }
  33. })
  34. if($scope.sendPeopleNum > 6){
  35. $scope.showSixListFlag = true;
  36. $scope.showshouqiFlag = true;
  37. }else{
  38. $scope.showSixListFlag = false;
  39. $scope.showshouqiFlag = false;
  40. }
  41. }
  42. $scope.hideLoadingToast();
  43. })
  44. $scope.showMorePeople = function(){
  45. $scope.showSixListFlag = !$scope.showSixListFlag;
  46. }
  47. $scope.notice = {};
  48. $scope.notice.templateid=1584977
  49. $scope.showLoadingToast = function () {
  50. $ionicLoading.show({
  51. template: '<p><ion-spinner icon="bubbles" class="spinner-calm"></ion-spinner><br><span style="color: #3B8BD0;font-size: 18px;font-weight: bold">努力加载中···</span></p>',
  52. content: '努力加载中',
  53. animation: 'fade-in',
  54. showBackdrop: true,//是否显示蒙层
  55. maxWidth: 150,
  56. showDelay: 0
  57. });
  58. // $timeout(function () {
  59. // $ionicLoading.hide();
  60. // }, 15000);
  61. };
  62. $scope.send = function () {
  63. if(!$scope.notice.templateid){
  64. $ionicPopup.alert({
  65. title: '提示',
  66. template: "请输入模板id"
  67. })
  68. return;
  69. }
  70. if(!$scope.notice.templatetext){
  71. $ionicPopup.alert({
  72. title: '提示',
  73. template: "请输入短信内容"
  74. })
  75. return;
  76. }
  77. $scope.telList = [];
  78. var templateid = $scope.notice.templateid;
  79. angular.forEach($scope.datalist, function (data) {
  80. angular.forEach(data.userInfoList, function (user) {
  81. if (user.tel) {
  82. var userinfo = data.resid;
  83. userinfo += "," + user.job + "," + user.name + "," + user.tel;
  84. $scope.telList.push(userinfo);
  85. }
  86. })
  87. })
  88. if($scope.telList.length ==0){
  89. $ionicPopup.alert({
  90. title: '提示',
  91. template: '您所选择的企业没有收件人,请重新选择!'
  92. })
  93. return;
  94. }
  95. if($scope.telList.length > 200){
  96. $ionicPopup.alert({
  97. title: '提示',
  98. template: '最多只能发送200个联系人!'
  99. })
  100. return;
  101. }
  102. ResourceLibraryService.sendMessageToUsers($scope.telList, templateid, $scope.notice.templatetext, $scope.resrole,UserService.node,UserService.id).then(function (res) {
  103. $scope.hideLoadingToast();
  104. if (res.code == 3350) {
  105. if (res.data == "全部发送成功") {
  106. $ionicPopup.alert({
  107. title: '提示',
  108. template: '全部发送成功'
  109. })
  110. $scope.showLoadingToast();
  111. ResourceLibraryService.getSmsList().then(function (res) {
  112. if (res.code == 3350) {
  113. if (res.data.length > 0) {
  114. $scope.go("noticeHelper", {list: res.data});
  115. } else {
  116. $scope.hideLoadingToast();
  117. $scope.go("tab.account");
  118. }
  119. }
  120. })
  121. }
  122. if (res.data == "部分发送失败") {
  123. $ionicPopup.alert({
  124. title: '提示',
  125. template: '部分发送失败,请检查发送号码'
  126. })
  127. $scope.showLoadingToast();
  128. ResourceLibraryService.getSmsList().then(function (res) {
  129. if (res.code == 3350) {
  130. if (res.data.length > 0) {
  131. $scope.go("noticeHelper", {list: res.data});
  132. } else {
  133. $scope.hideLoadingToast();
  134. $scope.go("tab.account");
  135. }
  136. }
  137. })
  138. }
  139. if (res.data == "全部发送失败") {
  140. $ionicPopup.alert({
  141. title: '提示',
  142. template: '全部发送失败,请检查发送号码和发送内容'
  143. })
  144. }
  145. } else {
  146. $ionicPopup.alert({
  147. title: '提示',
  148. template: '请检查发送号码和发送内容'
  149. })
  150. }
  151. })
  152. }
  153. });