/** * index * */ define([ 'angularAMD', 'ui.router', 'ui-bootstrap', 'ngLocal', 'ngTable', 'file-upload', 'common/directives', 'common/services', 'toaster', 'ngSanitize', 'services/Project', 'services/Activity', 'services/Organization', 'ui-form'], function(angularAMD) { 'use strict'; var app = angular.module('myApp', [ 'ui.router', 'ui.bootstrap', 'ng.local', 'ngTable', 'angularFileUpload', 'common.directives', 'common.services', 'toaster', 'ngSanitize', 'ProjectService', 'ActivityService', 'OrganizationService', 'ui.form']); app.init = function() { angularAMD.bootstrap(app); }; app.config(['$httpProvider', function ($httpProvider) { // http拦截 $httpProvider.interceptors.push('httpInterceptor'); }]); app.factory('httpInterceptor', ['$window', '$q', '$injector', 'BaseService', function ($window, $q, $injector, BaseService) { var httpInterceptor = { 'responseError': function (response) { if (response.status == 401) {// UNAUTHORIZED window.location.href = response.data.loginUrl || 'index'; return $q.reject(response); } return $q.reject(response); } } return httpInterceptor; }]); app.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) { $urlRouterProvider.otherwise("/"); $stateProvider.state("project", { url : '/', title : '项目列表', templateUrl : 'static/view/project/project_list.html', controller : 'ProjectListCtrl' }).state("launchProject1", { url : '/launchProject/baseInfo', title : '项目发起1', templateUrl : 'static/view/project/project_launch_1.html', controller : 'ProjectNewCtrl' }).state("launchProject2", { url : '/launchProject/detail/:id', title : '项目发起2', templateUrl : 'static/view/project/project_launch_2.html', controller : 'ProjectNewCtrl' }).state("launchProjectSuccess", { url : '/launchProject/success', title : '项目发起完成', templateUrl : 'static/view/project/project_launch_3.html', controller : 'ProjectNewCtrl' }).state("projectFinance", { url : '/project/finance', title : '项目财务披露', templateUrl : 'static/view/project/project_list_finance.html', controller : 'ProjectFinanceListCtrl' }).state("projectReport", { url : '/project/report', title : '项目报告', templateUrl : 'static/view/project/project_list_report.html', controller : 'ProjectReportListCtrl' }).state("projectManagement", { url : '/project/management', title : '项目结项管理', templateUrl : 'static/view/project/project_list_management.html', controller : 'ProjectManagementListCtrl' }).state("activityList", { url : '/activity', title : '活动列表', templateUrl : 'static/view/activity/activity_list.html', controller : 'ActivityListCtrl' }).state("launchActivity", { url : '/launchActivity', title : '发起活动', templateUrl : 'static/view/activity/activity_launch.html', controller : 'ActivityNewCtrl' }).state("selectInstitutionsNature", { url : '/selectInstitutionsNature', title : '机构入驻选择', templateUrl : 'static/view/user/selectInstitutionsNature.html', controller : 'SelectInstitutionsNatureCtrl' }).state("charityCertificationStep0", { url : '/charityCertificationStep0', title : '公益机构认证协议', templateUrl : 'static/view/user/charityCertification.html', controller : 'CertificationStep0Ctrl' }).state("charityCertificationStep1", { url : '/charityCertificationStep1', title : '公益机构认证第一步', templateUrl : 'static/view/user/charityCertification1.html', controller : 'CertificationStep1Ctrl' }).state("charityCertificationStep2", { url : '/charityCertificationStep2', title : '公益机构认证第二步', templateUrl : 'static/view/user/charityCertification2.html', controller : 'CertificationStep2Ctrl' }).state("charityCertificationStep3", { url : '/charityCertificationStep3', title : '公益机构认证第三步', templateUrl : 'static/view/user/charityCertification3.html', controller : 'CertificationStep3Ctrl' }).state("charityCertificationStep4", { url : '/charityCertificationStep4', title : '公益机构认证完成', templateUrl : 'static/view/user/charityCertification4.html', controller : 'CertificationStep4Ctrl' }).state("publicOfferingCertificationStep0", { url : '/publicOfferingCertificationStep0', title : '公募机构认证协议', templateUrl : 'static/view/user/publicOfferingCertification.html', controller : 'CertificationStep0Ctrl' }).state("publicOfferingCertificationStep1", { url : '/publicOfferingCertificationStep1', title : '公募机构认证第一步', templateUrl : 'static/view/user/publicOfferingCertification1.html', controller : 'CertificationStep1Ctrl' }).state("publicOfferingCertificationStep2", { url : '/publicOfferingCertificationStep2', title : '公募机构认证第二步', templateUrl : 'static/view/user/publicOfferingCertification2.html', controller : 'CertificationStep2Ctrl' }).state("publicOfferingCertificationStep3", { url : '/publicOfferingCertificationStep3', title : '公募机构认证第三步', templateUrl : 'static/view/user/publicOfferingCertification3.html', controller : 'CertificationStep3Ctrl' }).state("publicOfferingCertificationStep4", { url : '/publicOfferingCertificationStep4', title : '公募机构认证第四步', templateUrl : 'static/view/user/publicOfferingCertification4.html', controller : 'PublicCertificationStep4Ctrl' }).state("publicOfferingCertificationStep5", { url : '/publicOfferingCertificationStep5', title : '公益机构认证完成', templateUrl : 'static/view/user/publicOfferingCertification5.html', controller : 'charityCertificationStep4Ctrl' }).state("organizationList", { url : '/organization/list', title : '机构列表', templateUrl : 'static/view/user/organization_list.html', controller : 'OrgListCtrl' }).state("userList", { url : '/user/list', title : '用户列表', templateUrl : 'static/view/user/user_list.html', controller : 'UserListCtrl' }); }]); // html转义 var htmlEncode = function(sHtml) { return sHtml.replace(/[<>&"]/g,function(c){return {'<':'<','>':'>','&':'&','"':'"'}[c];}); }; var getObjectURL = function (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); } return url; }; /** * 项目列表 */ app.controller('ProjectListCtrl', ['$scope', '$rootScope', 'toaster', 'ngTableParams', 'BaseService', 'Project', '$modal', function ($scope, $rootScope, toaster, ngTableParams, BaseService, Project, $modal) { var getProjectState = function (active) { var fn = 'getAudited'; switch (active) { // 已审核 case 'audited': fn = 'getAudited'; break; // 未审核 case 'unaudited': fn = 'getUnaudited'; break; // 未通过 case 'disagreed': fn = 'getDisagreed'; break; } return fn; }; $scope.active = 'audited'; $scope.keyword = ''; /** * 修改分类 * @param value */ $scope.setState = function (value) { if ($scope.active != value) { $scope.active = value; if ($scope.projectParams.page() == 1) $scope.projectParams.reload(); else $scope.projectParams.page(1); } }; /** * 修改领域 * @param value */ $scope.setArea = function (value) { if ($scope.selectedArea != value) { $scope.selectedArea = value; if ($scope.projectParams.page() == 1) $scope.projectParams.reload(); else $scope.projectParams.page(1); } }; $scope.reload = function() { if ($scope.projectParams.page() == 1) $scope.projectParams.reload(); else $scope.projectParams.page(1); }; $scope.projectParams = new ngTableParams({ page: 1, count: 10, sorting: { 'id': 'desc' } }, { total: 0, counts: [], getData: function ($defer, params) { $scope.loading = true; var pageParams = params.url(); var realActive = {}; pageParams.searchFilter = { // 筛选条件 keyword: $scope.keyword, area: $scope.selectedArea }; Project[getProjectState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) { $scope.loading = false; if (page) { params.total(page.totalElements); $defer.resolve(page.content); // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段 } }, function (response) { $scope.loading = false; toaster.pop('error', '数据加载失败', response.data); }); } }); var getNum = function() { Project.getProjectsNum({}, {}, function(data) { $scope.auditedNum = data.auditedNum; $scope.unauditedNum = data.unauditedNum; $scope.disagreedNum = data.disagreedNum; }); }; getNum(); $scope.onSearch = function () { if ($scope.projectParams.page() == 1) $scope.projectParams.reload(); else $scope.projectParams.page(1); }; // $scope.onSearch = function (keyword) { // if (!angular.isUndefined(keyword)) { // $scope.keyword = keyword; // if ($scope.projectParams.page() == 1) // $scope.projectParams.reload(); // else // $scope.projectParams.page(1); // } // }; // 弹出详情页模态框 $scope.showDetail = function (id) { var modalInstance = $modal.open({ templateUrl: 'static/view/project/project_detail.html', controller: 'ProjectDetailCtrl', size: 'lg', resolve: { id: function () { return id; } } }); modalInstance.result.then(function(data){ if (data.success) { toaster.pop('success', '操作成功'); } $scope.projectParams.reload(); }, function(){ }); }; }]); /** * 项目详情框 */ app.controller('ProjectDetailCtrl', ['$scope', 'Project', 'toaster', '$modalInstance', 'BaseService', 'id', '$modal', '$sce', function($scope, Project, toaster, $modalInstance, BaseService, id, $modal, $sce) { var loadData = function() { // 获取项目详情 Project.getDetailById({id :id}, {}, function(data) { $scope.project = data; $scope.code = $sce.trustAsHtml($scope.project.introduction); }, function() { toaster.pop('error', '详情加载失败'); }); }; // 获取当前项目所有进度 $scope.getSchedules = function() { Project.getSchedules({id : id}, {}, function(data) { $scope.schedules = data; }, function() { toaster.pop('error', '项目进度加载失败'); }); }; // 获取当前项目捐款明细 $scope.getRecords = function() { Project.getRecords({id:id}, {}, function(data) { $scope.projectRecords = data; }, function() { toaster.pop('error', '捐款明细加载失败'); }); }; // 获取当前项目财务信息 $scope.getFinance = function() { Project.getFinance({id:id}, {}, function(data) { $scope.projectFinance = data.projectFinance; $scope.totalCost = data.totalCost; $scope.executeCost = data.executeCost; $scope.projectCost = data.projectCost; }, function() { toaster.pop('error','财务明细加载失败'); }); }; loadData(); $scope.cancel= function() { $modalInstance.dismiss(); }; $scope.deleteSchedule = function(scheduleId) { Project.deleteSchedule({id: scheduleId}, {}, function() { toaster.pop('success', '操作成功'); // 重新加载 $scope.getSchedules(); }, function() { toaster.pop('error', '出现错误,操作失败'); }); }; // true通过 false驳回 $scope.decide = function(type) { var modalInstance = $modal.open({ animation: true, templateUrl: 'static/view/project/audit_confirm.html', controller: 'AuditConfirmCtrl', resolve: { project : function() { return $scope.project; }, type : function() { return type; } } }); modalInstance.result.then(function(data){ if (data.success) { toaster.pop('success','操作成功'); } if (data.error) { toaster.pop('error','操作失败'); } loadData(); }, function(){ }); }; // 重新申请 $scope.reapply = function() { Project.reapply({id:id}, {}, function(data) { if (data.success) { toaster.pop('success', '重新申请成功'); } if (data.error) { toaster.pop('error', '申请失败,请联系管理员'); } loadData(); }, function(response) { toaster("error", "出现错误"); }); } }]); /** * 审核确认框 */ app.controller('AuditConfirmCtrl', ['$scope', 'project', 'type', '$modalInstance', 'toaster', 'Project', function($scope, project, type, $modalInstance, toaster, Project) { $scope.result = type; $scope.project = project; $scope.ok = function (type) { if (type) { Project.agree({id: project.id}, {}, function(data) { $modalInstance.close(data); }, function() { }); } else { Project.disagree({id: project.id, refuse: project.refuse}, {}, function(data) { $modalInstance.close(data); }, function() { }); } }; $scope.cancel = function() { $modalInstance.dismiss(); }; }]); /** * 机构入驻选择 */ app.controller('SelectInstitutionsNatureCtrl', ['$scope', 'toaster', 'Organization', '$location', function ($scope, toaster, Organization, $location) { // 获取当前账户注册机构情况 Organization.getByUuid({uuid : 222222}, {}, function(data) {//10041558 $scope.org = data; }, function() { toaster.pop('error', '注册情况加载失败'); }); //公益机构注册 $scope.registerCharityCertification = function () { if (typeof $scope.org.id == 'undefined') { $location.path('charityCertificationStep0'); } else { if ($scope.org.type == 2) { //之前已填写过公益机构注册信息 if ($scope.org.publish != 2) { //未完成或保存为草稿 $location.path('charityCertificationStep1'); } else { //发布正式 if ($scope.org.status == 0) { //已发布待审核 (暂时) $location.path('charityCertificationStep4'); } else if ($scope.org.status == 1) { //已发布已审核 $location.path('charityCertificationStep4'); } else if ($scope.org.status == 2) { //已发布已驳回 $location.path('charityCertificationStep1'); } } } else if ($scope.org.type == 1) { //之前填写过公募机构注册信息 if ($scope.org.publish != 2) { //未完成或保存为草稿 //TODO 模态框判断 var decideContinue = false; if (decideContinue) { //TODO 继续注册公益机构并替换掉之前的公募机构注册信息 $location.path('charityCertificationStep0'); } else { //TODO 继续之前的公募机构注册信息 toaster.pop('info', '继续之前的公募机构注册信息'); $location.path('publicOfferingCertificationStep1'); } } else { //发布正式 if ($scope.org.status == 0) { //已发布待审核 (暂时) $location.path('publicOfferingCertificationStep5'); } else if ($scope.org.status == 1) { //已发布已审核 $location.path('publicOfferingCertificationStep5'); } else if ($scope.org.status == 2) { //已发布已驳回 $location.path('publicOfferingCertificationStep1'); } } } } } //公募机构注册 $scope.registerPublicOfferingCertification = function () { if (typeof $scope.org.id == 'undefined') { $location.path('publicOfferingCertificationStep0'); } else { if ($scope.org.type == 1) { //之前已填写过公募机构注册信息 if ($scope.org.publish != 2) { //未完成或保存为草稿 $location.path('publicOfferingCertificationStep1'); } else { //发布正式 if ($scope.org.status == 0) { //已发布待审核 (暂时) $location.path('publicOfferingCertificationStep5'); } else if ($scope.org.status == 1) { //已发布已审核 $location.path('publicOfferingCertificationStep5'); } else if ($scope.org.status == 2) { //已发布已驳回 $location.path('publicOfferingCertificationStep1'); } } } else if ($scope.org.type == 2) { //之前填写过公益机构注册信息 if ($scope.org.publish != 2) { //未完成或保存为草稿 //TODO 模态框判断 var decideContinue = false; if (decideContinue) { //TODO 继续注册公募机构并替换掉之前的公益机构注册信息 $location.path('publicOfferingCertificationStep0'); } else { //TODO 继续之前的公益机构注册信息 toaster.pop('info', '继续之前的公益机构注册信息'); $location.path('charityCertificationStep1'); } } else { //发布正式 if ($scope.org.status == 0) { //已发布待审核 (暂时) $location.path('charityCertificationStep4'); } else if ($scope.org.status == 1) { //已发布已审核 $location.path('charityCertificationStep4'); } else if ($scope.org.status == 2) { //已发布已驳回 $location.path('charityCertificationStep1'); } } } } } }]); /** * 机构入驻同意协议 */ app.controller('CertificationStep0Ctrl', ['$scope', 'toaster', 'Organization', '$location', function ($scope, toaster, Organization, $location) { $scope.checked = false; $scope.changeChecked = function() { $scope.checked = !$scope.checked; }; $scope.stepNext = function (checked, orgType) { if (checked) { if (orgType == 1) { $location.path('publicOfferingCertificationStep1'); } else if (orgType == 2) { $location.path('charityCertificationStep1'); } } } // 获取当前账户注册机构情况 Organization.getByUuid({uuid : 222222}, {}, function(data) {//10041558 if (typeof data.id == 'undefined') { return; } $scope.checked = true; }, function() { toaster.pop('error', '注册情况加载失败'); }); }]); /** * 机构认证第一步 */ app.controller('CertificationStep1Ctrl', ['$scope', '$http', '$rootScope', '$timeout', '$location', 'toaster', 'Organization', function ($scope, $http, $rootScope, $timeout, $location, toaster, Organization) { // 主要领域 // $scope.areas = ['疾病援助', '扶贫/救灾', '教育/助学' , '环境/动物保护', '其他']; $scope.org = { majorArea: 1 }; var orgCopy; // 获取当前账户注册机构情况 Organization.getByUuid({uuid : 222222}, {}, function(data) {//10041558 if (typeof data.id == 'undefined') { return; } $scope.org = data; orgCopy = angular.copy($scope.org); }, function() { toaster.pop('error', '注册情况加载失败'); }); // 获取地址信息 $http.get('static/jsondata/city.json', { "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8" }).then(function (response) { $scope.provinces = response.data; }); // 设置主要领域 $scope.selectMajorArea = function(index) { $scope.org.majorArea = index; }; $scope.openDatePicker = function ($event, item, openParam) { $event.preventDefault(); $event.stopPropagation(); item[openParam] = !item[openParam]; }; //提交 $scope.saveStep1 = function (org, orgType) { if (orgCopy == org) { if (orgType == 1) { $location.path('publicOfferingCertificationStep2'); } else if (orgType == 2) { $location.path('charityCertificationStep2'); } } else { org.type = orgType;//机构类别(1:公募 2:非公募) //var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件 $http({ method : 'POST', url : '/org/save', params : { jsonStr : org }, }).success(function (data) { if (data.success) { toaster.pop('success', '提示', data.success); /*$timeout(function () { //提交后跳转到下一页,防止重复提交 window.location.href = "#/charityCertification2; }, 500);*/ if (orgType == 1) { $location.path('publicOfferingCertificationStep2'); } else if (orgType == 2) { $location.path('charityCertificationStep2'); } } if (data.error) { toaster.pop('error', '提示', data.error); } }).error(function (data, status) { $scope.loadingShow = false; if (status == 403) { toaster.pop('error', '操作失败', data); } else { toaster.pop('error', '操作失败', data.error); } }); } }; }]); /** * 机构认证第二步 */ app.controller('CertificationStep2Ctrl', ['$scope', '$http', '$rootScope', '$timeout', '$location', 'toaster', 'Organization', function ($scope, $http, $rootScope, $timeout, $location, toaster, Organization) { var orgCopy; // 获取当前账户注册机构情况 Organization.getByUuid({uuid : 222222}, {}, function(data) {//10041558 $scope.org = data; orgCopy = angular.copy($scope.org); }, function() { toaster.pop('error', '注册情况加载失败'); }); //提交 $scope.saveStep2 = function (org, orgType) { if (orgCopy == org) { if (orgType == 1) { $location.path('publicOfferingCertificationStep3'); } else if (orgType == 2) { $location.path('charityCertificationStep3'); } } else { $http({ method: 'POST', url: '/org/save', params: { jsonStr: org }, }).success(function (data) { if (data.success) { if (orgType == 1) { $location.path('publicOfferingCertificationStep3'); } else if (orgType == 2) { $location.path('charityCertificationStep3'); } } if (data.error) { toaster.pop('error', '提示', data.error); } }).error(function (data, status) { $scope.loadingShow = false; if (status == 403) { toaster.pop('error', '操作失败', data); } else { toaster.pop('error', '操作失败', data.error); } }); } }; }]); /** * 机构认证第三步 */ app.controller('CertificationStep3Ctrl', ['$scope', '$http', '$rootScope', '$timeout', '$location', 'toaster', 'Organization', function ($scope, $http, $rootScope, $timeout, $location, toaster, Organization) { var orgCopy; // 获取当前账户注册机构情况 Organization.getByUuid({uuid : 222222}, {}, function(data) {//10041558 if (typeof data.id == 'undefined') { return; } $scope.org = data; $scope.logoUrl = $scope.org.logo; $scope.personCertificateUrl = $scope.org.personCertificate; $scope.donateCertificateUrl = $scope.org.donateCertificate; $scope.legalIdCardUrl = $scope.org.legalIdCard; orgCopy = angular.copy($scope.org); }, function() { toaster.pop('error', '注册情况加载失败'); }); // 获取银行信息 $scope.getBankName = function (bankCard) { if (bankCard == null) { $scope.org.branchMessage = ""; } else if(bankCard.toString().length < 6) { $scope.org.branchMessage = ""; } else { bankCard = bankCard.toString(); $.getJSON("static/jsondata/bank.json", {}, function (data) { var bankBin = 0; var isFind = false; for (var key = 10; key >= 2; key--) { bankBin = bankCard.substring(0, key); $.each(data, function (i, item) { if (item.bin == bankBin) { isFind = true; $scope.org.branchMessage = item.bankName; } }); if (isFind) { break; } } if (!isFind) { $scope.org.branchMessage = "未知发卡银行"; } }); } } /*$scope.fileChanged = function(ele, order){ if (order == 0) { $scope.logo = ele.files[0]; } else if (order == 1) { $scope.personCertificate = ele.files[0]; } else if (order == 2) { $scope.donateCertificate = ele.files[0]; } else if (order == 3) { $scope.legalIdCard = ele.files[0]; } $scope.$apply(); };*/ //建立一个可存取到该file的url var getObjectURL = function (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); } return url; }; // 图片上传 $scope.fileChanged = function(ele, order){ if (order == 0) { $scope.logo = ele.files[0]; $scope.logoUrl = getObjectURL($scope.logo); } else if (order == 1) { $scope.personCertificate = ele.files[0]; $scope.personCertificateUrl = getObjectURL($scope.personCertificate); } else if (order == 2) { $scope.donateCertificate = ele.files[0]; $scope.donateCertificateUrl = getObjectURL($scope.donateCertificate); } else if (order == 3) { $scope.legalIdCard = ele.files[0]; $scope.legalIdCardUrl = getObjectURL($scope.legalIdCard); } $scope.$apply(); }; // 查看范例 $scope.showImg = function (type) { var img = null; var imgUrl = null; switch (type) { case 'logo': img = $scope.org.logo; imgUrl = $scope.logoUrl; break; case 'personCertificate': img = $scope.org.personCertificate; imgUrl = $scope.personCertificateUrl; break; case 'donateCertificate': img = $scope.org.donateCertificate; imgUrl = $scope.donateCertificateUrl; break; case 'legalIdCard': img = $scope.org.legalIdCard; imgUrl = $scope.legalIdCardUrl; break; } if (img) { var src = img, box = $('#image-box'); box.show(); box.find('img').attr('src', src); box.find('a').click(function () { box.hide(); }); box.dblclick(function () { box.hide(); }); } else if (imgUrl != null) { var src = imgUrl, box = $('#image-box'); box.show(); box.find('img').attr('src', src); box.find('a').click(function () { box.hide(); }); box.dblclick(function () { box.hide(); }); } }; // 删除 $scope.clearFile = function (type) { switch (type) { case 'logo': $scope.logo = null; $scope.logoUrl = null; break; case 'personCertificate': $scope.personCertificate = null; $scope.personCertificateUrl = null; break; case 'donateCertificate': $scope.donateCertificate = null; $scope.donateCertificateUrl = null; break; case 'legalIdCard': $scope.legalIdCard = null; $scope.legalIdCardUrl = null; break; } // 清空input框的内容 var file=document.getElementById(type); //IE,Safari,chrome if(file.outerHTML){ file.outerHTML=file.outerHTML; } else{ //FF file.value=""; } }; //提交 $scope.saveStep3 = function (org, isDraft, orgType) { if (orgCopy == org) { if (orgType == 1) { $location.path('publicOfferingCertificationStep4'); } else if (orgType == 2) { $location.path('charityCertificationStep4'); } } else { var url; if (isDraft) { url = '/org/save'; } else { url = '/org/submit'; } var data = new FormData(); //以下为像后台提交图片数据 data.append('logo', $scope.logo); data.append('personCertificate', $scope.personCertificate); data.append('donateCertificate', $scope.donateCertificate); data.append('legalIdCard', $scope.legalIdCard); $http({ headers: { 'Content-Type': undefined }, method: 'POST', processData: false, async: false, url: url, data: data, params: { jsonStr: org }, }).success(function (data) { if (data.success) { if (orgType == 1) { $location.path('publicOfferingCertificationStep4'); } else if (orgType == 2) { $location.path('charityCertificationStep4'); } } if (data.error) { toaster.pop('error', '提示', data.error); } }).error(function (data, status) { $scope.loadingShow = false; if (status == 403) { toaster.pop('error', '操作失败', data); } else { toaster.pop('error', '操作失败', data.error); } }); } }; }]); /** * 公募机构认证第四步 */ app.controller('PublicCertificationStep4Ctrl', ['$scope', '$http', '$rootScope', '$timeout', '$location', 'toaster', 'Organization', function ($scope, $http, $rootScope, $timeout, $location, toaster, Organization) { var orgCopy; // 获取当前账户注册机构情况 Organization.getByUuid({uuid : 222222}, {}, function(data) {//10041166 10041558 if (typeof data.id == 'undefined') { return; } $scope.org = data; $scope.materialUrl = $scope.org.material; $scope.certifyUrl = $scope.org.certify; orgCopy = angular.copy($scope.org); }, function() { toaster.pop('error', '注册情况加载失败'); }); /*$scope.fileChanged = function(ele, order){ if (order == 0) { //合作商户资料 $scope.material = ele.files[0]; } else if (order == 1) { //结算银行账号证明 $scope.certify = ele.files[0]; } $scope.$apply(); }*/ //建立一个可存取到该file的url var getObjectURL = function (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); } return url; }; // 图片上传 $scope.fileChanged = function(ele, order){ if (order == 0) { $scope.material = ele.files[0]; $scope.materialUrl = getObjectURL($scope.material); } else if (order == 1) { $scope.certify = ele.files[0]; $scope.certifyUrl = getObjectURL($scope.certify); } $scope.$apply(); }; // 查看范例 $scope.showImg = function (type) { var img = null; var imgUrl = null; switch (type) { case 'material': img = $scope.org.material; imgUrl = $scope.materialUrl; break; case 'certify': img = $scope.org.certify; imgUrl = $scope.certifyUrl; break; } if (img) { var src = img, box = $('#image-box'); box.show(); box.find('img').attr('src', src); box.find('a').click(function () { box.hide(); }); box.dblclick(function () { box.hide(); }); } else if (imgUrl != null) { var src = imgUrl, box = $('#image-box'); box.show(); box.find('img').attr('src', src); box.find('a').click(function () { box.hide(); }); box.dblclick(function () { box.hide(); }); } }; // 删除 $scope.clearFile = function (type) { switch (type) { case 'material': $scope.material = null; $scope.materialUrl = null; break; case 'certify': $scope.certify = null; $scope.certifyUrl = null; break; } // 清空input框的内容 var file=document.getElementById(type); //IE,Safari,chrome if(file.outerHTML){ file.outerHTML=file.outerHTML; } else{ //FF file.value=""; } }; //提交 $scope.saveStep4 = function (org, isDraft) { if (orgCopy == org) { $location.path('publicOfferingCertificationStep5'); } else { var url; if (isDraft) { url = '/org/save'; } else { url = '/org/submit'; } var data = new FormData(); //以下为像后台提交图片数据 data.append('material', $scope.material); data.append('certify', $scope.certify); $http({ headers: { 'Content-Type': undefined }, method: 'POST', processData: false, async: false, url: url, data: data, params: { jsonStr: org }, }).success(function (data) { if (data.success) { $location.path('publicOfferingCertificationStep5'); } if (data.error) { toaster.pop('error', '提示', data.error); } }).error(function (data, status) { $scope.loadingShow = false; if (status == 403) { toaster.pop('error', '操作失败', data); } else { toaster.pop('error', '操作失败', data.error); } }); } }; }]); /** * 新建项目 */ app.controller('ProjectNewCtrl', ['$scope', 'BaseService', 'Project', '$http', 'toaster', '$stateParams', '$rootScope', function($scope, BaseService, Project, $http, toaster, $stateParams, $rootScope) { if ($rootScope.active) { $rootScope.active = 'done'; } // 默认捐助领域 $scope.defaultAreas = ['疾病援助', '扶贫/救灾', '教育/助学' , '环境/动物保护', '其他']; // 默认具体分类 var defaultClassifys = ['白血病', '早产儿', '烧烫伤', '罕见病', '癌症', '唇腭裂', '因病致贫', '尘肺病', '病情危急', '尿毒症', '渐冻症', '意外受伤', '贫困大病', '视力健康', '听障', '其他']; $scope.populations = ['第三世界', '贫困妇女', '空巢/留守老人', '孤儿/事实孤儿', '残障', '抗战老兵', '自闭症', '弱势群体', '走失儿童', '失独家庭', '山区孩子', '义工志愿者', '困境儿童', '贫困家庭', '少数民族', '其他']; $scope.checked = true; $scope.changeChecked = function() { $scope.checked = !$scope.checked; }; // 获取已保存的项目 var getSavedProject = function() { // 获取地址信息 $http.get('static/jsondata/classify.json', { "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8" }).then(function (response) { $scope.areas = response.data; }); Project.getSavedProject({}, {}, function(data) { if(angular.isObject(data)) { $scope.project = data; $scope.pcImgUrl = data.pcImg; $scope.mobileImgUrl = data.mobileImg; $scope.mobileListImgUrl = data.listImg; $scope.logoUrl = data.logo; } }); if (!angular.isUndefined($stateParams.id)) { Project.getDetailById({id : $stateParams.id}, {}, function(data) { $scope.project = data; $scope.pcImgUrl = data.pcImg; $scope.mobileImgUrl = data.mobileImg; $scope.mobileListImgUrl = data.listImg; $scope.logoUrl = data.logo; }); } if (angular.isUndefined($scope.project)) { $scope.project = { area: $scope.defaultAreas[0], classify: defaultClassifys[0], population: $scope.populations[0] }; } }; getSavedProject(); // 日期选择 $scope.openDatePicker = function ($event, item, openParam) { $event.preventDefault(); $event.stopPropagation(); item[openParam] = !item[openParam]; }; // 设置区域 $scope.setArea = function(area) { $scope.project.area = area; $scope.classifys = $scope.areas[area]; $scope.project.classify = $scope.areas[area][0]; }; // 设置具体分类 $scope.setClassify = function(classify) { $scope.project.classify = classify; }; // 设置受助人群 $scope.setPopulation = function(index) { $scope.project.population = $scope.populations[index]; }; // 获取地址信息 $http.get('static/jsondata/city.json', { "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8" }).then(function (response) { $scope.provinces = response.data; }); // 保存基础信息 $scope.saveBaseInfo = function(project) { Project.saveBaseInfo({}, project, function(data) { $scope.project = data; var proId = $scope.project.id; if(proId) { BaseService.scrollBackToTop(); window.location.href = '#/launchProject/detail/' + proId; } },function(res) { toaster.pop('error', '出现错误,操作失败'); }); }; // 删除 $scope.cancel = function(type) { switch (type) { case 'pcImg': $scope.pcImg = null; break; case 'mobileImg': $scope.mobileImg = null; break; } }; //建立一个可存取到该file的url var getObjectURL = function (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); } return url; }; // 图片上传 $scope.fileChanged = function(ele, order){ if (order == 0) { $scope.pcImg = ele.files[0]; $scope.pcImgUrl = getObjectURL($scope.pcImg); } else if (order == 1) { $scope.mobileImg = ele.files[0]; $scope.mobileImgUrl = getObjectURL($scope.mobileImg); } if (order == 2) { $scope.mobileListImg = ele.files[0]; $scope.mobileListImgUrl = getObjectURL($scope.mobileListImg); } if (order == 3) { $scope.logo = ele.files[0]; $scope.logoUrl = getObjectURL($scope.logo); } $scope.$apply(); }; // 查看范例 $scope.showImg = function (type) { var img = null; var imgUrl = null; switch (type) { case 'pcImg': img = $scope.project.pcImg; imgUrl = $scope.pcImgUrl; break; case 'mobileImg': img = $scope.project.mobileImg; imgUrl = $scope.mobileImgUrl; break; case 'mobileListImg': img = $scope.project.mobileListImg; imgUrl = $scope.mobileListImgUrl; break; case 'logo': img = $scope.project.logo; imgUrl = $scope.logoUrl; break; } if (img) { var src = img, box = $('#image-box'); box.show(); box.find('img').attr('src', src); box.find('a').click(function () { box.hide(); }); box.dblclick(function () { box.hide(); }); } else if (imgUrl != null) { var src = imgUrl, box = $('#image-box'); box.show(); box.find('img').attr('src', src); box.find('a').click(function () { box.hide(); }); box.dblclick(function () { box.hide(); }); } }; // 删除 $scope.clearFile = function (type) { switch (type) { case 'pcImg': $scope.pcImg = null; $scope.pcImgUrl = null; break; case 'mobileImg': $scope.mobileImg = null; $scope.mobileImgUrl = null; break; case 'mobileListImg': $scope.mobileListImg = null; $scope.mobileListImgUrl = null; break; case 'logo': $scope.logo = null; $scope.logoUrl = null; break; } // 清空input框的内容 var file=document.getElementById(type); //IE,Safari,chrome if(file.outerHTML){ file.outerHTML=file.outerHTML; } else{ //FF file.value=""; } }; //提交 或 保存 $scope.saveDetail = function (project, type) { var data = new FormData(); //以下为像后台提交图片数据 data.append('pcImg', $scope.pcImg); data.append('mobileImg', $scope.mobileImg); data.append('mobileListImg', $scope.mobileListImg); data.append('logo', $scope.logo); data.append('jsonStr', JSON.stringify(project)); // type为true即为发布 var url; if (type) { url = '/project/submit'; } else { url = '/project/save'; } $http({ headers: { 'Content-Type': undefined }, method : 'POST', processData : false, contentType: false, async: false, url : url, data: data }).success(function (data) { if (type) { toaster.pop('success', '发布成功'); BaseService.scrollBackToTop(); $rootScope.active = 'todo'; window.location.href='#/launchProject/success'; } else { toaster.pop('success', '保存成功'); window.location.href='#/'; } }).error(function (data) { $scope.loadingShow = false; toaster.pop('error', '出现错误,操作失败'); }); }; }]); /** * 财务披露项目列表 */ app.controller('ProjectFinanceListCtrl', ['$scope', 'toaster', 'ngTableParams', 'BaseService', 'Project', '$modal', function ($scope, toaster, ngTableParams, BaseService, Project, $modal) { $scope.keyword = ''; $scope.reload = function() { if ($scope.projectParams.page() == 1) $scope.projectParams.reload(); else $scope.projectParams.page(1); }; $scope.projectParams = new ngTableParams({ page: 1, count: 5, sorting: { 'id': 'desc' } }, { total: 0, counts: [5, 10, 25, 50], getData: function ($defer, params) { $scope.loading = true; var pageParams = params.url(); var realActive = {}; pageParams.searchFilter = { // 筛选条件 keyword: $scope.keyword }; Project.getNotEnd.call(null, BaseService.parseParams(pageParams), function (page) { $scope.loading = false; if (page) { params.total(page.totalElements); $defer.resolve(page.content); // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段 } }, function (response) { $scope.loading = false; toaster.pop('error', '数据加载失败', response.data); }); } }); $scope.onSearch = function () { if ($scope.projectParams.page() == 1) $scope.projectParams.reload(); else $scope.projectParams.page(1); }; // 弹出详情页模态框 $scope.showFinance = function (id) { var modalInstance = $modal.open({ templateUrl: 'static/view/project/project_finance.html', controller: 'ProjectFinanceDetailCtrl', size: 'lg', resolve: { id: function () { return id; } } }); modalInstance.result.then(function(data){ if (data.success) { toaster.pop('success', '操作成功'); } $scope.projectParams.reload(); }, function(){ }); }; }]); /** * 财务披露详情框 */ app.controller('ProjectFinanceDetailCtrl', ['$scope', 'Project', 'toaster', '$modalInstance', 'BaseService', 'id', '$upload', '$http', function($scope, Project, toaster, $modalInstance, BaseService, id, $upload, $http) { $scope.newFinance = { amount: null, path: null, description: null, type : null }; $scope.imgUrl = null; var loadData = function() { // 获取项目详情 Project.getDetailById({id :id}, {}, function(data) { $scope.project = data; }, function() { toaster.pop('error', '详情加载失败'); }); // 获取当前项目财务信息 Project.getFinance({id:id}, {}, function(data) { $scope.projectFinance = data.projectFinance; $scope.totalCost = data.totalCost; $scope.executeCost = data.executeCost; $scope.projectCost = data.projectCost; }, function() { toaster.pop('error','财务明细加载失败'); }); }; loadData(); $scope.cancel= function() { $modalInstance.dismiss(); }; $scope.fileChanged = function(ele) { $scope.newFinance.file = ele.files[0]; $scope.imgUrl = getObjectURL(ele.files[0]); }; //建立一个可存取到该file的url var getObjectURL = function (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); } return url; }; // // 查看范例 // $scope.showImg = function () { // var imgUrl = $scope.imgUrl; // if (imgUrl != null) { // var src = imgUrl, box = $('#image-box'); // box.show(); // box.find('img').attr('src', src); // box.find('a').click(function () { // box.hide(); // }); // box.dblclick(function () { // box.hide(); // }); // } // }; // 删除活动图或banner $scope.clearFile = function (type) { $scope.newFinance.file = null; $scope.imgUrl = null; // 清空input框的内容 var file=document.getElementById(type); //IE,Safari,chrome if(file.outerHTML){ file.outerHTML=file.outerHTML; } else{ //FF file.value=""; } }; // 发布 $scope.saveFinance = function(finance) { var data = new FormData(); data.append('json', JSON.stringify(finance)); data.append('img', finance.file); $http({ headers: { 'Content-Type': undefined }, method: 'POST', processData: false, async: false, url: 'project/save/finance/' + id, data: data }).success(function(data){ toaster.pop('success', '发布财务信息成功'); $modalInstance.close(); }).error(function(data){ toaster.pop('error', '出现错误,发布失败'); }); }; }]); /** * 报告填写项目列表 */ app.controller('ProjectReportListCtrl', ['$scope', 'toaster', 'ngTableParams', 'BaseService', 'Project', '$modal', '$http', function ($scope, toaster, ngTableParams, BaseService, Project, $modal, $http) { $scope.keyword = ''; $scope.selectedArea = '全部'; $scope.reload = function() { if ($scope.projectParams.page() == 1) $scope.projectParams.reload(); else $scope.projectParams.page(1); }; $scope.projectParams = new ngTableParams({ page: 1, count: 5, sorting: { 'id': 'desc' } }, { total: 0, counts: [5, 10, 25, 50], getData: function ($defer, params) { $scope.loading = true; var pageParams = params.url(); var realActive = {}; pageParams.searchFilter = { // 筛选条件 keyword: $scope.keyword, area: $scope.selectedArea }; Project.getNotEnd.call(null, BaseService.parseParams(pageParams), function (page) { $scope.loading = false; if (page) { params.total(page.totalElements); $defer.resolve(page.content); // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段 } }, function (response) { $scope.loading = false; toaster.pop('error', '数据加载失败', response.data); }); } }); $scope.onSearch = function () { if ($scope.projectParams.page() == 1) $scope.projectParams.reload(); else $scope.projectParams.page(1); }; // 弹出详情页模态框 $scope.showReport = function (id) { var modalInstance = $modal.open({ templateUrl: 'static/view/project/project_report.html', controller: 'ProjectReportDetailCtrl', size: 'lg', resolve: { id: function () { return id; } } }); modalInstance.result.then(function(data){ if (data.success) { toaster.pop('success', '操作成功'); } $scope.projectParams.reload(); }, function(){ }); }; }]); /** * 报告填写详情框 */ app.controller('ProjectReportDetailCtrl', ['$scope', 'Project', 'toaster', '$modalInstance', 'BaseService', 'id', '$http', function($scope, Project, toaster, $modalInstance, BaseService, id, $http) { $scope.report = { path: null, description: null }; var loadData = function() { // 获取项目详情 Project.getDetailById({id :id}, {}, function(data) { $scope.project = data; }, function() { toaster.pop('error', '详情加载失败'); }); // 获取当前项目所有进度 Project.getSchedules({id : id}, {}, function(data) { $scope.schedules = data; }, function() { toaster.pop('error', '项目进度加载失败'); }); }; loadData(); // 图片上传 $scope.fileChanged = function(ele){ $scope.report.file = ele.files[0]; $scope.imgUrl = getObjectURL(ele.files[0]); $scope.$apply(); }; $scope.cancel= function() { $modalInstance.dismiss(); }; // delete $scope.deleteSchedule = function(scheduleId) { Project.deleteSchedule({id: scheduleId}, {}, function() { toaster.pop('success', '操作成功'); // 重新加载 loadData(); }, function() { toaster.pop('error', '出现错误,操作失败'); }); }; // 发布 $scope.saveReport = function(report) { var data = new FormData(); data.append('json', JSON.stringify(report)); data.append('img', report.file); $http({ headers: { 'Content-Type': undefined }, method: 'POST', processData: false, async: false, url: 'project/save/report/' + id, data: data }).success(function(data){ toaster.pop('success', '发布进度信息成功'); $modalInstance.close(); }).error(function(data){ toaster.pop('error', '出现错误,发布失败'); }); }; }]); /** * 结项管理项目列表 */ app.controller('ProjectManagementListCtrl', ['$scope', 'toaster', 'ngTableParams', 'BaseService', 'Project', '$modal', function ($scope, toaster, ngTableParams, BaseService, Project, $modal) { $scope.keyword = ''; $scope.selectedArea = '全部'; $scope.reload = function() { if ($scope.projectParams.page() == 1) $scope.projectParams.reload(); else $scope.projectParams.page(1); }; $scope.projectParams = new ngTableParams({ page: 1, count: 5, sorting: { 'id': 'desc' } }, { total: 0, counts: [5, 10, 25, 50], getData: function ($defer, params) { $scope.loading = true; var pageParams = params.url(); var realActive = {}; pageParams.searchFilter = { // 筛选条件 keyword: $scope.keyword, area: $scope.selectedArea }; Project.getNotEnd.call(null, BaseService.parseParams(pageParams), function (page) { $scope.loading = false; if (page) { params.total(page.totalElements); $defer.resolve(page.content); // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段 } }, function (response) { $scope.loading = false; toaster.pop('error', '数据加载失败', response.data); }); } }); $scope.onSearch = function () { if ($scope.projectParams.page() == 1) $scope.projectParams.reload(); else $scope.projectParams.page(1); }; // 弹出详情页模态框 $scope.showManagement = function (id) { var modalInstance = $modal.open({ templateUrl: 'static/view/project/project_management.html', controller: 'ProjectManagementDetailCtrl', size: 'lg', resolve: { id: function () { return id; } } }); modalInstance.result.then(function(data){ if (data.success) { toaster.pop('success', '操作成功'); } $scope.projectParams.reload(); }, function(){ }); }; }]); /** * 结项管理详情框 */ app.controller('ProjectManagementDetailCtrl', ['$scope', 'Project', 'toaster', '$modalInstance', 'BaseService', 'id', '$http', function($scope, Project, toaster, $modalInstance, BaseService, id, $http) { $scope.conclude = { description: null }; var loadData = function() { // 获取项目详情 Project.getDetailById({id :id}, {}, function(data) { $scope.project = data; }, function() { toaster.pop('error', '详情加载失败'); }); // 获取当前项目结项数据 $scope.getConcludeData = function() { Project.getConcludeData({id : id}, {}, function(data) { $scope.executeDays = data.executeDays; $scope.updateTimes = data.updateTimes; }, function() { toaster.pop('error', '加载失败'); }); }; }; loadData(); $scope.cancel= function() { $modalInstance.dismiss(); }; // 发布 $scope.saveConclude = function(conclude) { var data = new FormData(); data.append('json', JSON.stringify(conclude)); data.append('img', conclude.file); $http({ headers: { 'Content-Type': undefined }, method: 'POST', processData: false, async: false, url: 'project/save/conclude/' + id, data: data }).success(function(data){ toaster.pop('success', '发布结项信息成功'); $modalInstance.close(); }).error(function(data){ toaster.pop('error', '出现错误,发布失败'); }); }; }]); /** * 活动列表 */ app.controller('ActivityListCtrl', ['$scope', '$rootScope', 'toaster', 'ngTableParams', 'BaseService', 'Activity', '$modal', function ($scope, $rootScope, toaster, ngTableParams, BaseService, Activity, $modal) { var getActivityState = function (active) { // 正在进行 var fn = 'getDone'; switch (active) { // 未开始 case 'todo': fn = 'getTodo'; break; // 已结束 case 'end': fn = 'getEnd'; break; // 草稿 case 'waiting': fn = 'getWaiting'; break; } return fn; }; $scope.active = 'done'; $scope.keyword = ''; /** * 修改分类 * @param value */ $scope.setActive = function (value) { if ($scope.active != value) { $scope.active = value; if ($scope.activityParams.page() == 1) $scope.activityParams.reload(); else $scope.activityParams.page(1); } }; $scope.reload = function() { if ($scope.activityParams.page() == 1) $scope.activityParams.reload(); else $scope.activityParams.page(1); }; $scope.activityParams = new ngTableParams({ page: 1, count: 5, sorting: { 'id': 'desc' } }, { total: 0, counts: [5, 10, 25, 50], getData: function ($defer, params) { $scope.loading = true; var pageParams = params.url(); var realActive = {}; pageParams.searchFilter = { // 筛选条件 keyword: $scope.keyword }; Activity[getActivityState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) { $scope.loading = false; if (page) { params.total(page.totalElements); $defer.resolve(page.content); // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段 } }, function (response) { $scope.loading = false; toaster.pop('error', '数据加载失败', response.data); }); } }); $scope.onSearch = function () { if ($scope.activityParams.page() == 1) $scope.activityParams.reload(); else $scope.activityParams.page(1); }; var getNum = function() { Activity.getActivitiesNum({}, {}, function(data) { $scope.doneNum = data.doneNum; $scope.todoNum = data.todoNum; $scope.endNum = data.endNum; $scope.waitingNum = data.waitingNum; }); }; getNum(); // 开奖 $scope.openAward = function(id) { Activity.openAward({id: id}, {}, function() { toaster.pop('success', '开奖成功'); $scope.activityParams.reload(); }, function(response) { toaster.pop('error', '数据加载错误'); }); }; // 弹出详情页模态框 $scope.showDetail = function (id) { var modalInstance = $modal.open({ templateUrl: 'static/view/activity/activity_detail.html', controller: 'ActivityDetailCtrl', size: 'lg', resolve: { id: function () { return id; } } }); modalInstance.result.then(function(data){ if (data.success) { toaster.pop('success', '操作成功'); } $scope.activityParams.reload(); }, function(){ }); }; }]); /** * 活动详情框 */ app.controller('ActivityDetailCtrl', ['$scope', 'Activity', 'toaster', '$modalInstance', 'BaseService', 'id', '$modal', function($scope, Activity, toaster, $modalInstance, BaseService, id, $modal) { var loadData = function() { // 获取项目详情 Activity.getDetailById({id :id}, {}, function(data) { $scope.activity = data; }, function() { toaster.pop('error', '详情加载失败'); }); Activity.getRelatedProject({id:id}, {}, function(data) { $scope.relatedProjects = data; }); }; loadData(); $scope.cancel= function() { $modalInstance.dismiss(); }; }]); /** * 活动发起 */ app.controller('ActivityNewCtrl', ['$scope', 'BaseService', 'toaster', 'Activity', '$http', '$upload', function($scope, BaseService, toaster, Activity, $http, $upload) { $scope.activity = { awards:[], projects: [] }; $scope.awards = []; $scope.projects = []; $scope.tempProjects = []; $scope.selectedProjects = []; $scope.tempSelectedProjects = []; $scope.keyword = ''; var loadSavedActivity = function() { Activity.getSavedActivity({}, function(data) { if (null !== data) { $scope.activity = data; $scope.awards = data.awards; $scope.selectedProjects = data.projects; } }); }; loadSavedActivity(); // 日期选择 $scope.openDatePicker = function ($event, item, openParam) { $event.preventDefault(); $event.stopPropagation(); item[openParam] = !item[openParam]; }; // 富文本编辑器配置 // $scope.editorConfig = { // dialogsInBody: true, // lang: 'zh-CN', // toolbar:[ // ['edit',['undo','redo']], // ['style',['bold','italic','underline','clear' ]], // ['fontsize',['fontsize']], // ['para',['ul','ol','paragraph']], // ['color',['color']], // ['remove', ['removeMedia']], // ['insert', ['link', 'picture', 'table', 'hr']], // ['view', ['fullscreen', 'codeview']] // ] // }; // 添加奖品 $scope.addAward = function() { if ($scope.awards.length >= 4) { toaster.pop('warning', '提示', '最多可添加四个奖品'); } else { $scope.awards.push({ name: '', amount: null, awardLevel: '', way: 1 }); } }; // 删除某一奖品 $scope.deleteAward = function($index) { var path = $scope.awards[$index].img; if (!angular.isUndefined(path)) { Activity.deletePrizeImg({path: path}, {}, function(data) { }); } $scope.awards.splice($index, 1); }; // 获取项目列表 var getProject = function() { var selectedIds = []; if ([] !== $scope.selectedProjects) { angular.forEach($scope.selectedProjects, function(selectedProject) { selectedIds.push(selectedProject.id); }); } Activity.getActivityRelatedProjects({keyword: $scope.keyword, selectedIds: selectedIds}, {}, function(data) { $scope.projects = data; }); }; getProject(); // 搜索项目 $scope.onSearch = function() { getProject(); }; // 选择未被选择的项目 // $scope.checkSelected = function (project) { // if (project.checked) { // project.checked = !project.checked; // } else { // project.checked = true; // } // }; // 添加选中 $scope.addSelected = function() { $scope.tempSelectedProjects = angular.copy($scope.selectedProjects); $scope.tempProjects = angular.copy($scope.projects); angular.forEach($scope.projects, function(project, index) { if (project.checked) { project.checked = false; $scope.selectedProjects.push(project); $scope.projects.splice(index, 1); } }); angular.forEach($scope.projects, function(project, index) { if (project.checked) { project.checked = false; $scope.selectedProjects.push(project); $scope.projects.splice(index, 1); } }); }; // 删除选中 $scope.deleteSelected = function() { $scope.tempSelectedProjects = angular.copy($scope.selectedProjects); $scope.tempProjects = angular.copy($scope.projects); // 存在取消操作,用temp过渡 // 因为会splice,所以相邻的被选中需要遍历两次 angular.forEach($scope.selectedProjects, function(project, index) { if (project.checked) { project.checked = false; $scope.projects.push(project); $scope.selectedProjects.splice(index, 1); } }); angular.forEach($scope.selectedProjects, function(project, index) { if (project.checked) { project.checked = false; $scope.projects.push(project); $scope.selectedProjects.splice(index, 1); } }); }; // 取消 $scope.cancelSelected = function() { $scope.projects = angular.copy($scope.tempProjects); $scope.selectedProjects = angular.copy($scope.tempSelectedProjects); }; // 刷新 $scope.refresh = function() { window.location.reload(); }; // 图片上传 $scope.fileChanged = function(ele, value){ if (value == 0) { $scope.actImg = ele.files[0]; $scope.actImgUrl = getObjectURL($scope.actImg); } else if (value == 1) { $scope.banner = ele.files[0]; $scope.bannerUrl = getObjectURL($scope.banner); // } else if (value == 2) { // $scope.award1 = ele.files[0]; // } else if (value == 3) { // $scope.award2 = ele.files[0]; // } else if (value == 4) { // $scope.award3 = ele.files[0]; // } else if (value == 5) { // $scope.award4 = ele.files[0]; } $scope.$apply(); }; //建立一个可存取到该file的url var getObjectURL = function (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); } return url; }; // 查看范例 $scope.showImg = function (type) { var img = type; var imgUrl = null; switch (type) { case 'actImg': img = $scope.activity.actImg; imgUrl = $scope.actImgUrl; break; case 'banner': img = $scope.activity.banner; imgUrl = $scope.bannerUrl; break; } if (img) { var src = img, box = $('#image-box'); box.show(); box.find('img').attr('src', src); box.find('a').click(function () { box.hide(); }); box.dblclick(function () { box.hide(); }); } else if (imgUrl != null) { var src = imgUrl, box = $('#image-box'); box.show(); box.find('img').attr('src', src); box.find('a').click(function () { box.hide(); }); box.dblclick(function () { box.hide(); }); } }; // 删除活动图或banner $scope.clearFile = function (type) { switch (type) { case 'actImg': $scope.actImg = null; $scope.actImgUrl = null; break; case 'banner': $scope.banner = null; $scope.bannerUrl = null; break; } // 清空input框的内容 var file=document.getElementById(type); //IE,Safari,chrome if(file.outerHTML){ file.outerHTML=file.outerHTML; } else{ //FF file.value=""; } }; // 删除奖品图片 $scope.deletePrizeImg = function(path, index) { $scope.awards[index].img = null; var type = 'award' + index; // 清空input框的内容 var file=document.getElementById(type); //IE,Safari,chrome if(file.outerHTML){ file.outerHTML=file.outerHTML; } else{ //FF file.value=""; } if (!angular.isUndefined(path)) { Activity.deletePrizeImg({path: path}, {}, function(data) { }); } }; $scope.uploadPrizeImg = function(award, index) { $scope.loading = true; var files = award.prizeImgs, file = files && files.length > 0 ? files[0] : null; $upload.upload({ url: 'activity/upload/prizeImg', method: 'POST', file: file }).success(function (data) { $scope.awards[index].img = data.path; $scope.loading = false; }).error(function (data) { $scope.loading = false; // toaster.pop('error', '错误', data); }); }; // 保存 或 提交 $scope.submit = function(type) { var projectList = []; angular.forEach($scope.selectedProjects, function(project) { projectList.push(project); }); $scope.activity.projects = projectList; $scope.activity.awards = $scope.awards; var url; if (type) { url = 'activity/submit'; } else { url = 'activity/save'; } var data = new FormData(); data.append('actImg', $scope.actImg); data.append('banner', $scope.banner); // data.append('award1', $scope.award1); // data.append('award2', $scope.award2); // data.append('award3', $scope.award3); // data.append('award4', $scope.award4); data.append('jsonStr', JSON.stringify($scope.activity)); $http({ headers: { 'Content-Type': undefined }, method : 'POST', processData : false, async: false, url : url, data: data }).success(function (data) { if (type) { toaster.pop('success', '发布成功'); } else { toaster.pop('success', '保存成功'); } window.location.href='#/activity'; }).error(function (data) { $scope.loadingShow = false; toaster.pop('error', '出现错误,操作失败'); }); } }]); /** * 机构列表 */ app.controller('OrgListCtrl', ['$scope', '$rootScope', 'toaster', 'ngTableParams', 'BaseService', 'Organization', '$modal', function ($scope, $rootScope, toaster, ngTableParams, BaseService, Organization, $modal) { var getOrgState = function (active) { var fn = 'getAudited'; switch (active) { // 已审核 case 'audited': fn = 'getAudited'; break; // 未审核 case 'unaudited': fn = 'getUnaudited'; break; // 未通过 case 'disagreed': fn = 'getDisagreed'; break; } return fn; }; $scope.active = 'done'; if ($rootScope.active) { $scope.active = $rootScope.active; } $scope.keyword = ''; /** * 修改分类 * @param value */ $scope.setActive = function (value) { if ($scope.active != value) { $scope.active = value; if ($scope.activityParams.page() == 1) $scope.activityParams.reload(); else $scope.activityParams.page(1); } }; $scope.reload = function() { if ($scope.activityParams.page() == 1) $scope.activityParams.reload(); else $scope.activityParams.page(1); }; $scope.orgParams = new ngTableParams({ page: 1, count: 5, sorting: { 'id': 'desc' } }, { total: 0, counts: [5, 10, 25, 50], getData: function ($defer, params) { $scope.loading = true; var pageParams = params.url(); var realActive = {}; pageParams.searchFilter = { // 筛选条件 keyword: $scope.keyword, area: $scope.selectedArea, type: $scope.selectedType }; Organization[getOrgState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) { $scope.loading = false; if (page) { params.total(page.totalElements); $defer.resolve(page.content); // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段 } }, function (response) { $scope.loading = false; toaster.pop('error', '数据加载失败', response.data); }); } }); $scope.onSearch = function () { if ($scope.activityParams.page() == 1) $scope.activityParams.reload(); else $scope.activityParams.page(1); }; var getNum = function() { Organization.getOrgsNum({}, {}, function(data) { $scope.auditedNum = data.auditedNum; $scope.unauditedNum = data.unauditedNum; $scope.disagreedNum = data.disagreedNum; }); }; getNum(); // 弹出详情页模态框 $scope.showDetail = function (id) { var modalInstance = $modal.open({ templateUrl: 'static/view/user/organization_detail.html', controller: 'OrgDetailCtrl', size: 'lg', resolve: { id: function () { return id; } } }); modalInstance.result.then(function(data){ if (data.success) { toaster.pop('success', '操作成功'); } $scope.orgParams.reload(); }, function(){ }); }; }]); /** * 机构详情框 */ app.controller('OrgDetailCtrl', ['$scope', 'Organization', 'toaster', '$modalInstance', 'BaseService', 'id', '$modal', function($scope, Organization, toaster, $modalInstance, BaseService, id, $modal) { var loadData = function() { // 获取项目详情 Organization.getDetailById({id :id}, {}, function(data) { $scope.org = data; }, function() { toaster.pop('error', '详情加载失败'); }); }; loadData(); $scope.cancel= function() { $modalInstance.dismiss(); }; // true通过 false驳回 $scope.auditOrg = function(type) { var modalInstance = $modal.open({ animation: true, templateUrl: 'static/view/user/org_audit.html', controller: 'OrgAuditCtrl', resolve: { org : function() { return $scope.org; }, type : function() { return type; } } }); modalInstance.result.then(function(data){ if (data.success) { toaster.pop('success','操作成功'); } if (data.error) { toaster.pop('error','操作失败'); } loadData(); }, function(){ }); }; }]); /** * 审核机构框 */ app.controller('OrgAuditCtrl', ['$scope', 'Organization', 'toaster', '$modalInstance', 'BaseService', 'org', 'type', function($scope, Organization, toaster, $modalInstance, BaseService, org, type) { $scope.org = org; // 区别是通过还是驳回 $scope.result = type; $scope.cancel= function() { $modalInstance.dismiss(); }; // true通过 false驳回 $scope.ensure = function(type) { if (type) { Organization.agree({id: $scope.org.id}, {}, function () { toaster.pop('success', '审核成功'); }); } else { Organization.disagree({id: $scope.org.id, refuse: $scope.org.refuse}, {}, function () { toaster.pop('success', '驳回成功'); }); } }; }]); return app; });