ActivityScheduleCtrl.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. angular.module('push')
  2. .controller('ActivityScheduleCtrl', function ($scope, $stateParams, CommentService, $ionicActionSheet, DockingService, UtilService, $ionicSlideBoxDelegate, $timeout, $ionicScrollDelegate, UserService) {
  3. var today = UtilService.formatDate().formattime3.substring(0,11);
  4. $scope.activityobj = {
  5. isUpdate: 1,//1新增 2编辑
  6. aid: 0,
  7. atitle: "",
  8. connid: $stateParams.infoid,
  9. sourcefrom: 1,// 来源:1-APP 2-WEB
  10. leadername: "",// 团队负责人姓名
  11. leaderuniversity: "",// 所属院校id
  12. leaderuniversityname: "",// 所属院校
  13. leadertel: "",// 联系方式
  14. companyid: "",// 企业id
  15. orgname: "",// 企业名称
  16. orgleadername: "",// 企业负责人姓名
  17. orgleaderduties: "",// 负责人职务
  18. registplace: "",// 所在地区
  19. areaid: "",
  20. orgaddress: "",// 详细地址
  21. orgtel: "",// 企业联系方式
  22. tagname: "",// 对接状态名称
  23. tagid: 0,// 对接状态
  24. tagtime: today,// 对接时间
  25. tagcontent: "",// 需求指导思路
  26. // capital_scale: 0,// 需求预算
  27. // cooperationmodelname: "",// 拟合作模式名称
  28. dockingid : 0,// 对接需求id
  29. docking_content: "",// 对接需求名称
  30. newdocking_content: "",
  31. techrequirementdetail: "",
  32. technical_description: "",// 现场需求简介
  33. imagelist: []
  34. // industry_title: "",// 产学研或科技服务项目名称
  35. // industry_description: ""// 产学研或科技服务项目简介
  36. };
  37. $("#dockingDateTime").attr("value",today);
  38. $scope.showreqdetail = false;
  39. $scope.imagelist = [];
  40. $scope.showmorecompany = false;
  41. $scope.showmorereq = false;
  42. //获取对接状态标签
  43. var reqnamebuttons = [];
  44. //根据记录id获取新建需求反馈所需的初始化信息
  45. var initActivitiesFollowup = function () {
  46. DockingService.initActivitiesFollowup($stateParams.infoid).then(function (response) {
  47. console.log(response);
  48. if (UtilService.isDefined(response.activitymodel)) {
  49. $scope.activityobj.aid = response.activitymodel.id;
  50. $scope.activityobj.atitle = response.activitymodel.title;
  51. }
  52. if (UtilService.isDefined(response.sysUsersInfo)) {
  53. $scope.activityobj.leadername = response.sysUsersInfo.name;
  54. $scope.activityobj.leaderuniversity = response.sysUsersInfo.universityid;
  55. $scope.activityobj.leaderuniversityname = response.sysUsersInfo.universityname;
  56. $scope.$broadcast("recuniversity",response.sysUsersInfo.universityname);
  57. $scope.activityobj.leadertel = UserService.user.user.mobile;
  58. }
  59. if (UtilService.isDefined(response.company)) {
  60. $scope.activityobj.companyid = response.company.companyid;
  61. $scope.activityobj.orgname = response.company.companyname;
  62. $scope.activityobj.orgleadername = response.company.contact;
  63. $scope.activityobj.orgleaderduties = response.company.c_title;
  64. $scope.activityobj.registplace = response.company.district;
  65. $scope.$broadcast("recregistplace",$scope.activityobj.registplace);
  66. $scope.activityobj.areaid = response.company.companyareaid;
  67. $scope.activityobj.orgaddress = response.company.detailaddress;
  68. $scope.activityobj.orgtel = response.company.contactnum;
  69. }
  70. if (UtilService.isDefined(response.reqList) && response.reqList.length>0) {
  71. angular.forEach(response.reqList, function (value, index) {
  72. var temphtml = {
  73. text: '<a class="action-sheet-push">' + value.techrequirementname + '</a>',
  74. reqid: value.id,
  75. reqname: value.techrequirementname
  76. };
  77. reqnamebuttons.push(temphtml);
  78. });
  79. var temphtml2 = {
  80. text: '<a class="action-sheet-push">现场发现需求</a>',
  81. reqid: 0,
  82. reqname: "现场发现需求"
  83. };
  84. reqnamebuttons.push(temphtml2);
  85. }
  86. }, function () {
  87. });
  88. };
  89. initActivitiesFollowup();
  90. //获取对接状态标签
  91. var buttons = [];
  92. var getLabelList = function () {
  93. CommentService.getLabelList().then(function (response) {
  94. angular.forEach(response, function (value, index) {
  95. var temphtml = {
  96. text: '<a class="action-sheet-push">' + value.name + '</a>',
  97. tagid: value.id,
  98. tagname: value.name
  99. };
  100. buttons.push(temphtml);
  101. });
  102. }, function () {
  103. })
  104. };
  105. getLabelList();
  106. //保存活动跟进表
  107. var saveflg = 0;
  108. $scope.saveActivitySchedule = function () {
  109. var tempstr = $("#dockingDateTime").val();
  110. if (UtilService.isDefined(tempstr)) {
  111. $scope.activityobj.tagtime = UtilService.formatTime(tempstr);
  112. }
  113. if (!UtilService.isDefined($scope.activityobj.tagtime)) {
  114. UtilService.showMess("对接时间不能为空");
  115. return;
  116. }
  117. if (!UtilService.isDefined($scope.activityobj.tagname)) {
  118. UtilService.showMess("请选择对接状态");
  119. return;
  120. }
  121. if (!UtilService.isDefined($scope.activityobj.leadername)) {
  122. UtilService.showMess("团队负责人姓名不能为空");
  123. return;
  124. }
  125. if (!UtilService.isDefined($scope.activityobj.leaderuniversityname)) {
  126. UtilService.showMess("所属院校名称不能为空");
  127. return;
  128. }
  129. /*if (!UtilService.isDefined($scope.activityobj.leadertel)) {
  130. UtilService.showMess("负责人联系方式不能为空");
  131. return;
  132. }*/
  133. if (!UtilService.isDefined($scope.activityobj.orgname)) {
  134. UtilService.showMess("对接企业名称不能为空");
  135. return;
  136. }
  137. /*if (!UtilService.isDefined($scope.activityobj.orgleadername)) {
  138. UtilService.showMess("对接企业负责人姓名不能为空");
  139. return;
  140. }
  141. if (!UtilService.isDefined($scope.activityobj.orgleaderduties)) {
  142. UtilService.showMess("对接企业负责人职务不能为空");
  143. return;
  144. }
  145. if (!UtilService.isDefined($scope.activityobj.registplace)) {
  146. UtilService.showMess("对接企业所在地区不能为空");
  147. return;
  148. }
  149. if (!UtilService.isDefined($scope.activityobj.orgaddress)) {
  150. UtilService.showMess("对接企业详细地址不能为空");
  151. return;
  152. }
  153. if (!UtilService.isDefined($scope.activityobj.orgtel)) {
  154. UtilService.showMess("企业联系方式不能为空");
  155. return;
  156. }*/
  157. if ($scope.activityobj.dockingid != 0 && !UtilService.isDefined($scope.activityobj.docking_content)) {
  158. UtilService.showMess("需求名称不能为空");
  159. return;
  160. }
  161. if ($scope.activityobj.dockingid == 0 && !UtilService.isDefined($scope.activityobj.newdocking_content)) {
  162. UtilService.showMess("现场需求名称不能为空");
  163. return;
  164. }
  165. if ($scope.activityobj.dockingid == 0){
  166. $scope.activityobj.docking_content = $scope.activityobj.newdocking_content;
  167. }
  168. if (!UtilService.isDefined($scope.activityobj.tagcontent)) {
  169. UtilService.showMess("需求指导思路不能为空");
  170. return;
  171. }
  172. /*if (!UtilService.isDefined($scope.activityobj.industry_title)) {
  173. UtilService.showMess("项目名称不能为空");
  174. return;
  175. }
  176. if (!UtilService.isDefined($scope.activityobj.industry_description)) {
  177. UtilService.showMess("对接项目简介不能为空");
  178. return;
  179. }*/
  180. if (saveflg != 0) {
  181. return;
  182. }
  183. saveflg = 1;
  184. $scope.showLoadingToast();
  185. if ($scope.imagelist.length > 0) {
  186. uploadImages();
  187. } else {
  188. saveInfo();
  189. }
  190. };
  191. var tempimages = [];
  192. var uploadImages = function () {
  193. tempimages = [];
  194. var upimages = [];
  195. angular.forEach($scope.imagelist, function (data) {
  196. upimages.push(data.photo_name);
  197. });
  198. UtilService.uploadFile(upimages, 0, "image/jpeg").then(function (response) {
  199. // console.log(response);
  200. angular.forEach(response, function (value) {
  201. if (value.status) {
  202. tempimages.push({
  203. photo_name: value.userPhoto,
  204. original_name: value.originalPhoto,
  205. source_name: value.sourcePhoto,
  206. source_size: value.source_size
  207. });
  208. }
  209. });
  210. $timeout(function () {
  211. $scope.activityobj.imagelist = angular.toJson(tempimages);
  212. saveInfo();
  213. }, 100);
  214. }, function () {
  215. $scope.hideLoadingToast();
  216. UtilService.showMess("网络不给力,请重试");
  217. saveflg = 0;
  218. })
  219. };
  220. var saveInfo = function () {
  221. console.log($scope.activityobj);
  222. DockingService.saveActivitySchedule($scope.activityobj).then(function (response) {
  223. console.log(response);
  224. if (response.isSuccess == 1) {
  225. UtilService.showMess("添加成功");
  226. $timeout(function () {
  227. $scope.goback();
  228. }, 1500);
  229. } else {
  230. UtilService.showMess("网络不给力,请重试");
  231. }
  232. $scope.hideLoadingToast();
  233. saveflg = 0;
  234. }, function () {
  235. UtilService.showMess("网络不给力,请重试");
  236. $scope.hideLoadingToast();
  237. saveflg = 0;
  238. })
  239. };
  240. //展示企业选择列表
  241. $scope.selectCompany = function () {
  242. $scope.showmorecompany = !$scope.showmorecompany;
  243. };
  244. //选择企业
  245. $scope.checkCompany = function (company) {
  246. $scope.activityobj.orgname = company;
  247. $scope.showmorecompany = false;
  248. };
  249. //展示需求选择列表
  250. $scope.selectReq = function () {
  251. $scope.showmorereq = !$scope.showmorereq;
  252. };
  253. //选择需求
  254. $scope.checkReq = function (req) {
  255. $scope.activityobj.docking_content = req;
  256. $scope.showmorereq = false;
  257. };
  258. //选择对接状态
  259. $scope.showDockingStatus = function () {
  260. $ionicActionSheet.show({
  261. buttons: buttons,
  262. cancelText: '取消',
  263. buttonClicked: function (index) {
  264. $scope.activityobj.tagid = buttons[index].tagid;
  265. $scope.activityobj.tagname = buttons[index].tagname;
  266. return true;
  267. }
  268. });
  269. };
  270. //选择需求名称
  271. $scope.showReqName = function () {
  272. $ionicActionSheet.show({
  273. buttons: reqnamebuttons,
  274. cancelText: '取消',
  275. buttonClicked: function (index) {
  276. $scope.activityobj.dockingid = reqnamebuttons[index].reqid;
  277. $scope.activityobj.docking_content = reqnamebuttons[index].reqname;
  278. if(reqnamebuttons[index].reqid==0){
  279. $scope.showreqdetail = true;
  280. }else {
  281. $scope.showreqdetail = false;
  282. }
  283. return true;
  284. }
  285. });
  286. };
  287. //接收高校选择数据
  288. var reciveuniversity = $scope.$on("university", function (event, data) {
  289. $scope.activityobj.leaderuniversity = data.id;
  290. $scope.activityobj.leaderuniversityname = data.name;
  291. });
  292. //接收城市选择数据
  293. var reciveregplace = $scope.$on("registplace", function (event, data) {
  294. $scope.activityobj.areaid = data.areaid;
  295. $scope.activityobj.registplace = data.registplace;
  296. });
  297. //页面销毁时 回收广播
  298. $scope.$on('$destroy', function () {
  299. reciveregplace();
  300. reciveuniversity();
  301. });
  302. $scope.openCamera = function () {
  303. if ($scope.imagelist.length >= 9) {
  304. UtilService.showMess("最多选取9张图片");
  305. return;
  306. }
  307. UtilService.getPicture(1).then(function (results) {
  308. // console.log(results);
  309. $scope.imagelist.push({photo_name: results, original_name: results});
  310. $scope.totalImglength = 600 * $scope.imagelist.length;
  311. $ionicScrollDelegate.$getByHandle("scrollimage").resize();
  312. }, function (err) {
  313. });
  314. };
  315. $scope.show = function () {
  316. $ionicActionSheet.show({
  317. buttons: [
  318. {text: '<a class="action-sheet-push">相册中添加照片</a>'},
  319. {text: '<a class="action-sheet-push">拍照</a>'}
  320. ],
  321. cancelText: '取消',
  322. buttonClicked: function (index) {
  323. if (index == 0) {
  324. getPictures();
  325. } else if (index == 1) {
  326. $scope.openCamera();
  327. }
  328. return true;
  329. }
  330. });
  331. };
  332. var verifyStorage = function () {
  333. window.imagePicker.verifyStorage(
  334. function (results) {
  335. if (results == "1") {
  336. getPic();
  337. }
  338. }, function (error) {
  339. }
  340. );
  341. };
  342. var getPic = function () {
  343. if ($scope.imagelist.length >= 9) {
  344. UtilService.showMess("最多选取9张图片");
  345. return;
  346. }
  347. UtilService.getPictureList(9 - $scope.imagelist.length).then(function (results) {
  348. // console.log(results);
  349. angular.forEach(results, function (value, index) {
  350. $scope.imagelist.push({photo_name: value, original_name: value})
  351. });
  352. $scope.totalImglength = 600 * $scope.imagelist.length;
  353. $ionicScrollDelegate.$getByHandle("scrollimage").resize();
  354. }, function (err) {
  355. });
  356. };
  357. var getPictures = function () {
  358. if (device.platform == "Android") {
  359. verifyStorage();
  360. } else {
  361. getPic();
  362. }
  363. };
  364. //点击图片放大
  365. $scope.bigImage = false; //初始默认大图是隐藏的
  366. $scope.hideBigImage = function () {
  367. if($scope.app){
  368. $scope.setStatusBar(0);
  369. }
  370. $timeout(function () {
  371. $scope.bigImage = false;
  372. }, 400);
  373. };
  374. $scope.shouBigImage = function (index) { //传递一个参数(图片的URl)
  375. if($scope.app){
  376. $scope.setStatusBar(1);
  377. }
  378. $(function () {
  379. $('div.pinch-zoom').each(function () {
  380. new RTP.PinchZoom($(this), {});
  381. });
  382. });
  383. $scope.bigImage = true;//显示大图
  384. $ionicSlideBoxDelegate.update();//重绘,让图片显示出来
  385. //图片总数量
  386. setTimeout(function () {
  387. $ionicSlideBoxDelegate.$getByHandle('slide_detail').slide(index, -10);
  388. //获取图片
  389. var imgObj = document.getElementsByClassName('bigimage');
  390. var n;
  391. for (n = 0; n < imgObj.length; n++) {
  392. // 获取图片的原始高度和宽度
  393. var oldWid = imgObj[n].naturalWidth;
  394. var oldHei = imgObj[n].naturalHeight;
  395. var screen = document.body.offsetWidth;
  396. var screenH = window.innerHeight;
  397. // console.log(oldWid / oldHei);
  398. // console.log(screen);
  399. var cc = screen / (oldWid / oldHei);
  400. imgObj[n].style.height = cc + 'px';
  401. if (cc < screenH) {
  402. imgObj[n].style.marginTop = (screenH - cc) / 2 + 'px';
  403. // console.log("e:"+imgObj[n].style.marginTop);
  404. } else {
  405. imgObj[n].style.marginTop = 0 + 'px';
  406. // console.log((cc-screenH) +'px')
  407. }
  408. }
  409. }, 10);
  410. };
  411. //删除图片
  412. $scope.deletePhoto = function (index) {
  413. $scope.imagelist.splice(index, 1);
  414. };
  415. //时间选择器
  416. $(function () {
  417. var currYear = (new Date()).getFullYear();
  418. var opt = {};
  419. opt.date = {preset: 'date'};
  420. opt.datetime = {preset: 'datetime'};
  421. opt.time = {preset: 'time'};
  422. opt.default = {
  423. theme: 'android-ics light', //皮肤样式
  424. display: 'bottom', //显示方式
  425. mode: 'scroller', //日期选择模式
  426. dateFormat: 'yyyy年mm月dd日',
  427. lang: 'zh',
  428. showNow: true,
  429. nowText: "今天",
  430. startYear: currYear - 50, //开始年份
  431. endYear: currYear + 10 //结束年份
  432. };
  433. /*$("#appDateTime").mobiscroll($.extend(opt['date'], opt['default']));*/
  434. var optDateTime = $.extend(opt['datetime'], opt['default']);
  435. $("#dockingDateTime").mobiscroll(optDateTime).date(optDateTime);
  436. });
  437. });