123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- /**
- * 七鱼挂牌
- * Created by Michael .
- */
- (function (angular) {
- var app = angular.module('dydb.datasource.dataQiYuUp', [
- 'ngResource',
- 'base.param',
- 'eccrm.angular',
- 'eccrm.angularstrap'
- ]);
- app.service('DataQiYuUpService', function (CommonUtils, $resource) {
- return $resource(CommonUtils.contextPathURL('/dydb/datasource/dataQiYuUp/:method'), {}, {
- // 保存
- save: {method: 'POST', params: {method: 'save'}, isArray: false},
- // 更新
- update: {method: 'POST', params: {method: 'update'}, isArray: false},
- // 不带分页的列表查询
- query: {method: 'POST', params: {method: 'query'}, isArray: false},
- // 导入数据
- importData: {method: 'POST', params: {method: 'import'}, isArray: false},
- // 根据id查询信息
- get: {method: 'GET', params: {method: 'get', id: '@id'}, isArray: false},
- // 获得行政区域数据
- getCityMap: {method: 'GET', params: {method: 'citymap',parentId:'@parentId'}, isArray: false},
- // 分页查询
- pageQuery: {method: 'POST', params: {method: 'pageQuery', limit: '@limit', start: '@start',orderBy:'@orderBy'}, isArray: false},
- // 接受字符串数组
- deleteByIds: {method: 'POST', params: {method: 'delete'}, isArray: false}
- })
- });
- app.service('DataQiYuUpParam', function(ParameterLoader) {
- var o = {
- };
- return o;
- });
- app.service('DataQiYuUpModal', function($modal, ModalFactory, AlertFactory, CommonUtils, DataQiYuUpService) {
- var common = function (options, callback) {
- var defaults = {
- id: null,//id
- pageType: null, // 必填项,页面类型add/modify/view
- callback: null // 点击确定后要执行的函数
- };
- options = angular.extend({}, defaults, options);
- callback = callback || options.callback;
- var modal = $modal({
- template: CommonUtils.contextPathURL('/app/dydb/datasource/dataQiYuUp/template/dataQiYuUp-modal.ftl.html'),
- backdrop: 'static'
- });
- var $scope = modal.$scope;
- var pageType = $scope.pageType = options.pageType;
- var id = options.id;
- $scope.save = function () {
- var promise = DataQiYuUpService.save($scope.beans, function(data){
- AlertFactory.success('保存成功!');
- angular.isFunction(callback) && callback();
- $scope.$hide();
- });
- CommonUtils.loading(promise);
- };
- $scope.update = function () {
- var promise = DataQiYuUpService.update($scope.beans, function(data){
- AlertFactory.success('更新成功!');
- angular.isFunction(callback) && callback();
- $scope.$hide();
- });
- CommonUtils.loading(promise);
- };
- var load = function (id, callback){
- var promise = DataQiYuUpService.get({id: id}, function(data) {
- $scope.beans = data.data || {};
- callback && callback($scope.beans);
- });
- CommonUtils.loading(promise);
- };
- if (pageType === 'add') {
- $scope.beans = {
- // 在这里初始化你的数据
- };
- } else if (pageType === 'modify') {
- load(id);
- } else {
- load(id, function () {
- $('.modal-body').find('input,select,textarea').attr('disabled', 'disabled');
- $('.modal-body').find('.icons.icon').remove();
- });
- }
- };
- return {
- add: function (options, callback) {
- var o = angular.extend({}, options, {pageType: 'add'});
- common(o, callback);
- },
- modify: function (id, callback) {
- var o = angular.extend({id:id, pageType: 'modify'});
- common(o, callback);
- },
- view: function (id, callback) {
- var o = angular.extend({id:id, pageType: 'view'});
- common(o, callback);
- },
- /**
- * @param condition 默认的查询条件,类型{}
- * @param callback 回调函数,接收被选中的对象,类型function
- */
- pick: function (condition, callback) {
- var modal = $modal({
- template: CommonUtils.contextPathURL('/app/dydb/datasource/dataQiYuUp/template/dataQiYuUp-pick.html'),
- backdrop: 'static'
- });
- var $scope = modal.$scope;
- $scope.selected = {};
- $scope.condition = condition || {};
- $scope.pager = {
- limit: 5,
- fetch: function () {
- var obj = {start: this.start, limit: this.limit};
- return CommonUtils.promise(function (defer) {
- angular.extend(obj, $scope.condition);
- var promise = DataQiYuUpService.pageQuery(obj, function (data) {
- $scope.beans = data.data || {};
- defer.resolve(data.data.total);
- });
- CommonUtils.loading(promise);
- });
- },
- finishInit: function () {
- this.query();
- }
- };
- $scope.select = function (bean) {
- $scope.selected = bean;
- };
- // 查询
- $scope.query = function () {
- $scope.pager.query();
- };
- // 确认
- $scope.confirm = function (bean) {
- modal.hide();
- callback(bean || $scope.selected);
- }
- }
- }
- });
- })(angular);
|