joinerManage.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. app.controller('joinerManageCtrl', ['$scope', "$state", '$stateParams', '$http', '$timeout', 'uiGridConstants', 'i18nService', 'toaster', 'md5', 'QRCodeOptions', function ($scope, $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. function setColumnDefs() {
  41. $scope.gridOptions.columnDefs = [
  42. {field: 'name', displayName: '商家名称'},
  43. {
  44. field: 'devTotalNum', minWidth: '200',
  45. displayName: '设备数量',
  46. cellTemplate: '<div class="temp-row text-left" ng-bind="\'总:\'+row.entity.devTotalNum + \' 在线:\'+row.entity.onlineTotal+ \' 离线:\'+row.entity.offlineTotal "></div>'
  47. },
  48. {field: 'tel', displayName: '联系方式'},
  49. {
  50. field: 'dateTimeAdded',
  51. displayName: '注册时间',
  52. cellTemplate: '<div class="temp-row" ng-bind="row.entity.dateTimeAdded"></div>'
  53. },
  54. {
  55. field: 'lineCoins', minWidth: '150',
  56. displayName: '今日线下投币',
  57. cellTemplate: '<div class="temp-row" ng-bind="(row.entity.lineCoins| currency:\'¥\') " ></div>'
  58. },
  59. {
  60. field: 'payIncome', minWidth: '150',
  61. displayName: '今日在线收入',
  62. cellTemplate: '<div class="temp-row" ng-bind="(row.entity.payIncome| currency:\'¥\')"></div>'
  63. },
  64. {
  65. field: 'todayRechargeIncome', minWidth: '80',
  66. displayName: '今日扫码充值',
  67. },
  68. {
  69. field: 'todayChargeCardIncome', minWidth: '80',
  70. displayName: '今日卡充值',
  71. },
  72. {
  73. field: 'userCount', minWidth: '80',
  74. displayName: '用户总数',
  75. },
  76. {
  77. field: 'userCountAddedThisMonth', minWidth: '80',
  78. displayName: '本月新增用户',
  79. },
  80. {
  81. field: 'balance',
  82. displayName: '商家余额',
  83. cellTemplate: '<div class="temp-row" ng-bind="grid.appScope.showBalance(row.entity)"></div>'
  84. },
  85. {
  86. field: 'agentInfo',
  87. displayName: '代理商',
  88. },
  89. {
  90. field: 'detail',
  91. displayName: '详细信息',
  92. cellTemplate: '<div class="temp-row" ng-click="grid.appScope.showInfoDetail(\'详细信息\',row.entity.detail)" >{{row.entity.detail}}</div>'
  93. },
  94. ];
  95. $scope.showBalance = function (entity) {
  96. if (entity.detail) {
  97. var detail = {}
  98. try {
  99. detail = JSON.parse(entity.detail)
  100. } catch (e) {
  101. }
  102. return '¥' + (detail.balance || "0.00")
  103. }
  104. return '未知'
  105. }
  106. var operCol = {
  107. field: 'operation',
  108. displayName: '操作',
  109. enableFiltering: false,
  110. enableSorting: false,
  111. enableHiding: false,//禁止在列选择器中隐藏
  112. enableColumnMenu: false,// 是否显示列头部菜单按钮
  113. minWidth: 168,
  114. cellTemplate: '<div class="grid-button">' +
  115. '<button class="btn btn-sm btn-rounded btn-info" ng-click="grid.appScope.checkDevice(row.entity)"><i class="glyphicon glyphicon-phone"></i> 查看设备</button>' +
  116. '</div>'
  117. };
  118. $scope.gridOptions.columnDefs.push(operCol)
  119. var fields = $scope.gridOptions.columnDefs;
  120. for (var index in fields) {
  121. var item = fields[index];
  122. if (item && item['minWidth'] == null) {
  123. item['minWidth'] = 100;
  124. }
  125. }
  126. }
  127. $scope.setPagingData = function (data, curPage, pageSize) {
  128. var firstRow = (curPage - 1) * pageSize;
  129. var pagedData = data.data.dataList;
  130. $scope.myData = pagedData;
  131. $scope.gridOptions.totalItems = data.data.total;
  132. };
  133. $scope.getPagedDataAsync = function (curPage, pageSize, searchText) {
  134. if ($scope.gridOptionsLoading) {
  135. return;
  136. }
  137. var params = {
  138. pageSize: pageSize,
  139. pageIndex: curPage
  140. };
  141. if (condition.searchKey != "") {
  142. params.searchKey = condition.searchKey
  143. }
  144. if (condition.agentId) {
  145. params.agentId = condition.agentId
  146. }
  147. $scope.gridOptionsLoading = true;
  148. $http.get('/dealer/getJoinerDetailList', {
  149. params: params
  150. }).then(function (data) {
  151. $scope.gridOptionsLoading = false;
  152. $scope.setPagingData(data.data, curPage, pageSize);
  153. }).catch(function (data) {
  154. toaster.pop("error", "提示", "获取数据列表失败");
  155. });
  156. };
  157. function initDataGrid() {
  158. //首次加载表格
  159. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  160. }
  161. setColumnDefs();
  162. initDataGrid();
  163. //展示详情
  164. $scope.showInfoDetail = function (title, content) {
  165. $scope.infoDetail = {title: title, content: JSON.parse(content)};
  166. $("#detailInfoPanel").modal();
  167. };
  168. $scope.closeDetailInfoPanel = function () {
  169. $("#detailInfoPanel").modal("hide");
  170. };
  171. //添加
  172. $scope.add = function () {
  173. //重置表单状态
  174. $scope.dealerForm.$setPristine();
  175. $scope.dealerForm.$setUntouched();
  176. $scope.dialogName = "代理商开户";
  177. $scope.dialogData = {};
  178. $("#dealerPanel").modal();
  179. };
  180. //编辑
  181. $scope.edit = function () {
  182. //重置表单状态
  183. $scope.dealerForm.$setPristine();
  184. $scope.dealerForm.$setUntouched();
  185. $scope.dialogName = "编辑经销商信息";
  186. var rows = $scope.gridApi.selection.getSelectedRows();
  187. if (rows.length == 0) {
  188. toaster.pop("info", "提示", "请选择数据!");
  189. return;
  190. }
  191. if (rows.length > 1) {
  192. toaster.pop("info", "提示", "只能选中编辑一条数据");
  193. return;
  194. }
  195. var item = rows[0];
  196. $scope.dialogData = $.extend({}, item);
  197. $("#dealerPanel").modal();
  198. };
  199. //提交表单保存
  200. $scope.saveData = function () {
  201. //表单未校验通过不能提交
  202. if ($scope.dealerForm.$invalid) {
  203. return;
  204. }
  205. var url = "/manager/editDealer";
  206. $http({
  207. method: 'POST',
  208. url: url,
  209. data: {
  210. id: $scope.dialogData.id,
  211. name: $scope.dialogData.name,
  212. tel: $scope.dialogData.tel,
  213. openId: $scope.dialogData.openId
  214. }
  215. }).then(function (response) {
  216. $('#dealerPanel').modal('hide');//弹窗消失
  217. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  218. }, function (response) {
  219. toaster.pop("error", "提示", "保存失败!");
  220. });
  221. };
  222. //查看经销商
  223. $scope.checkDevice = function (entity) {
  224. $state.go('app.dev.joinDevManage', {
  225. dealerId: entity.id,
  226. }, {
  227. reload: true
  228. });
  229. };
  230. //编辑密码 默认123456
  231. $scope.editPassword = function () {
  232. //重置表单状态
  233. $scope.passwordForm.$setPristine();
  234. $scope.passwordForm.$setUntouched();
  235. var rows = $scope.gridApi.selection.getSelectedRows();
  236. if (rows.length == 0) {
  237. toaster.pop("info", "提示", "请选择数据!");
  238. return;
  239. }
  240. if (rows.length > 1) {
  241. toaster.pop("info", "提示", "只能选中编辑一条数据");
  242. return;
  243. }
  244. var item = rows[0];
  245. $scope.passwordData = $.extend({password: 123456}, item);
  246. $("#passwordPanel").modal();
  247. };
  248. //修改密码提交
  249. $scope.savePassword = function () {
  250. //表单未校验通过不能提交
  251. if ($scope.passwordForm.$invalid) {
  252. return;
  253. }
  254. var url = "/manager/editDealerPassword";
  255. var password = MD5.createHash($scope.passwordData.password + '');
  256. $http({
  257. method: 'POST',
  258. url: url,
  259. data: {
  260. id: $scope.passwordData.id,
  261. password: password
  262. }
  263. }).then(function (response) {
  264. $('#passwordPanel').modal('hide');//弹窗消失
  265. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  266. }, function (response) {
  267. toaster.pop("error", "提示", "修改密码失败!");
  268. });
  269. };
  270. //解锁经销商的登录限制,如密码输错后导致的锁
  271. $scope.unlock = function () {
  272. var rows = $scope.gridApi.selection.getSelectedRows();
  273. if (rows.length == 0) {
  274. toaster.pop("info", "提示", "请选择数据!");
  275. return;
  276. }
  277. if (rows.length > 1) {
  278. toaster.pop("info", "提示", "只能选中编辑一条数据");
  279. return;
  280. }
  281. var item = rows[0];
  282. var url = "/manager/unlockDealer";
  283. $http({
  284. method: 'POST',
  285. url: url,
  286. data: {
  287. id: item.id
  288. }
  289. }).then(function (response) {
  290. toaster.pop("info", "提示", "解锁成功!")
  291. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  292. }, function (response) {
  293. toaster.pop("error", "提示", "解锁失败!");
  294. });
  295. }
  296. $scope.editDefaultJoiner = function () {
  297. $http.get('/dealer/getDefaultJoiner', {
  298. params: {}
  299. }).then(function (data) {
  300. $scope.dialogData = data.data.payload
  301. }).catch(function (data) {
  302. toaster.pop("error", "提示", "获取数据失败");
  303. });
  304. $("#editDefaultJoinerForm").modal();
  305. };
  306. $scope.saveDefaultJoiner = function () {
  307. if ($scope.editDefaultJoinerForm.$invalid) {
  308. return;
  309. }
  310. var url = "/dealer/editDefaultJoiner";
  311. $http({
  312. method: 'POST',
  313. url: url,
  314. data: $scope.dialogData
  315. }).then(function (response) {
  316. $('#editDefaultJoinerForm').modal('hide');//弹窗消失
  317. }, function (response) {
  318. toaster.pop("error", "提示", "保存失败!");
  319. });
  320. };
  321. }]);