angular.module('push') .controller('newNotificationCtrl', function ($scope, $sce, $stateParams, ResourceLibraryService, $ionicPopup, UserService, CommentService, AccountService, $ionicActionSheet, UtilService, $timeout, CommonService) { //$scope.notice为空即新增,非空即编辑 $scope.notice = $stateParams.notice; $scope.noticecontent = $sce.trustAsHtml($scope.notice.content); ResourceLibraryService.getPictureList($scope.notice.unique, $scope.notice.creator).then(function (res) { if(res.code == 3350) { $scope.picturelist = res.data; angular.forEach($scope.picturelist, function(picture){ angular.forEach($scope.formList, function(form){ if(form.doctype == picture.doctype){ form.imageSaveList.push(picture); } }) }) } }) //富文本 var editor = CKEDITOR.replace('editor'); $scope.notification = {}; $scope.notification.title = $scope.notice.newtitle; $scope.notification.region = $scope.notice.address; $scope.params = {}; //发送通知公告 $scope.sendNotice = function () { if (!$scope.notification.title) { $ionicPopup.alert({ title: '提示', template: "请填写通知公告标题" }) return; } //notice.snowflakeID存在,即代表编辑功能 if ($stateParams.notice.snowflakeID) { $scope.params.resid = $stateParams.notice.unique; } $scope.notification.context = editor.getData(); $scope.notification.summary = editor.document.getBody().getText(); $scope.params.data = $scope.notification; $scope.params.userid = UserService.id; $scope.params.node = UserService.node; $scope.params.formList = $scope.formList; AccountService.publicNotification($scope.params).then(function (res) { if (res.code == 3350) { if($scope.notice.title){ $scope.template = '编辑成功'; }else{ $scope.template = '发布成功'; } $ionicPopup.alert({ title: '提示', template: $scope.template }) $scope.go("notification"); } }) } //以下皆为添加附件相关方法 $scope.formList = [{ title: '附件', content: '[]', type: 'upload', needed: true, imagelist: [], imageSaveList: [], imageDeleteList: [], doctype: 4902, remarkType: 'normal', rowMargin: true }, { title: '图片', content: '[]', type: 'upload', needed: false, imagelist: [], imageSaveList: [], imageDeleteList: [], doctype: 4901, remarkType: 'add' } ]; $scope.addImage = function (index) { listIndex = index; if ($scope.app) { var list = [ {text: '拍照'}, {text: '从相册上传'}, ]; var clickfunction = function (indx) { if (indx == 0) { $scope.openCamera(); } else { getPictures(); } return true; } } else { // var list = [ // {text: '从相册上传'}, // ]; // var clickfunction = function (indx) { // if (indx == 0) { var files; if (index == 0) { files = document.getElementById('file'); } else { files = document.getElementById('img'); } files.click(); $(files).unbind().on('change', function (e) { // console.log(e); if (index == 1) { var str=document.getElementById('img').value.split('.'); if(str&&str.length>0&&str[1]!='jpg'&&str[1]!='gif'&&str[1]!='bmp'&&str[1]!='png'&&str[1]!='jpeg'&&str[1]!='tiff'&&str[1]!='pjp'&& str[1]!='pjpeg'&&str[1]!='jfif'&&str[1]!='tif'&&str[1]!='svg'&&str[1]!='svgz'&&str[1]!='webp'&&str[1]!='ico'&&str[1]!='xbm'&&str[1]!='dib') { $ionicPopup.alert({ title: '提示', template: '请上传图片!' }); return; } } $.each(e.target.files, function (i, file) { var url = null; if (window.createObjectURL != undefined) { // basic url = window.createObjectURL(file); } else if (window.URL != undefined) { // mozilla(firefox) url = window.URL.createObjectURL(file); } else if (window.webkitURL != undefined) { // webkit or chrome url = window.webkitURL.createObjectURL(file); } $scope.formList[listIndex].imagelist.push({photoName: url, originalName: url}); }) $.each(e.target.files, function (i, file) { var data = new FormData(); data.append('file', file); CommonService.webUploadImage(data).then(function (res) { var temp = { id: 0, title: res.title, doctype: $scope.formList[listIndex].doctype,//文档类型 1图片,2文件,3pdf,4xls isenabled: 1,//是否可用:0-不可用,1-可用,2-已停用 photoName: res.photoName, originalName: res.originalName, sourceName: res.sourceName, sourceSize: res.sourceSize } $scope.formList[listIndex].imageSaveList.push(temp); // console.log(temp); // console.log($scope.formList[listIndex]); }) }); }) // } return true; // } } $ionicActionSheet.show({ buttons: list, cancelText: '取消', buttonClicked: clickfunction }) } $scope.openCamera = function () { if ($scope.formList[listIndex].imagelist.length >= 9) { if ($scope.app) { UtilService.showMess("最多选取9张图片"); } else { CommonService.showMessage("最多选取9张图片", $scope) } return; } UtilService.getPicture(1).then(function (results) { $scope.showLoadingToast(); $scope.formList[listIndex].imagelist.push({photoName: results, originalName: results}) UtilService.uploadFile([results], 0, "image/jpeg").then(function (response) { angular.forEach(response, function (value) { $scope.formList[listIndex].imageSaveList.push({ id: 0, title: response.getTitle(), doctype: $scope.formList[listIndex].doctype,//文档类型 1图片,2文件,3pdf,4xls isenabled: 1,//是否可用:0-不可用,1-可用,2-已停用 photoName: value.photoName, originalName: value.originalName, sourceName: value.sourceName, sourceSize: value.sourceSize }) }) $scope.hideLoadingToast(); }, function () { $scope.hideLoadingToast(); if ($scope.app) { UtilService.showMess("网络不给力,请重试"); } else { CommonService.showMessage("网络不给力,请重试", $scope) } }); $ionicScrollDelegate.$getByHandle("scrollimage").resize(); }, function (err) { }); } var getPictures = function () { if (device.platform == "Android") { verifyStorage(); } else { getPic(); } }; var verifyStorage = function () { window.imagePicker.verifyStorage( function (results) { if (results == "1") { getPic(); } }, function (error) { } ); }; var getPic = function () { var imagelistLength = $scope.formList[listIndex].imagelist.length; if (imagelistLength >= 9) { if ($scope.app) { UtilService.showMess("最多选取9张图片"); } else { CommonService.showMessage("最多选取9张图片", $scope) } return; } UtilService.getPictureList(9 - imagelistLength).then(function (results) { $scope.showLoadingToast(); angular.forEach(results, function (val, i) { $scope.formList[listIndex].imagelist.push({photoName: val, originalName: val}); }) UtilService.uploadFile(results, 0, "image/jpeg").then(function (response) { angular.forEach(response, function (value) { if (value.status) { $scope.formList[listIndex].imageSaveList.push({ id: 0, title: response.getTitle(), doctype: $scope.formList[listIndex].doctype,//文档类型 1图片,2文件,3pdf,4xls isenabled: 1,//是否可用:0-不可用,1-可用,2-已停用 photoName: value.photoName, originalName: value.originalName, sourceName: value.sourceName, sourceSize: value.sourceSize }); } }) $scope.hideLoadingToast(); }, function () { $scope.hideLoadingToast(); if ($scope.app) { UtilService.showMess("网络不给力,请重试"); } else { CommonService.showMessage("网络不给力,请重试", $scope) } }); $ionicScrollDelegate.$getByHandle("scrollimage").resize(); }, function (err) { }); }; //删除图片 $scope.deletePhoto = function (index, outerIndex) { console.log($scope.formList[outerIndex]); if ($scope.formList[outerIndex].imageSaveList[index].id != 0) { $scope.formList[outerIndex].imageSaveList[index].isenabled = 2; $scope.formList[outerIndex].imageDeleteList.push($scope.formList[outerIndex].imageSaveList[index]); } $scope.formList[outerIndex].imagelist.splice(index, 1); $scope.formList[outerIndex].imageSaveList.splice(index, 1); // console.log($scope.formList[outerIndex].imagelist); // console.log($scope.formList[outerIndex].imageSaveList); // console.log($scope.formList[outerIndex].imageDeleteList); } $scope.uploadPic = function (e) { // console.log(2); // console.log(e.target); } }) ;