devBind.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. app.controller('devBindCtrl', ['$scope', '$filter', '$http', '$stateParams', '$timeout', 'uiGridConstants', 'i18nService', 'toaster', 'FileUploader', function ($scope, $filter, $http, $stateParams, $timeout, uiGridConstants, i18nService, toaster, FileUploader) {
  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. //事件
  31. $scope.event = {
  32. search: function () {
  33. $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize);
  34. }
  35. };
  36. function setColumnDefs() {
  37. $scope.gridOptions.columnDefs = [
  38. {field: 'logicalCode', displayName: '逻辑编号'},
  39. {field: 'devTypeName', displayName: '设备类型'},
  40. {field: 'imei', displayName: 'imei'},
  41. {field: 'inputTime', displayName: '录入时间',},
  42. {field: 'createdTime', displayName: '注册时间',},
  43. {field: 'dealerName', displayName: '商户名称'},
  44. {field: 'dealerTel', displayName: '商户电话'},
  45. {field: 'groupName', displayName: '场地'},
  46. ];
  47. var fields = $scope.gridOptions.columnDefs;
  48. for (var index in fields) {
  49. var item = fields[index];
  50. if (item && item['minWidth'] == null) {
  51. item['minWidth'] = 100;
  52. }
  53. }
  54. }
  55. $scope.setPagingData = function (data, curPage, pageSize) {
  56. var pagedData = data.data.dataList;
  57. $scope.myData = pagedData;
  58. $scope.gridOptions.totalItems = data.data.total;
  59. };
  60. $scope.getPagedDataAsync = function (curPage, pageSize) {
  61. var params = {
  62. pageSize: pageSize,
  63. pageIndex: curPage
  64. };
  65. if (condition.searchKey != "") {
  66. params.searchKey = condition.searchKey
  67. }
  68. $http.get('/manager/getInputEquipment', {
  69. params: params
  70. }).then(function (data) {
  71. $scope.setPagingData(data.data, curPage, pageSize);
  72. }).catch(function (data) {
  73. toaster.pop("error", "提示", "获取数据列表失败");
  74. });
  75. };
  76. function initDataGrid() {
  77. //首次加载表格
  78. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  79. }
  80. setColumnDefs();
  81. initDataGrid();
  82. //广告开关
  83. $scope.selectedIds = []
  84. function getSelectRows() {
  85. var rows = $scope.gridApi.selection.getSelectedRows();
  86. if (rows.length === 0) {
  87. toaster.pop("info", "提示", "请选择数据!");
  88. return false;
  89. }
  90. var ids = [];
  91. for (var i = 0; i < rows.length; i++) {
  92. ids.push(rows[i].logicalCode);
  93. }
  94. $scope.selectedIds = ids;
  95. return ids
  96. }
  97. $scope.dialogData = {};
  98. $scope.add = function () {
  99. $scope.dialogData = {};
  100. $('#inputPanel').modal()
  101. }
  102. $scope.saveAdd = function () {
  103. //表单未校验通过不能提交
  104. if ($scope.inputPanel.$invalid) {
  105. return;
  106. }
  107. var url = "/manager/inputEquipment";
  108. $http({
  109. method: 'POST',
  110. url: url,
  111. data: {
  112. logicalCode: $scope.dialogData.logicalCode,
  113. }
  114. }).then(function (response) {
  115. var data = response.data;
  116. if (data.result == 1) {
  117. toaster.pop("success", "提示", "录入成功!");
  118. $timeout(function () {
  119. $scope.dialogData = {};
  120. }, 200)
  121. }
  122. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  123. }, function (response) {
  124. toaster.pop("error", "提示", "操作失败!");
  125. });
  126. }
  127. /***********excel上传工具*******************/
  128. var uploader2 = $scope.uploader2 = new FileUploader({
  129. url: '/manager/file/uploadLogicalExcel',
  130. queueLimit: 1, //文件个数
  131. removeAfterUpload: true //上传后删除文件
  132. });
  133. //注册上传事件
  134. uploader2.onCompleteItem = function (fileItem, response, status, headers) {
  135. if (response) {
  136. toaster.pop("success", "提示", "批量录入成功!");
  137. }
  138. clearUploader2();
  139. };
  140. uploader2.onErrorItem = function (fileItem, response, status, headers) {
  141. toaster.pop("error", "提示", "上传失败,请重试");
  142. clearUploader2();
  143. };
  144. /*恢复上传框初始状态*/
  145. function clearUploader2() {
  146. $("#fileUpload2").val("");
  147. uploader2.clearQueue();
  148. uploader2.cancelAll();
  149. }
  150. $scope.addMore = function () {
  151. $('#excelForm').modal()
  152. }
  153. $scope.delete = function () {
  154. var ids = getSelectRows()
  155. if (!ids) {
  156. return
  157. }
  158. $.confirm({
  159. content: '确定删除?',
  160. buttons: {
  161. ok: {
  162. btnClass: 'btn-red',
  163. action: function () {
  164. $http({
  165. method: 'POST',
  166. url: '/manager/deleteInputEquipment',
  167. data: {logicalCode: ids}
  168. }).then(function (response) {
  169. initDataGrid();
  170. }, function (response) {
  171. toaster.pop("error", "提示", "删除失败!");
  172. });
  173. }
  174. },
  175. }
  176. });
  177. }
  178. }]);