123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- angular.module('push')
- .controller('quarterlyImportCtrl', function ($scope, $stateParams, ConfigService, UserService, taskModuleService, $ionicPopup, CommentService, UtilService, $timeout, CommonService) {
- $scope.importsuccess = $stateParams.importsuccess;
- var enterprise = [
- {
- title: '上传季报文件',
- content: '[]',
- type: 'upload',
- needed: false,
- imagelist: [],
- imageSaveList: [],
- imageDeleteList: [],
- doctype: 4908,
- remarkType: 'normal'
- }
- ];
- $scope.formList = enterprise;
- taskModuleService.getOrgStatsDataList().then(function (res) {
- if (res.code == 3350) {
- $scope.orgnamelist = res.data;
- }
- })
- $scope.sendAnalysisToDB = function () {
- angular.forEach($scope.formList, function (val) {
- if (val.type == "upload") {
- if (val.imageSaveList.length == 0 && val.imagelist.length != 0) {
- val.imageSaveList = val.imagelist;
- }
- }
- })
- if (!$scope.formList[0].imageSaveList || $scope.formList[0].imageSaveList.length == 0) {
- $ionicPopup.alert({
- title: '提示',
- template: '没有文件需要导入!'
- })
- return;
- }
- var imagelist = $scope.formList[0].imageSaveList;
- for (var i = 0; i < imagelist.length; i++) {
- var fileDiveded = imagelist[i].title.split(".");
- if (fileDiveded.length > 0 ) {
- if (fileDiveded[fileDiveded.length - 1] != "xls" && fileDiveded[fileDiveded.length - 1] != "xlsx") {
- $ionicPopup.alert({
- title: '提示',
- template: '只能上传excel文件!'
- })
- return;
- }
- }
- }
- var params = {};
- params.data = $scope.formList;
- params.node = UserService.node;
- params.userid = UserService.id;
- params.path = ConfigService.imgurl;
- $scope.showLoadingToastUtilEnd();
- taskModuleService.sendAnalysisToDB(params).then(function (res) {
- $scope.hideLoadingToast();
- if (res.code == 3350) {
- $ionicPopup.alert({
- title: '提示',
- template: '导入成功!'
- })
- $scope.go('quarterlyAnalysis');
- } else {
- $ionicPopup.alert({
- title: '提示',
- template: '导入失败!'
- })
- return;
- }
- })
- }
- $scope.addImage = function (index) {
- listIndex = index;
- if ($scope.app) {
- var list = [
- {text: '<a class="action-sheet-push">拍照</a>'},
- {text: '<a class="action-sheet-push">从相册上传</a>'},
- ];
- var clickfunction = function (indx) {
- if (indx == 0) {
- $scope.openCamera();
- } else {
- getPictures();
- }
- return true;
- }
- } else {
- var files = document.getElementById('file');
- files.click();
- $(files).unbind().on('change', function (e) {
- // console.log(e);
- if ($scope.formList[listIndex].imagelist.length > 8) {
- $ionicPopup.alert({
- title: '提示',
- template: '最多只能上传9个文件!'
- });
- 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({title: file.name, photoName: url, originalName: url});
- });
- $scope.showLoadingToast();
- var data = new FormData();
- $.each(e.target.files, function (i, file) {
- data.append('file', file);
- });
- CommonService.mutipleUploadImage(data).then(function (res) {
- if (res.code == 3350) {
- angular.forEach(res.data, function (value) {
- $scope.formList[listIndex].imageSaveList.push({
- id: 0,
- title: value.title,
- 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
- })
- })
- }
- // console.log(temp);
- // console.log($scope.formList[listIndex]);
- })
- })
- $scope.hideLoadingToast();
- 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: value.title,
- 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: "",
- 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);
- }
- if ($scope.importsuccess == 1) {
- $scope.formList[0].imagelist = [];
- $scope.formList[0].imageSaveList = [];
- $scope.formList[0].imageDeleteList = [];
- $scope.orgnamelist = [];
- angular.forEach($stateParams.orgdatalist, function(val){
- $scope.orgnamelist.push(val.orgName);
- })
- }
- });
|