agentsManage.js 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069
  1. app.controller('agentsManageCtrl', ['$scope', '$http', '$stateParams', "$state", '$timeout', 'uiGridConstants', 'i18nService', 'FileUploader', 'toaster', 'md5', function ($scope, $http, $stateParams, $state, $timeout, uiGridConstants, i18nService, FileUploader, toaster, MD5) {
  2. i18nService.setCurrentLang("zh-cn");
  3. var managerId = $stateParams.managerId;
  4. var moniAppId = $stateParams.moniAppId;// 根据是否有监督号查询代理商
  5. $scope.gridOptions = {
  6. data: 'myData',
  7. showGridFooter: true, //是否显示grid footer
  8. // rowHeight: 80,
  9. //-------- 分页属性 ----------------
  10. paginationPageSizes: [10, 20, 50, 100], //每页显示个数可选项
  11. paginationCurrentPage: 1, //当前页码
  12. paginationPageSize: 10, //每页显示个数
  13. totalItems: 0,// 总数量
  14. useExternalPagination: true,//是否使用分页按钮
  15. //过滤
  16. // enableFiltering: true,
  17. columnDefs: [],
  18. //---------------api---------------------
  19. onRegisterApi: function (gridApi) {
  20. $scope.gridApi = gridApi;
  21. gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
  22. if ($scope.setPagingData) {
  23. $scope.getPagedDataAsync(newPage, pageSize);
  24. }
  25. });
  26. }
  27. };
  28. //枚举常量
  29. $scope.enum = {};
  30. $scope.enum.adShow = [
  31. {value: "", label: "广告状态"},
  32. {value: false, label: "无广告"},
  33. {value: true, label: "有广告"}
  34. ];
  35. $scope.enum.forceFollowGzh = [
  36. {value: "", label: "-强制关注状态-"},
  37. {value: "yes", label: "强制关注"},
  38. {value: "no", label: "不强制关注"},
  39. ];
  40. $scope.enum.forceFollowGzhForDealer = [
  41. {value: "", label: "-经销商的是否允许关注-"},
  42. {value: "never", label: "永不强制关注公众号"},
  43. {value: "free", label: "自由选择"},
  44. ];
  45. $scope.enum.platformSupport = [
  46. {value: "", label: "-客服接管状态-"},
  47. {value: "yes", label: "用平台客服"},
  48. {value: "no", label: "不用"},
  49. {value: "never", label: "用自己的"},
  50. ];
  51. $scope.enum.beforeChargeUnpay = [
  52. {value: "", label: "-使用前充值-"},
  53. {value: "yes", label: "是"},
  54. {value: "no", label: "否"},
  55. {value: "never", label: "永不"},
  56. {value: "free", label: "自由选择"},
  57. ];
  58. var managerDefault = {"nickname": "厂商"}
  59. //查询条件
  60. var condition = $scope.condition = {
  61. adShow: $.extend({}, $scope.enum.adShow[0]),
  62. forceFollowGzh: $.extend({}, $scope.enum.forceFollowGzh[0]),
  63. forceFollowGzhForDealer: $.extend({}, $scope.enum.forceFollowGzhForDealer[0]),
  64. beforeChargeUnpay: $.extend({}, $scope.enum.beforeChargeUnpay[0]),
  65. managerDefault: managerDefault,
  66. managerList: [
  67. managerDefault
  68. ],
  69. manager: managerDefault,
  70. searchKey: ""
  71. };
  72. var searchTimer = null;
  73. //事件
  74. $scope.event = {
  75. statusChange: function (key, item) {
  76. condition[key].value = item.value;
  77. condition[key].label = item.label;
  78. this.search()
  79. },
  80. managerInit: function ($event) {
  81. var searchKey = $event ? $event.target.value : "";
  82. $timeout.cancel(searchTimer);
  83. searchTimer = $timeout(function () {
  84. $http.get('/superadmin/getManagerList', {
  85. params: {
  86. pageSize: 1000,
  87. pageIndex: 1,
  88. searchKey: searchKey,
  89. }
  90. }).then(function (data) {
  91. data = data.data
  92. $scope.condition.managerList = data.data.dataList;
  93. }).catch(function (data) {
  94. toaster.pop("error", "提示", "搜索失败");
  95. });
  96. }, 500);//延迟搜索,否则请求太频繁
  97. },
  98. search: function () {
  99. $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize);
  100. },
  101. generateNewAppKeyPair: function () {
  102. var dialogData = $scope.dialogData
  103. if (!dialogData.aliPayApp.appid) {
  104. toaster.pop("warning", "提示", "请填写支付宝的APP ID!");
  105. return
  106. }
  107. $http({
  108. method: 'POST',
  109. url: '/common/generateNewAppKeyPair',
  110. data: {
  111. appid: dialogData.aliPayApp.appid,
  112. }
  113. }).then(function (response) {
  114. if (response.data.result) {
  115. toaster.pop("success", "提示", "生成成功!");
  116. $scope.dialogData.aliPayApp.app_private_key_path = response.data.payload.path;
  117. $scope.dialogData.aliPayApp.hasAlipayAppKeyPair = true;
  118. $scope.dialogData.aliPayApp.appPublicKeyContent = response.data.payload.appPublicKeyContent;
  119. } else {
  120. toaster.pop("error", "提示", "生成失败");
  121. }
  122. }, function (response) {
  123. toaster.pop("error", "提示", "生成失败!");
  124. });
  125. },
  126. };
  127. // 初始化一次
  128. $scope.event.managerInit();
  129. function setColumnDefs() {
  130. $scope.gridOptions.columnDefs = [
  131. {
  132. field: 'nickname', displayName: '代理商名称',
  133. cellTemplate: '<div class="temp-row" ng-class="{\' text-info\':row.entity.isPrimary}"><i class="fa fa-bullhorn text-success" title="已开启广告" ng-if="row.entity.adShow" ></i> <i class="fa fa-user" title="主代理商" ng-if="row.entity.isPrimary" ></i> {{row.entity.nickname}}</div>',
  134. },
  135. {field: 'username', displayName: '用户名'},
  136. {
  137. field: 'dateTimeAdded',
  138. displayName: '注册时间',
  139. cellTemplate: '<div class="temp-row" ng-bind="row.entity.dateTimeAdded"></div>'
  140. },
  141. {
  142. field: 'dealerTotal',
  143. displayName: '经销商总数',
  144. cellTemplate: '<div class="temp-row" ng-bind="row.entity.dealerTotal"></div>'
  145. },
  146. {
  147. field: 'annualTrafficCost',
  148. displayName: '流量年费下限',
  149. cellTemplate: '<div class="temp-row" ng-bind="row.entity.annualTrafficCost"></div>'
  150. },
  151. {
  152. field: 'trafficCardCost',
  153. displayName: '流量卡成本',
  154. cellTemplate: '<div class="temp-row" ng-bind="row.entity.trafficCardCost"></div>'
  155. },
  156. {
  157. field: 'productName',
  158. displayName: '产品名称',
  159. },
  160. {
  161. field: 'moniApps',
  162. displayName: '监督号',
  163. cellTemplate: '<div class="temp-row"><span ng-repeat="item in row.entity.moniApps">{{item.appName}};</span></div>'
  164. },
  165. {
  166. field: 'moniApps',
  167. displayName: '监督号位置',
  168. cellTemplate: '<div class="temp-row"><span ng-repeat="item in row.entity.pointDict" ng-class="{\'text-success\':item.switch}">{{item.name}};</span></div>'
  169. },
  170. {
  171. field: 'forceFollowGzh',
  172. displayName: '强制关注状态',
  173. },
  174. {
  175. field: 'forceFollowGzhForDealer',
  176. displayName: '经销商的是否允许关注',
  177. minWidth: 180,
  178. },
  179. // {
  180. // field: 'beforeChargeUnpay',
  181. // displayName: '使用前充值',
  182. // },
  183. {
  184. field: 'detail',
  185. displayName: '详细信息',
  186. cellTemplate: '<div class="temp-row" ng-click="grid.appScope.showInfoDetail(\'详细信息\',row.entity.detail)">{{row.entity.detail}}</div>'
  187. },
  188. {
  189. field: 'operation',
  190. displayName: '操作',
  191. enableFiltering: false,
  192. enableSorting: false,
  193. enableHiding: false,//禁止在列选择器中隐藏
  194. enableColumnMenu: false,// 是否显示列头部菜单按钮
  195. minWidth: 300,
  196. cellTemplate: '<div class="grid-button">' +
  197. '<button class="btn btn-sm btn-rounded btn-danger" ng-if="row.entity.status==\'normal\'" ng-click="grid.appScope.ban(row.entity,false)"><i class="fa fa-ban"></i> 封号</button>' +
  198. '<button class="btn btn-sm btn-rounded btn-success" ng-if="row.entity.status!==\'normal\'" ng-click="grid.appScope.ban(row.entity,true)"><i class="fa fa-unlock"></i> 解封</button>' +
  199. // '<button class="btn btn-sm btn-rounded btn-info"ng-click="grid.appScope.unfreeze(row.entity)"><i class="fa fa-smile-o"></i> 解除限制</button>' +
  200. '<button class="btn btn-sm btn-rounded btn-default" ng-click="grid.appScope.checkDealer(row.entity)"><i class="fa fa-users"></i> 经销商</button>' +
  201. '<button class="btn btn-sm btn-rounded btn-default" ng-click="grid.appScope.checkDevice(row.entity)"><i class="glyphicon glyphicon-phone"></i> 设备</button>' +
  202. '</div>'
  203. },
  204. ];
  205. var fields = $scope.gridOptions.columnDefs;
  206. for (var index in fields) {
  207. var item = fields[index];
  208. if (item && item['minWidth'] == null) {
  209. item['minWidth'] = 120;
  210. }
  211. }
  212. }
  213. $scope.setPagingData = function (data, curPage, pageSize) {
  214. var firstRow = (curPage - 1) * pageSize;
  215. var pagedData = data.data.dataList;
  216. $scope.myData = pagedData;
  217. $scope.gridOptions.totalItems = data.data.total;
  218. };
  219. $scope.getPagedDataAsync = function (curPage, pageSize, searchText) {
  220. if ($scope.gridOptionsLoading) {
  221. return;
  222. }
  223. var params = {
  224. adShow: condition.adShow.value,
  225. forceFollowGzh: condition.forceFollowGzh.value,
  226. forceFollowGzhForDealer: condition.forceFollowGzhForDealer.value,
  227. beforeChargeUnpay: condition.beforeChargeUnpay.value,
  228. pageSize: pageSize,
  229. pageIndex: curPage
  230. };
  231. if (condition.searchKey != "") {
  232. params.searchKey = condition.searchKey
  233. }
  234. // 路由参数也可能有managerId
  235. if (managerId) {
  236. params.managerId = managerId
  237. }
  238. // 也可以直接根据筛选条件进行查询,优先级高
  239. if (condition.manager.id && condition.manager.id != "") {
  240. params.managerId = condition.manager.id
  241. }
  242. // 路由参数也可能有moniAppId
  243. if (moniAppId) {
  244. params.moniAppId = moniAppId
  245. }
  246. $scope.gridOptionsLoading = true;
  247. $http.get('/superadmin/getAgentsDetailList', {
  248. params: params
  249. }).then(function (data) {
  250. data = data.data
  251. $scope.gridOptionsLoading = false;
  252. $scope.setPagingData(data, curPage, pageSize);
  253. }).catch(function (data) {
  254. toaster.pop("error", "提示", "获取数据列表失败");
  255. });
  256. };
  257. function initDataGrid() {
  258. //首次加载表格
  259. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  260. }
  261. setColumnDefs();
  262. initDataGrid();
  263. //封号|解封
  264. $scope.ban = function (entity, targetStatus) {
  265. var url = "/superadmin/toggleAgentStatus";
  266. $.confirm({
  267. content: '确定这样操作?',
  268. buttons: {
  269. ok: {
  270. btnClass: 'btn-red',
  271. action: function () {
  272. $http({
  273. method: 'POST',
  274. url: url,
  275. data: {
  276. id: entity.id,
  277. normal: targetStatus
  278. }
  279. }).then(function (response) {
  280. entity.normal = targetStatus;
  281. console.log(response);
  282. if (response.data.result) {
  283. toaster.pop("success", "提示", "修改状态成功!");
  284. } else {
  285. toaster.pop("error", "提示", "修改状态失败!");
  286. }
  287. }, function (response) {
  288. toaster.pop("error", "提示", "修改状态失败!");
  289. });
  290. }
  291. },
  292. }
  293. });
  294. };
  295. // 解除5次错误限制
  296. $scope.unfreeze = function (entity) {
  297. var entity = getOneRow();
  298. if (!entity) {
  299. return
  300. }
  301. var url = "/superadmin/unfreeze";
  302. $http({
  303. method: 'POST',
  304. url: url,
  305. data: {
  306. role: "agent",
  307. id: entity.id,
  308. }
  309. }).then(function (response) {
  310. if (response.data.result) {
  311. toaster.pop("success", "提示", "解除限制成功!");
  312. } else {
  313. toaster.pop("error", "提示", "解除限制失败!");
  314. }
  315. }, function (response) {
  316. toaster.pop("error", "提示", "解除限制失败!");
  317. });
  318. };
  319. function getOneRow() {
  320. var rows = $scope.gridApi.selection.getSelectedRows();
  321. if (rows.length === 0) {
  322. toaster.pop("info", "提示", "请选择数据!");
  323. return false;
  324. }
  325. if (rows.length > 1) {
  326. toaster.pop("info", "提示", "只能选中编辑一条数据");
  327. return false;
  328. }
  329. return rows[0]
  330. }
  331. /********************链接拷贝面板***********************/
  332. var copyLinkData = $scope.copyLinkData = {};
  333. var currentDomain = location.protocol + "//" + location.host;
  334. //生成推广链接
  335. $scope.openLinkPanel = function () {
  336. var entity = getOneRow();
  337. if (!entity) {
  338. return
  339. }
  340. $("#copyLinkPanel").modal();
  341. //经销商注册链接
  342. var url = currentDomain + "/dealerAccess?agentId=" + entity.id;
  343. copyLinkData.link1 = url;
  344. // 个人主页链接
  345. var url = currentDomain + "/userLogin?agentId=" + entity.id + "&redirect=" + encodeURIComponent("/user/index.html#/user/me");
  346. copyLinkData.link2 = url;
  347. // 用户地图链接
  348. var url = currentDomain + "/userLogin?agentId=" + entity.id + "&redirect=" + encodeURIComponent("/user/index.html#/user/index");
  349. copyLinkData.link3 = url;
  350. // 用户扫码
  351. var url = currentDomain + "/userLogin?agentId=" + entity.id + "&redirect=" + encodeURIComponent("/user/index.html#/dev");
  352. copyLinkData.link4 = url;
  353. };
  354. // 关闭链接生成器
  355. $scope.closeCopyLinkPanel = function () {
  356. $("#copyLinkPanel").modal("hide");
  357. };
  358. var clipboard;
  359. //事件绑定
  360. $timeout(function () {
  361. //在弹窗绑定 COPY组件
  362. clipboard = new ClipboardJS('.copyLinkBtn');
  363. clipboard.on('success', function (e) {
  364. e.clearSelection();
  365. toaster.pop("info", "提示", "复制成功");
  366. $scope.$apply();
  367. });
  368. clipboard.on('error', function (e) {
  369. toaster.pop("info", "提示", "请选择“拷贝”进行复制!");
  370. $scope.$apply();
  371. });
  372. });
  373. $scope.$on("$destroy", function () {
  374. if (clipboard) {
  375. clipboard.destroy();
  376. console.log("clipboard destroy");
  377. }
  378. });
  379. //查看经销商
  380. $scope.checkDealer = function (entity) {
  381. $state.go('app.user.dealer', {
  382. agentId: entity.id,
  383. managerId: ""
  384. }, {
  385. reload: true
  386. });
  387. };
  388. //查看设备
  389. $scope.checkDevice = function (entity) {
  390. $state.go('app.dev.devManage', {
  391. managerId: "",
  392. agentId: entity.id,
  393. dealerId: "",
  394. searchKey: "",
  395. }, {
  396. reload: true
  397. });
  398. };
  399. //展示详情
  400. $scope.showInfoDetail = function (title, content) {
  401. $scope.infoDetail = {title: title, content: content};
  402. $("#detailInfoPanel").modal();
  403. };
  404. $scope.closeDetailInfoPanel = function () {
  405. $("#detailInfoPanel").modal("hide");
  406. };
  407. // 必须先声明,否则ui-select无法双绑
  408. $scope.dialogData = {};
  409. // 配置特性
  410. $scope.editFeature = function () {
  411. var entity = getOneRow();
  412. if (!entity) {
  413. return
  414. }
  415. $scope.dialogData = {
  416. id: entity.id,
  417. featureList: entity.featureList,
  418. specialFeature: entity.specialFeature,
  419. };
  420. $("#featureForm").modal();
  421. }
  422. $scope.saveFeature = function () {
  423. if ($scope.featureForm.$invalid) {
  424. toaster.pop("warning", "提示", "请填写正确的数据");
  425. return
  426. }
  427. $.confirm({
  428. content: '确定要变更特性?',
  429. buttons: {
  430. ok: {
  431. btnClass: 'btn-red',
  432. action: function () {
  433. var url = "/superadmin/editAgentFeature";
  434. $http({
  435. method: 'POST',
  436. url: url,
  437. data: $scope.dialogData
  438. }).then(function (response) {
  439. //保存成功 弹窗消失
  440. $('#featureForm').modal('hide');
  441. if (response.data.result) {
  442. toaster.pop("info", "提示", "成功")
  443. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  444. }
  445. }, function (response) {
  446. toaster.pop("error", "提示", "保存失败!");
  447. });
  448. }
  449. },
  450. }
  451. });
  452. };
  453. //广告开关
  454. $scope.selectedIds = []
  455. function getSelectRows() {
  456. var rows = $scope.gridApi.selection.getSelectedRows();
  457. if (rows.length === 0) {
  458. toaster.pop("info", "提示", "请选择数据!");
  459. return false;
  460. }
  461. var ids = [];
  462. for (var i = 0; i < rows.length; i++) {
  463. ids.push(rows[i].id);
  464. }
  465. $scope.selectedIds = ids;
  466. return ids
  467. }
  468. $scope.editAdShow = function () {
  469. $scope.dialogData = {};
  470. if (getSelectRows()) {
  471. $("#editAdForm").modal();
  472. }
  473. }
  474. $scope.saveAdEdit = function () {
  475. var ids = $scope.selectedIds
  476. if ($scope.editAdForm.$invalid) {
  477. toaster.pop("warning", "提示", "请填写正确的数据");
  478. return
  479. }
  480. $http({
  481. method: 'POST',
  482. url: '/superadmin/editAdShow',
  483. data: {ids: ids, adShow: $scope.dialogData.adShow, role: "agent"}
  484. }).then(function (response) {
  485. initDataGrid();
  486. $('#editAdForm').modal('hide');
  487. toaster.pop("success", "提示", "保存成功!");
  488. }, function (response) {
  489. toaster.pop("error", "提示", "保存失败!");
  490. });
  491. }
  492. //流量卡配置
  493. $scope.editCardShow = function () {
  494. $scope.dialogData = {};
  495. if (getSelectRows()) {
  496. $("#editCardForm").modal();
  497. }
  498. }
  499. $scope.saveCardEdit = function () {
  500. var ids = $scope.selectedIds
  501. if ($scope.editCardForm.$invalid) {
  502. toaster.pop("warning", "提示", "请填写正确的数据");
  503. return
  504. }
  505. $http({
  506. method: 'POST',
  507. url: '/superadmin/setTrafficCardCost',
  508. data: {ids: ids, cost: $scope.dialogData.cost}
  509. }).then(function (response) {
  510. initDataGrid();
  511. $('#editCardForm').modal('hide');
  512. }, function (response) {
  513. toaster.pop("error", "提示", "保存失败!");
  514. });
  515. }
  516. // 编辑代理商
  517. $scope.editAgents = function (entity) {
  518. var entity = getOneRow();
  519. if (!entity) {
  520. return
  521. }
  522. $scope.dialogData = entity;
  523. $("#agentsForm").modal();
  524. }
  525. $scope.saveAgents = function () {
  526. if ($scope.agentsForm.$invalid) {
  527. toaster.pop("warning", "提示", "请填写正确的数据");
  528. return
  529. }
  530. $http({
  531. method: 'POST',
  532. url: '/superadmin/editUserInfo',
  533. data: {
  534. role: 'agent',
  535. id: $scope.dialogData.id,
  536. 'info': {
  537. username: $scope.dialogData.username,
  538. isChangingPaymentGateway: $scope.dialogData.isChangingPaymentGateway,
  539. maxPayLimit: $scope.dialogData.maxPayLimit,
  540. }
  541. }
  542. }).then(function (response) {
  543. initDataGrid();
  544. $('#agentsForm').modal('hide');
  545. }, function (response) {
  546. toaster.pop("error", "提示", "保存失败!");
  547. });
  548. }
  549. /*****************公众号*********************/
  550. $scope.editWechat = function () {
  551. //重置表单状态
  552. $scope.wechatForm.$setPristine();
  553. $scope.wechatForm.$setUntouched();
  554. var row = getOneRow();
  555. if (!row) {
  556. return
  557. }
  558. $scope.dialogData = $.extend({user: {}, dealer: {}, dealer_sub: {}, user_sub: {}}, row);//非深度克隆的优点是:如果不小心取消了,下次编辑时,子对象的数据还在
  559. $("#wechatForm").modal();
  560. }
  561. $scope.saveWechat = function () {
  562. var url = "/superadmin/bind_wechat_cust";
  563. var data = {};
  564. // 防止为空没填报错
  565. $scope.dialogData.dealer = $scope.dialogData.dealer || {};
  566. $scope.dialogData.dealer_sub = $scope.dialogData.dealer_sub || {};
  567. $scope.dialogData.user = $scope.dialogData.user || {};
  568. $scope.dialogData.user_sub = $scope.dialogData.user_sub || {};
  569. //编辑
  570. $.extend(data, {
  571. 'id': $scope.dialogData.id,
  572. customizedDealerGzhAllowable: $scope.dialogData.customizedDealerGzhAllowable,
  573. customizedDealerSubGzhAllowable: $scope.dialogData.customizedDealerSubGzhAllowable,
  574. dealer: {
  575. appid: $scope.dialogData.dealer.appid,
  576. secret: $scope.dialogData.dealer.secret,
  577. templateIdMap: $scope.dialogData.dealer.templateIdMap,
  578. name: $scope.dialogData.dealer.name,
  579. companyName: $scope.dialogData.dealer.companyName
  580. },
  581. dealer_sub: {
  582. appid: $scope.dialogData.dealer_sub.appid,
  583. secret: $scope.dialogData.dealer_sub.secret,
  584. templateIdMap: $scope.dialogData.dealer_sub.templateIdMap,
  585. name: $scope.dialogData.dealer_sub.name,
  586. companyName: $scope.dialogData.dealer_sub.companyName
  587. },
  588. customizedUserGzhAllowable: $scope.dialogData.customizedUserGzhAllowable,
  589. customizedUserSubGzhAllowable: $scope.dialogData.customizedUserSubGzhAllowable,
  590. user: {
  591. appid: $scope.dialogData.user.appid,
  592. secret: $scope.dialogData.user.secret,
  593. templateIdMap: $scope.dialogData.user.templateIdMap,
  594. name: $scope.dialogData.user.name,
  595. companyName: $scope.dialogData.user.companyName
  596. },
  597. user_sub: {
  598. appid: $scope.dialogData.user_sub.appid,
  599. secret: $scope.dialogData.user_sub.secret,
  600. templateIdMap: $scope.dialogData.user_sub.templateIdMap,
  601. name: $scope.dialogData.user_sub.name,
  602. companyName: $scope.dialogData.user_sub.companyName
  603. },
  604. })
  605. $http({
  606. method: 'POST',
  607. url: url,
  608. data: data
  609. }).then(function (response) {
  610. $('#wechatForm').modal('hide');//弹窗消失
  611. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  612. }, function (response) {
  613. toaster.pop("error", "提示", "操作失败!");
  614. });
  615. };
  616. /*****************资金池*********************/
  617. $scope.cashPoolWechat = function () {
  618. //重置表单状态
  619. $scope.cashPoolWechatForm.$setPristine();
  620. $scope.cashPoolWechatForm.$setUntouched();
  621. var row = getOneRow();
  622. if (!row) {
  623. return
  624. }
  625. $scope.dialogData = $.extend({wechatPayApp: {}}, row);//非深度克隆的优点是:如果不小心取消了,下次编辑时,子对象的数据还在
  626. $("#cashPoolWechatForm").modal();
  627. };
  628. $scope.cashPoolAlipay = function () {
  629. //重置表单状态
  630. $scope.cashPoolAlipayForm.$setPristine();
  631. $scope.cashPoolAlipayForm.$setUntouched();
  632. var row = getOneRow();
  633. if (!row) {
  634. return
  635. }
  636. $scope.dialogData = $.extend({aliPayApp: {}}, row);//非深度克隆的优点是:如果不小心取消了,下次编辑时,子对象的数据还在
  637. $("#cashPoolAlipayForm").modal();
  638. };
  639. $scope.changeFile = function (files,key) {
  640. if (files.length) {
  641. var file = files[0];
  642. var reader = new FileReader();
  643. // 文件不能大于1M
  644. if (file.size > 1000 * 1024) {
  645. toaster.pop("info", "提示", "文件太大,请重新选择");
  646. } else {
  647. reader.onload = function() {
  648. if(reader.result) {
  649. var text = reader.result
  650. $scope.dialogData.wechatPayApp[key] = btoa(text)
  651. $scope.$apply();
  652. }
  653. };
  654. reader.readAsText(file);
  655. }
  656. }
  657. }
  658. /***********监督号************/
  659. $scope.moniApps = []
  660. $http.get('/superadmin/getMoniApps', {
  661. params: {
  662. pageSize: 1000,
  663. pageIndex: 1
  664. }
  665. }).then(function (res) {
  666. var payload = res.data.payload;
  667. $scope.moniApps = payload.dataList;
  668. }).catch(function (data) {
  669. toaster.pop("error", "提示", "获取监督号列表失败");
  670. });
  671. $scope.moniConfig = function () {
  672. var ids = getSelectRows()
  673. if (ids) {
  674. $("#moniConfigForm").modal();
  675. $scope.dialogData = {}
  676. for (var key in $scope.moniApps) {
  677. var item = $scope.moniApps[key]
  678. $scope.dialogData[item.appId] = false
  679. }
  680. }
  681. };
  682. $scope.setMoniAppId = function (appId) {
  683. var data = {
  684. agentIds: $scope.selectedIds,
  685. moniApp: [],
  686. }
  687. // 单个保存
  688. if (appId) {
  689. data.moniApp.push({
  690. appId: appId,
  691. switch: $scope.dialogData[appId] || false,// 默认为false
  692. })
  693. } else {
  694. var tempApp = []
  695. for (var key in $scope.dialogData) {
  696. tempApp.push({
  697. appId: key,
  698. switch: $scope.dialogData[key] || false,// 默认为false
  699. })
  700. }
  701. data.moniApp = tempApp
  702. }
  703. $http({
  704. method: 'POST',
  705. url: "/superadmin/editMoniAppForAgents",
  706. data: data
  707. }).then(function (response) {
  708. toaster.pop("success", "提示", "保存成功!");
  709. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  710. //批量保存关闭弹窗
  711. if (!appId) {
  712. $('#moniConfigForm').modal('hide');//弹窗消失
  713. }
  714. }, function (response) {
  715. toaster.pop("error", "提示", "保存失败!");
  716. });
  717. };
  718. /**监督号展现位置**/
  719. $scope.moniPoint = []
  720. $http.get('/superadmin/getMoniPointList', {
  721. params: {
  722. pageSize: 1000,
  723. pageIndex: 1
  724. }
  725. }).then(function (res) {
  726. var payload = res.data.payload;
  727. $scope.moniPoint = payload.dataList;
  728. }).catch(function (data) {
  729. toaster.pop("error", "提示", "获取监督号展现位置列表失败");
  730. });
  731. $scope.moniPointConfig = function () {
  732. var ids = getSelectRows()
  733. if (ids) {
  734. $("#moniPointForm").modal();
  735. $scope.dialogData = {}
  736. for (var key in $scope.moniPoint) {
  737. var item = $scope.moniPoint[key]
  738. $scope.dialogData[item.key] = false
  739. }
  740. }
  741. };
  742. $scope.setMoniPoint = function (pointKey) {
  743. var data = {
  744. agentIds: $scope.selectedIds,
  745. moniPoint: [],
  746. }
  747. // 单个保存
  748. if (pointKey) {
  749. data.moniPoint.push({
  750. key: pointKey,
  751. switch: $scope.dialogData[pointKey] || false,// 默认为false
  752. })
  753. } else {
  754. var tempApp = []
  755. for (var key in $scope.dialogData) {
  756. tempApp.push({
  757. key: key,
  758. switch: $scope.dialogData[key] || false,// 默认为false
  759. })
  760. }
  761. data.moniPoint = tempApp
  762. }
  763. $http({
  764. method: 'POST',
  765. url: "/superadmin/editMoniPointForAgents",
  766. data: data
  767. }).then(function (response) {
  768. toaster.pop("success", "提示", "保存成功!");
  769. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  770. //批量保存关闭弹窗
  771. if (!pointKey) {
  772. $('#moniPointForm').modal('hide');//弹窗消失
  773. }
  774. }, function (response) {
  775. toaster.pop("error", "提示", "保存失败!");
  776. });
  777. };
  778. // 强制关注公众号
  779. $scope.forceFollowGzh = function () {
  780. $scope.dialogData = {};
  781. var rows = getSelectRows()
  782. if (rows) {
  783. $("#editGzhForm").modal();
  784. }
  785. }
  786. $scope.saveGzg = function () {
  787. var ids = $scope.selectedIds
  788. if ($scope.editGzhForm.$invalid) {
  789. toaster.pop("warning", "提示", "请填写正确的数据");
  790. return
  791. }
  792. $http({
  793. method: 'POST',
  794. url: '/superadmin/editAgentForceFollowGzh',
  795. data: {
  796. ids: ids,
  797. forceFollowGzh: $scope.dialogData.forceFollowGzh,
  798. forceFollowGzhForDealer: $scope.dialogData.forceFollowGzhForDealer
  799. }
  800. }).then(function (response) {
  801. initDataGrid();
  802. $('#editGzhForm').modal('hide');
  803. toaster.pop("success", "提示", "保存成功!");
  804. }, function (response) {
  805. toaster.pop("error", "提示", "保存失败!");
  806. });
  807. }
  808. $scope.editSupporter = function () {
  809. $scope.dialogData = {};
  810. var rows = getSelectRows()
  811. if (rows) {
  812. $("#editSupporterForm").modal();
  813. }
  814. }
  815. $scope.saveSuporter = function () {
  816. var ids = $scope.selectedIds
  817. if ($scope.editSupporterForm.$invalid) {
  818. toaster.pop("warning", "提示", "请填写正确的数据");
  819. return
  820. }
  821. $http({
  822. method: 'POST',
  823. url: '/superadmin/editSupporterForAgents',
  824. data: {
  825. ids: ids,
  826. platformSupport: $scope.dialogData.platformSupport
  827. }
  828. }).then(function (response) {
  829. initDataGrid();
  830. $('#editSupporterForm').modal('hide');
  831. toaster.pop("success", "提示", "保存成功!");
  832. }, function (response) {
  833. toaster.pop("error", "提示", "保存失败!");
  834. });
  835. }
  836. // 使用前充值
  837. $scope.openSaveBeforeCharge = function () {
  838. $scope.dialogData = {};
  839. var rows = getSelectRows()
  840. if (rows) {
  841. $("#beforeChargeUnpayForm").modal();
  842. }
  843. }
  844. $scope.saveBeforeChargeUnpay = function () {
  845. var ids = $scope.selectedIds
  846. if ($scope.beforeChargeUnpayForm.$invalid) {
  847. toaster.pop("warning", "提示", "请填写正确的数据");
  848. return
  849. }
  850. $http({
  851. method: 'POST',
  852. url: '/superadmin/editDealerBeforeChargeUnpay',
  853. data: {ids: ids, beforeChargeUnpay: $scope.dialogData.beforeChargeUnpay}
  854. }).then(function (response) {
  855. initDataGrid();
  856. $('#beforeChargeUnpayForm').modal('hide');
  857. toaster.pop("success", "提示", "保存成功!");
  858. }, function (response) {
  859. toaster.pop("error", "提示", "保存失败!");
  860. });
  861. }
  862. //编辑密码 默认123456
  863. $scope.editPassword = function () {
  864. //重置表单状态
  865. $scope.passwordForm.$setPristine();
  866. $scope.passwordForm.$setUntouched();
  867. var rows = $scope.gridApi.selection.getSelectedRows();
  868. if (rows.length == 0) {
  869. toaster.pop("info", "提示", "请选择数据!");
  870. return;
  871. }
  872. if (rows.length > 1) {
  873. toaster.pop("info", "提示", "只能选中编辑一条数据");
  874. return;
  875. }
  876. var item = rows[0];
  877. $scope.passwordData = $.extend({password: 123456}, item);
  878. $("#passwordPanel").modal();
  879. };
  880. //修改密码提交
  881. $scope.savePassword = function () {
  882. //表单未校验通过不能提交
  883. if ($scope.passwordForm.$invalid) {
  884. return;
  885. }
  886. var url = "/superadmin/changeAgentPassword"
  887. var password = MD5.createHash($scope.passwordData.password + '');
  888. $http({
  889. method: 'POST',
  890. url: url,
  891. data: {
  892. id: $scope.passwordData.id,
  893. password: password,
  894. }
  895. }).then(function (response) {
  896. $('#passwordPanel').modal('hide');//弹窗消失
  897. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  898. }, function (response) {
  899. toaster.pop("error", "提示", "修改密码失败!");
  900. });
  901. };
  902. $scope.setDisclaimer = function () {
  903. var entity = getOneRow();
  904. if (!entity) {
  905. return
  906. }
  907. $state.go('app.user.disclaimer', {
  908. agentId: entity.id,
  909. agentName: entity.nickname,
  910. });
  911. }
  912. $scope.editDeviceType = function () {
  913. var entity = getOneRow();
  914. if (!entity) {
  915. return
  916. }
  917. if (entity.isPrimary) {
  918. toaster.pop("warning", "提示", "该角色是主代理商,不能配置!");
  919. return
  920. }
  921. $("#editDeviceTypePanel").modal();
  922. $scope.dialogName = entity.nickname + "配置设备类型";
  923. $("#dealerDevList").modal();
  924. // todo 由于ui-grid 之前隐藏,表格渲染有问题
  925. setTimeout(function () {
  926. // 刷新设备
  927. $scope.$broadcast("initDriverCodeList", {id: entity.id, role: "agent"});
  928. }, 100);
  929. };
  930. $scope.closeDeviceConfig = function (entity) {
  931. $("#editDeviceTypePanel").modal('hide');
  932. };
  933. }]);