moniListCtrl.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. app.controller('moniListCtrl', ['$scope', '$http', "$state", '$timeout', 'uiGridConstants', 'i18nService', 'toaster', function ($scope, $http, $state, $timeout, uiGridConstants, i18nService, toaster) {
  2. i18nService.setCurrentLang("zh-cn");
  3. moment.locale('zh-cn');
  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. $scope.enum = {
  28. status: [
  29. {value: "addingFans", label: "加粉中"},
  30. {value: "fansFull", label: "粉丝已满"},
  31. {value: "adminStop", label: "管理员暂停"},
  32. {value: "dayFullStop", label: "日限额满停"},
  33. {value: "appOver", label: "公众号不可用", disabled: true},
  34. ],
  35. priority: [
  36. {value: 5, label: "最高"},
  37. {value: 4, label: "高"},
  38. {value: 3, label: "一般"},
  39. {value: 2, label: "低"},
  40. {value: 1, label: "最低"},
  41. ],
  42. };
  43. //查询条件
  44. $scope.query = {
  45. searchKey: "",
  46. };
  47. $scope.ngEvent = {
  48. //查询
  49. query: function () {
  50. $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize);
  51. },
  52. compressorImg: function (file, callback) {
  53. if (file) {
  54. var imageCompressor = new Compressor(file, {
  55. quality: .7,
  56. // 图片尺寸
  57. maxWidth: 1920,
  58. maxHeight: 1920,
  59. success: function (result) {
  60. var formData = new FormData();
  61. formData.append('file', result, result.name);
  62. if (callback) {
  63. callback(formData);
  64. }
  65. }
  66. });
  67. }
  68. },
  69. addPic: function () {
  70. var imgUpload = $("#addImg");
  71. var file = imgUpload[0].files[0];
  72. this.compressorImg(file, function (formData) {
  73. var url = '/common/upload?type=moniQrCode';
  74. $http({
  75. method: 'POST',
  76. url: url,
  77. transformRequest: angular.identity,
  78. headers: {
  79. 'Content-Type': undefined// 禁止angular对data的处理
  80. },
  81. data: formData
  82. }).then(function (response) {
  83. var url = response.data.para;
  84. $scope.dialogData.qrCode = url;
  85. //重置文件路径,避免选中重复不触发onchange
  86. var imgUpload = $("#addImg");
  87. imgUpload[0].value = "";
  88. }, function (response) {
  89. toaster.pop("error", "提示", "上传失败!");
  90. });
  91. })
  92. },
  93. };
  94. function setColumnDefs() {
  95. $scope.gridOptions.columnDefs = [
  96. {field: 'appName', displayName: '公众号',},
  97. {field: 'appId', displayName: 'appId',},
  98. {field: 'rawAppId', displayName: '原始appId',},
  99. {field: 'secret', displayName: 'secret',},
  100. {
  101. field: 'priority', displayName: '优先级',
  102. cellTemplate: '<div class="ui-grid-cell-contents" >{{grid.appScope.formatterPriority(row.entity)}}</div>'
  103. },
  104. {
  105. field: 'status', displayName: '状态',
  106. cellTemplate: '<div class="ui-grid-cell-contents" >{{grid.appScope.formatterStatus(row.entity)}}</div>'
  107. },
  108. {field: 'title', displayName: '广告词', minWidth: 300,},
  109. {field: 'desc', displayName: '说明',},
  110. {field: 'maxDayAddingCount', displayName: '每日加粉限额',},
  111. {
  112. field: 'operation',
  113. displayName: '操作',
  114. enableFiltering: false,
  115. enableSorting: false,
  116. enableHiding: false,//禁止在列选择器中隐藏
  117. enableColumnMenu: false,// 是否显示列头部菜单按钮
  118. minWidth: 150,
  119. cellTemplate: '<div class="grid-button">' +
  120. '<button class="btn btn-sm btn-rounded btn-default" ng-click="grid.appScope.goAgents(row.entity)"><i class="fa fa-users"></i> 代理商</button>' +
  121. '</div>'
  122. },
  123. ];
  124. var fields = $scope.gridOptions.columnDefs;
  125. for (var index in fields) {
  126. var item = fields[index];
  127. if (item && item['minWidth'] == null) {
  128. item['minWidth'] = 100;
  129. }
  130. }
  131. }
  132. $scope.formatterStatus = function (entity) {
  133. var status = entity.status;
  134. var statusList = $scope.enum.status;
  135. var label = "";
  136. for (var index = 0; index < statusList.length; index++) {
  137. var item = statusList[index];
  138. if (item.value == status) {
  139. label = item.label
  140. }
  141. }
  142. return label;
  143. };
  144. $scope.formatterPriority = function (entity) {
  145. var targetValue = entity.priority;
  146. var enumList = $scope.enum.priority;
  147. var label = "";
  148. for (var index = 0; index < enumList.length; index++) {
  149. var item = enumList[index];
  150. if (item.value == targetValue) {
  151. label = item.label
  152. }
  153. }
  154. return label;
  155. };
  156. $scope.setPagingData = function (data) {
  157. var pagedData = data.data.dataList;
  158. $scope.myData = pagedData;
  159. $scope.gridOptions.totalItems = data.data.total;
  160. };
  161. $scope.getPagedDataAsync = function (curPage, pageSize) {
  162. var params = {
  163. pageSize: pageSize,
  164. pageIndex: curPage
  165. };
  166. var query = $scope.query;
  167. params.searchKey = query.searchKey
  168. $http.get('/superadmin/getMoniApps', {
  169. params: params
  170. }).then(function (data) {
  171. data = data.data
  172. $scope.setPagingData(data, curPage, pageSize);
  173. }).catch(function (data) {
  174. toaster.pop("error", "提示", "获取数据列表失败");
  175. });
  176. };
  177. function initDataGrid() {
  178. //首次加载表格
  179. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  180. }
  181. setColumnDefs();
  182. initDataGrid();
  183. $scope.goAgents = function (entity) {
  184. $state.go('app.user.agents', {
  185. moniAppId: entity.appId,
  186. managerId: "",
  187. }, {
  188. reload: true
  189. });
  190. }
  191. function getOneRow() {
  192. var rows = $scope.gridApi.selection.getSelectedRows();
  193. if (rows.length === 0) {
  194. toaster.pop("info", "提示", "请选择数据!");
  195. return false;
  196. }
  197. if (rows.length > 1) {
  198. toaster.pop("info", "提示", "只能选中编辑一条数据");
  199. return false;
  200. }
  201. return rows[0]
  202. }
  203. $scope.dialogData = {};
  204. $scope.add = function () {
  205. $scope.dialogData = {};
  206. $("#moniEdit").modal()
  207. }
  208. $scope.edit = function () {
  209. var row = getOneRow();
  210. if (!row) {
  211. return
  212. }
  213. $("#moniEdit").modal()
  214. $scope.dialogData = $.extend(true, {}, row);
  215. }
  216. $scope.save = function () {
  217. //表单未校验通过不能提交
  218. if ($scope.moniEdit.$invalid) {
  219. return;
  220. }
  221. $http({
  222. method: 'POST',
  223. url: "/superadmin/editMoniApp",
  224. data: $scope.dialogData
  225. }).then(function (response) {
  226. $('#moniEdit').modal('hide');//弹窗消失
  227. toaster.pop("success", "提示", "保存成功!");
  228. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  229. }, function (response) {
  230. toaster.pop("error", "提示", "保存失败!");
  231. });
  232. }
  233. $scope.delete = function () {
  234. var rows = $scope.gridApi.selection.getSelectedRows();
  235. if (rows.length == 0) {
  236. toaster.pop("info", "提示", "请选择数据!");
  237. return;
  238. }
  239. var ids = [];
  240. for (var i = 0; i < rows.length; i++) {
  241. ids.push(rows[i].appId);
  242. }
  243. $.confirm({
  244. content: '确定删除?',
  245. buttons: {
  246. ok: {
  247. btnClass: 'btn-red',
  248. action: function () {
  249. $http({
  250. method: 'POST',
  251. url: '/superadmin/deleteMoniApp',
  252. data: {ids: ids}
  253. }).then(function (response) {
  254. initDataGrid();
  255. }, function (response) {
  256. toaster.pop("error", "提示", "删除失败!");
  257. });
  258. }
  259. },
  260. }
  261. });
  262. }
  263. }]);