dealerManage.js 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216
  1. app.controller('dealerManageCtrl', ['$scope', "$state", '$stateParams', '$http', '$timeout', 'uiGridConstants', 'i18nService', 'toaster', 'md5', function ($scope, $state, $stateParams, $http, $timeout, uiGridConstants, i18nService, toaster, MD5) {
  2. i18nService.setCurrentLang("zh-cn");
  3. var managerId = $stateParams.managerId;
  4. var agentId = $stateParams.agentId;
  5. $scope.gridOptions = {
  6. data: 'myData',
  7. showGridFooter: true, //是否显示grid footer
  8. // rowHeight: 80,
  9. //-------- 分页属性 ----------------
  10. paginationPageSizes: [50, 200, 500, 1000, 2000], //每页显示个数可选项
  11. paginationCurrentPage: 1, //当前页码
  12. paginationPageSize: 50, //每页显示个数
  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. $scope.ngEvent = {
  29. changeProvince: function (bankInfo) {
  30. console.log("changeProvince")
  31. //无论是否选择了数据,都清空子级下拉框选中的项
  32. bankInfo.bankCity = null;
  33. var bankProvinceID = bankInfo.bankProvince.value;
  34. if (bankProvinceID)
  35. $scope.searchArea(bankProvinceID,bankInfo)
  36. else
  37. bankInfo.cityList = []
  38. }
  39. }
  40. //枚举常量
  41. $scope.enum = {};
  42. $scope.enum.adShow = [
  43. {value: "", label: "-广告状态-"},
  44. {value: false, label: "无广告"},
  45. {value: true, label: "有广告"}
  46. ];
  47. $scope.enum.forceFollowGzh = [
  48. {value: "", label: "-强制关注状态-"},
  49. {value: "agent", label: "以代理商为准"},
  50. {value: "yes", label: "强制关注"},
  51. {value: "no", label: "不允许强制关注"},
  52. {value: "never", label: "永不强制关注公众号"},
  53. {value: "free", label: "自由选择"},
  54. ];
  55. $scope.enum.platformSupport = [
  56. {value: "", label: "-客服接管状态-"},
  57. {value: "agent", label: "以代理商为准"},
  58. {value: "yes", label: "需要平台"},
  59. {value: "no", label: "不需要平台"},
  60. {value: "never", label: "永远用自己的客服"},
  61. {value: "free", label: "无所谓"},
  62. ];
  63. $scope.enum.beforeChargeUnpay = [
  64. {value: "", label: "-使用前充值-"},
  65. {value: "yes", label: "是"},
  66. {value: "no", label: "否"},
  67. {value: "never", label: "永不"},
  68. {value: "free", label: "自由选择"},
  69. ];
  70. $scope.findEnum = function (list, value) {
  71. return list.find((item) => item.value === value)
  72. }
  73. var managerDefault = {"nickname": "厂商"}
  74. var agentDefault = {"nickname": "代理商"}
  75. //查询条件
  76. var condition = $scope.condition = {
  77. adShow: $.extend({}, $scope.enum.adShow[0]),
  78. forceFollowGzh: $.extend({}, $scope.enum.forceFollowGzh[0]),
  79. beforeChargeUnpay: $.extend({}, $scope.enum.beforeChargeUnpay[0]),
  80. managerDefault: managerDefault,
  81. managerList: [managerDefault],
  82. manager: managerDefault,
  83. agentDefault: agentDefault,
  84. agentList: [agentDefault],
  85. agent: agentDefault,
  86. searchKey: "",
  87. };
  88. var searchTimer = null;
  89. //事件
  90. $scope.event = {
  91. statusChange: function (key, item) {
  92. condition[key].value = item.value;
  93. condition[key].label = item.label;
  94. this.search()
  95. },
  96. managerInit: function ($event) {
  97. var searchKey = $event ? $event.target.value : "";
  98. $timeout.cancel(searchTimer);
  99. searchTimer = $timeout(function () {
  100. $http.get('/superadmin/getManagerList', {
  101. params: {
  102. pageSize: 1000,
  103. pageIndex: 1,
  104. searchKey: searchKey,
  105. }
  106. }).then(function (data) {
  107. data = data.data
  108. $scope.condition.managerList = data.data.dataList;
  109. }).catch(function (data) {
  110. toaster.pop("error", "提示", "搜索失败");
  111. });
  112. }, 500);//延迟搜索,否则请求太频繁
  113. },
  114. agentInit: function ($event) {
  115. var searchKey = $event.target.value;
  116. var managerId = "";
  117. if (condition.manager.id != "") {
  118. managerId = condition.manager.id
  119. }
  120. $timeout.cancel(searchTimer);
  121. searchTimer = $timeout(function () {
  122. $http.get('/superadmin/getAgentsDetailList', {
  123. params: {
  124. pageSize: 1000,
  125. pageIndex: 1,
  126. searchKey: searchKey,
  127. managerId: managerId,
  128. }
  129. }).then(function (data) {
  130. data = data.data
  131. $scope.condition.agentList = data.data.dataList;
  132. }).catch(function (data) {
  133. toaster.pop("error", "提示", "搜索失败");
  134. });
  135. }, 500);//延迟搜索,否则请求太频繁
  136. },
  137. search: function () {
  138. $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize);
  139. }
  140. };
  141. // 初始化一次
  142. $scope.event.managerInit();
  143. function setColumnDefs() {
  144. $scope.gridOptions.columnDefs = [
  145. {
  146. field: 'nickname', displayName: '商家名称',
  147. cellTemplate: '<div class="temp-row">' +
  148. '<i class="fa fa-bullhorn text-success" title="已开启广告" ng-if="row.entity.adShow" ></i>' +
  149. ' {{row.entity.nickname}} ' +
  150. '<i class="fa fa-lock text-warning" title="被锁定" ng-if="!row.entity.status==\'normal\'" ></i>' +
  151. ' </div>',
  152. },
  153. {field: 'username', displayName: '用户名'},
  154. {
  155. field: 'createdTime',
  156. displayName: '注册时间',
  157. cellTemplate: '<div class="temp-row" ng-bind="row.entity.dateTimeAdded"></div>'
  158. },
  159. {
  160. field: 'annualTrafficCost',
  161. displayName: '流量卡年费',
  162. cellTemplate: '<div class="temp-row" ng-bind="row.entity.annualTrafficCost"></div>'
  163. },
  164. {
  165. field: 'balance',
  166. displayName: '商家余额',
  167. cellTemplate: '<div class="temp-row" ng-bind="row.entity.balance| currency:\'¥\'"></div>'
  168. },
  169. {
  170. field: 'withdrawFeeRatio',
  171. displayName: '提现手续费',
  172. cellTemplate: '<div class="temp-row">{{row.entity.withdrawFeeRatio+"‰"}}</div>',
  173. },
  174. {
  175. field: 'agentInfo',
  176. displayName: '代理商',
  177. },
  178. {
  179. field: 'productName',
  180. displayName: '产品名称',
  181. },
  182. {
  183. field: 'agentForceFollowGzh',
  184. displayName: '代理商强制关注',
  185. minWidth: 140,
  186. },
  187. {
  188. field: 'moniAppName',
  189. displayName: '监督号名称',
  190. },
  191. {
  192. field: 'pointDict',
  193. displayName: '监督号位置',
  194. cellTemplate: '<div class="temp-row"><span ng-repeat="item in row.entity.pointDict" ng-class="{\'text-success\':item.switch}">{{item.name}};</span></div>'
  195. },
  196. {
  197. field: 'forceFollowGzh',
  198. displayName: '强制关注公众号',
  199. minWidth: 140,
  200. },
  201. {
  202. field: 'devCount',
  203. displayName: '设备数量',
  204. },
  205. // {
  206. // field: 'beforeChargeUnpay',
  207. // displayName: '使用前充值',
  208. // },
  209. {
  210. field: 'maxPackagePrice',
  211. displayName: '最大套餐价格',
  212. },
  213. {
  214. field: 'detail',
  215. displayName: '详细信息',
  216. cellTemplate: '<div class="temp-row" ng-click="grid.appScope.showInfoDetail(\'详细信息\',row.entity.detail)" >{{row.entity.detail}}</div>'
  217. },
  218. {
  219. field: 'status',
  220. displayName: '状态',
  221. cellTemplate: '<div class="temp-row" >{{row.entity.status}}</div>'
  222. },
  223. ];
  224. var operCol = {
  225. field: 'operation',
  226. displayName: '操作',
  227. enableFiltering: false,
  228. enableSorting: false,
  229. enableHiding: false,//禁止在列选择器中隐藏
  230. enableColumnMenu: false,// 是否显示列头部菜单按钮
  231. minWidth: 320,
  232. cellTemplate: '<div class="grid-button">' +
  233. '<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>' +
  234. '<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>' +
  235. // '<button class="btn btn-sm btn-rounded btn-info"ng-click="grid.appScope.unfreeze(row.entity)"><i class="fa fa-smile-o"></i> 解除限制</button>' +
  236. '<button class="btn btn-sm btn-rounded btn-danger" ng-if="row.entity.status==\'normal\'" ng-click="grid.appScope.toggleDealerWithdrawStatus(row.entity,true)"><i class="fa fa-ban"></i> 禁止提现</button>' +
  237. '<button class="btn btn-sm btn-rounded btn-success" ng-if="row.entity.status!==\'normal\'" ng-click="grid.appScope.toggleDealerWithdrawStatus(row.entity,false)"><i class="fa fa-unlock"></i> 允许提现</button>' +
  238. '<button class="btn btn-sm btn-rounded btn-danger" ng-click="grid.appScope.editFeature(row.entity)"><i class="fa fa-cubes"></i> 配置特性</button>' +
  239. '<button class="btn btn-sm btn-rounded btn-default" ng-click="grid.appScope.checkDevice(row.entity)"><i class="glyphicon glyphicon-phone"></i> 设备</button>' +
  240. '</div>'
  241. };
  242. $scope.gridOptions.columnDefs.push(operCol)
  243. var fields = $scope.gridOptions.columnDefs;
  244. for (var index in fields) {
  245. var item = fields[index];
  246. if (item && item['minWidth'] == null) {
  247. item['minWidth'] = 120;
  248. }
  249. }
  250. }
  251. $scope.setPagingData = function (data, curPage, pageSize) {
  252. var firstRow = (curPage - 1) * pageSize;
  253. var pagedData = data.data.dataList;
  254. $scope.myData = pagedData;
  255. $scope.gridOptions.totalItems = data.data.total;
  256. };
  257. $scope.getPagedDataAsync = function (curPage, pageSize, searchText) {
  258. if ($scope.gridOptionsLoading) {
  259. return;
  260. }
  261. var params = {
  262. forceFollowGzh: condition.forceFollowGzh.value,
  263. beforeChargeUnpay: condition.beforeChargeUnpay.value,
  264. devCountMin: condition.devCountMin,
  265. devCountMax: condition.devCountMax,
  266. adShow: condition.adShow.value,
  267. pageSize: pageSize,
  268. pageIndex: curPage
  269. };
  270. if (condition.searchKey != "") {
  271. params.searchKey = condition.searchKey
  272. }
  273. // 路由参数也可能有managerId
  274. if (managerId) {
  275. params.managerId = managerId
  276. }
  277. if (agentId) {
  278. params.agentId = agentId
  279. }
  280. if (condition.manager.id && condition.manager.id != "") {
  281. params.managerId = condition.manager.id
  282. }
  283. if (condition.agent.id && condition.agent.id != "") {
  284. params.agentId = condition.agent.id
  285. }
  286. $scope.gridOptionsLoading = true;
  287. $http.get('/superadmin/getDealerDetailList', {
  288. params: params
  289. }).then(function (data) {
  290. data = data.data
  291. $scope.gridOptionsLoading = false;
  292. $scope.setPagingData(data, curPage, pageSize);
  293. }).catch(function (data) {
  294. toaster.pop("error", "提示", "获取数据列表失败");
  295. });
  296. };
  297. function initDataGrid() {
  298. //首次加载表格
  299. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  300. }
  301. setColumnDefs();
  302. // initDataGrid(); 由于比较卡,初始化不加载
  303. //广告开关
  304. $scope.selectedIds = []
  305. function getSelectRows() {
  306. var rows = $scope.gridApi.selection.getSelectedRows();
  307. if (rows.length === 0) {
  308. toaster.pop("info", "提示", "请选择数据!");
  309. return false;
  310. }
  311. var ids = [];
  312. for (var i = 0; i < rows.length; i++) {
  313. ids.push(rows[i].id);
  314. }
  315. $scope.selectedIds = ids;
  316. return ids
  317. }
  318. $scope.provinceList = []
  319. $scope.searchSubBank = function (bankInfo) {
  320. let form = bankInfo
  321. $http.get('/common/withdraw/branchBank/list', {
  322. params: {
  323. bankCode: form?.bankItem?.value,
  324. provinceCode: form?.bankProvince?.value,
  325. cityCode: form?.bankCity?.value,
  326. }
  327. }).then(function (data) {
  328. data = data.data
  329. let {payload} = data
  330. let list = payload?.dataList || []
  331. list = list.map(item => ({
  332. text: item.name,
  333. value: item.code,
  334. }))
  335. bankInfo.branchBankList = list;
  336. }).catch(function (data) {
  337. toaster.pop("error", "提示", "支行获取失败");
  338. });
  339. }
  340. $scope.searchBank = function (bankInfo) {
  341. bankInfo.bankList = []
  342. $http.get('/common/withdraw/bank/list', {
  343. params: {
  344. keyWord: bankInfo.keyWord,
  345. range: 'all'
  346. }
  347. }).then(function (data) {
  348. var bankList = data.data.payload.dataList
  349. bankList.forEach(function (item, index) {
  350. bankInfo.bankList.push({value: item.code, text: item.name})
  351. })
  352. });
  353. }
  354. $scope.searchArea = function (province, bankInfo) {
  355. return new Promise((resolve => {
  356. //加载地址列表
  357. $http.get('/common/withdraw/area/list', {params: {province: province || ""}}).then(function (data) {
  358. data = data.data
  359. var payload = data.payload
  360. let dataRe = (payload.dataList || []).map(item => {
  361. return {
  362. ...item,
  363. text: item.name,
  364. value: item.code,
  365. }
  366. })
  367. if (province) {
  368. bankInfo.cityList = dataRe
  369. } else {
  370. $scope.provinceList = dataRe
  371. }
  372. resolve()
  373. });
  374. }))
  375. }
  376. $scope.searchArea();// 加载省
  377. //封号|解封
  378. $scope.ban = function (entity, isNormal) {
  379. var url = "/superadmin/toggleDealerStatus";
  380. $.confirm({
  381. content: '确定这样操作?',
  382. buttons: {
  383. ok: {
  384. btnClass: 'btn-red',
  385. action: function () {
  386. $http({
  387. method: 'POST',
  388. url: url,
  389. data: {
  390. id: entity.id,
  391. normal: isNormal
  392. }
  393. }).then(function (response) {
  394. if (isNormal) {
  395. entity.status = "normal";
  396. } else {
  397. entity.status = "ban";
  398. }
  399. console.log(response);
  400. if (response.data.result) {
  401. toaster.pop("success", "提示", "修改状态成功!");
  402. } else {
  403. toaster.pop("error", "提示", "修改状态失败!");
  404. }
  405. }, function (response) {
  406. toaster.pop("error", "提示", "修改状态失败!");
  407. });
  408. }
  409. },
  410. }
  411. });
  412. };
  413. function getOneRow() {
  414. var rows = $scope.gridApi.selection.getSelectedRows();
  415. if (rows.length === 0) {
  416. toaster.pop("info", "提示", "请选择数据!");
  417. return false;
  418. }
  419. if (rows.length > 1) {
  420. toaster.pop("info", "提示", "只能选中编辑一条数据");
  421. return false;
  422. }
  423. return rows[0]
  424. }
  425. // 解除5次错误限制
  426. $scope.unfreeze = function (entity) {
  427. var entity = getOneRow();
  428. if (!entity) {
  429. return
  430. }
  431. var url = "/superadmin/unfreeze";
  432. $http({
  433. method: 'POST',
  434. url: url,
  435. data: {
  436. role: "dealer",
  437. id: entity.id,
  438. }
  439. }).then(function (response) {
  440. if (response.data.result) {
  441. toaster.pop("success", "提示", "解除限制成功!");
  442. } else {
  443. toaster.pop("error", "提示", "解除限制失败!");
  444. }
  445. }, function (response) {
  446. toaster.pop("error", "提示", "解除限制失败!");
  447. });
  448. };
  449. // 解除注册限制
  450. $scope.unlockRegisterLimit = function () {
  451. var entity = getOneRow();
  452. if (!entity) {
  453. return
  454. }
  455. var url = "/superadmin/unlockRegisterLimit";
  456. $http({
  457. method: 'POST',
  458. url: url,
  459. data: {
  460. role: "dealer",
  461. id: entity.id,
  462. }
  463. }).then(function (response) {
  464. if (response.data.result) {
  465. toaster.pop("success", "提示", "解除限制成功!");
  466. } else {
  467. toaster.pop("error", "提示", "解除限制失败!");
  468. }
  469. }, function (response) {
  470. toaster.pop("error", "提示", "解除限制失败!");
  471. });
  472. };
  473. // 允许|禁止提现
  474. $scope.toggleDealerWithdrawStatus = function (entity, noWithdraw) {
  475. var url = "/superadmin/toggleDealerWithdrawStatus";
  476. $.confirm({
  477. content: '确定这样操作?',
  478. buttons: {
  479. ok: {
  480. btnClass: 'btn-red',
  481. action: function () {
  482. $http({
  483. method: 'POST',
  484. url: url,
  485. data: {
  486. dealer_id: entity.id,
  487. noWithdraw: noWithdraw
  488. }
  489. }).then(function (response) {
  490. if (noWithdraw) {
  491. entity.status = "noWithdraw"; // 仅仅用于刷新显示效果
  492. } else {
  493. entity.status = "normal";
  494. }
  495. console.log(response);
  496. if (response.data.result) {
  497. toaster.pop("success", "提示", "提现功能切换成功!");
  498. } else {
  499. toaster.pop("error", "提示", "提现功能切换失败!");
  500. }
  501. }, function (response) {
  502. toaster.pop("error", "提示", "提现功能切换失败!");
  503. });
  504. }
  505. },
  506. }
  507. });
  508. };
  509. //查看设备
  510. $scope.checkDevice = function (entity) {
  511. if (entity.id == null) {
  512. toaster.pop("error", "提示", "接口缺少经销商id!");
  513. return
  514. }
  515. $state.go('app.dev.devManage', {
  516. managerId: "",
  517. agentId: "",
  518. dealerId: entity.id || "",
  519. searchKey: "",
  520. }, {
  521. reload: true
  522. });
  523. };
  524. //展示详情
  525. $scope.showInfoDetail = function (title, content) {
  526. if (content) {
  527. $scope.infoDetail = {title: title, content: JSON.parse(content)};
  528. $("#detailInfoPanel").modal();
  529. } else {
  530. toaster.pop("info", "提示", "没有更多信息");
  531. }
  532. }
  533. $scope.closeDetailInfoPanel = function () {
  534. $("#detailInfoPanel").modal("hide");
  535. };
  536. // 必须先声明,否则ui-select无法双绑
  537. $scope.dialogData = {};
  538. // 配置特性
  539. $scope.editFeature = function (entity) {
  540. $scope.dialogData = {
  541. id: entity.id,
  542. featureList: entity.featureList,
  543. specialFeature: entity.specialFeature,
  544. };
  545. $("#featureForm").modal();
  546. }
  547. $scope.saveFeature = function () {
  548. if ($scope.featureForm.$invalid) {
  549. toaster.pop("warning", "提示", "请填写正确的数据");
  550. return
  551. }
  552. $.confirm({
  553. content: '确定要变更特性?',
  554. buttons: {
  555. ok: {
  556. btnClass: 'btn-red',
  557. action: function () {
  558. var url = "/superadmin/editDealerFeature";
  559. $http({
  560. method: 'POST',
  561. url: url,
  562. data: $scope.dialogData
  563. }).then(function (response) {
  564. //保存成功 弹窗消失
  565. $('#featureForm').modal('hide');
  566. if (response.data.result) {
  567. toaster.pop("info", "提示", "成功");
  568. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  569. }
  570. }, function (response) {
  571. toaster.pop("error", "提示", "保存失败!");
  572. });
  573. }
  574. },
  575. }
  576. });
  577. };
  578. //广告开关
  579. $scope.selectedIds = []
  580. $scope.editAdShow = function () {
  581. $scope.dialogData = {};
  582. var rows = getSelectRows()
  583. if (rows) {
  584. $("#editAdForm").modal();
  585. }
  586. }
  587. $scope.saveAdEdit = function () {
  588. var ids = $scope.selectedIds
  589. if ($scope.editAdForm.$invalid) {
  590. toaster.pop("warning", "提示", "请填写正确的数据");
  591. return
  592. }
  593. $http({
  594. method: 'POST',
  595. url: '/superadmin/editAdShow',
  596. data: {ids: ids, adShow: $scope.dialogData.adShow, role: "dealer"}
  597. }).then(function (response) {
  598. initDataGrid();
  599. $('#editAdForm').modal('hide');
  600. toaster.pop("success", "提示", "保存成功!");
  601. }, function (response) {
  602. toaster.pop("error", "提示", "保存失败!");
  603. });
  604. }
  605. // 强制关注公众号
  606. $scope.forceFollowGzh = function () {
  607. $scope.dialogData = {};
  608. var rows = getSelectRows()
  609. if (rows) {
  610. $("#editGzhForm").modal();
  611. }
  612. }
  613. $scope.saveGzg = function () {
  614. var ids = $scope.selectedIds
  615. if ($scope.editGzhForm.$invalid) {
  616. toaster.pop("warning", "提示", "请填写正确的数据");
  617. return
  618. }
  619. $http({
  620. method: 'POST',
  621. url: '/superadmin/editDealerFollowGzh',
  622. data: {ids: ids, forceFollowGzh: $scope.dialogData.forceFollowGzh}
  623. }).then(function (response) {
  624. initDataGrid();
  625. $('#editGzhForm').modal('hide');
  626. toaster.pop("success", "提示", "保存成功!");
  627. }, function (response) {
  628. toaster.pop("error", "提示", "保存失败!");
  629. });
  630. }
  631. // 编辑
  632. $scope.editDealer = function (entity) {
  633. var rows = $scope.gridApi.selection.getSelectedRows();
  634. if (rows.length === 0) {
  635. toaster.pop("info", "提示", "请选择数据!");
  636. return;
  637. }
  638. if (rows.length > 1) {
  639. toaster.pop("info", "提示", "只能选中编辑一条数据");
  640. return;
  641. }
  642. $scope.dialogData = rows[0];
  643. $("#dealerForm").modal();
  644. }
  645. $scope.saveDealer = function () {
  646. if ($scope.dealerForm.$invalid) {
  647. toaster.pop("warning", "提示", "请填写正确的数据");
  648. return
  649. }
  650. $http({
  651. method: 'POST',
  652. url: '/superadmin/editUserInfo',
  653. data: {role: 'dealer', id: $scope.dialogData.id, 'info': {username: $scope.dialogData.username}}
  654. }).then(function (response) {
  655. initDataGrid();
  656. $('#dealerForm').modal('hide');
  657. }, function (response) {
  658. toaster.pop("error", "提示", "保存失败!");
  659. });
  660. }
  661. /**监督号展现位置**/
  662. $scope.moniPoint = []
  663. $http.get('/superadmin/getMoniPointList', {
  664. params: {
  665. pageSize: 1000,
  666. pageIndex: 1
  667. }
  668. }).then(function (res) {
  669. var payload = res.data.payload;
  670. $scope.moniPoint = payload.dataList;
  671. }).catch(function (data) {
  672. toaster.pop("error", "提示", "获取监督号展现位置列表失败");
  673. });
  674. $scope.moniPointConfig = function () {
  675. var ids = getSelectRows()
  676. if (ids) {
  677. $("#moniPointForm").modal();
  678. $scope.dialogData = {}
  679. for (var key in $scope.moniPoint) {
  680. var item = $scope.moniPoint[key]
  681. $scope.dialogData[item.key] = false
  682. }
  683. }
  684. };
  685. $scope.setMoniPoint = function (pointKey) {
  686. var data = {
  687. dealerIds: $scope.selectedIds,
  688. moniPoint: [],
  689. }
  690. // 单个保存
  691. if (pointKey) {
  692. data.moniPoint.push({
  693. key: pointKey,
  694. switch: $scope.dialogData[pointKey] || false,// 默认为false
  695. })
  696. } else {
  697. var tempApp = []
  698. for (var key in $scope.dialogData) {
  699. tempApp.push({
  700. key: key,
  701. switch: $scope.dialogData[key] || false,// 默认为false
  702. })
  703. }
  704. data.moniPoint = tempApp
  705. }
  706. $http({
  707. method: 'POST',
  708. url: "/superadmin/editMoniPointForDealers",
  709. data: data
  710. }).then(function (response) {
  711. toaster.pop("success", "提示", "保存成功!");
  712. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  713. //批量保存关闭弹窗
  714. if (!pointKey) {
  715. $('#moniPointForm').modal('hide');//弹窗消失
  716. }
  717. }, function (response) {
  718. toaster.pop("error", "提示", "保存失败!");
  719. });
  720. };
  721. $scope.editSupporter = function () {
  722. $scope.dialogData = {};
  723. var rows = getSelectRows()
  724. if (rows) {
  725. $("#editSupporterForm").modal();
  726. }
  727. }
  728. $scope.saveSuporter = function () {
  729. var ids = $scope.selectedIds
  730. if ($scope.editSupporterForm.$invalid) {
  731. toaster.pop("warning", "提示", "请填写正确的数据");
  732. return
  733. }
  734. $http({
  735. method: 'POST',
  736. url: '/superadmin/editSupporterForDealers',
  737. data: {
  738. ids: ids,
  739. platformSupport: $scope.dialogData.platformSupport
  740. }
  741. }).then(function (response) {
  742. initDataGrid();
  743. $('#editSupporterForm').modal('hide');
  744. toaster.pop("success", "提示", "保存成功!");
  745. }, function (response) {
  746. toaster.pop("error", "提示", "保存失败!");
  747. });
  748. }
  749. // 使用前充值
  750. $scope.openSaveBeforeCharge = function () {
  751. $scope.dialogData = {};
  752. var rows = getSelectRows()
  753. if (rows) {
  754. $("#beforeChargeUnpayForm").modal();
  755. }
  756. }
  757. $scope.saveBeforeChargeUnpay = function () {
  758. var ids = $scope.selectedIds
  759. if ($scope.beforeChargeUnpayForm.$invalid) {
  760. toaster.pop("warning", "提示", "请填写正确的数据");
  761. return
  762. }
  763. $http({
  764. method: 'POST',
  765. url: '/superadmin/editDealerBeforeChargeUnpay',
  766. data: {ids: ids, beforeChargeUnpay: $scope.dialogData.beforeChargeUnpay}
  767. }).then(function (response) {
  768. initDataGrid();
  769. $('#beforeChargeUnpayForm').modal('hide');
  770. toaster.pop("success", "提示", "保存成功!");
  771. }, function (response) {
  772. toaster.pop("error", "提示", "保存失败!");
  773. });
  774. }
  775. //编辑密码 默认123456
  776. $scope.editPassword = function () {
  777. //重置表单状态
  778. $scope.passwordForm.$setPristine();
  779. $scope.passwordForm.$setUntouched();
  780. var rows = $scope.gridApi.selection.getSelectedRows();
  781. if (rows.length == 0) {
  782. toaster.pop("info", "提示", "请选择数据!");
  783. return;
  784. }
  785. if (rows.length > 1) {
  786. toaster.pop("info", "提示", "只能选中编辑一条数据");
  787. return;
  788. }
  789. var item = rows[0];
  790. $scope.passwordData = $.extend({password: 123456}, item);
  791. $("#passwordPanel").modal();
  792. };
  793. //修改密码提交
  794. $scope.savePassword = function () {
  795. //表单未校验通过不能提交
  796. if ($scope.passwordForm.$invalid) {
  797. return;
  798. }
  799. var url = "/superadmin/changeDealerPassword"
  800. var password = MD5.createHash($scope.passwordData.password + '');
  801. $http({
  802. method: 'POST',
  803. url: url,
  804. data: {
  805. id: $scope.passwordData.id,
  806. password: password,
  807. }
  808. }).then(function (response) {
  809. $('#passwordPanel').modal('hide');//弹窗消失
  810. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  811. }, function (response) {
  812. toaster.pop("error", "提示", "修改密码失败!");
  813. });
  814. };
  815. // 获取此经销商的银行卡配置
  816. function getBankConfigs(id) {
  817. return new Promise(((resolve, reject) => {
  818. $http.get('/superadmin/getDealerBanks', {
  819. params: {
  820. dealerId: id,
  821. }
  822. }).then(function (res) {
  823. resolve(res.data?.payload?.dataList)
  824. }).catch(function (data) {
  825. toaster.pop("error", "提示", "getDealerBanks失败。");
  826. reject()
  827. });
  828. }))
  829. }
  830. var lastRowId = ""
  831. async function renderBanksDialog(id){
  832. let list = await getBankConfigs(id) || [];
  833. list.forEach(bankInfo => {
  834. findName(bankInfo)
  835. })
  836. function findName(bankInfo) {
  837. if (bankInfo) {
  838. // 必须用provinceList ,确保引用地址一致,ui-select才能双绑。
  839. for (var index in $scope.provinceList) {
  840. var item = $scope.provinceList[index];
  841. if (item.value == bankInfo.provinceCode) {
  842. // 设置省份对应关系
  843. bankInfo.bankProvince = item
  844. // 初始化二级 市(暂时不查接口)
  845. bankInfo.bankCity = {
  846. "text": bankInfo.city,
  847. "value": bankInfo.cityCode,
  848. }
  849. bankInfo.cityList = [
  850. {
  851. "text": bankInfo.city,
  852. "value": bankInfo.cityCode,
  853. }
  854. ]
  855. break
  856. }
  857. }
  858. bankInfo.bankItem = {
  859. text: bankInfo.bankName,
  860. value: bankInfo.bankCode
  861. }
  862. bankInfo.branchBankItem = {
  863. text: bankInfo.branchBankName,
  864. value: bankInfo.branchBankCode
  865. }
  866. }
  867. }
  868. $scope.dialogData = {
  869. id: id,
  870. bankCards: list
  871. }
  872. $scope.$apply();
  873. }
  874. $scope.editBankAccount = async function () {
  875. var rows = $scope.gridApi.selection.getSelectedRows();
  876. if (rows.length === 0) {
  877. toaster.pop("info", "提示", "请选择数据!");
  878. return;
  879. }
  880. if (rows.length > 1) {
  881. toaster.pop("info", "提示", "只能选中编辑一条数据");
  882. return;
  883. }
  884. var row = rows[0]
  885. lastRowId = row.id;
  886. await renderBanksDialog(lastRowId)
  887. $("#bankAccountForm").modal();
  888. }
  889. $scope.addBank = function () {
  890. $scope.dialogData.bankCards.push({})
  891. }
  892. $scope.deleteBank = function (index, bankInfo) {
  893. if(bankInfo.id) {
  894. $.confirm({
  895. content: '确定删除?',
  896. buttons: {
  897. ok: {
  898. btnClass: 'btn-red',
  899. action: function () {
  900. $http({
  901. method: 'POST',
  902. url: '/superadmin/deleteDealerBankAccount',
  903. data: {id: bankInfo.id}
  904. }).then(function () {
  905. renderBanksDialog(lastRowId)
  906. }, function () {
  907. toaster.pop("error", "提示", "删除失败!");
  908. });
  909. }
  910. },
  911. }
  912. });
  913. } else {
  914. $scope.dialogData.bankCards.splice(index, 1)
  915. }
  916. }
  917. $scope.saveBankAccount = function (bankInfo) {
  918. bankInfo = $.extend(true, {dealerId: lastRowId}, bankInfo);
  919. if (bankInfo.isPublic) {
  920. if ($.isEmptyObject(bankInfo.bankProvince) || $.isEmptyObject(bankInfo.bankCity)) {
  921. toaster.pop("warning", "提示", "请填写省市");
  922. return
  923. }
  924. if ($.isEmptyObject(bankInfo.branchBankItem)) {
  925. toaster.pop("warning", "提示", "请填写支行名称");
  926. return
  927. }
  928. bankInfo.cityCode = bankInfo?.bankCity?.value
  929. bankInfo.city = bankInfo?.bankCity?.text
  930. bankInfo.provinceCode = bankInfo?.bankProvince?.value
  931. bankInfo.province = bankInfo?.bankProvince?.text
  932. bankInfo.bankCode = bankInfo?.bankItem?.value
  933. bankInfo.bankName = bankInfo?.bankItem?.text
  934. bankInfo.branchBankCode = bankInfo?.branchBankItem?.value
  935. bankInfo.branchBankName = bankInfo?.branchBankItem?.text
  936. } else {
  937. bankInfo.bankName = bankInfo?.bankItem?.text
  938. }
  939. delete bankInfo.bankCity
  940. delete bankInfo.bankProvince
  941. delete bankInfo.bankItem
  942. delete bankInfo.branchBankItem
  943. delete bankInfo.keyWord
  944. delete bankInfo.cityList
  945. delete bankInfo.branchBankList
  946. delete bankInfo.bankList
  947. $http({
  948. method: 'POST',
  949. url: '/superadmin/saveDealerBankAccount',
  950. data: bankInfo
  951. }).then(function () {
  952. renderBanksDialog(lastRowId)
  953. toaster.pop("success", "提示", "保存成功!");
  954. }, function () {
  955. toaster.pop("error", "提示", "保存失败!");
  956. });
  957. }
  958. $scope.editCardFee = function () {
  959. var rows = $scope.gridApi.selection.getSelectedRows();
  960. if (rows.length === 0) {
  961. toaster.pop("info", "提示", "请选择数据!");
  962. return;
  963. }
  964. var ids = [];
  965. for (var i = 0; i < rows.length; i++) {
  966. ids.push(rows[i].id);
  967. }
  968. $scope.dialogData = {ids: ids}
  969. $("#editCardFeeForm").modal();
  970. }
  971. $scope.saveCardFeeEdit = function () {
  972. if ($scope.editCardFeeForm.$invalid) {
  973. return;
  974. }
  975. var url = "/superadmin/changeDealerAnnualTrafficCost"
  976. $http({
  977. method: 'POST',
  978. url: url,
  979. data: {
  980. ids: $scope.dialogData.ids,
  981. annualTrafficCost: $scope.dialogData.annualTrafficCost,
  982. }
  983. }).then(function (response) {
  984. $('#editCardFeeForm').modal('hide');
  985. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  986. }, function (response) {
  987. toaster.pop("error", "提示", "保存失败!");
  988. });
  989. }
  990. $scope.setDealerMaxPackagePrice = function () {
  991. var rows = $scope.gridApi.selection.getSelectedRows();
  992. if (rows.length === 0) {
  993. toaster.pop("info", "提示", "请选择数据!");
  994. return;
  995. }
  996. var ids = [];
  997. let maxPackagePrice = 100
  998. if (rows.length) {
  999. maxPackagePrice = rows[0].maxPackagePrice
  1000. }
  1001. for (var i = 0; i < rows.length; i++) {
  1002. ids.push(rows[i].id);
  1003. }
  1004. $scope.dialogData = {ids: ids, maxPackagePrice: maxPackagePrice}
  1005. $("#dealerMaxPackagePrice").modal();
  1006. }
  1007. $scope.saveDealerMaxPackagePrice = function () {
  1008. if ($scope.dealerMaxPackagePrice.$invalid) {
  1009. return;
  1010. }
  1011. var url = "/superadmin/setDealerMaxPackagePrice"
  1012. $http({
  1013. method: 'POST',
  1014. url: url,
  1015. data: {
  1016. ids: $scope.dialogData.ids,
  1017. maxPackagePrice: $scope.dialogData.maxPackagePrice,
  1018. }
  1019. }).then(function (response) {
  1020. $('#dealerMaxPackagePrice').modal('hide');
  1021. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  1022. }, function (response) {
  1023. toaster.pop("error", "提示", "保存失败!");
  1024. });
  1025. }
  1026. $scope.editApiShow = function () {
  1027. var entity = getOneRow();
  1028. if (!entity) {
  1029. return
  1030. }
  1031. $scope.dialogData = {
  1032. id: entity.id
  1033. }
  1034. $http.get('/superadmin/apiapp/get', {
  1035. params: {
  1036. dealerId: entity.id,
  1037. }
  1038. }).then(function (res) {
  1039. $scope.dialogData = res.data.payload;
  1040. $scope.dialogData.id = entity.id;
  1041. $("#apiAppForm").modal();
  1042. }).catch(function (data) {
  1043. toaster.pop("error", "提示", "查询api应用信息失败。");
  1044. });
  1045. }
  1046. $scope.saveApiApp = function () {
  1047. if ($scope.apiAppForm.$invalid) {
  1048. return
  1049. }
  1050. var url = "/superadmin/apiapp/set";
  1051. $http({
  1052. method: 'POST',
  1053. url: url,
  1054. data: {
  1055. dealerId: $scope.dialogData.id,
  1056. people: $scope.dialogData.people,
  1057. tel: $scope.dialogData.tel,
  1058. callbackUrl: $scope.dialogData.callbackUrl,
  1059. apiDeviceMax: $scope.dialogData.apiDeviceMax,
  1060. apiDevicePerCost: $scope.dialogData.apiDevicePerCost,
  1061. }
  1062. }).then(function (response) {
  1063. $('#apiAppForm').modal('hide');
  1064. if (response.data.result) {
  1065. toaster.pop("info", "提示", "成功")
  1066. }
  1067. }, function (response) {
  1068. toaster.pop("error", "提示", "保存失败!");
  1069. });
  1070. }
  1071. }]);