dealerManage.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. app.controller('dealerManageCtrl', ['$scope', "$localStorage", "$state", '$stateParams', '$http', '$timeout', 'uiGridConstants', 'i18nService', 'toaster', 'md5', 'QRCodeOptions', function ($scope, $localStorage, $state, $stateParams, $http, $timeout, uiGridConstants, i18nService, toaster, MD5, QRCodeOptions) {
  2. i18nService.setCurrentLang("zh-cn");
  3. var agentId = $stateParams.agentId;
  4. $scope.gridOptions = {
  5. data: 'myData',
  6. showGridFooter: true, //是否显示grid footer
  7. // rowHeight: 80,
  8. //-------- 分页属性 ----------------
  9. paginationPageSizes: [10, 20, 50, 100], //每页显示个数可选项
  10. paginationCurrentPage: 1, //当前页码
  11. paginationPageSize: 10, //每页显示个数
  12. totalItems: 0,// 总数量
  13. useExternalPagination: true,//是否使用分页按钮
  14. //过滤
  15. // enableFiltering: true,
  16. columnDefs: [],
  17. //---------------api---------------------
  18. onRegisterApi: function (gridApi) {
  19. $scope.gridApi = gridApi;
  20. gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
  21. if ($scope.setPagingData) {
  22. $scope.getPagedDataAsync(newPage, pageSize);
  23. }
  24. });
  25. }
  26. };
  27. //查询条件
  28. var condition = $scope.condition = {
  29. searchKey: "",
  30. agentId: agentId
  31. };
  32. //枚举常量
  33. $scope.enum = {};
  34. //事件
  35. $scope.event = {
  36. search: function () {
  37. $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize);
  38. }
  39. };
  40. $scope.ngEvent = {
  41. exportExcelOpen: false,
  42. //导出
  43. exportExcel: function () {
  44. var params = {
  45. };
  46. if (condition.searchKey != "") {
  47. params.searchKey = condition.searchKey
  48. }
  49. if (condition.agentId) {
  50. params.agentId = condition.agentId
  51. }
  52. if ($scope.ngEvent.exportExcelOpen) {
  53. toaster.pop("info", "提示", "有一份报表正在生成,请稍候!");
  54. return;
  55. } else {
  56. $scope.ngEvent.exportExcelOpen = true;
  57. }
  58. $http.get('/manager/exportDealerDetailList', {params: params}).then(function (data) {
  59. data = data.data
  60. $scope.ngEvent.exportExcelOpen = false;
  61. if (data.result == 1) {
  62. var payload = data.payload;
  63. toaster.pop("success", data.description);
  64. $state.go('app.tool.offlineTask', {
  65. searchKey: payload
  66. });
  67. }
  68. }).catch(function (data) {
  69. $scope.ngEvent.exportExcelOpen = false;
  70. if (data.status == 504) {
  71. toaster.pop("error", "计算超时,请前往任务->执行离线生成报表");
  72. } else {
  73. toaster.pop("error", "系统错误,请重试");
  74. }
  75. });
  76. }
  77. };
  78. function setColumnDefs() {
  79. var cols = $scope.gridOptions.columnDefs = [
  80. {field: 'name', displayName: '商家名称'},
  81. {
  82. field: 'devTotalNum', minWidth: '200',
  83. displayName: '设备数量',
  84. cellTemplate: '<div class="temp-row text-left" ng-bind="\'总:\'+row.entity.devTotalNum + \' 在线:\'+row.entity.onlineTotal+ \' 离线:\'+row.entity.offlineTotal "></div>'
  85. },
  86. {field: 'tel', displayName: '联系方式'},
  87. {
  88. field: 'dateTimeAdded',
  89. displayName: '注册时间',
  90. cellTemplate: '<div class="temp-row" ng-bind="row.entity.dateTimeAdded"></div>'
  91. },
  92. {
  93. field: 'lineCoins', minWidth: '118',
  94. displayName: '今日线下投币',
  95. cellTemplate: '<div class="temp-row" ng-bind="(row.entity.lineCoins| currency:\'¥\') " ></div>'
  96. },
  97. {
  98. field: 'payIncome', minWidth: '118',
  99. displayName: '今日在线收入',
  100. cellTemplate: '<div class="temp-row" ng-bind="(row.entity.payIncome| currency:\'¥\')"></div>'
  101. },
  102. {
  103. field: 'todayRechargeIncome', minWidth: '80',
  104. displayName: '今日扫码充值',
  105. },
  106. {
  107. field: 'todayChargeCardIncome', minWidth: '80',
  108. displayName: '今日卡充值',
  109. },
  110. {
  111. field: 'userCount', minWidth: '80',
  112. displayName: '用户总数',
  113. },
  114. {
  115. field: 'userCountAddedThisMonth', minWidth: '80',
  116. displayName: '本月新增用户',
  117. },
  118. {
  119. field: 'balance',
  120. displayName: '商家余额',
  121. cellTemplate: '<div class="temp-row" ng-bind="grid.appScope.showBalance(row.entity)"></div>'
  122. },
  123. {
  124. field: 'agentInfo',
  125. displayName: '代理商',
  126. },
  127. {
  128. field: 'detail',
  129. displayName: '详细信息',
  130. cellTemplate: '<div class="temp-row" ng-click="grid.appScope.showInfoDetail(\'详细信息\',row.entity.detail)" >{{row.entity.detail}}</div>'
  131. },
  132. ];
  133. $scope.showBalance = function (entity) {
  134. if (entity.detail) {
  135. var detail = {}
  136. try {
  137. detail = JSON.parse(entity.detail)
  138. } catch (e) {
  139. }
  140. return '¥' + (detail.balance || "0.00")
  141. }
  142. return '未知'
  143. }
  144. var feature_map = $localStorage.feature_map
  145. if (feature_map && feature_map.disableDevice) {
  146. cols.push(
  147. {
  148. field: 'disableDevice', displayName: '禁用设备权限',
  149. cellTemplate: '<div class="temp-row" >{{row.entity.disableDevice?\'有权限\':\'无权限\'}}</div>'
  150. }
  151. )
  152. }
  153. var operCol = {
  154. field: 'operation',
  155. displayName: '操作',
  156. enableFiltering: false,
  157. enableSorting: false,
  158. enableHiding: false,//禁止在列选择器中隐藏
  159. enableColumnMenu: false,// 是否显示列头部菜单按钮
  160. minWidth: 256,
  161. cellTemplate: '<div class="grid-button">' +
  162. ((feature_map && feature_map.disableDevice) ? ('<button class="btn btn-sm btn-rounded " ng-class="{\'btn-info\':!row.entity.disableDevice,\'btn-danger\':row.entity.disableDevice}" ng-click="grid.appScope.disableDeviceToggle(row.entity)"><i class="fa fa-wrench"></i> {{row.entity.disableDevice?\'关闭设备禁用权限\':\'打开设备禁用权限\'}}</button>') : ('')) +
  163. '<button class="btn btn-sm btn-rounded btn-info" ng-click="grid.appScope.checkDevice(row.entity)"><i class="glyphicon glyphicon-phone"></i> 查看设备</button>' +
  164. '</div>'
  165. };
  166. $scope.gridOptions.columnDefs.push(operCol)
  167. var fields = $scope.gridOptions.columnDefs;
  168. for (var index in fields) {
  169. var item = fields[index];
  170. if (item && item['minWidth'] == null) {
  171. item['minWidth'] = 100;
  172. }
  173. }
  174. }
  175. // 切换禁用状态
  176. $scope.disableDeviceToggle = function (entity) {
  177. $http.get('/manager/dealerDisableDevice', {
  178. params: {id: entity.id, disable: !entity.disableDevice}
  179. }).then(function (data) {
  180. data = data.data
  181. if (data.result == 1) {
  182. entity.disableDevice = !entity.disableDevice
  183. toaster.pop("success", "操作成功!");
  184. }
  185. }).catch(function (data) {
  186. toaster.pop("error", "提示", "操作失败!");
  187. });
  188. };
  189. $scope.setPagingData = function (data, curPage, pageSize) {
  190. var firstRow = (curPage - 1) * pageSize;
  191. var pagedData = data.data.dataList;
  192. $scope.myData = pagedData;
  193. $scope.gridOptions.totalItems = data.data.total;
  194. };
  195. $scope.getPagedDataAsync = function (curPage, pageSize, searchText) {
  196. if ($scope.gridOptionsLoading) {
  197. return;
  198. }
  199. var params = {
  200. pageSize: pageSize,
  201. pageIndex: curPage
  202. };
  203. if (condition.searchKey != "") {
  204. params.searchKey = condition.searchKey
  205. }
  206. if (condition.agentId) {
  207. params.agentId = condition.agentId
  208. }
  209. $scope.gridOptionsLoading = true;
  210. $http.get('/dealer/getDealerDetailList', {
  211. params: params
  212. }).then(function (data) {
  213. $scope.gridOptionsLoading = false;
  214. $scope.setPagingData(data.data, curPage, pageSize);
  215. }).catch(function (data) {
  216. toaster.pop("error", "提示", "获取数据列表失败");
  217. });
  218. };
  219. function initDataGrid() {
  220. //首次加载表格
  221. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  222. }
  223. setColumnDefs();
  224. initDataGrid();
  225. //展示详情
  226. $scope.showInfoDetail = function (title, content) {
  227. $scope.infoDetail = {title: title, content: JSON.parse(content)};
  228. $("#detailInfoPanel").modal();
  229. };
  230. $scope.closeDetailInfoPanel = function () {
  231. $("#detailInfoPanel").modal("hide");
  232. };
  233. //添加
  234. $scope.add = function () {
  235. //重置表单状态
  236. $scope.dealerForm.$setPristine();
  237. $scope.dealerForm.$setUntouched();
  238. $scope.dialogName = "代理商开户";
  239. $scope.dialogData = {};
  240. $("#dealerPanel").modal();
  241. };
  242. //编辑
  243. $scope.edit = function () {
  244. //重置表单状态
  245. $scope.dealerForm.$setPristine();
  246. $scope.dealerForm.$setUntouched();
  247. $scope.dialogName = "编辑经销商信息";
  248. var rows = $scope.gridApi.selection.getSelectedRows();
  249. if (rows.length == 0) {
  250. toaster.pop("info", "提示", "请选择数据!");
  251. return;
  252. }
  253. if (rows.length > 1) {
  254. toaster.pop("info", "提示", "只能选中编辑一条数据");
  255. return;
  256. }
  257. var item = rows[0];
  258. $scope.dialogData = $.extend({}, item);
  259. $("#dealerPanel").modal();
  260. };
  261. //提交表单保存
  262. $scope.saveData = function () {
  263. //表单未校验通过不能提交
  264. if ($scope.dealerForm.$invalid) {
  265. return;
  266. }
  267. var url = "/manager/editDealer";
  268. $http({
  269. method: 'POST',
  270. url: url,
  271. data: {
  272. id: $scope.dialogData.id,
  273. name: $scope.dialogData.name,
  274. tel: $scope.dialogData.tel,
  275. openId: $scope.dialogData.openId
  276. }
  277. }).then(function (response) {
  278. $('#dealerPanel').modal('hide');//弹窗消失
  279. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  280. }, function (response) {
  281. toaster.pop("error", "提示", "保存失败!");
  282. });
  283. };
  284. //编辑
  285. $scope.editOtherAPI = function () {
  286. //重置表单状态
  287. $scope.otherAPIForm.$setPristine();
  288. $scope.otherAPIForm.$setUntouched();
  289. var rows = $scope.gridApi.selection.getSelectedRows();
  290. if (rows.length == 0) {
  291. toaster.pop("info", "提示", "请选择数据!");
  292. return;
  293. }
  294. if (rows.length > 1) {
  295. toaster.pop("info", "提示", "只能选中编辑一条数据");
  296. return;
  297. }
  298. var item = rows[0];
  299. if (!item.hasZJFirePlatform) {
  300. toaster.pop("warning", "提示", "该经销商没有权限配置");
  301. return;
  302. }
  303. $scope.dialogFireData = $.extend(true, {id: item.id}, item.ZJFirePlatform);
  304. $("#otherAPIForm").modal();
  305. };
  306. $scope.saveOtherAPIForm = function () {
  307. if ($scope.otherAPIForm.$invalid) {
  308. return;
  309. }
  310. var url = "/manager/editDealerZJFirePlatform";
  311. $http({
  312. method: 'POST',
  313. url: url,
  314. data: $scope.dialogFireData
  315. }).then(function (response) {
  316. $('#otherAPIForm').modal('hide');
  317. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  318. }, function (response) {
  319. toaster.pop("error", "提示", "保存失败!");
  320. });
  321. }
  322. //查看经销商
  323. $scope.checkDevice = function (entity) {
  324. $scope.nowDealerName = entity.name;
  325. $("#dealerDevList").modal();
  326. // todo 由于ui-grid 之前隐藏,表格渲染有问题
  327. setTimeout(function () {
  328. // 刷新设备
  329. $scope.$broadcast("initDevList", {dealerId: entity.id});
  330. }, 100);
  331. };
  332. $scope.closeDevice = function () {
  333. $("#dealerDevList").modal('hide');
  334. };
  335. //编辑密码 默认123456
  336. $scope.editPassword = function () {
  337. //重置表单状态
  338. $scope.passwordForm.$setPristine();
  339. $scope.passwordForm.$setUntouched();
  340. var rows = $scope.gridApi.selection.getSelectedRows();
  341. if (rows.length == 0) {
  342. toaster.pop("info", "提示", "请选择数据!");
  343. return;
  344. }
  345. if (rows.length > 1) {
  346. toaster.pop("info", "提示", "只能选中编辑一条数据");
  347. return;
  348. }
  349. var item = rows[0];
  350. $scope.passwordData = $.extend({password: 123456}, item);
  351. $("#passwordPanel").modal();
  352. };
  353. //修改密码提交
  354. $scope.savePassword = function () {
  355. //表单未校验通过不能提交
  356. if ($scope.passwordForm.$invalid) {
  357. return;
  358. }
  359. var url = "/manager/editDealerPassword";
  360. var password = MD5.createHash($scope.passwordData.password + '');
  361. $http({
  362. method: 'POST',
  363. url: url,
  364. data: {
  365. id: $scope.passwordData.id,
  366. password: password
  367. }
  368. }).then(function (response) {
  369. $('#passwordPanel').modal('hide');//弹窗消失
  370. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  371. }, function (response) {
  372. toaster.pop("error", "提示", "修改密码失败!");
  373. });
  374. };
  375. //解锁经销商的登录限制,如密码输错后导致的锁
  376. $scope.unlock = function () {
  377. var rows = $scope.gridApi.selection.getSelectedRows();
  378. if (rows.length == 0) {
  379. toaster.pop("info", "提示", "请选择数据!");
  380. return;
  381. }
  382. if (rows.length > 1) {
  383. toaster.pop("info", "提示", "只能选中编辑一条数据");
  384. return;
  385. }
  386. var item = rows[0];
  387. var url = "/manager/unlockDealer";
  388. $http({
  389. method: 'POST',
  390. url: url,
  391. data: {
  392. id: item.id
  393. }
  394. }).then(function (response) {
  395. toaster.pop("info", "提示", "解锁成功!")
  396. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  397. }, function (response) {
  398. toaster.pop("error", "提示", "解锁失败!");
  399. });
  400. }
  401. }]);