AuditComponentMaintenanceCtrl.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. define([ 'app/app' ], function(app) {
  2. // 器件维护
  3. app.register.controller('AuditComponentMaintenanceCtrl', ['$scope', 'ngTableParams', '$modal', 'BaseService','toaster', '$rootScope', '$http', 'Search',function($scope, ngTableParams, $modal, BaseService, toaster, $rootScope, $http, Search) {
  4. BaseService.scrollBackToTop();
  5. $scope.showHeader = false;
  6. // 表格参数
  7. $scope.componentTableParams = new ngTableParams({
  8. page : 1,
  9. count : 20,
  10. }, {
  11. total : 0,
  12. getData : function($defer, params) {
  13. var param = BaseService.parseParams(params.url());
  14. param.w = $scope.keyword;
  15. Search.componentSearch(param, function(page) {
  16. if (page) {
  17. params.total(page.total);
  18. page.content = page.components;
  19. $defer.resolve(page.content);
  20. }
  21. });
  22. }
  23. });
  24. // 搜索
  25. $scope.search = function() {
  26. $scope.componentTableParams.reload();
  27. $scope.showHeader = true ;
  28. $scope.actives = false;
  29. };
  30. // 搜索框获得焦点,显示联想框
  31. $scope.onFocus = function() {
  32. $scope.associate = true;
  33. $scope.selectIndex = -1;
  34. if(!$scope.keyword) $scope.keyword = '';
  35. };
  36. // 搜索框失去焦点,关闭联想框
  37. $scope.onBlur = function() {
  38. $scope.associate = false;
  39. };
  40. // 搜索框通过按键选取想要的联想词
  41. $scope.onKeyup = function() {
  42. if($scope.associates && $scope.associates.length) {
  43. if(event.keyCode == 40) { //监听到按下键
  44. $scope.selectIndex ++;
  45. if($scope.selectIndex >= $scope.associates.length) $scope.selectIndex = 0;
  46. $scope.keyword = $scope.associates[$scope.selectIndex];
  47. } else if(event.keyCode == 38) { //监听到按上键
  48. $scope.selectIndex --;
  49. if($scope.selectIndex < 0) $scope.selectIndex = $scope.associates.length - 1;
  50. $scope.keyword = $scope.keyword = $scope.associates[$scope.selectIndex];
  51. } else if(event.keyCode == 13) { //确定键
  52. $scope.search();
  53. }
  54. }
  55. };
  56. // 输入框内容变化,获取新的联想词
  57. $scope.onChange = function() {
  58. var params = {
  59. keyword: $scope.keyword
  60. };
  61. if($rootScope.userInfo) {
  62. params.userUU = $rootScope.userInfo.userUU;
  63. }
  64. $http.get('search/similarComponents', {
  65. params : params
  66. }).success(function(data){
  67. $scope.associates = data;// 联想词数组
  68. console.log(data);
  69. }).error(function(response) {
  70. });
  71. };
  72. // 点击联想词
  73. $scope.onAssociateClick = function(component) {
  74. $scope.keyword = component;
  75. $scope.search();
  76. };
  77. // 鼠标进入联想词框,不能关闭联想词框
  78. $scope.onAssociateEnter = function() {
  79. $scope.associateEnter = true;
  80. };
  81. // 鼠标离开联想词框,可以关闭联想词框
  82. $scope.onAssociateLeave = function() {
  83. $scope.associateEnter = false;
  84. };
  85. // 选择类目
  86. $scope.chooseKind = function() {
  87. $modal.open({
  88. animation: true,
  89. size: 'lg',
  90. templateUrl: 'static/view/prod/product_kindChoose_modal.html',
  91. controller: 'KindChooseCtrl',
  92. resolve: {
  93. actives: function() {
  94. return $scope.actives;
  95. }
  96. }
  97. }).result.then(function(data){
  98. $scope.active = data.active;
  99. $scope.actives = data.actives;
  100. }, function(){
  101. });
  102. };
  103. }]);
  104. //类目选择模态框
  105. app.register.controller('KindChooseCtrl', ['$scope', 'KindAPI', 'actives', 'toaster', '$modalInstance', function($scope, KindAPI, actives, toaster, $modalInstance) {
  106. $scope.actives = actives;
  107. $scope.kinds = [[], [], [], []];
  108. // 获取子类目
  109. var getChildren = function(pid, deep) {
  110. KindAPI.getChildren({parentId: pid}, function(data) {
  111. $scope.kinds[deep] = data;
  112. }, function(response) {
  113. toaster.pop('error', '获取子类目失败', response.data);
  114. });
  115. };
  116. // 改变节点选中状态
  117. var changeStatus = function(item, deep) {
  118. var actives = [], level = 0;
  119. angular.forEach($scope.kinds, function(ks, i) {
  120. if(i > deep) {
  121. $scope.kinds[i] = [];
  122. } else {
  123. angular.forEach(ks, function(k, j) {
  124. if(i == deep) {
  125. if(k.id == item.id) {
  126. $scope.kinds[i][j].$active = true;
  127. actives.push(k);
  128. } else {
  129. k.$active = null;
  130. }
  131. } else {
  132. if(k.$active) {
  133. actives.push(k);
  134. }
  135. }
  136. });
  137. }
  138. });
  139. // 选择的节点
  140. $scope.actives = actives;
  141. $scope.active = item;
  142. // 当前可操作的层级
  143. if(deep < 3) {
  144. $scope.activeDeep = deep + 1;
  145. }
  146. };
  147. // 节点点击后获取子类目,节点被选中
  148. $scope.onItemClick = function(item, deep) {
  149. changeStatus(item, deep);
  150. if (!item.isLeaf) {
  151. getChildren(item.id, deep + 1);
  152. }
  153. };
  154. // 重新加载数据
  155. function reload(deep) {
  156. var pid;
  157. if(deep) {
  158. pid = $scope.actives[deep - 1].id;
  159. } else {
  160. pid = 0;
  161. deep = 0;
  162. }
  163. getChildren(pid, deep);
  164. };
  165. // 初始加载数据,获取第一层的类目
  166. if($scope.actives) {
  167. angular.forEach($scope.actives, function(v, k) {
  168. KindAPI.getChildren({parentId: v.parentid}, function(data) {
  169. $scope.kinds[k] = data;
  170. angular.forEach($scope.kinds[k], function(kind, i){
  171. if(kind.id == v.id) {
  172. $scope.kinds[k][i].$active = true;
  173. $scope.actives[k] = $scope.kinds[k][i];
  174. }
  175. })
  176. }, function(response) {
  177. toaster.pop('error', '获取子类目失败', response.data);
  178. });
  179. });
  180. } else {
  181. reload();
  182. };
  183. // 取消
  184. $scope.cancel = function() {
  185. $modalInstance.dismiss();
  186. };
  187. // 确认选择
  188. $scope.check = function() {
  189. var a = {
  190. active: $scope.active,
  191. actives: $scope.actives
  192. };
  193. $modalInstance.close(a);
  194. };
  195. }]);
  196. });