activityApplyCtrl.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /**
  2. * Created by pushkeji on 2018/12/27.
  3. */
  4. angular.module('push')
  5. .controller('activityApplyCtrl', ['$scope','activitiesModuleService','$timeout','$q','UserService','$stateParams','ResourceLibraryService','$ionicSlideBoxDelegate','CommentService','ConfigService','ScienceCircleService','CommonService','$ionicScrollDelegate','ConstantService','$ionicActionSheet','UtilService','ShareService','dataToolsService','$sce',function($scope,activitiesModuleService,$timeout,$q,UserService,$stateParams,ResourceLibraryService,$ionicSlideBoxDelegate,CommentService,ConfigService,ScienceCircleService,CommonService,$ionicScrollDelegate,ConstantService,$ionicActionSheet,UtilService,ShareService,dataToolsService,$sce){
  6. console.log($stateParams);
  7. $scope.formList=JSON.parse(localStorage.settingItems||$stateParams.settingItems);
  8. localStorage.emptyFormList=$stateParams.settingItems;
  9. var activityid=$stateParams.activityid||localStorage.activityid;
  10. var title='';
  11. // console.log(JSON.parse(localStorage.feedbackItem||'{}'));
  12. // console.log(activityid);
  13. // console.log($stateParams);
  14. angular.forEach($scope.formList,function(val){
  15. if(val.type=='configurablePages'&&!val.otherid){
  16. val.isedit=0;
  17. val.buttonText='添加'+val.text;
  18. val.acitivityid=$stateParams.acitivityid||localStorage.activityid;
  19. }
  20. if(val.type=='select'){
  21. dataToolsService.getTypeEntryListByTypeName(val.selectkey).then(function(res){
  22. if(res.code==3350){
  23. // console.log(res);
  24. val.listItem=[];
  25. angular.forEach(res.data,function(value){
  26. val.listItem.push({
  27. text: '<a class="action-sheet-push">' + value.itemkey + '</a>',
  28. itemkey: value.itemvalue,
  29. itemvalue: value.itemkey //名字
  30. })
  31. })
  32. }
  33. });
  34. }
  35. });
  36. var feedbackItem=JSON.parse(localStorage.feedbackItem||'{}');
  37. for(var key in feedbackItem){
  38. if(feedbackItem[key].length>0&&key!='connid'){
  39. for(var i=0;i<$scope.formList.length;i++){
  40. if((key=='achievement'&&$scope.formList[i].text=='成果')||(key=='demand'&&$scope.formList[i].text=='需求')||(key=='patent'&&$scope.formList[i].text=='专利')){
  41. $scope.formList[i].isedit=1;//编辑
  42. $scope.formList[i].content=feedbackItem.connid;//
  43. $scope.formList[i].buttonText='编辑'+$scope.formList[i].text;
  44. $scope.formList[i].otherid='';
  45. angular.forEach(feedbackItem[key],function(val){
  46. $scope.formList[i].otherid+=val.id+',';
  47. });
  48. break;
  49. }
  50. }
  51. }
  52. }
  53. $scope.selectItems=function(index){
  54. if($scope.formList[index].type=='select'||$scope.formList[index].type=='selectDomain'||$scope.formList[index].type=='affiliatedOrg'||$scope.formList[index].type=='companyTaskSelect'){
  55. var list=$scope.formList[index].listItem;
  56. $ionicActionSheet.show({
  57. buttons:list,
  58. cancelText:'取消',
  59. buttonClicked:function(indx){
  60. $scope.formList[index].key=list[indx].itemkey;
  61. $scope.formList[index].content=list[indx].itemvalue;
  62. return true;
  63. }
  64. })
  65. }
  66. }
  67. // 录入
  68. var orgType = "";
  69. $scope.goToInput=function(index){
  70. angular.forEach($scope.formList, function(val){
  71. if(val.text == "身份类别"){
  72. if(val.content == "高校"){
  73. orgType = 10105;
  74. }
  75. if(val.content == "企业"){
  76. orgType = 10104;
  77. }
  78. }
  79. })
  80. console.log($scope.formList[index]);
  81. localStorage.settingItems=JSON.stringify($scope.formList);
  82. localStorage.activityid=$stateParams.activityid||localStorage.activityid;
  83. for(var i=0;i<$scope.formList.length;i++){
  84. if($scope.formList[i].text=='所属机构'){
  85. title=$scope.formList[i].content;
  86. }
  87. }
  88. if (UserService.node == '330122000' && $scope.formList[index].pageid == 4) {
  89. $scope.go('visitModularFormDemand', {
  90. companyid: 0,
  91. connid:$scope.formList[index].content,
  92. pageid: $scope.formList[index].pageid,
  93. orgtype: orgType,
  94. pagecode: $scope.formList[index].pagecode,
  95. isedit: $scope.formList[index].isedit,
  96. node: UserService.node,
  97. pageTitle: '新建录入',
  98. comfrom:$stateParams.comfrom||'activityApply',
  99. title:title
  100. });
  101. } else{
  102. $scope.go('visitModularForm', {companyid: 0,connid:$scope.formList[index].content, pageid: $scope.formList[index].pageid, orgtype: orgType,pagecode:$scope.formList[index].pagecode, isedit: $scope.formList[index].isedit,node:UserService.node,pageTitle:$scope.formList[index].isedit?'编辑录入':'新建录入',comfrom:$stateParams.comfrom||'activityApply',title:title});
  103. }
  104. }
  105. var saveflg=0;
  106. // 活动报名
  107. $scope.submitForm=function(){
  108. console.log($scope.formList);
  109. if(saveflg){
  110. return;
  111. }
  112. saveflg=1;
  113. // 非空判断
  114. for(var i=0;i<$scope.formList.length;i++){
  115. if($scope.formList[i].isneed&&(!$scope.formList[i].content&&!$scope.formList[i].otherid)){
  116. if($scope.app){
  117. UtilService.showMess($scope.formList[i].text+'是必填项');
  118. }else{
  119. CommonService.showMessage($scope.formList[i].text+'是必填项',$scope);
  120. }
  121. $scope.hideLoadingToast();
  122. saveflg =0;
  123. return;
  124. }
  125. }
  126. var params={};
  127. params.data=[];
  128. angular.forEach($scope.formList,function(val){
  129. params.data.push({
  130. "activityid":$stateParams.activityid||localStorage.activityid,
  131. "userid":UserService.id,
  132. "itemid":val.id,
  133. "otherid":val.otherid||'',
  134. "linktype":val.linktype,
  135. "itemvalue":val.content||''
  136. })
  137. });
  138. params.node = UserService.node;
  139. // console.log(params);
  140. activitiesModuleService.applyForActivity(params).then(function(res){
  141. console.log(res);
  142. if(res.code==3350){
  143. localStorage.settingItems='';
  144. localStorage.activityid='';
  145. localStorage.feedbackItem='';
  146. if($stateParams.comfrom=='participantList'){
  147. $scope.go('participantList',{activityid:activityid,settingItems:localStorage.emptyFormList});
  148. }else{
  149. $scope.go('activityDetail',{activityid:activityid});
  150. }
  151. }
  152. })
  153. }
  154. // 模糊查询
  155. $scope.queryOrgName=function(index){
  156. if($scope.formList[index].fuzzyquery){
  157. if($scope.formList[index].content){
  158. var pagecode=$scope.code==4803?1000003:1000004;
  159. dataToolsService.getOrganizationModelByOrgname($scope.formList[index].content,pagecode,0).then(function (response) {
  160. // console.log(response);
  161. if(response.code==3350){
  162. $scope.orgList = response.data;
  163. $scope.isRelateUl = true;
  164. }else{
  165. $scope.orgList = [];
  166. $scope.isRelateUl = false;
  167. }
  168. }, function () {
  169. })
  170. }else{
  171. $scope.isRelateUl=false;
  172. $scope.orgList=[];
  173. }
  174. }
  175. }
  176. $scope.ttt=function(tmptitle){
  177. return $sce.trustAsHtml(tmptitle);
  178. }
  179. // 选中机构
  180. $scope.setOrgName=function(org,index){
  181. console.log(org);
  182. $scope.orgid=org.id;
  183. $scope.formList[index].content=org.name;
  184. $scope.formList[index].otherid=org.id;
  185. // console.log($scope.formList);
  186. $scope.isRelateUl = false;
  187. }
  188. $scope.gobackToComfrom=function(){
  189. if($stateParams.comfrom=='participantList'){
  190. $scope.go('participantList',{activityid:activityid,settingItems:localStorage.emptyFormList});
  191. }else{
  192. $scope.go('activityDetail',{activityid:activityid});
  193. }
  194. }
  195. $scope.$on("$ionicView.beforeLeave", function(){
  196. // localStorage.settingItems='';
  197. })
  198. }]);