systemConfigCtrl.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. app.controller('systemConfigCtrl', ['$scope', '$http', '$timeout', 'toaster', 'uiGridConstants', 'FileUploader', 'i18nService', function ($scope, $http, $timeout, toaster, uiGridConstants, FileUploader, 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){ return flag ? "开启" : "不开启" };
  99. //角色转换
  100. $scope.formatterRole = function (role) {
  101. var list = $scope.enum.role;
  102. for (var index in list) {
  103. var item = list[index];
  104. if (item.value == role) {
  105. return item.label;
  106. }
  107. }
  108. };
  109. //事件
  110. $scope.event = {
  111. search: function () {
  112. $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize);
  113. }
  114. };
  115. //编辑弹窗需要的数据
  116. $scope.dialogName = "编辑";
  117. $scope.dialogData = {};
  118. //添加
  119. $scope.addFeature = function () {
  120. //重置表单状态
  121. $scope.FeaturePanel.$setPristine();
  122. $scope.FeaturePanel.$setUntouched();
  123. $scope.dialogName = "添加";
  124. $scope.dialogData = {};
  125. $("#FeaturePanel").modal();
  126. };
  127. //编辑
  128. $scope.editFeature = function () {
  129. //重置表单状态
  130. $scope.FeaturePanel.$setPristine();
  131. $scope.FeaturePanel.$setUntouched();
  132. $scope.dialogName = "编辑";
  133. var rows = $scope.gridApi.selection.getSelectedRows();
  134. if (rows.length == 0) {
  135. toaster.pop("info", "提示", "请选择数据!");
  136. return;
  137. }
  138. if (rows.length > 1) {
  139. toaster.pop("info", "提示", "只能选中编辑一条数据");
  140. return;
  141. }
  142. var item = rows[0];
  143. $scope.dialogData = $.extend(true, {}, item);
  144. $("#FeaturePanel").modal();
  145. };
  146. //提交表单保存
  147. $scope.saveData = function () {
  148. //表单未校验通过不能提交
  149. if ($scope.FeaturePanel.$invalid) {
  150. return;
  151. }
  152. var url = "";
  153. if ($scope.dialogData.id == null) {
  154. url = "/superadmin/addFeature";
  155. } else {
  156. url = "/superadmin/editFeature";
  157. }
  158. //深度克隆 避免操作原对象
  159. var data = $.extend(true, {}, $scope.dialogData);
  160. delete data.createdTime //创建时间后台修改
  161. $http({
  162. method: 'POST',
  163. url: url,
  164. data: data
  165. }).then(function (response) {
  166. $('#FeaturePanel').modal('hide');//弹窗消失
  167. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  168. }, function (response) {
  169. toaster.pop("error", "提示", "保存失败!");
  170. });
  171. };
  172. //删除特性
  173. $scope.deleteFeature = function () {
  174. var rows = $scope.gridApi.selection.getSelectedRows();
  175. if (rows.length == 0) {
  176. toaster.pop("info", "提示", "请选择数据!");
  177. return;
  178. }
  179. var ids = [];
  180. for (var i = 0; i < rows.length; i++) {
  181. ids.push(rows[i].id);
  182. }
  183. $.confirm({
  184. content: '确定删除?',
  185. buttons: {
  186. ok: {
  187. btnClass: 'btn-red',
  188. action: function () {
  189. $http({
  190. method: 'POST',
  191. url: '/superadmin/removeFeatures',
  192. data: {ids: ids}
  193. }).then(function (response) {
  194. initDataGrid();
  195. }, function (response) {
  196. toaster.pop("error", "提示", "删除失败!");
  197. });
  198. }
  199. },
  200. }
  201. });
  202. };
  203. /********默认充值优惠设置**********/
  204. $scope.config = {
  205. chargeList: [],
  206. };
  207. $http.get("/manager/getChargeList").then(function (data) {
  208. data = data.data
  209. $scope.config.chargeList = data.data;
  210. $timeout(function () {
  211. //由于出现滚动条,导致横向空间减少,导致表格控件多出横向滚动条,需要resize
  212. $(window).trigger("resize");
  213. })
  214. });
  215. $scope.deleteCharge = function (index) {
  216. var chargeList = $scope.config.chargeList;
  217. if (chargeList[index]) {
  218. chargeList.splice(index, 1);
  219. }
  220. };
  221. //充值套餐
  222. $scope.addCharge = function () {
  223. var chargeList = $scope.config.chargeList;
  224. if (!$.isArray(chargeList)) {
  225. chargeList = $scope.config.chargeList = [];
  226. }
  227. var length = chargeList.length;
  228. var data = {};
  229. if (length == 0) {
  230. data = {
  231. payAmount: 1,
  232. coins: 1
  233. };
  234. } else {
  235. data = {
  236. payAmount: chargeList[length - 1]["payAmount"] * 2,
  237. coins: chargeList[length - 1]["coins"] * 2
  238. };
  239. }
  240. chargeList.push(data);
  241. };
  242. //保存充值优惠
  243. $scope.saveChargeData = function () {
  244. $http({
  245. method: 'POST',
  246. url: "/manager/saveChargeData",
  247. data: $scope.config.chargeList
  248. }).then(function (response) {
  249. toaster.pop("success", "提示", "保存成功!");
  250. }, function (response) {
  251. toaster.pop("error", "提示", "保存失败!");
  252. });
  253. };
  254. }]);