technicalBrokerPublishTrainCtrl.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. angular.module('push')
  2. .controller('technicalBrokerPublishTrainCtrl', function ($scope, $stateParams, $ionicActionSheet, $ionicPopup, ActivityService, UtilService, $ionicSlideBoxDelegate,
  3. $timeout, $ionicScrollDelegate, UserService, $ionicModal, TechnicalBrokerPublishTrainService,
  4. AccountService) {
  5. var today = UtilService.formatDate().formattime3.substring(0, 20);
  6. $scope.trainListobj = {
  7. isUpdate: 1,//1新增 2编辑
  8. id: 0,
  9. traintype: 0,
  10. traintypename: "",
  11. title: "",
  12. content: "",
  13. trainbegintime: "",
  14. signupenddate: "",
  15. areaid: 0,
  16. areaname: "",
  17. detailaddress: "",
  18. isactive: 1,// 培训状态:是否有效,0无效,1有效
  19. sponsors: "",// 传到后台的主办方json stype:类别:1.主办方 2.协办方
  20. cosponsors: "",// 传到后台的协办方json stype:类别:1.主办方 2.协办方
  21. delsponsors: "",// 删除的主办方/协办方
  22. sponsorlist: [],// 取得详情里的主办方
  23. sponsor: [{
  24. id: 0,
  25. sid: 0,
  26. stype: 2,
  27. orgtype: 0,
  28. sponsorname: "",
  29. introduce: "",
  30. categorydetail: "",
  31. logo: ""
  32. }],// 取得添加主办方的内容
  33. lecturers: "",// 传到后台的讲师
  34. dellecturers: "",// 删除的讲师
  35. images: "",// 传到后台的图片json
  36. delimages: "",// 删除的图片
  37. imagelist: []// app端图片插件进行传递的变量
  38. };
  39. // $("#trainbegintime").attr("value", today);
  40. $scope.showreqdetail = false;
  41. $scope.sponsors = "";
  42. $scope.delsponsors = "";
  43. $scope.sponsorlist = [];
  44. $scope.lecturers = "";
  45. $scope.dellecturers = "";
  46. $scope.images = "";
  47. $scope.delimages = "";
  48. $scope.imagelist = [];
  49. $scope.showmorecompany = false;
  50. $scope.showmorereq = false;
  51. $scope.companylist = [];
  52. $scope.sponsorList = [];// 主办方
  53. $scope.cosponsorList = [{
  54. id: 0,
  55. sid: 0,
  56. stype: 2,
  57. orgtype: 0,
  58. sponsorname: "",
  59. introduce: "",
  60. categorydetail: "",
  61. logo: ""
  62. }];// 协办方
  63. var delsponsors = [];
  64. $scope.lecturerList = [{
  65. id: 0,
  66. lecturername: ""
  67. }];
  68. var dellecturers = [];
  69. // 获取培训种类列表
  70. var buttons = [];
  71. var getTraintypeList = function () {
  72. TechnicalBrokerPublishTrainService.getTraintypeList().then(function (response) {
  73. // console.log(response);
  74. if (UtilService.isDefined(response.traintypeList) && response.traintypeList.length > 0) {
  75. $scope.trainListobj.traintype = response.traintypeList[0].itemvalue;
  76. $scope.trainListobj.traintypename = response.traintypeList[0].itemkey;
  77. angular.forEach(response.traintypeList, function (value, index) {
  78. var temphtml = {
  79. text: '<a class="action-sheet-push">' + value.itemkey + '</a>',
  80. traintype: value.itemvalue,
  81. traintypename: value.itemkey
  82. };
  83. buttons.push(temphtml);
  84. });
  85. }
  86. }, function () {
  87. })
  88. };
  89. getTraintypeList();
  90. // 获取机构类型列表
  91. var orgtypebuttons = [];
  92. var getOrgtypeList = function () {
  93. TechnicalBrokerPublishTrainService.getOrgtypeList().then(function (response) {
  94. if (UtilService.isDefined(response.orgtypeList) && response.orgtypeList.length > 0) {
  95. angular.forEach(response.orgtypeList, function (value, index) {
  96. var temphtml = {
  97. text: '<a class="action-sheet-push">' + value.itemkey + '</a>',
  98. orgtype: value.itemvalue,
  99. orgtypename: value.itemkey
  100. };
  101. orgtypebuttons.push(temphtml);
  102. });
  103. // console.log(orgtypebuttons);
  104. }
  105. }, function () {
  106. })
  107. };
  108. getOrgtypeList();
  109. // 获取行业领域列表
  110. var categorybuttons = [];
  111. var getCategoryList = function () {
  112. TechnicalBrokerPublishTrainService.getCategoryList().then(function (response) {
  113. if (UtilService.isDefined(response.categoryList) && response.categoryList.length > 0) {
  114. angular.forEach(response.categoryList, function (value, index) {
  115. var temphtml = {
  116. text: '<a class="action-sheet-push">' + value.name + '</a>',
  117. categorydetail: value.code,
  118. categoryname: value.name
  119. };
  120. categorybuttons.push(temphtml);
  121. });
  122. }
  123. }, function () {
  124. })
  125. };
  126. getCategoryList();
  127. //保存培训信息表
  128. var saveflg = 0;
  129. $scope.saveTrainInfo = function () {
  130. var tempstr = $("#trainbegintime").val();
  131. if (UtilService.isDefined(tempstr)) {
  132. $scope.trainListobj.trainbegintime = UtilService.formatTime(tempstr);
  133. }
  134. if (!UtilService.isDefined($scope.trainListobj.trainbegintime)) {
  135. UtilService.showMess("培训时间不能为空");
  136. return;
  137. }
  138. if (!UtilService.isDefined($scope.trainListobj.traintype)) {
  139. UtilService.showMess("请选择培训类别");
  140. return;
  141. }
  142. if (!UtilService.isDefined($scope.trainListobj.sponsor.orgtype)) {
  143. UtilService.showMess("请填写主办方信息");
  144. return;
  145. }
  146. if (!UtilService.isDefined($scope.trainListobj.sponsor.sponsorname)) {
  147. UtilService.showMess("请填写主办方信息");
  148. return;
  149. }
  150. // 若协办方名称为空,当前这条不保存
  151. if ($scope.cosponsorList.length > 0) {
  152. angular.forEach($scope.cosponsorList, function (cosponsorList,index,$index) {
  153. if (!UtilService.isDefined($scope.cosponsorList[index].sponsorname)) {
  154. $scope.cosponsorList.splice($index, 1);
  155. }
  156. });
  157. }
  158. if ($scope.lecturerList.length > 0) {
  159. var lecturerresult = 1;
  160. angular.forEach($scope.lecturerList, function (lecturerList,index) {
  161. if (!UtilService.isDefined($scope.lecturerList[index].lecturername)) {
  162. lecturerresult = 0;
  163. }
  164. });
  165. if(lecturerresult == 0){
  166. UtilService.showMess("讲师不能为空");
  167. return;
  168. }
  169. }
  170. var tempstr = $("#signupenddate").val();
  171. if (UtilService.isDefined(tempstr)) {
  172. $scope.trainListobj.signupenddate = UtilService.formatTime(tempstr);
  173. }
  174. if (!UtilService.isDefined($scope.trainListobj.signupenddate)) {
  175. UtilService.showMess("培训报名截止时间不能为空");
  176. return;
  177. }
  178. if (!UtilService.isDefined($scope.trainListobj.areaid)) {
  179. UtilService.showMess("培训所在地区不能为空");
  180. return;
  181. }
  182. if (!UtilService.isDefined($scope.trainListobj.detailaddress)) {
  183. UtilService.showMess("培训的详细地址不能为空");
  184. return;
  185. }
  186. if ($scope.trainListobj.dockingid != 0 && !UtilService.isDefined($scope.trainListobj.title)) {
  187. UtilService.showMess("培训标题不能为空");
  188. return;
  189. }
  190. if (!UtilService.isDefined($scope.trainListobj.content)) {
  191. UtilService.showMess("培训内容不能为空");
  192. return;
  193. }
  194. if (saveflg != 0) {
  195. return;
  196. }
  197. saveflg = 1;
  198. $scope.showLoadingToast();
  199. if ($scope.imagelist.length > 0) {
  200. uploadImages();
  201. } else {
  202. saveInfo();
  203. }
  204. };
  205. var tempimages = [];
  206. var uploadImages = function () {
  207. tempimages = [];
  208. var upimages = [];
  209. angular.forEach($scope.imagelist, function (data) {
  210. upimages.push(data.photo_name);
  211. });
  212. UtilService.uploadFile(upimages, 0, "image/jpeg").then(function (response) {
  213. // console.log(response);
  214. angular.forEach(response, function (value) {
  215. if (value.status) {
  216. tempimages.push({
  217. id: 0,
  218. title: "",
  219. photo_name: value.userPhoto,
  220. original_name: value.originalPhoto,
  221. source_name: value.sourcePhoto,
  222. source_size: value.source_size
  223. });
  224. }
  225. });
  226. $timeout(function () {
  227. saveInfo();
  228. }, 100);
  229. }, function () {
  230. $scope.hideLoadingToast();
  231. UtilService.showMess("网络不给力,请重试");
  232. saveflg = 0;
  233. })
  234. };
  235. var saveInfo = function () {
  236. // console.log($scope.trainListobj);
  237. $scope.trainListobj.sponsors = angular.toJson($scope.sponsorList);
  238. $scope.trainListobj.cosponsors = angular.toJson($scope.cosponsorList);
  239. $scope.trainListobj.delsponsors = delsponsors.join(",");
  240. $scope.trainListobj.lecturers = angular.toJson($scope.lecturerList);
  241. $scope.trainListobj.dellecturers = dellecturers.join(",");
  242. TechnicalBrokerPublishTrainService.saveTrainInfo($scope.trainListobj, tempimages).then(function (response) {
  243. // console.log(response);
  244. if (response.isSuccess == 1) {
  245. UtilService.showMess("添加成功");
  246. $timeout(function () {
  247. $scope.goback();
  248. }, 1500);
  249. } else {
  250. UtilService.showMess("网络不给力,请重试");
  251. }
  252. $scope.hideLoadingToast();
  253. saveflg = 0;
  254. }, function () {
  255. UtilService.showMess("网络不给力,请重试");
  256. $scope.hideLoadingToast();
  257. saveflg = 0;
  258. })
  259. };
  260. //选择机构类型
  261. $scope.showOrgTypeStatus = function () {
  262. $ionicActionSheet.show({
  263. buttons: orgtypebuttons,
  264. cancelText: '取消',
  265. buttonClicked: function (index) {
  266. $scope.trainListobj.sponsor.orgtype = orgtypebuttons[index].orgtype;
  267. $scope.trainListobj.sponsor.orgtypename = orgtypebuttons[index].orgtypename;
  268. return true;
  269. }
  270. });
  271. };
  272. // 选择专业领域
  273. $scope.showStudyStatusshowStudyStatus=function () {
  274. $ionicActionSheet.show({
  275. cancelOnStateChange: true,
  276. cssClass: 'action_s',
  277. cancelText: '取消',
  278. buttons: categorybuttons,
  279. buttonClicked: function (index) {
  280. $scope.trainListobj.sponsor.categorydetail = categorybuttons[index].categorydetail;
  281. $scope.trainListobj.sponsor.categoryname = categorybuttons[index].categoryname;
  282. return true;
  283. },
  284. destructiveButtonClicked: function () {
  285. return true;
  286. }
  287. });
  288. }
  289. //添加、删除更多协办方
  290. $scope.AddOrDelCosponsor = function (ind) {
  291. if (ind == 0) {
  292. $scope.cosponsorList.push({
  293. id: 0,
  294. stype: 2,
  295. sponsorname: ""
  296. });
  297. } else {
  298. if ($scope.cosponsorList[ind].id != 0) {
  299. delsponsors.push($scope.cosponsorList[ind].id);
  300. }
  301. $scope.cosponsorList.splice(ind, 1);
  302. }
  303. };
  304. //添加、删除更多讲师
  305. $scope.AddOrDellecturer = function (ind) {
  306. if (ind == 0) {
  307. $scope.lecturerList.push({
  308. id: 0,
  309. lecturername: ""
  310. });
  311. } else {
  312. if ($scope.lecturerList[ind].id != 0) {
  313. dellecturers.push($scope.lecturerList[ind].id);
  314. }
  315. $scope.lecturerList.splice(ind, 1);
  316. }
  317. };
  318. //选择培训类别
  319. $scope.showTrainStatus = function () {
  320. $ionicActionSheet.show({
  321. buttons: buttons,
  322. cancelText: '取消',
  323. buttonClicked: function (index) {
  324. $scope.trainListobj.traintype = buttons[index].traintype;
  325. $scope.trainListobj.traintypename = buttons[index].traintypename;
  326. return true;
  327. }
  328. });
  329. };
  330. //接收城市选择数据
  331. var reciveregplace = $scope.$on("registplace", function (event, data) {
  332. $scope.trainListobj.areaid = data.areaid;
  333. $scope.trainListobj.areaname = data.registplace;
  334. });
  335. //页面销毁时 回收广播
  336. $scope.$on('$destroy', function () {
  337. reciveregplace();
  338. });
  339. $scope.openCamera = function () {
  340. if ($scope.imagelist.length >= 9) {
  341. UtilService.showMess("最多选取9张图片");
  342. return;
  343. }
  344. UtilService.getPicture(1).then(function (results) {
  345. // console.log(results);
  346. $scope.imagelist.push({photo_name: results, original_name: results});
  347. $scope.totalImglength = 600 * $scope.imagelist.length;
  348. $ionicScrollDelegate.$getByHandle("scrollimage").resize();
  349. }, function (err) {
  350. });
  351. };
  352. $scope.show = function () {
  353. $ionicActionSheet.show({
  354. buttons: [
  355. {text: '<a class="action-sheet-push">相册中添加照片</a>'},
  356. {text: '<a class="action-sheet-push">拍照</a>'}
  357. ],
  358. cancelText: '取消',
  359. buttonClicked: function (index) {
  360. if (index == 0) {
  361. getPictures();
  362. } else if (index == 1) {
  363. $scope.openCamera();
  364. }
  365. return true;
  366. }
  367. });
  368. };
  369. var verifyStorage = function () {
  370. window.imagePicker.verifyStorage(
  371. function (results) {
  372. if (results == "1") {
  373. getPic();
  374. }
  375. }, function (error) {
  376. }
  377. );
  378. };
  379. var getPic = function () {
  380. if ($scope.imagelist.length >= 9) {
  381. UtilService.showMess("最多选取9张图片");
  382. return;
  383. }
  384. UtilService.getPictureList(9 - $scope.imagelist.length).then(function (results) {
  385. // console.log(results);
  386. angular.forEach(results, function (value, index) {
  387. $scope.imagelist.push({photo_name: value, original_name: value})
  388. });
  389. $scope.totalImglength = 600 * $scope.imagelist.length;
  390. $ionicScrollDelegate.$getByHandle("scrollimage").resize();
  391. }, function (err) {
  392. });
  393. };
  394. var getPictures = function () {
  395. if (device.platform == "Android") {
  396. verifyStorage();
  397. } else {
  398. getPic();
  399. }
  400. };
  401. //点击图片放大
  402. $scope.bigImage = false; //初始默认大图是隐藏的
  403. $scope.hideBigImage = function () {
  404. if($scope.app){
  405. $scope.setStatusBar(0);
  406. }
  407. $timeout(function () {
  408. $scope.bigImage = false;
  409. }, 400);
  410. };
  411. $scope.shouBigImage = function (index) { //传递一个参数(图片的URl)
  412. if($scope.app){
  413. $scope.setStatusBar(1);
  414. }
  415. $(function () {
  416. $('div.pinch-zoom').each(function () {
  417. new RTP.PinchZoom($(this), {});
  418. });
  419. });
  420. $scope.bigImage = true;//显示大图
  421. $ionicSlideBoxDelegate.update();//重绘,让图片显示出来
  422. //图片总数量
  423. setTimeout(function () {
  424. $ionicSlideBoxDelegate.$getByHandle('slide_detail').slide(index, -10);
  425. //获取图片
  426. var imgObj = document.getElementsByClassName('bigimage');
  427. var n;
  428. for (n = 0; n < imgObj.length; n++) {
  429. // 获取图片的原始高度和宽度
  430. var oldWid = imgObj[n].naturalWidth;
  431. var oldHei = imgObj[n].naturalHeight;
  432. var screen = document.body.offsetWidth;
  433. var screenH = window.innerHeight;
  434. // console.log(oldWid / oldHei);
  435. // console.log(screen);
  436. var cc = screen / (oldWid / oldHei);
  437. imgObj[n].style.height = cc + 'px';
  438. if (cc < screenH) {
  439. imgObj[n].style.marginTop = (screenH - cc) / 2 + 'px';
  440. // console.log("e:"+imgObj[n].style.marginTop);
  441. } else {
  442. imgObj[n].style.marginTop = 0 + 'px';
  443. // console.log((cc-screenH) +'px')
  444. }
  445. }
  446. }, 10);
  447. };
  448. //删除图片
  449. $scope.deletePhoto = function (index) {
  450. $scope.imagelist.splice(index, 1);
  451. };
  452. //培训时间
  453. $(function () {
  454. var currYear = (new Date()).getFullYear();
  455. var opt = {};
  456. opt.date = {preset: 'date'};
  457. opt.datetime = {preset: 'datetime'};
  458. opt.time = {preset: 'time'};
  459. opt.default = {
  460. theme: 'android-ics light', //皮肤样式
  461. display: 'modal', //显示方式
  462. mode: 'scroller', //日期选择模式
  463. dateFormat: 'yyyy年mm月dd日',
  464. lang: 'zh',
  465. showNow: true,
  466. nowText: "今天",
  467. startYear: currYear - 50, //开始年份
  468. endYear: currYear + 10 //结束年份
  469. };
  470. var optDateTime = $.extend(opt['datetime'], opt['default']);
  471. $("#trainbegintime").mobiscroll(optDateTime).datetime(optDateTime);
  472. });
  473. //报名截止日期
  474. $(function () {
  475. var currYear = (new Date()).getFullYear();
  476. var opt = {};
  477. opt.date = {preset: 'date'};
  478. opt.datetime = {preset: 'datetime'};
  479. opt.time = {preset: 'time'};
  480. opt.default = {
  481. theme: 'android-ics light', //皮肤样式
  482. display: 'modal', //显示方式
  483. mode: 'scroller', //日期选择模式
  484. dateFormat: 'yyyy年mm月dd日',
  485. lang: 'zh',
  486. showNow: true,
  487. nowText: "今天",
  488. startYear: currYear - 50, //开始年份
  489. endYear: currYear + 10 //结束年份
  490. };
  491. var optDateTime = $.extend(opt['datetime'], opt['default']);
  492. $("#signupenddate").mobiscroll(optDateTime).datetime(optDateTime);
  493. });
  494. $scope.isShowAddcosponsor = false;
  495. $scope.isShowAddlecturer = false;
  496. //添加协办方
  497. if ($scope.trainListobj.cosponsor != '') {
  498. $scope.isShowAddcosponsor = true;
  499. }
  500. //添加讲师
  501. if ($scope.trainListobj.lecturer != '') {
  502. $scope.isShowAddlecturer = true;
  503. }
  504. $ionicModal.fromTemplateUrl('./modules/technicalBroker/views/technicalBrokerAddMainSponsor.html', {
  505. scope: $scope,
  506. animation: 'slide-in-up'
  507. }).then(function (modal) {
  508. $scope.mainsponsor = modal;
  509. });
  510. $scope.showView = function () {
  511. $scope.mainsponsor.show();
  512. };
  513. // 添加主办方保存
  514. $scope.hideView = function () {
  515. if (!UtilService.isDefined($scope.trainListobj.sponsor.orgtype)) {
  516. UtilService.showMess("请选择主办方的机构类型");
  517. return;
  518. }
  519. if (!UtilService.isDefined($scope.trainListobj.sponsor.sponsorname)) {
  520. UtilService.showMess("请填写主办方名称");
  521. return;
  522. }
  523. $scope.sponsorList = [];// 主办方
  524. $scope.sponsorList.push({
  525. id: $scope.trainListobj.sponsor.id,
  526. sid: $scope.trainListobj.sponsor.sid,
  527. stype: 1,
  528. orgtype: $scope.trainListobj.sponsor.orgtype,
  529. sponsorname: $scope.trainListobj.sponsor.sponsorname,
  530. introduce: $scope.trainListobj.sponsor.introduce,
  531. categorydetail: $scope.trainListobj.sponsor.categorydetail,
  532. logo: $scope.trainListobj.sponsor.logo
  533. });
  534. $scope.mainsponsor.hide();
  535. };
  536. $scope.saveSponsor = function () {
  537. $scope.mainsponsor.hide();
  538. };
  539. // 编辑头像
  540. $scope.show_header = function () {
  541. // 弹出头像选择框
  542. $ionicActionSheet.show({
  543. cancelOnStateChange: true,
  544. cssClass: 'action_s',
  545. cancelText: '取消',
  546. buttons: [
  547. {text: "拍照"},
  548. {text: "从相册上传"}
  549. ],
  550. buttonClicked: function (index) {
  551. if (index == 0) {
  552. openCamera(1);
  553. } else {
  554. openCamera(0);
  555. }
  556. return true;
  557. },
  558. destructiveButtonClicked: function () {
  559. return true;
  560. }
  561. });
  562. };
  563. var openCamera = function (srcType) {
  564. var options = {
  565. // Some common settings are 20, 50, and 100
  566. quality: 50,
  567. destinationType: Camera.DestinationType.FILE_URI,
  568. // In this app, dynamically set the picture source, Camera or photo gallery
  569. sourceType: srcType,
  570. encodingType: Camera.EncodingType.JPEG,
  571. mediaType: Camera.MediaType.PICTURE,
  572. allowEdit: false,
  573. correctOrientation: true //Corrects Android orientation quirks
  574. };
  575. navigator.camera.getPicture(function (imageData) {
  576. $scope.imgurl = imageData;
  577. $scope.showLoadingToast();
  578. UtilService.uploadFile([imageData], 0, "image/jpeg").then(function (response) {
  579. // console.log(response);
  580. $scope.trainListobj.sponsor.logo = response[0].userPhoto;
  581. $scope.hideLoadingToast();
  582. }, function () {
  583. $scope.hideLoadingToast();
  584. });
  585. }, function (message) {
  586. }, options);
  587. };
  588. // 切换状态
  589. $scope.changeToggle = function () {
  590. $scope.taskListobj.isactive = $scope.taskListobj.actives ? 1 : 0;
  591. };
  592. });