advertiser.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. app.controller('advertiserCtrl', ['$scope', '$http', '$timeout', 'uiGridConstants', 'i18nService', 'toaster', 'md5', function ($scope, $http, $timeout, uiGridConstants, i18nService, toaster, MD5) {
  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. //状态 true false 默认激活
  30. activited: {value: true, label: "激活"},
  31. };
  32. //枚举常量
  33. $scope.enum = {
  34. activited: [
  35. {value: null, label: "-全部状态-"},
  36. {value: true, label: "激活"},
  37. {value: false, label: "禁用"}
  38. ],
  39. };
  40. //事件
  41. $scope.event = {
  42. conditionChange: function (key, item) {
  43. condition[key].value = item.value;
  44. condition[key].label = item.label;
  45. $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize);
  46. },
  47. search: function () {
  48. $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize);
  49. }
  50. };
  51. function setColumnDefs() {
  52. $scope.gridOptions.columnDefs = [
  53. {field: 'nickname', displayName: '姓名'},
  54. {field: 'username', displayName: '联系方式'},
  55. {field: 'quota', displayName: '额度'},
  56. {
  57. field: 'dateTimeAdded',
  58. displayName: '注册时间',
  59. cellTemplate: '<div class="temp-row" ng-bind="row.entity.dateTimeAdded"></div>'
  60. },
  61. // {
  62. // field: 'status', displayName: '状态',
  63. // cellTemplate: '<div class="temp-row" ng-class="{' +
  64. // '\'text-dark\':row.entity.status==false,' +
  65. // '\'text-success\':row.entity.status==true' +
  66. // '}" >{{row.entity.status==false?"停用":"激活"}}</div>'
  67. // },
  68. {
  69. field: 'oper', displayName: '操作',
  70. enableFiltering: false,
  71. enableSorting: false,
  72. enableHiding: false,//禁止在列选择器中隐藏
  73. enableColumnMenu: false,// 是否显示列头部菜单按钮
  74. width: 200,
  75. cellTemplate: '<div class="grid-button">' +
  76. '<button class="btn btn-sm btn-rounded btn-success" ng-if="row.entity.activited==false" ng-click="grid.appScope.openOrClose(row.entity,true)"><i class="fa fa-play"></i> 激活</button>' +
  77. '<button class="btn btn-sm btn-rounded btn-default" ng-if="row.entity.activited==true" ng-click="grid.appScope.openOrClose(row.entity,false)"><i class="fa fa-close"></i> 停用</button>' +
  78. '</div>'
  79. }
  80. ];
  81. var fields = $scope.gridOptions.columnDefs;
  82. for (var index in fields) {
  83. var item = fields[index];
  84. if (item && item['minWidth'] == null) {
  85. item['minWidth'] = 100;
  86. }
  87. }
  88. }
  89. //打开或关闭
  90. $scope.openOrClose = function (entity, activited) {
  91. $http({
  92. method: 'POST',
  93. url: '/manager/toggleAdvertiserActivation',
  94. data: {id: entity.id, activited: activited}
  95. }).then(function (response) {
  96. initDataGrid();
  97. }, function (response) {
  98. toaster.pop("error", "提示", "操作失败!");
  99. });
  100. };
  101. $scope.setPagingData = function (data, curPage, pageSize) {
  102. var firstRow = (curPage - 1) * pageSize;
  103. var pagedData = data.data.dataList;
  104. $scope.myData = pagedData;
  105. $scope.gridOptions.totalItems = data.data.total;
  106. };
  107. $scope.getPagedDataAsync = function (curPage, pageSize, searchText) {
  108. var params = {
  109. pageSize: pageSize,
  110. pageIndex: curPage
  111. };
  112. if (condition.searchKey != "") {
  113. params.searchKey = condition.searchKey
  114. }
  115. if (condition.activited.value != null) {
  116. params.activited = condition.activited.value
  117. }
  118. $http.get('/manager/getAdvertiserList', {
  119. params: params
  120. }).then(function (data) {
  121. $scope.setPagingData(data.data, curPage, pageSize);
  122. }).catch(function (data) {
  123. toaster.pop("error", "提示", "获取数据列表失败");
  124. });
  125. };
  126. function initDataGrid() {
  127. //首次加载表格
  128. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  129. }
  130. setColumnDefs();
  131. initDataGrid();
  132. //添加
  133. $scope.add = function () {
  134. //重置表单状态
  135. $scope.modelForm.$setPristine();
  136. $scope.modelForm.$setUntouched();
  137. $scope.dialogName = "开户";
  138. $scope.dialogData = {activited: true, isNew: true};
  139. $("#modelPanel").modal();
  140. };
  141. //编辑密码 默认123456
  142. $scope.editPassword = function () {
  143. //重置表单状态
  144. $scope.passwordForm.$setPristine();
  145. $scope.passwordForm.$setUntouched();
  146. var rows = $scope.gridApi.selection.getSelectedRows();
  147. if (rows.length == 0) {
  148. toaster.pop("info", "提示", "请选择数据!");
  149. return;
  150. }
  151. if (rows.length > 1) {
  152. toaster.pop("info", "提示", "只能选中编辑一条数据");
  153. return;
  154. }
  155. var item = rows[0];
  156. $scope.passwordData = $.extend({password: 123456}, item);
  157. $("#passwordPanel").modal();
  158. };
  159. $scope.setAdvertiserQuota = function () {
  160. //重置表单状态
  161. $scope.quotaForm.$setPristine();
  162. $scope.quotaForm.$setUntouched();
  163. var rows = $scope.gridApi.selection.getSelectedRows();
  164. if (rows.length == 0) {
  165. toaster.pop("info", "提示", "请选择数据!");
  166. return;
  167. }
  168. if (rows.length > 1) {
  169. toaster.pop("info", "提示", "只能选中编辑一条数据");
  170. return;
  171. }
  172. var item = rows[0];
  173. $scope.quotaData = $.extend({}, item);
  174. $("#quotaPanel").modal();
  175. };
  176. //提交表单保存
  177. $scope.saveData = function () {
  178. //表单未校验通过不能提交
  179. if ($scope.modelForm.$invalid) {
  180. return;
  181. }
  182. var url = "";
  183. if ($scope.dialogData.id == null) {
  184. url = "/manager/addAdvertiser";
  185. } else {
  186. url = "/manager/editAdvertiser";
  187. }
  188. //深度克隆 避免操作原对象
  189. var data = $.extend(true, {}, $scope.dialogData);
  190. if ($scope.dialogData.isNew) {
  191. var password = MD5.createHash($scope.dialogData.password + '');
  192. data.password = password;
  193. }
  194. // 删除多余的字段
  195. delete data.isNew
  196. $http({
  197. method: 'POST',
  198. url: url,
  199. data: data
  200. }).then(function (response) {
  201. $('#modelPanel').modal('hide');//弹窗消失
  202. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  203. toaster.pop("success", "提示", "开户成功!");
  204. }, function (response) {
  205. toaster.pop("error", "提示", "开户失败!");
  206. });
  207. };
  208. //编辑
  209. $scope.edit = function () {
  210. //重置表单状态
  211. $scope.editForm.$setPristine();
  212. $scope.editForm.$setUntouched();
  213. var rows = $scope.gridApi.selection.getSelectedRows();
  214. if (rows.length == 0) {
  215. toaster.pop("info", "提示", "请选择数据!");
  216. return;
  217. }
  218. if (rows.length > 1) {
  219. toaster.pop("info", "提示", "只能选中编辑一条数据");
  220. return;
  221. }
  222. var item = rows[0];
  223. $scope.dialogData = $.extend(true, {}, item);
  224. var devConditionSrc = $.extend(true, [], item.devCondition);
  225. // 数据适配
  226. $scope.dialogData.devCondition = $scope.conditionFun.getRenderingCondition(devConditionSrc);
  227. //标记这是编辑框在加载
  228. $scope.conditionFun.noClearSelect = true;
  229. $("#editForm").modal();
  230. };
  231. //提交表单保存
  232. $scope.saveEditData = function () {
  233. //表单未校验通过不能提交
  234. if ($scope.editForm.$invalid) {
  235. return;
  236. }
  237. var url = "/manager/editAdvertiser";
  238. //深度克隆 避免操作原对象
  239. var dialogData = $.extend(true, {}, $scope.dialogData);
  240. //精简保存的数据
  241. dialogData.devCondition = $scope.conditionFun.getCondition(dialogData);
  242. $http({
  243. method: 'POST',
  244. url: url,
  245. data: {
  246. id: dialogData.id,
  247. devCondition: dialogData.devCondition,
  248. }
  249. }).then(function (response) {
  250. $('#editForm').modal('hide');//弹窗消失
  251. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  252. toaster.pop("success", "提示", "操作成功!");
  253. }, function (response) {
  254. toaster.pop("error", "提示", "操作失败!");
  255. });
  256. };
  257. //修改密码提交
  258. $scope.savePassword = function () {
  259. //表单未校验通过不能提交
  260. if ($scope.passwordForm.$invalid) {
  261. return;
  262. }
  263. var url = "/manager/editAdvertiserPassword";
  264. var password = MD5.createHash($scope.passwordData.password + '');
  265. $http({
  266. method: 'POST',
  267. url: url,
  268. data: {
  269. id: $scope.passwordData.id,
  270. password: password
  271. }
  272. }).then(function (response) {
  273. $('#passwordPanel').modal('hide');//弹窗消失
  274. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  275. }, function (response) {
  276. toaster.pop("error", "提示", "修改密码失败!");
  277. });
  278. };
  279. $scope.saveQuota = function () {
  280. //表单未校验通过不能提交
  281. if ($scope.quotaForm.$invalid) {
  282. return;
  283. }
  284. var url = "/manager/setAdvertiserQuota ";
  285. $http({
  286. method: 'POST',
  287. url: url,
  288. data: {
  289. id: $scope.quotaData.id,
  290. quota: $scope.quotaData.quota
  291. }
  292. }).then(function (response) {
  293. $('#quotaPanel').modal('hide');//弹窗消失
  294. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  295. }, function (response) {
  296. toaster.pop("error", "提示", "修改失败!");
  297. });
  298. };
  299. }]);