technicalBrokerEditTrainCtrl.js 19 KB

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