manufacturer.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. app.controller('manufacturerCtrl', ['$scope', '$http', "$state", '$timeout', 'uiGridConstants', 'i18nService', 'toaster', 'md5', 'FileUploader', function ($scope, $http, $state, $timeout, uiGridConstants, i18nService, toaster, MD5, FileUploader) {
  2. i18nService.setCurrentLang("zh-cn");
  3. $scope.gridOptions = {
  4. data: 'myData',
  5. showGridFooter: true, //是否显示grid footer
  6. // rowHeight: 80,
  7. //-------- 分页属性 ----------------
  8. paginationPageSizes: [10, 20, 50, 100], //每页显示个数可选项
  9. paginationCurrentPage: 1, //当前页码
  10. paginationPageSize: 10, //每页显示个数
  11. totalItems: 0,// 总数量
  12. useExternalPagination: true,//是否使用分页按钮
  13. //过滤
  14. // enableFiltering: true,
  15. columnDefs: [],
  16. //---------------api---------------------
  17. onRegisterApi: function (gridApi) {
  18. $scope.gridApi = gridApi;
  19. gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
  20. if ($scope.setPagingData) {
  21. $scope.getPagedDataAsync(newPage, pageSize);
  22. }
  23. });
  24. }
  25. };
  26. //枚举常量
  27. $scope.enum = {};
  28. $scope.enum.adShow = [
  29. {value: "", label: "广告状态"},
  30. {value: false, label: "无广告"},
  31. {value: true, label: "有广告"}
  32. ];
  33. //查询条件
  34. var condition = $scope.condition = {
  35. adShow: $.extend({}, $scope.enum.adShow[0]),
  36. searchKey: "",
  37. searchType: {value: "", text: "厂商信息"},
  38. searchTypeList: [
  39. {value: "", text: "厂商信息"},
  40. {value: "dealer", text: "经销商查厂商"},
  41. {value: "agent", text: "代理商查厂商"},
  42. ],
  43. };
  44. //事件
  45. $scope.event = {
  46. statusChange: function (key, item) {
  47. condition[key].value = item.value;
  48. condition[key].label = item.label;
  49. this.search()
  50. },
  51. search: function () {
  52. $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize);
  53. }
  54. };
  55. function setColumnDefs() {
  56. $scope.gridOptions.columnDefs = [
  57. {
  58. field: 'nickname', displayName: '厂商名称',
  59. cellTemplate: '<div class="temp-row"><i class="fa fa-bullhorn text-success" title="已开启广告" ng-if="row.entity.adShow" ></i> {{row.entity.nickname}} </div>',
  60. },
  61. {field: 'brandName', displayName: '品牌名称'},
  62. {field: 'username', displayName: '联系方式'},
  63. {
  64. field: 'createdTime',
  65. displayName: '注册时间',
  66. cellTemplate: '<div class="temp-row" ng-bind="row.entity.createdTime| date:\'yyyy-MM-dd HH:mm:ss\'"></div>'
  67. },
  68. {
  69. field: 'agentTotal',
  70. displayName: '代理商总数',
  71. cellTemplate: '<div class="temp-row" ng-bind="row.entity.agentTotal"></div>'
  72. },
  73. {
  74. field: 'logo',
  75. displayName: '厂商图标',
  76. enableFiltering: false,
  77. cellTemplate: '<img ng-src="{{row.entity.logo}}" class="img-circle center-block" style="max-height: 100%"/>'
  78. },
  79. {
  80. field: 'withdrawFeeRatioCost',
  81. displayName: '提现费率',
  82. cellTemplate: '<div class="temp-row">{{row.entity.withdrawFeeRatioCost}}‰</div>'
  83. },
  84. {
  85. field: 'operation',
  86. displayName: '操作',
  87. minWidth: 680,
  88. enableFiltering: false,
  89. enableSorting: false,
  90. enableHiding: false,//禁止在列选择器中隐藏
  91. enableColumnMenu: false,// 是否显示列头部菜单按钮
  92. cellTemplate: '<div class="grid-button">' +
  93. '<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>' +
  94. '<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>' +
  95. // '<button class="btn btn-sm btn-rounded btn-info"ng-click="grid.appScope.unfreeze(row.entity)"><i class="fa fa-smile-o"></i> 解除限制</button>' +
  96. '<button class="btn btn-sm btn-rounded btn-danger" ng-click="grid.appScope.editFeature(row.entity)"><i class="fa fa-cubes"></i> 特性</button>' +
  97. '<button class="btn btn-sm btn-rounded btn-dark" ng-click="grid.appScope.editDeviceType(row.entity)"><i class="fa fa-cubes"></i> 设备类型</button>' +
  98. '<button class="btn btn-sm btn-rounded btn-default" ng-click="grid.appScope.openLinkPanel(row.entity)"><i class="fa fa-link"></i> 链接生成</button>' +
  99. '<button class="btn btn-sm btn-rounded btn-default" ng-click="grid.appScope.checkAgent(row.entity)"><i class="fa fa-user"></i> 代理商</button>' +
  100. '<button class="btn btn-sm btn-rounded btn-default" ng-click="grid.appScope.checkDealer(row.entity)"><i class="fa fa-users"></i> 经销商</button>' +
  101. '<button class="btn btn-sm btn-rounded btn-default" ng-click="grid.appScope.checkDevice(row.entity)"><i class="glyphicon glyphicon-phone"></i> 设备</button>' +
  102. '<button class="btn btn-sm btn-rounded btn-default" ng-click="grid.appScope.goLogin(row.entity)"><i class="glyphicon glyphicon-log-in"></i> 去登录</button>' +
  103. '</div>'
  104. }
  105. ];
  106. var fields = $scope.gridOptions.columnDefs;
  107. for (var index in fields) {
  108. var item = fields[index];
  109. if (item && item['minWidth'] == null) {
  110. item['minWidth'] = 100;
  111. }
  112. }
  113. }
  114. $scope.setPagingData = function (data) {
  115. var pagedData = data.data.dataList;
  116. $scope.myData = pagedData;
  117. $scope.gridOptions.totalItems = data.data.total;
  118. };
  119. $scope.getPagedDataAsync = function (curPage, pageSize) {
  120. var params = {
  121. adShow: condition.adShow.value,
  122. pageSize: pageSize,
  123. pageIndex: curPage
  124. };
  125. // 查询关键字
  126. if (condition.searchKey != "") {
  127. params.searchKey = condition.searchKey
  128. }
  129. // 查询类型
  130. if (condition.searchType.value != "") {
  131. params.searchType = condition.searchType.value;
  132. if (condition.searchKey == "") {
  133. toaster.pop("warning", "提示", "请输入 " + condition.searchType.text + " 信息");
  134. return
  135. }
  136. }
  137. $http.get('/superadmin/getManagerList', {
  138. params: params
  139. }).then(function (data) {
  140. data = data.data
  141. $scope.setPagingData(data, curPage, pageSize);
  142. }).catch(function (data) {
  143. toaster.pop("error", "提示", "获取数据列表失败");
  144. });
  145. };
  146. function initDataGrid() {
  147. //首次加载表格
  148. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  149. }
  150. setColumnDefs();
  151. initDataGrid();
  152. //封号|解封
  153. $scope.ban = function (entity, targetStatus) {
  154. var url = "/superadmin/toggleManufacturerStatus";
  155. $.confirm({
  156. content: '确定这样操作?',
  157. buttons: {
  158. ok: {
  159. btnClass: 'btn-red',
  160. action: function () {
  161. $http({
  162. method: 'POST',
  163. url: url,
  164. data: {
  165. id: entity.id,
  166. normal: targetStatus
  167. }
  168. }).then(function (response) {
  169. entity.normal = targetStatus;
  170. console.log(response);
  171. if (response.data.result) {
  172. toaster.pop("success", "提示", "修改状态成功!");
  173. } else {
  174. toaster.pop("error", "提示", "修改状态失败!");
  175. }
  176. }, function (response) {
  177. toaster.pop("error", "提示", "修改状态失败!");
  178. });
  179. }
  180. },
  181. }
  182. });
  183. };
  184. function getOneRow() {
  185. var rows = $scope.gridApi.selection.getSelectedRows();
  186. if (rows.length === 0) {
  187. toaster.pop("info", "提示", "请选择数据!");
  188. return false;
  189. }
  190. if (rows.length > 1) {
  191. toaster.pop("info", "提示", "只能选中编辑一条数据");
  192. return false;
  193. }
  194. return rows[0]
  195. }
  196. // 解除5次错误限制
  197. $scope.unfreeze = function (entity) {
  198. var entity = getOneRow();
  199. if (!entity) {
  200. return
  201. }
  202. var url = "/superadmin/unfreeze";
  203. $http({
  204. method: 'POST',
  205. url: url,
  206. data: {
  207. role: "manager",
  208. id: entity.id,
  209. }
  210. }).then(function (response) {
  211. if (response.data.result) {
  212. toaster.pop("success", "提示", "解除限制成功!");
  213. } else {
  214. toaster.pop("error", "提示", "解除限制失败!");
  215. }
  216. }, function (response) {
  217. toaster.pop("error", "提示", "解除限制失败!");
  218. });
  219. };
  220. // 必须先声明,否则ui-select无法双绑
  221. $scope.dialogData = {};
  222. //添加
  223. $scope.add = function () {
  224. //重置表单状态
  225. $scope.manageForm.$setPristine();
  226. $scope.manageForm.$setUntouched();
  227. //重置图片上传控件
  228. closeUploader();
  229. $scope.dialogName = "厂商开户";
  230. $scope.dialogData = {isNew: true};
  231. $("#manageForm").modal();
  232. };
  233. //编辑
  234. $scope.edit = function () {
  235. //重置表单状态
  236. $scope.manageForm.$setPristine();
  237. $scope.manageForm.$setUntouched();
  238. //重置图片上传控件
  239. closeUploader();
  240. $scope.dialogName = "编辑厂商信息";
  241. var rows = $scope.gridApi.selection.getSelectedRows();
  242. if (rows.length == 0) {
  243. toaster.pop("info", "提示", "请选择数据!");
  244. return;
  245. }
  246. if (rows.length > 1) {
  247. toaster.pop("info", "提示", "只能选中编辑一条数据");
  248. return;
  249. }
  250. var item = rows[0];
  251. $scope.dialogData = $.extend({}, item);
  252. $("#manageForm").modal();
  253. };
  254. //提交表单保存
  255. $scope.saveData = function () {
  256. //表单未校验通过不能提交,上传文件提示
  257. if ($scope.manageForm.$invalid) {
  258. return
  259. }
  260. var url = "";
  261. if ($scope.dialogData.id == null) {
  262. url = "/superadmin/addManager";
  263. } else {
  264. url = "/superadmin/editManager";
  265. }
  266. var data = {
  267. nickname: $scope.dialogData.nickname,
  268. brandName: $scope.dialogData.brandName,
  269. username: $scope.dialogData.username,
  270. remarks: $scope.dialogData.remarks,
  271. logo: $scope.dialogData.logo,
  272. };
  273. if ($scope.dialogData.id != null) {
  274. //编辑
  275. $.extend(data, {'id': $scope.dialogData.id})
  276. } else {
  277. //新建时才会保存密码
  278. data.password = MD5.createHash($scope.dialogData.password + '');
  279. // 新增时才会修改首席代理商信息
  280. data.primaryAgentUsername = $scope.dialogData.primaryAgentUsername;
  281. data.primaryAgentPassword = MD5.createHash($scope.dialogData.primaryAgentPassword + '');
  282. data.primaryAgentNickName = $scope.dialogData.primaryAgentNickName;
  283. data.trafficCardCost = $scope.dialogData.trafficCardCost;
  284. data.withdrawFeeRatioCost = $scope.dialogData.withdrawFeeRatioCost;
  285. }
  286. $http({
  287. method: 'POST',
  288. url: url,
  289. data: data
  290. }).then(function (response) {
  291. $('#manageForm').modal('hide');//弹窗消失
  292. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  293. }, function (response) {
  294. toaster.pop("error", "提示", "开户失败!");
  295. });
  296. };
  297. $scope.editAddress = function () {
  298. //重置表单状态
  299. $scope.editAddressForm.$setPristine();
  300. $scope.editAddressForm.$setUntouched();
  301. $scope.dialogName = "编辑厂商售后收货地址";
  302. var rows = $scope.gridApi.selection.getSelectedRows();
  303. if (rows.length == 0) {
  304. toaster.pop("info", "提示", "请选择数据!");
  305. return;
  306. }
  307. if (rows.length > 1) {
  308. toaster.pop("info", "提示", "只能选中编辑一条数据");
  309. return;
  310. }
  311. var item = rows[0];
  312. $scope.dialogData = item.exchangeAddress || {};
  313. $scope.dialogData.managerId = item.id
  314. $("#editAddressForm").modal();
  315. };
  316. $scope.saveAddress = function () {
  317. //表单未校验通过不能提交,上传文件提示
  318. if ($scope.editAddressForm.$invalid) {
  319. return
  320. }
  321. var url = "/superadmin/saveFactoryAddress";
  322. var data = $scope.dialogData
  323. $http({
  324. method: 'POST',
  325. url: url,
  326. data: data
  327. }).then(function (response) {
  328. $('#editAddressForm').modal('hide');
  329. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  330. }, function (response) {
  331. toaster.pop("error", "提示", "保存失败!");
  332. });
  333. };
  334. //查看代理商
  335. $scope.checkAgent = function (entity) {
  336. $state.go('app.user.agents', {
  337. moniAppId: '',
  338. managerId: entity.id,
  339. }, {
  340. reload: true
  341. });
  342. };
  343. //查看经销商
  344. $scope.checkDealer = function (entity) {
  345. $state.go('app.user.dealer', {
  346. managerId: entity.id,
  347. agentId: "",
  348. }, {
  349. reload: true
  350. });
  351. };
  352. //查看设备
  353. $scope.checkDevice = function (entity) {
  354. $state.go('app.dev.devManage', {
  355. managerId: entity.id,
  356. agentId: "",
  357. dealerId: "",
  358. searchKey: "",
  359. }, {
  360. reload: true
  361. });
  362. };
  363. $scope.goLogin = function (entity) {
  364. var username = entity.username;
  365. var url = "/1.0/index.html?username=" + username + "#/access/signin";
  366. window.open(url);
  367. };
  368. //事件绑定
  369. $timeout(function () {
  370. $("#fileUpload").on("change", function () {
  371. var objUrl = getObjectURL(this.files[0]);
  372. if (objUrl) {
  373. $("#previewImg").attr("src", objUrl);
  374. }
  375. });
  376. $("#fileUploadValue").on("focus", function () {
  377. $(this).blur();
  378. })
  379. });
  380. //建立一個可存取到該file的url
  381. function getObjectURL(file) {
  382. var url = null;
  383. if (window.createObjectURL != undefined) { // basic
  384. url = window.createObjectURL(file);
  385. } else if (window.URL != undefined) { // mozilla(firefox)
  386. url = window.URL.createObjectURL(file);
  387. } else if (window.webkitURL != undefined) { // webkit or chrome
  388. url = window.webkitURL.createObjectURL(file);
  389. }
  390. return url;
  391. }
  392. //图片提交控件
  393. var uploader = $scope.uploader = new FileUploader({
  394. url: '/common/upload?type=logo',
  395. queueLimit: 1, //文件个数
  396. removeAfterUpload: true //上传后删除文件
  397. });
  398. //注册上传事件
  399. uploader.onCompleteItem = function (fileItem, response, status, headers) {
  400. if (response.payload) {
  401. //适配数据
  402. response.data = response.payload;
  403. }
  404. if (response.result) {
  405. toaster.pop("success", "提示", "上传成功!");
  406. $scope.dialogData.logo = response.data;
  407. } else {
  408. toaster.pop("error", "失败", response.description);
  409. }
  410. };
  411. uploader.onErrorItem = function (fileItem, response, status, headers) {
  412. toaster.pop("error", "提示", "上传失败,请重试");
  413. };
  414. /*关闭上传框窗口后恢复上传框初始状态*/
  415. function closeUploader() {
  416. $("#fileUpload").val("");
  417. $("#previewImg").attr("src", "");
  418. uploader.clearQueue();
  419. uploader.cancelAll();
  420. }
  421. /********************链接拷贝面板***********************/
  422. var copyLinkData = $scope.copyLinkData = {};
  423. var currentDomain = location.protocol + "//" + location.host;
  424. //生成推广链接
  425. $scope.openLinkPanel = function (entity) {
  426. $("#copyLinkPanel").modal();
  427. //代理商入口
  428. var url = currentDomain + "/agents/index.html?managerId=" + entity.id;
  429. copyLinkData.link1 = url;
  430. };
  431. // 关闭链接生成器
  432. $scope.closeCopyLinkPanel = function () {
  433. $("#copyLinkPanel").modal("hide");
  434. };
  435. var clipboard;
  436. //事件绑定
  437. $timeout(function () {
  438. //在弹窗绑定 COPY组件
  439. clipboard = new ClipboardJS('.copyLinkBtn');
  440. clipboard.on('success', function (e) {
  441. e.clearSelection();
  442. toaster.pop("info", "提示", "复制成功");
  443. $scope.$apply();
  444. });
  445. clipboard.on('error', function (e) {
  446. toaster.pop("info", "提示", "请选择“拷贝”进行复制!");
  447. $scope.$apply();
  448. });
  449. });
  450. $scope.$on("$destroy", function () {
  451. if (clipboard) {
  452. clipboard.destroy();
  453. console.log("clipboard destroy");
  454. }
  455. });
  456. // 分配厂商的设备类型弹窗
  457. $scope.editDeviceType = function (entity) {
  458. $("#editDeviceTypePanel").modal();
  459. $scope.dialogName = entity.nickname + "配置设备类型";
  460. $("#dealerDevList").modal();
  461. // todo 由于ui-grid 之前隐藏,表格渲染有问题
  462. setTimeout(function () {
  463. // 刷新设备
  464. $scope.$broadcast("initDriverCodeList", {id: entity.id, role: "manager"});
  465. }, 100);
  466. };
  467. $scope.closeDeviceConfig = function (entity) {
  468. $("#editDeviceTypePanel").modal('hide');
  469. };
  470. //------------配置特性--------------------
  471. $scope.editFeature = function (entity) {
  472. $scope.dialogData = {
  473. id: entity.id,
  474. featureList: entity.featureList,
  475. specialFeature: entity.specialFeature,
  476. };
  477. $("#featureForm").modal();
  478. }
  479. $scope.saveFeature = function () {
  480. if ($scope.featureForm.$invalid) {
  481. return
  482. }
  483. $.confirm({
  484. content: '确定要变更特性?',
  485. buttons: {
  486. ok: {
  487. btnClass: 'btn-red',
  488. action: function () {
  489. var url = "/superadmin/editManagerFeature";
  490. $http({
  491. method: 'POST',
  492. url: url,
  493. data: {
  494. id: $scope.dialogData.id,
  495. featureList: $scope.dialogData.featureList,
  496. specialFeature: $scope.dialogData.specialFeature,
  497. }
  498. }).then(function (response) {
  499. //保存成功 弹窗消失
  500. $('#featureForm').modal('hide');
  501. if (response.data.result) {
  502. toaster.pop("info", "提示", "成功")
  503. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  504. }
  505. }, function (response) {
  506. toaster.pop("error", "提示", "保存失败!");
  507. });
  508. }
  509. },
  510. }
  511. });
  512. };
  513. //广告开关
  514. $scope.selectedIds = []
  515. $scope.editAdShow = function () {
  516. $scope.dialogData = {};
  517. var rows = $scope.gridApi.selection.getSelectedRows();
  518. if (rows.length === 0) {
  519. toaster.pop("info", "提示", "请选择数据!");
  520. return;
  521. }
  522. var ids = [];
  523. for (var i = 0; i < rows.length; i++) {
  524. ids.push(rows[i].id);
  525. }
  526. $scope.selectedIds = ids;
  527. $("#editAdForm").modal();
  528. }
  529. $scope.saveAdEdit = function () {
  530. var ids = $scope.selectedIds
  531. if ($scope.editAdForm.$invalid) {
  532. return
  533. }
  534. $http({
  535. method: 'POST',
  536. url: '/superadmin/editAdShow',
  537. data: {ids: ids, adShow: $scope.dialogData.adShow, role: "manager"}
  538. }).then(function (response) {
  539. initDataGrid();
  540. $('#editAdForm').modal('hide');
  541. toaster.pop("success", "提示", "保存成功!");
  542. }, function (response) {
  543. toaster.pop("error", "提示", "保存失败!");
  544. });
  545. }
  546. //编辑密码 默认123456
  547. $scope.editPassword = function () {
  548. //重置表单状态
  549. $scope.passwordForm.$setPristine();
  550. $scope.passwordForm.$setUntouched();
  551. var rows = $scope.gridApi.selection.getSelectedRows();
  552. if (rows.length == 0) {
  553. toaster.pop("info", "提示", "请选择数据!");
  554. return;
  555. }
  556. if (rows.length > 1) {
  557. toaster.pop("info", "提示", "只能选中编辑一条数据");
  558. return;
  559. }
  560. var item = rows[0];
  561. $scope.passwordData = $.extend({password: 123456}, item);
  562. $("#passwordPanel").modal();
  563. };
  564. //修改密码提交
  565. $scope.savePassword = function () {
  566. //表单未校验通过不能提交
  567. if ($scope.passwordForm.$invalid) {
  568. return;
  569. }
  570. var url = "/superadmin/changeManagerPassword"
  571. var password = MD5.createHash($scope.passwordData.password + '');
  572. $http({
  573. method: 'POST',
  574. url: url,
  575. data: {
  576. id: $scope.passwordData.id,
  577. password: password,
  578. }
  579. }).then(function (response) {
  580. $('#passwordPanel').modal('hide');//弹窗消失
  581. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  582. }, function (response) {
  583. toaster.pop("error", "提示", "修改密码失败!");
  584. });
  585. };
  586. }]);