replaceDevice.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. app.controller('replaceDeviceCtrl', ['$scope', '$filter', '$http', '$stateParams', '$timeout', 'uiGridConstants', 'i18nService', 'toaster', function ($scope, $filter, $http, $stateParams, $timeout, uiGridConstants, i18nService, toaster) {
  2. i18nService.setCurrentLang("zh-cn");
  3. $scope.gridOptions = {
  4. data: 'myData',
  5. showGridFooter: true, //是否显示grid footer
  6. // rowHeight: 80,
  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. $scope.dialogData = {};
  31. //枚举常量
  32. $scope.enum = {};
  33. //事件
  34. $scope.event = {
  35. search: function () {
  36. dealerId = "";//清空跳转带入的条件
  37. $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize);
  38. }
  39. };
  40. function setColumnDefs() {
  41. $scope.gridOptions.columnDefs = [
  42. {
  43. field: 'newLogicalCode', displayName: '新逻辑码',
  44. cellTemplate: '<div class="temp-row text-success">{{row.entity.newLogicalCode}}</div>'
  45. },
  46. {field: 'oldLogicalCode', displayName: '旧逻辑码'},
  47. {field: 'devNo', displayName: '电子标签'},
  48. {field: 'devType', displayName: '设备类型'},
  49. {
  50. field: 'createdTime',
  51. displayName: '操作时间',
  52. cellTemplate: '<div class="temp-row" ng-bind="row.entity.createdTime| date:\'yyyy-MM-dd HH:mm:ss\'"></div>'
  53. },
  54. {
  55. field: 'oper', displayName: '操作',
  56. enableFiltering: false,
  57. enableSorting: false,
  58. enableHiding: false,//禁止在列选择器中隐藏
  59. enableColumnMenu: false,// 是否显示列头部菜单按钮
  60. width: 180,
  61. cellTemplate: '<div class="grid-button">' +
  62. '<button class="btn btn-sm btn-rounded btn-danger" ng-click="grid.appScope.rollback(row.entity)"><i class="fa fa-trash-o"></i> 回滚</button>' +
  63. '</div>'
  64. },
  65. ];
  66. var fields = $scope.gridOptions.columnDefs;
  67. for (var index in fields) {
  68. var item = fields[index];
  69. if (item && item['minWidth'] == null) {
  70. item['minWidth'] = 100;
  71. }
  72. }
  73. }
  74. $scope.setPagingData = function (data) {
  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/getDeviceReplacements', {
  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. function initDataGrid() {
  97. //首次加载表格
  98. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  99. }
  100. setColumnDefs();
  101. initDataGrid();
  102. // 回滚
  103. $scope.rollback = function (entity) {
  104. $.confirm({
  105. content: '确定回滚该操作?',
  106. buttons: {
  107. ok: {
  108. btnClass: 'btn-red',
  109. action: function () {
  110. $http({
  111. method: 'POST',
  112. url: "/superadmin/rollbackDeviceReplacement",
  113. data: {id: entity.id}
  114. }).then(function (response) {
  115. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  116. toaster.pop("info", "提示", "操作成功!");
  117. }, function (response) {
  118. toaster.pop("error", "提示", "操作失败!");
  119. });
  120. }
  121. },
  122. }
  123. });
  124. }
  125. //添加
  126. $scope.addRollback = function () {
  127. //重置表单状态
  128. $scope.rollbackPanel.$setPristine();
  129. $scope.rollbackPanel.$setUntouched();
  130. $scope.dialogName = "设备换绑";
  131. $scope.dialogData = {};
  132. $("#rollbackPanel").modal();
  133. };
  134. // 确认添加并保存
  135. $scope.saveRollback = function () {
  136. if ($scope.rollbackPanel.$invalid) {
  137. return
  138. }
  139. var url = "/superadmin/replaceDevice ";
  140. $http({
  141. method: 'POST',
  142. url: url,
  143. data: $scope.dialogData
  144. }).then(function (response) {
  145. //保存成功 弹窗消失
  146. $('#rollbackPanel').modal('hide');
  147. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  148. }, function (response) {
  149. toaster.pop("error", "提示", "保存失败!");
  150. });
  151. };
  152. }]);