activitiesHollCtrl.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. angular.module('push')
  2. .controller('activitiesHollCtrl', ['$scope', 'activitiesModuleService', '$timeout', '$q', 'UserService', 'ConfigService', '$ionicScrollDelegate', 'CommonService', '$ionicPopup', 'UtilService', 'dataToolsService', '$stateParams', function ($scope, activitiesModuleService, $timeout, $q, UserService, ConfigService, $ionicScrollDelegate, CommonService, $ionicPopup, UtilService, dataToolsService, $stateParams) {
  3. //虚拟搜索框
  4. $scope.isShowSearchButton = true;
  5. $scope.keyfilter = {
  6. key: ''
  7. }
  8. $scope.pagenum = 1;
  9. $scope.pagesize = 6;
  10. $scope.noData = false;
  11. $scope.activitiytype = 0;
  12. $scope.defaultLan = UserService.defaultLan;
  13. var type = 0;
  14. var totalpage = 0;
  15. $scope.allData = [];
  16. if ($scope.app) {
  17. if (device.platform != "Android") {
  18. $scope.isIos = true;
  19. } else {
  20. $scope.isIos = false;
  21. }
  22. }
  23. $scope.goBackWhere = function () {
  24. if ($stateParams.comfrom == 'homepageOfNode') {
  25. $scope.go('homepageOfNode');
  26. } else if ($stateParams.comfrom == 'tab.account') {
  27. $scope.go('tab.account');
  28. } else {
  29. $scope.go('tab.activityIndex');
  30. }
  31. };
  32. // taskModuleService.getAllTaskLable(UserService.node).then(function(res){
  33. // $scope.labelList=[{
  34. // itemvalue:0,
  35. // itemkey:'全部',
  36. // isSelected:true
  37. // }];
  38. // if(res.code==3350){
  39. // angular.forEach(res.data,function(val){
  40. // val.isSelected=false;
  41. // })
  42. // $scope.labelList=$scope.labelList.concat(res.data);
  43. // }
  44. // });
  45. // taskModuleService.getEnterpriseList().then(function(res){
  46. // console.log(res);
  47. // })
  48. if ($scope.defaultLan == 'Chinese') {
  49. $scope.taskHollList = [
  50. { title: '活动列表', selected: true, type: 0 },
  51. { title: '我发布的', selected: false, type: 1 },
  52. { title: '我参与的', selected: false, type: 2 }
  53. ];
  54. } else {
  55. $scope.taskHollList = [
  56. { title: 'Activities List', selected: true, type: 0 },
  57. { title: 'My Submission', selected: false, type: 1 },
  58. { title: 'My Participation', selected: false, type: 2 }
  59. ];
  60. }
  61. if ($stateParams.comfrom == 'tab.account') {
  62. $scope.taskHollList = [
  63. { title: '活动列表', selected: false, type: 0 },
  64. { title: '我发布的', selected: false, type: 1 },
  65. { title: '我参与的', selected: true, type: 2 }
  66. ]
  67. }
  68. $scope.addrKey = '';
  69. $scope.tasktype = 0;
  70. var searchList = function () {
  71. $scope.showLoadingToast();
  72. var deferred = $q.defer();
  73. //查询任务列表
  74. // addr, type,status,keyword,pagenum,pagesize
  75. activitiesModuleService.getAllActivitiesList(type, $scope.addrKey, 0, $scope.tasktype, $scope.keyfilter.key, $scope.pagenum, $scope.pagesize).then(function (res) {
  76. console.log(res);
  77. $scope.hideLoadingToast();
  78. totalpage = res.page.totalPage;
  79. if ($scope.pagenum >= totalpage) {
  80. // 如果没有数据了 用ng-if彻底结束
  81. $scope.showLoadMore = false;
  82. }
  83. deferred.resolve(res.data);
  84. })
  85. return deferred.promise;
  86. }
  87. // 获取活动类别
  88. var activityType = [];
  89. dataToolsService.getTypeEntryListByTypeName('activity_type').then(function (res) {
  90. console.log(res);
  91. if (res.code == 3350) {
  92. activityType = res.data;
  93. }
  94. });
  95. var editTime = function (time) {
  96. var a = time.split(':');
  97. a.pop();
  98. return a.join(':');
  99. }
  100. $scope.getData = function () {
  101. searchList().then(function (data) {
  102. $scope.allData = data;
  103. // $scope.logo=JSON.parse(data.images).photoName;
  104. $scope.noData = $scope.allData.length == 0;
  105. angular.forEach($scope.allData, function (val) {
  106. // console.log(val);
  107. val.logo = val.images ? JSON.parse(val.images).originalName : '';
  108. // console.log(JSON.parse(val.images));
  109. // 处理时间
  110. val.begintime = editTime(val.begintime);
  111. val.endtime = editTime(val.endtime);
  112. var bgTime = val.begintime.split(' ');
  113. var edTime = val.endtime.split(' ');
  114. val.organizeTime = '';
  115. if (bgTime[0] === edTime[0]) {
  116. val.organizeTime = bgTime[0] + ' ' + bgTime[1] + ' ~ ' + edTime[1];
  117. } else {
  118. val.organizeTime = val.begintime + ' ~ ' + val.endtime;
  119. }
  120. // 反查活动类型
  121. for (var i = 0; i < activityType.length; i++) {
  122. if (val.type == activityType[i].itemvalue) {
  123. val.typename = activityType[i].itemkey;
  124. break;
  125. }
  126. }
  127. // if(val)
  128. // 事件按钮
  129. // val.action0=false;//对接录入 5322
  130. // val.action1=false;//对接录入 5322
  131. // val.action2=false;//评价 5323
  132. // val.action3=false;//申请奖励 5324
  133. // val.action4=false;//任务完成 5325
  134. // val.actionNum=0;
  135. // var tempArr=val.otherObj.actions?val.otherObj.actions.split(','):[];
  136. // // console.log(tempArr);
  137. // if(tempArr.length>0){
  138. // for(var i=0;i<tempArr.length;i++){
  139. // switch (Number(tempArr[i])){
  140. // case 5321:val.action0=true;val.actionNum++;break;
  141. // case 5322:val.action1=true;val.actionNum++;break;
  142. // // case 5323:val.action2=true;val.actionNum++;break;
  143. // case 5324:val.action3=true;val.actionNum++;break;
  144. // case 5325:val.action4=true;val.actionNum++;break;
  145. // }
  146. //
  147. // }
  148. // }
  149. // val.noSuthority=false;
  150. // if(val.otherObj.creator!=UserService.id&&val.otherObj.taskstatus==5300&&val.actionNum==0){
  151. // val.noSuthority=true;
  152. // }
  153. })
  154. });
  155. }
  156. $scope.getData();
  157. $scope.changeSelected = function (index) {
  158. $scope.pagenum = 1;
  159. $scope.showLoadMore = true;
  160. if ((index == 1 || index == 2) && !ConfigService.islogin) {
  161. if (localStorage.wxFlag == "true") {
  162. if (localStorage.isUserFocusXW == 0) {
  163. var title = localStorage.appidStr;
  164. $ionicPopup.alert({
  165. title: '提示',
  166. template: '请先关注微信公众号"' + title + '"!'
  167. });
  168. return;
  169. } else {
  170. if (localStorage.isUserBindWx == 0) {
  171. var wxFlag = JSON.parse(localStorage.params);
  172. if (wxFlag.weChatModel) {
  173. $scope.go('bindPhone', {
  174. params: localStorage.params,
  175. comfrom: 'maincontroller',
  176. url: window.location.href.split('#/')[1]
  177. });
  178. } else {
  179. $scope.go('login');
  180. return;
  181. }
  182. } else {
  183. $scope.go('login');
  184. return;
  185. }
  186. }
  187. } else {
  188. $scope.go('login');
  189. return;
  190. }
  191. }
  192. angular.forEach($scope.taskHollList, function (val) {
  193. val.selected = false;
  194. })
  195. $scope.taskHollList[index].selected = true;
  196. type = $scope.taskHollList[index].type;
  197. $scope.allData = [];
  198. $scope.getData();
  199. $ionicScrollDelegate.$getByHandle('privateContent').scrollTop(true);
  200. }
  201. $scope.showSearchButtonLeft = function () {
  202. // console.log('aaa');
  203. $scope.isShowSearchButton = false;
  204. $timeout(function () {
  205. $(".showSearchInput").focus();
  206. }, 300)
  207. };
  208. $scope.clearSearch = function () {
  209. $scope.isShowSearchButton = true;
  210. $scope.keyfilter.key = "";
  211. $scope.getData();
  212. }
  213. // 下拉刷新
  214. $scope.refreshData = function () {
  215. $scope.pagenum = 1;
  216. $scope.showLoadMore = true;
  217. $scope.getData();
  218. $scope.$broadcast('scroll.refreshComplete');
  219. };
  220. $scope.showLoadMore = true;
  221. $scope.loadMore = function () {
  222. if ($scope.showLoadMore) {
  223. $scope.pagenum++;
  224. searchList().then(function (data) {
  225. $scope.allData = $scope.allData.concat(data);
  226. $scope.$broadcast(
  227. 'scroll.infiniteScrollComplete'
  228. );
  229. });
  230. }
  231. // if($scope.pagenum>=totalpage){
  232. // // 如果没有数据了 用ng-if彻底结束
  233. // $scope.showLoadMore=false;
  234. // }else{
  235. // searchList().then(function(data){
  236. // $scope.allData=$scope.allData.concat(data);
  237. // $scope.$broadcast(
  238. // 'scroll.infiniteScrollComplete'
  239. // );
  240. // });
  241. // }
  242. }
  243. // $scope.$on('stateChangeSuccess', function() {
  244. // $scope.loadMore();
  245. // });
  246. $scope.releaseActivity = function () {
  247. // console.log(1);
  248. if (!ConfigService.islogin) {
  249. if (localStorage.wxFlag == "true") {
  250. if (localStorage.isUserFocusXW == 0) {
  251. var title = localStorage.appidStr;
  252. $ionicPopup.alert({
  253. title: '提示',
  254. template: '请先关注微信公众号"' + title + '"!'
  255. });
  256. return;
  257. } else {
  258. if (localStorage.isUserBindWx == 0) {
  259. var wxFlag = JSON.parse(localStorage.params);
  260. if (wxFlag.weChatModel) {
  261. $scope.go('bindPhone', {
  262. params: localStorage.params,
  263. comfrom: 'maincontroller',
  264. url: window.location.href.split('#/')[1]
  265. });
  266. } else {
  267. $scope.go('login');
  268. return;
  269. }
  270. } else {
  271. $scope.go('login');
  272. return;
  273. }
  274. }
  275. } else {
  276. $scope.go('login');
  277. return;
  278. }
  279. } else {
  280. activitiesModuleService.hasReleaseAuthority().then(function (res) {
  281. console.log(res);
  282. if (res.data) {
  283. $scope.go('activityRelease');
  284. } else {
  285. // if($scope.app){
  286. // UtilService.showMess('没有权限,请先认证');
  287. // }else{
  288. // CommonService.showMessage('没有权限,请先认证',$scope);
  289. // }
  290. var myPopup = $ionicPopup.show({
  291. // template: '<input type="password" ng-model="data.wifi">',
  292. title: '认证通过方可发布活动',
  293. // subTitle: '没有权限,请先认证',
  294. scope: $scope,
  295. buttons: [
  296. { text: '取消' },
  297. {
  298. text: '<b>去认证</b>',
  299. type: 'button-positive',
  300. onTap: function (e) {
  301. $scope.go('identifySystem', { comfrom: 'activitiesHoll' })
  302. }
  303. },
  304. ]
  305. });
  306. }
  307. });
  308. }
  309. }
  310. $scope.goToTaskDetail = function (list) {
  311. if (!ConfigService.islogin) {
  312. if (localStorage.wxFlag == "true") {
  313. if (localStorage.isUserFocusXW == 0) {
  314. var title = localStorage.appidStr;
  315. $ionicPopup.alert({
  316. title: '提示',
  317. template: '请先关注微信公众号"' + title + '"!'
  318. });
  319. return;
  320. } else {
  321. if (localStorage.isUserBindWx == 0) {
  322. var wxFlag = JSON.parse(localStorage.params);
  323. if (wxFlag.weChatModel) {
  324. $scope.go('bindPhone', {
  325. params: localStorage.params,
  326. comfrom: 'maincontroller',
  327. url: window.location.href.split('#/')[1]
  328. });
  329. } else {
  330. $scope.go('login');
  331. return;
  332. }
  333. } else {
  334. $scope.go('login');
  335. return;
  336. }
  337. }
  338. } else {
  339. $scope.go('login');
  340. return;
  341. }
  342. } else {
  343. $scope.go('activityDetail', {
  344. activityid: list.id,
  345. });
  346. }
  347. }
  348. $scope.goToTaskAction = function (list, action, index) {
  349. console.log(list);
  350. if (!ConfigService.islogin) {
  351. if (localStorage.wxFlag == "true") {
  352. if (localStorage.isUserFocusXW == 0) {
  353. var title = localStorage.appidStr;
  354. $ionicPopup.alert({
  355. title: '提示',
  356. template: '请先关注微信公众号"' + title + '"!'
  357. });
  358. return;
  359. } else {
  360. if (localStorage.isUserBindWx == 0) {
  361. var wxFlag = JSON.parse(localStorage.params);
  362. if (wxFlag.weChatModel) {
  363. $scope.go('bindPhone', {
  364. params: localStorage.params,
  365. comfrom: 'maincontroller',
  366. url: window.location.href.split('#/')[1]
  367. });
  368. } else {
  369. $scope.go('login');
  370. return;
  371. }
  372. } else {
  373. $scope.go('login');
  374. return;
  375. }
  376. }
  377. } else {
  378. $scope.go('login');
  379. return;
  380. }
  381. }
  382. if (action == 5323) {
  383. $scope.go('taskEvaluate', {
  384. taskRes: JSON.stringify(list)
  385. })
  386. } else if (action == 5322) {
  387. // 对接录入
  388. $scope.go('dockingInput', {
  389. comfrom: 'dockingInput',
  390. taskTitle: list.title,
  391. taskid: list.otherObj.id,
  392. companyName: list.school,
  393. companyid: list.otherObj.companyid,
  394. })
  395. } else if (action == 5324) {
  396. $scope.go('visitModularForm', {
  397. companyid: list.otherObj.companyid,
  398. pageTitle: '新建录入',
  399. pagecode: 1000027,
  400. pageid: 15,
  401. restype: 0,
  402. node: list.source,
  403. title: list.school,
  404. })
  405. } else if (action == 5325) {
  406. var confirmPopup = $ionicPopup.confirm({
  407. title: '提示信息',
  408. template: '是否确定结束任务?',
  409. buttons: [
  410. { text: '取消' },
  411. {
  412. text: '<b>确定</b>',
  413. type: 'button-positive',
  414. onTap: function () {
  415. return 'ok'
  416. }
  417. },
  418. ]
  419. });
  420. confirmPopup.then(function (res) {
  421. if (res == 'ok') {
  422. var senddata = {
  423. data: {
  424. resourceid: list.unique,
  425. action: 5325,
  426. creator: UserService.id
  427. },
  428. node: UserService.node
  429. }
  430. $scope.showLoadingToast();
  431. console.log(senddata);
  432. taskModuleService.saveOrupdatetaskAction(senddata).then(function (res) {
  433. console.log(res);
  434. $scope.getData();
  435. // if(res.code==3350){
  436. // // $scope.go('taskHoll');
  437. // $scope.showDockingButton=true;
  438. // $scope.showApplyButton=false;
  439. // if($scope.app){
  440. // UtilService.showMess("任务申请成功!");
  441. // }else{
  442. // CommonService.showMessage("任务申请成功!",$scope);
  443. // }
  444. // getTaskDetail();
  445. // getAllParticipant();
  446. // }
  447. $scope.hideLoadingToast();
  448. })
  449. } else {
  450. return;
  451. }
  452. });
  453. } else if (action == 5321) {
  454. senddata = {
  455. data: {
  456. resourceid: list.unique,
  457. action: 5321,
  458. creator: UserService.id
  459. },
  460. node: UserService.node
  461. }
  462. $scope.showLoadingToast();
  463. console.log(senddata);
  464. taskModuleService.saveOrupdatetaskAction(senddata).then(function (res) {
  465. console.log(res);
  466. if (res.code == 3350) {
  467. // $scope.go('taskHoll');
  468. // $scope.showDockingButton=true;
  469. // $scope.showApplyButton=false;
  470. if ($scope.app) {
  471. UtilService.showMess("任务申请成功!");
  472. } else {
  473. CommonService.showMessage("任务申请成功!", $scope);
  474. }
  475. // getTaskDetail();
  476. // getAllParticipant();
  477. // getTaskDetail().then(function(data){
  478. // getAllParticipant();
  479. // })
  480. $scope.allData[index].action1 = true;
  481. $scope.allData[index].action0 = false;
  482. $scope.allData[index].action3 = true;
  483. $scope.allData[index].otherObj.actions = '5322,5324';
  484. // $scope.go('taskDetail',$stateParams,{reload:true});
  485. }
  486. $scope.hideLoadingToast();
  487. })
  488. }
  489. }
  490. }]);