addStateCtrl.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. angular.module('push')
  2. .controller('addStateCtrl', function ($scope, $stateParams, CommentService, $ionicActionSheet, DockingService, UtilService, $timeout, $ionicScrollDelegate,$ionicSlideBoxDelegate) {
  3. var folupid = $stateParams.folupid;
  4. $scope.activityobj = {
  5. tagid: 0,
  6. tagtime: "",// 对接时间
  7. tagname: "",// 对接状态
  8. tagcontent: "",// 对接状态简介
  9. imagelist: []
  10. };
  11. $scope.imagelist = [];
  12. //获取对接状态标签
  13. var buttons = [];
  14. var getLabelList = function () {
  15. CommentService.getLabelList().then(function (response) {
  16. angular.forEach(response, function (value, index) {
  17. var temphtml = {
  18. text: '<a class="action-sheet-push">' + value.name + '</a>',
  19. tagid: value.id,
  20. tagname: value.name
  21. };
  22. buttons.push(temphtml);
  23. });
  24. }, function () {
  25. })
  26. };
  27. getLabelList();
  28. //选择对接状态
  29. $scope.showDockingStatus = function () {
  30. $ionicActionSheet.show({
  31. buttons: buttons,
  32. cancelText: '取消',
  33. buttonClicked: function (index) {
  34. $scope.activityobj.tagid = buttons[index].tagid;
  35. $scope.activityobj.tagname = buttons[index].tagname;
  36. return true;
  37. }
  38. });
  39. };
  40. //添加对接状态
  41. var addflg = 0;
  42. $scope.addState = function () {
  43. var tempstr = $("#dockingDateTime").val();
  44. if (UtilService.isDefined(tempstr)) {
  45. $scope.activityobj.tagtime = UtilService.formatTime(tempstr);
  46. }
  47. if (!UtilService.isDefined($scope.activityobj.tagtime)) {
  48. UtilService.showMess("对接时间不能为空");
  49. return;
  50. }
  51. if (!UtilService.isDefined($scope.activityobj.tagname)) {
  52. UtilService.showMess("请选择对接状态");
  53. return;
  54. }
  55. if (!UtilService.isDefined($scope.activityobj.tagcontent)) {
  56. UtilService.showMess("对接状态简介不能为空");
  57. return;
  58. }
  59. if (addflg != 0) {
  60. return;
  61. }
  62. addflg = 1;
  63. $scope.showLoadingToast();
  64. if ($scope.imagelist.length > 0) {
  65. uploadImages();
  66. } else {
  67. saveInfo();
  68. }
  69. };
  70. var tempimages = [];
  71. var uploadImages = function () {
  72. tempimages = [];
  73. var upimages = [];
  74. angular.forEach($scope.imagelist, function (data) {
  75. upimages.push(data.photo_name);
  76. });
  77. UtilService.uploadFile(upimages, 0, "image/jpeg").then(function (response) {
  78. // console.log(response);
  79. angular.forEach(response, function (value) {
  80. if (value.status) {
  81. tempimages.push({
  82. photo_name: value.userPhoto,
  83. original_name: value.originalPhoto,
  84. source_name: value.sourcePhoto,
  85. source_size: value.source_size
  86. });
  87. }
  88. });
  89. $timeout(function () {
  90. $scope.activityobj.imagelist = angular.toJson(tempimages);
  91. saveInfo();
  92. }, 100);
  93. }, function () {
  94. $scope.hideLoadingToast();
  95. UtilService.showMess("网络不给力,请重试");
  96. addflg = 0;
  97. })
  98. };
  99. var saveInfo = function () {
  100. DockingService.saveActivitiesFollowupTag(folupid, 1, $scope.activityobj).then(function (response) {
  101. if (response.isSuccess == 1) {
  102. UtilService.showMess("添加成功");
  103. $timeout(function () {
  104. $scope.goback();
  105. }, 1500);
  106. } else {
  107. UtilService.showMess("网络不给力,请重试");
  108. }
  109. addflg = 0;
  110. $scope.hideLoadingToast();
  111. }, function () {
  112. UtilService.showMess("网络不给力,请重试");
  113. $scope.hideLoadingToast();
  114. addflg = 0;
  115. });
  116. };
  117. $scope.openCamera = function () {
  118. if ($scope.imagelist.length >= 9) {
  119. UtilService.showMess("最多选取9张图片");
  120. return;
  121. }
  122. UtilService.getPicture(1).then(function (results) {
  123. // console.log(results);
  124. $scope.imagelist.push({photo_name: results, original_name: results});
  125. $scope.totalImglength = 600 * $scope.imagelist.length;
  126. $ionicScrollDelegate.$getByHandle("scrollimage").resize();
  127. }, function (err) {
  128. });
  129. };
  130. $scope.show = function () {
  131. $ionicActionSheet.show({
  132. buttons: [
  133. {text: '<a class="action-sheet-push">相册中添加照片</a>'},
  134. {text: '<a class="action-sheet-push">拍照</a>'}
  135. ],
  136. cancelText: '取消',
  137. buttonClicked: function (index) {
  138. if (index == 0) {
  139. getPictures();
  140. } else if (index == 1) {
  141. $scope.openCamera();
  142. }
  143. return true;
  144. }
  145. });
  146. };
  147. var verifyStorage = function () {
  148. window.imagePicker.verifyStorage(
  149. function (results) {
  150. if (results == "1") {
  151. getPic();
  152. }
  153. }, function (error) {
  154. }
  155. );
  156. };
  157. var getPic = function () {
  158. if ($scope.imagelist.length >= 9) {
  159. UtilService.showMess("最多选取9张图片");
  160. return;
  161. }
  162. UtilService.getPictureList(9 - $scope.imagelist.length).then(function (results) {
  163. // console.log(results);
  164. angular.forEach(results, function (value, index) {
  165. $scope.imagelist.push({photo_name: value, original_name: value})
  166. });
  167. $scope.totalImglength = 600 * $scope.imagelist.length;
  168. $ionicScrollDelegate.$getByHandle("scrollimage").resize();
  169. }, function (err) {
  170. });
  171. };
  172. var getPictures = function () {
  173. if (device.platform == "Android") {
  174. verifyStorage();
  175. } else {
  176. getPic();
  177. }
  178. };
  179. //时间选择器
  180. $(function () {
  181. var currYear = (new Date()).getFullYear();
  182. var opt = {};
  183. opt.date = {preset: 'date'};
  184. opt.datetime = {preset: 'datetime'};
  185. opt.time = {preset: 'time'};
  186. opt.default = {
  187. theme: 'android-ics light', //皮肤样式
  188. display: 'bottom', //显示方式
  189. mode: 'scroller', //日期选择模式
  190. dateFormat: 'yyyy年mm月dd日',
  191. lang: 'zh',
  192. showNow: true,
  193. nowText: "今天",
  194. startYear: currYear - 50, //开始年份
  195. endYear: currYear + 10 //结束年份
  196. };
  197. /*$("#appDateTime").mobiscroll($.extend(opt['date'], opt['default']));*/
  198. var optDateTime = $.extend(opt['datetime'], opt['default']);
  199. $("#dockingDateTime").mobiscroll(optDateTime).date(optDateTime);
  200. });
  201. //点击图片放大
  202. $scope.bigImage = false; //初始默认大图是隐藏的
  203. $scope.hideBigImage = function () {
  204. if($scope.app){
  205. $scope.setStatusBar(0);
  206. }
  207. $timeout(function () {
  208. $scope.bigImage = false;
  209. }, 400);
  210. };
  211. $scope.shouBigImage = function (index) { //传递一个参数(图片的URl)
  212. if($scope.app){
  213. $scope.setStatusBar(1);
  214. }
  215. $(function () {
  216. $('div.pinch-zoom').each(function () {
  217. new RTP.PinchZoom($(this), {});
  218. });
  219. });
  220. $scope.bigImage = true;//显示大图
  221. $ionicSlideBoxDelegate.update();//重绘,让图片显示出来
  222. //图片总数量
  223. setTimeout(function () {
  224. $ionicSlideBoxDelegate.$getByHandle('slide_detail').slide(index, -10);
  225. //获取图片
  226. var imgObj = document.getElementsByClassName('bigimage');
  227. var n;
  228. for (n = 0; n < imgObj.length; n++) {
  229. // 获取图片的原始高度和宽度
  230. var oldWid = imgObj[n].naturalWidth;
  231. var oldHei = imgObj[n].naturalHeight;
  232. var screen = document.body.offsetWidth;
  233. var screenH = window.innerHeight;
  234. // console.log(oldWid / oldHei);
  235. // console.log(screen);
  236. var cc = screen / (oldWid / oldHei);
  237. imgObj[n].style.height = cc + 'px';
  238. if (cc < screenH) {
  239. imgObj[n].style.marginTop = (screenH - cc) / 2 + 'px';
  240. // console.log("e:"+imgObj[n].style.marginTop);
  241. } else {
  242. imgObj[n].style.marginTop = 0 + 'px';
  243. // console.log((cc-screenH) +'px')
  244. }
  245. }
  246. }, 10);
  247. };
  248. //删除图片
  249. $scope.deletePhoto = function (index) {
  250. $scope.imagelist.splice(index, 1);
  251. };
  252. });