dataQiYuUp.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /**
  2. * 七鱼挂牌
  3. * Created by Michael .
  4. */
  5. (function (angular) {
  6. var app = angular.module('dydb.datasource.dataQiYuUp', [
  7. 'ngResource',
  8. 'base.param',
  9. 'eccrm.angular',
  10. 'eccrm.angularstrap'
  11. ]);
  12. app.service('DataQiYuUpService', function (CommonUtils, $resource) {
  13. return $resource(CommonUtils.contextPathURL('/dydb/datasource/dataQiYuUp/:method'), {}, {
  14. // 保存
  15. save: {method: 'POST', params: {method: 'save'}, isArray: false},
  16. // 更新
  17. update: {method: 'POST', params: {method: 'update'}, isArray: false},
  18. // 不带分页的列表查询
  19. query: {method: 'POST', params: {method: 'query'}, isArray: false},
  20. // 导入数据
  21. importData: {method: 'POST', params: {method: 'import'}, isArray: false},
  22. // 根据id查询信息
  23. get: {method: 'GET', params: {method: 'get', id: '@id'}, isArray: false},
  24. // 获得行政区域数据
  25. getCityMap: {method: 'GET', params: {method: 'citymap',parentId:'@parentId'}, isArray: false},
  26. // 分页查询
  27. pageQuery: {method: 'POST', params: {method: 'pageQuery', limit: '@limit', start: '@start',orderBy:'@orderBy'}, isArray: false},
  28. // 接受字符串数组
  29. deleteByIds: {method: 'POST', params: {method: 'delete'}, isArray: false}
  30. })
  31. });
  32. app.service('DataQiYuUpParam', function(ParameterLoader) {
  33. var o = {
  34. };
  35. return o;
  36. });
  37. app.service('DataQiYuUpModal', function($modal, ModalFactory, AlertFactory, CommonUtils, DataQiYuUpService) {
  38. var common = function (options, callback) {
  39. var defaults = {
  40. id: null,//id
  41. pageType: null, // 必填项,页面类型add/modify/view
  42. callback: null // 点击确定后要执行的函数
  43. };
  44. options = angular.extend({}, defaults, options);
  45. callback = callback || options.callback;
  46. var modal = $modal({
  47. template: CommonUtils.contextPathURL('/app/dydb/datasource/dataQiYuUp/template/dataQiYuUp-modal.ftl.html'),
  48. backdrop: 'static'
  49. });
  50. var $scope = modal.$scope;
  51. var pageType = $scope.pageType = options.pageType;
  52. var id = options.id;
  53. $scope.save = function () {
  54. var promise = DataQiYuUpService.save($scope.beans, function(data){
  55. AlertFactory.success('保存成功!');
  56. angular.isFunction(callback) && callback();
  57. $scope.$hide();
  58. });
  59. CommonUtils.loading(promise);
  60. };
  61. $scope.update = function () {
  62. var promise = DataQiYuUpService.update($scope.beans, function(data){
  63. AlertFactory.success('更新成功!');
  64. angular.isFunction(callback) && callback();
  65. $scope.$hide();
  66. });
  67. CommonUtils.loading(promise);
  68. };
  69. var load = function (id, callback){
  70. var promise = DataQiYuUpService.get({id: id}, function(data) {
  71. $scope.beans = data.data || {};
  72. callback && callback($scope.beans);
  73. });
  74. CommonUtils.loading(promise);
  75. };
  76. if (pageType === 'add') {
  77. $scope.beans = {
  78. // 在这里初始化你的数据
  79. };
  80. } else if (pageType === 'modify') {
  81. load(id);
  82. } else {
  83. load(id, function () {
  84. $('.modal-body').find('input,select,textarea').attr('disabled', 'disabled');
  85. $('.modal-body').find('.icons.icon').remove();
  86. });
  87. }
  88. };
  89. return {
  90. add: function (options, callback) {
  91. var o = angular.extend({}, options, {pageType: 'add'});
  92. common(o, callback);
  93. },
  94. modify: function (id, callback) {
  95. var o = angular.extend({id:id, pageType: 'modify'});
  96. common(o, callback);
  97. },
  98. view: function (id, callback) {
  99. var o = angular.extend({id:id, pageType: 'view'});
  100. common(o, callback);
  101. },
  102. /**
  103. * @param condition 默认的查询条件,类型{}
  104. * @param callback 回调函数,接收被选中的对象,类型function
  105. */
  106. pick: function (condition, callback) {
  107. var modal = $modal({
  108. template: CommonUtils.contextPathURL('/app/dydb/datasource/dataQiYuUp/template/dataQiYuUp-pick.html'),
  109. backdrop: 'static'
  110. });
  111. var $scope = modal.$scope;
  112. $scope.selected = {};
  113. $scope.condition = condition || {};
  114. $scope.pager = {
  115. limit: 5,
  116. fetch: function () {
  117. var obj = {start: this.start, limit: this.limit};
  118. return CommonUtils.promise(function (defer) {
  119. angular.extend(obj, $scope.condition);
  120. var promise = DataQiYuUpService.pageQuery(obj, function (data) {
  121. $scope.beans = data.data || {};
  122. defer.resolve(data.data.total);
  123. });
  124. CommonUtils.loading(promise);
  125. });
  126. },
  127. finishInit: function () {
  128. this.query();
  129. }
  130. };
  131. $scope.select = function (bean) {
  132. $scope.selected = bean;
  133. };
  134. // 查询
  135. $scope.query = function () {
  136. $scope.pager.query();
  137. };
  138. // 确认
  139. $scope.confirm = function (bean) {
  140. modal.hide();
  141. callback(bean || $scope.selected);
  142. }
  143. }
  144. }
  145. });
  146. })(angular);