sysFeatures.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. app.controller('sysFeaturesCtrl', ['$scope', '$http', '$timeout', 'toaster', 'uiGridConstants', 'i18nService', function ($scope, $http, $timeout, toaster, uiGridConstants, i18nService) {
  2. i18nService.setCurrentLang("zh-cn");//中文环境,如表格分页
  3. /**配置特性列表**/
  4. $scope.gridOptions = {
  5. data: 'myData',
  6. showGridFooter: true, //是否显示grid footer
  7. //-------- 分页属性 ----------------
  8. paginationPageSizes: [10, 20, 50, 100], //每页显示个数可选项
  9. paginationCurrentPage: 1, //当前页码
  10. paginationPageSize: 10, //每页显示个数
  11. totalItems: 0,// 总数量
  12. useExternalPagination: true,//是否使用分页按钮
  13. //过滤
  14. enableFiltering: true,
  15. columnDefs: [],
  16. //---------------api---------------------
  17. onRegisterApi: function (gridApi) {
  18. $scope.gridApi = gridApi;
  19. gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
  20. if ($scope.setPagingData) {
  21. $scope.getPagedDataAsync(newPage, pageSize);
  22. }
  23. });
  24. }
  25. };
  26. //查询条件
  27. var condition = $scope.condition = {
  28. searchKey: ""
  29. };
  30. //枚举常量
  31. $scope.enum = {
  32. role: [
  33. {value: "dealer", label: "经销商"},
  34. {value: "agent", label: "代理商"},
  35. {value: "manager", label: "厂商"},
  36. ]
  37. };
  38. function setColumnDefs() {
  39. $scope.gridOptions.columnDefs = [
  40. {
  41. field: 'role', displayName: '所属角色',
  42. filter: {
  43. term: '',
  44. type: uiGridConstants.filter.SELECT,
  45. selectOptions: $scope.enum.role
  46. },
  47. cellTemplate: '<div class="temp-row">{{grid.appScope.formatterRole(row.entity.role)}}</div>'
  48. },
  49. {field: 'name', displayName: '特性名称'},
  50. {field: 'key', displayName: '特性关键字'},
  51. {
  52. field: 'default', displayName: '特性默认值',
  53. cellTemplate: '<div class="temp-row">{{ grid.appScope.translateDefault(row.entity.default) }}</div>'
  54. },
  55. {
  56. field: 'createdTime',
  57. displayName: '创建时间',
  58. cellTemplate: '<div class="temp-row" ng-bind="row.entity.createdTime| date:\'yyyy-MM-dd HH:mm:ss\'"></div>'
  59. },
  60. {field: 'desc', displayName: '特性说明', minWidth: 420},
  61. ];
  62. var fields = $scope.gridOptions.columnDefs;
  63. for (var index in fields) {
  64. var item = fields[index];
  65. if (item && item['minWidth'] == null) {
  66. item['minWidth'] = 100;
  67. }
  68. }
  69. }
  70. function initDataGrid() {
  71. //首次加载表格
  72. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  73. }
  74. $scope.setPagingData = function (data, curPage, pageSize) {
  75. var pagedData = data.data.dataList;
  76. $scope.myData = pagedData;
  77. $scope.gridOptions.totalItems = data.data.total;
  78. };
  79. $scope.getPagedDataAsync = function (curPage, pageSize) {
  80. var params = {
  81. pageSize: pageSize,
  82. pageIndex: curPage
  83. };
  84. if (condition.searchKey != "") {
  85. params.searchKey = condition.searchKey
  86. }
  87. $http.get('/superadmin/getFeatureList', {
  88. params: params
  89. }).then(function (data) {
  90. data = data.data
  91. $scope.setPagingData(data, curPage, pageSize);
  92. }).catch(function (data) {
  93. toaster.pop("error", "提示", "获取数据失败");
  94. });
  95. };
  96. setColumnDefs();
  97. initDataGrid();
  98. $scope.translateDefault = function (flag) {
  99. return flag ? "true" : "false"
  100. };
  101. //角色转换
  102. $scope.formatterRole = function (role) {
  103. var list = $scope.enum.role;
  104. for (var index in list) {
  105. var item = list[index];
  106. if (item.value == role) {
  107. return item.label;
  108. }
  109. }
  110. };
  111. //事件
  112. $scope.event = {
  113. search: function () {
  114. $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize);
  115. }
  116. };
  117. //编辑弹窗需要的数据
  118. $scope.dialogName = "编辑";
  119. $scope.dialogData = {};
  120. //添加
  121. $scope.addFeature = function () {
  122. //重置表单状态
  123. $scope.FeaturePanel.$setPristine();
  124. $scope.FeaturePanel.$setUntouched();
  125. $scope.dialogName = "添加";
  126. $scope.dialogData = {};
  127. $("#FeaturePanel").modal();
  128. };
  129. //编辑
  130. $scope.editFeature = function () {
  131. //重置表单状态
  132. $scope.FeaturePanel.$setPristine();
  133. $scope.FeaturePanel.$setUntouched();
  134. $scope.dialogName = "编辑";
  135. var rows = $scope.gridApi.selection.getSelectedRows();
  136. if (rows.length == 0) {
  137. toaster.pop("info", "提示", "请选择数据!");
  138. return;
  139. }
  140. if (rows.length > 1) {
  141. toaster.pop("info", "提示", "只能选中编辑一条数据");
  142. return;
  143. }
  144. var item = rows[0];
  145. $scope.dialogData = $.extend(true, {}, item);
  146. $("#FeaturePanel").modal();
  147. };
  148. //提交表单保存
  149. $scope.saveData = function () {
  150. //表单未校验通过不能提交
  151. if ($scope.FeaturePanel.$invalid) {
  152. return;
  153. }
  154. var url = "";
  155. if ($scope.dialogData.id == null) {
  156. url = "/superadmin/addFeature";
  157. } else {
  158. url = "/superadmin/editFeature";
  159. }
  160. //深度克隆 避免操作原对象
  161. var data = $.extend(true, {}, $scope.dialogData);
  162. delete data.createdTime //创建时间后台修改
  163. $http({
  164. method: 'POST',
  165. url: url,
  166. data: data
  167. }).then(function (response) {
  168. $('#FeaturePanel').modal('hide');//弹窗消失
  169. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  170. }, function (response) {
  171. toaster.pop("error", "提示", "保存失败!");
  172. });
  173. };
  174. //删除特性
  175. $scope.deleteFeature = function () {
  176. var rows = $scope.gridApi.selection.getSelectedRows();
  177. if (rows.length == 0) {
  178. toaster.pop("info", "提示", "请选择数据!");
  179. return;
  180. }
  181. var ids = [];
  182. for (var i = 0; i < rows.length; i++) {
  183. ids.push(rows[i].id);
  184. }
  185. $.confirm({
  186. content: '确定删除?',
  187. buttons: {
  188. ok: {
  189. btnClass: 'btn-red',
  190. action: function () {
  191. $http({
  192. method: 'POST',
  193. url: '/superadmin/removeFeatures',
  194. data: {ids: ids}
  195. }).then(function (response) {
  196. initDataGrid();
  197. }, function (response) {
  198. toaster.pop("error", "提示", "删除失败!");
  199. });
  200. }
  201. },
  202. }
  203. });
  204. };
  205. }]);