123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- angular.module('push')
- .controller('addStateCtrl', function ($scope, $stateParams, CommentService, $ionicActionSheet, DockingService, UtilService, $timeout, $ionicScrollDelegate,$ionicSlideBoxDelegate) {
- var folupid = $stateParams.folupid;
- $scope.activityobj = {
- tagid: 0,
- tagtime: "",// 对接时间
- tagname: "",// 对接状态
- tagcontent: "",// 对接状态简介
- imagelist: []
- };
- $scope.imagelist = [];
- //获取对接状态标签
- var buttons = [];
- var getLabelList = function () {
- CommentService.getLabelList().then(function (response) {
- angular.forEach(response, function (value, index) {
- var temphtml = {
- text: '<a class="action-sheet-push">' + value.name + '</a>',
- tagid: value.id,
- tagname: value.name
- };
- buttons.push(temphtml);
- });
- }, function () {
- })
- };
- getLabelList();
- //选择对接状态
- $scope.showDockingStatus = function () {
- $ionicActionSheet.show({
- buttons: buttons,
- cancelText: '取消',
- buttonClicked: function (index) {
- $scope.activityobj.tagid = buttons[index].tagid;
- $scope.activityobj.tagname = buttons[index].tagname;
- return true;
- }
- });
- };
- //添加对接状态
- var addflg = 0;
- $scope.addState = function () {
- var tempstr = $("#dockingDateTime").val();
- if (UtilService.isDefined(tempstr)) {
- $scope.activityobj.tagtime = UtilService.formatTime(tempstr);
- }
- if (!UtilService.isDefined($scope.activityobj.tagtime)) {
- UtilService.showMess("对接时间不能为空");
- return;
- }
- if (!UtilService.isDefined($scope.activityobj.tagname)) {
- UtilService.showMess("请选择对接状态");
- return;
- }
- if (!UtilService.isDefined($scope.activityobj.tagcontent)) {
- UtilService.showMess("对接状态简介不能为空");
- return;
- }
- if (addflg != 0) {
- return;
- }
- addflg = 1;
- $scope.showLoadingToast();
- if ($scope.imagelist.length > 0) {
- uploadImages();
- } else {
- saveInfo();
- }
- };
- var tempimages = [];
- var uploadImages = function () {
- tempimages = [];
- var upimages = [];
- angular.forEach($scope.imagelist, function (data) {
- upimages.push(data.photo_name);
- });
- UtilService.uploadFile(upimages, 0, "image/jpeg").then(function (response) {
- // console.log(response);
- angular.forEach(response, function (value) {
- if (value.status) {
- tempimages.push({
- photo_name: value.userPhoto,
- original_name: value.originalPhoto,
- source_name: value.sourcePhoto,
- source_size: value.source_size
- });
- }
- });
- $timeout(function () {
- $scope.activityobj.imagelist = angular.toJson(tempimages);
- saveInfo();
- }, 100);
- }, function () {
- $scope.hideLoadingToast();
- UtilService.showMess("网络不给力,请重试");
- addflg = 0;
- })
- };
- var saveInfo = function () {
- DockingService.saveActivitiesFollowupTag(folupid, 1, $scope.activityobj).then(function (response) {
- if (response.isSuccess == 1) {
- UtilService.showMess("添加成功");
- $timeout(function () {
- $scope.goback();
- }, 1500);
- } else {
- UtilService.showMess("网络不给力,请重试");
- }
- addflg = 0;
- $scope.hideLoadingToast();
- }, function () {
- UtilService.showMess("网络不给力,请重试");
- $scope.hideLoadingToast();
- addflg = 0;
- });
- };
- $scope.openCamera = function () {
- if ($scope.imagelist.length >= 9) {
- UtilService.showMess("最多选取9张图片");
- return;
- }
- UtilService.getPicture(1).then(function (results) {
- // console.log(results);
- $scope.imagelist.push({photo_name: results, original_name: results});
- $scope.totalImglength = 600 * $scope.imagelist.length;
- $ionicScrollDelegate.$getByHandle("scrollimage").resize();
- }, function (err) {
- });
- };
- $scope.show = function () {
- $ionicActionSheet.show({
- buttons: [
- {text: '<a class="action-sheet-push">相册中添加照片</a>'},
- {text: '<a class="action-sheet-push">拍照</a>'}
- ],
- cancelText: '取消',
- buttonClicked: function (index) {
- if (index == 0) {
- getPictures();
- } else if (index == 1) {
- $scope.openCamera();
- }
- return true;
- }
- });
- };
- var verifyStorage = function () {
- window.imagePicker.verifyStorage(
- function (results) {
- if (results == "1") {
- getPic();
- }
- }, function (error) {
- }
- );
- };
- var getPic = function () {
- if ($scope.imagelist.length >= 9) {
- UtilService.showMess("最多选取9张图片");
- return;
- }
- UtilService.getPictureList(9 - $scope.imagelist.length).then(function (results) {
- // console.log(results);
- angular.forEach(results, function (value, index) {
- $scope.imagelist.push({photo_name: value, original_name: value})
- });
- $scope.totalImglength = 600 * $scope.imagelist.length;
- $ionicScrollDelegate.$getByHandle("scrollimage").resize();
- }, function (err) {
- });
- };
- var getPictures = function () {
- if (device.platform == "Android") {
- verifyStorage();
- } else {
- getPic();
- }
- };
- //时间选择器
- $(function () {
- var currYear = (new Date()).getFullYear();
- var opt = {};
- opt.date = {preset: 'date'};
- opt.datetime = {preset: 'datetime'};
- opt.time = {preset: 'time'};
- opt.default = {
- theme: 'android-ics light', //皮肤样式
- display: 'bottom', //显示方式
- mode: 'scroller', //日期选择模式
- dateFormat: 'yyyy年mm月dd日',
- lang: 'zh',
- showNow: true,
- nowText: "今天",
- startYear: currYear - 50, //开始年份
- endYear: currYear + 10 //结束年份
- };
- /*$("#appDateTime").mobiscroll($.extend(opt['date'], opt['default']));*/
- var optDateTime = $.extend(opt['datetime'], opt['default']);
- $("#dockingDateTime").mobiscroll(optDateTime).date(optDateTime);
- });
- //点击图片放大
- $scope.bigImage = false; //初始默认大图是隐藏的
- $scope.hideBigImage = function () {
- if($scope.app){
- $scope.setStatusBar(0);
- }
- $timeout(function () {
- $scope.bigImage = false;
- }, 400);
- };
- $scope.shouBigImage = function (index) { //传递一个参数(图片的URl)
- if($scope.app){
- $scope.setStatusBar(1);
- }
- $(function () {
- $('div.pinch-zoom').each(function () {
- new RTP.PinchZoom($(this), {});
- });
- });
- $scope.bigImage = true;//显示大图
- $ionicSlideBoxDelegate.update();//重绘,让图片显示出来
- //图片总数量
- setTimeout(function () {
- $ionicSlideBoxDelegate.$getByHandle('slide_detail').slide(index, -10);
- //获取图片
- var imgObj = document.getElementsByClassName('bigimage');
- var n;
- for (n = 0; n < imgObj.length; n++) {
- // 获取图片的原始高度和宽度
- var oldWid = imgObj[n].naturalWidth;
- var oldHei = imgObj[n].naturalHeight;
- var screen = document.body.offsetWidth;
- var screenH = window.innerHeight;
- // console.log(oldWid / oldHei);
- // console.log(screen);
- var cc = screen / (oldWid / oldHei);
- imgObj[n].style.height = cc + 'px';
- if (cc < screenH) {
- imgObj[n].style.marginTop = (screenH - cc) / 2 + 'px';
- // console.log("e:"+imgObj[n].style.marginTop);
- } else {
- imgObj[n].style.marginTop = 0 + 'px';
- // console.log((cc-screenH) +'px')
- }
- }
- }, 10);
- };
- //删除图片
- $scope.deletePhoto = function (index) {
- $scope.imagelist.splice(index, 1);
- };
- });
|