123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714 |
- app.controller('agentsManageCtrl', ['$scope', '$http', "$state", '$timeout', 'uiGridConstants', 'i18nService', 'FileUploader', 'toaster', 'md5', function ($scope, $http, $state, $timeout, uiGridConstants, i18nService, FileUploader, toaster, MD5) {
- i18nService.setCurrentLang("zh-cn");
- $scope.gridOptions = {
- data: 'myData',
- showGridFooter: true, //是否显示grid footer
- // rowHeight: 80,
- //-------- 分页属性 ----------------
- paginationPageSizes: [10, 20, 50, 100], //每页显示个数可选项
- paginationCurrentPage: 1, //当前页码
- paginationPageSize: 10, //每页显示个数
- totalItems: 0,// 总数量
- useExternalPagination: true,//是否使用分页按钮
- //过滤
- // enableFiltering: true,
- columnDefs: [],
- //---------------api---------------------
- onRegisterApi: function (gridApi) {
- $scope.gridApi = gridApi;
- gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
- if ($scope.setPagingData) {
- $scope.getPagedDataAsync(newPage, pageSize);
- }
- });
- }
- };
- //查询条件
- var condition = $scope.condition = {
- searchKey: ""
- };
- //枚举常量
- $scope.enum = {};
- // 事件
- $scope.ngEvent = {
- compressorImg: function (file, callback) {
- if (file) {
- var imageCompressor = new Compressor(file, {
- quality: .7,
- // 图片尺寸
- maxWidth: 1920,
- maxHeight: 1920,
- success: function (result) {
- var formData = new FormData();
- formData.append('file', result, result.name);
- if (callback) {
- callback(formData);
- }
- }
- });
- }
- },
- deletePic: function (index) {
- $scope.dialogData.bannerImgList.splice(index, 1);
- },
- editPicUrl: function (index) {
- if ($scope.nowClickPicIndex == index) {
- $scope.nowClickPicIndex = null
- } else {
- $scope.nowClickPicIndex = index
- }
- },
- addPic: function () {
- var imgUpload = $("#addImg");
- var file = imgUpload[0].files[0];
- this.compressorImg(file, function (formData) {
- var url = '/common/upload?type=banner';
- $http({
- method: 'POST',
- url: url,
- transformRequest: angular.identity,
- headers: {
- 'Content-Type': undefined// 禁止angular对data的处理
- },
- data: formData
- }).then(function (response) {
- var url = response.data.para;
- $scope.dialogData.bannerImgList.push({img: url});
- //重置文件路径,避免选中重复不触发onchange
- var imgUpload = $("#addImg");
- imgUpload[0].value = "";
- }, function (response) {
- toaster.pop("error", "提示", "上传失败!");
- });
- })
- },
- saveBanner: function () {
- $http({
- method: 'POST',
- url: "/manager/setAgentBanner",
- data: {
- id: $scope.dialogData.id,
- bannerImgList: $scope.dialogData.bannerImgList,
- bannerName: $scope.dialogData.bannerName,
- }
- }).then(function (response) {
- if (response.data.result === 1) {
- toaster.pop("success", "提示", "保存成功!")
- }
- }, function (response) {
- toaster.pop("error", "提示", "保存失败!");
- });
- }
- };
- //事件
- $scope.event = {
- search: function () {
- $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize);
- },
- generateNewAppKeyPair: function () {
- var dialogData = $scope.dialogData
- if (!dialogData.aliPayApp.appid) {
- toaster.pop("warning", "提示", "请填写支付宝的APP ID!");
- return
- }
- $http({
- method: 'POST',
- url: '/common/generateNewAppKeyPair',
- data: {
- appid: dialogData.aliPayApp.appid,
- }
- }).then(function (response) {
- if (response.data.result) {
- toaster.pop("success", "提示", "生成成功!");
- $scope.dialogData.aliPayApp.app_private_key_path = response.data.payload.path;
- $scope.dialogData.aliPayApp.hasAlipayAppKeyPair = true;
- $scope.dialogData.aliPayApp.appPublicKeyContent = response.data.payload.appPublicKeyContent;
- } else {
- toaster.pop("error", "提示", "生成失败");
- }
- }, function (response) {
- toaster.pop("error", "提示", "生成失败!");
- });
- },
- };
- function setColumnDefs() {
- $scope.gridOptions.columnDefs = [
- {
- field: 'nickname', displayName: '代理商名称',
- cellTemplate: '<div class="temp-row" ng-class="{\' text-info\':row.entity.isPrimary}"><i class="fa fa-user" title="主代理商" ng-if="row.entity.isPrimary" ></i> {{row.entity.nickname}}</div>',
- },
- {field: 'username', displayName: '联系方式'},
- {
- field: 'dateTimeAdded',
- displayName: '注册时间',
- cellTemplate: '<div class="temp-row" ng-bind="row.entity.dateTimeAdded"></div>'
- },
- {
- field: 'dealerTotal',
- displayName: '经销商总数',
- cellTemplate: '<div class="temp-row" ng-bind="row.entity.dealerTotal"></div>'
- },
- {
- field: 'annualTrafficCost',
- displayName: '流量卡最低费用',
- cellTemplate: '<div class="temp-row" ng-bind="row.entity.annualTrafficCost"></div>'
- },
- {
- field: 'withdrawFeeRatio',
- displayName: '最低提现费率',
- cellTemplate: '<div class="temp-row">{{row.entity.withdrawFeeRatio}}‰</div>'
- },
- {
- field: 'pay_config',
- displayName: '资金池',
- cellTemplate: '<div class="temp-row"><span class="iconfont icon-wechat c-wechat" ng-if="row.entity.customizedWechatCashflowAllowable" title="微信"></span> <span class="iconfont icon-alipay c-alipay" ng-if="row.entity.customizedAlipayCashflowAllowable" title="支付宝"></span><span ng-if="!row.entity.customizedAlipayCashflowAllowable&&!row.entity.customizedAlipayCashflowAllowable">暂无</span></div>',
- enableFiltering: false,
- enableSorting: false
- },
- {
- field: 'detail',
- displayName: '详细信息',
- cellTemplate: '<div class="temp-row" ng-click="grid.appScope.showInfoDetail(\'详细信息\',row.entity.detail)">{{row.entity.detail}}</div>'
- },
- {
- field: 'operation',
- displayName: '操作',
- enableFiltering: false,
- enableSorting: false,
- enableHiding: false,//禁止在列选择器中隐藏
- enableColumnMenu: false,// 是否显示列头部菜单按钮
- minWidth: 160,
- // 注意,主代理商自己不能分配设备类型
- cellTemplate: '<div class="grid-button">' +
- '<button class="btn btn-sm btn-rounded btn-green" ng-click="grid.appScope.goDealer(row.entity)"><i class="fa fa-male"></i> 经销商</button>' +
- '</div>'
- },
- ];
- var fields = $scope.gridOptions.columnDefs;
- for (var index in fields) {
- var item = fields[index];
- if (item && item['minWidth'] == null) {
- item['minWidth'] = 100;
- }
- }
- }
- function getOneRow() {
- var rows = $scope.gridApi.selection.getSelectedRows();
- if (rows.length === 0) {
- toaster.pop("info", "提示", "请选择数据!");
- return false;
- }
- if (rows.length > 1) {
- toaster.pop("info", "提示", "只能选中编辑一条数据");
- return false;
- }
- return rows[0]
- }
- //查看经销商
- $scope.goDealer = function (entity) {
- $scope.nowAgentName = entity.nickname;
- $("#agentDealerList").modal();
- $timeout(function () {
- // random避免刷新后显示问题
- $state.go('app.user.agents.dealer', {
- agentId: entity.id,
- v: "v" + new Date().getTime()
- });
- });
- };
- $scope.closeDealer = function () {
- $("#agentDealerList").modal('hide');
- };
- $scope.setPagingData = function (data, curPage, pageSize) {
- var firstRow = (curPage - 1) * pageSize;
- var pagedData = data.data.dataList;
- $scope.myData = pagedData;
- $scope.gridOptions.totalItems = data.data.total;
- };
- $scope.getPagedDataAsync = function (curPage, pageSize, searchText) {
- if ($scope.gridOptionsLoading) {
- return;
- }
- var params = {
- pageSize: pageSize,
- pageIndex: curPage
- };
- if (condition.searchKey != "") {
- params.searchKey = condition.searchKey
- }
- $scope.gridOptionsLoading = true;
- $http.get('/agent/getAgentsDetailList', {
- params: params
- }).then(function (data) {
- $scope.gridOptionsLoading = false;
- $scope.setPagingData(data.data, curPage, pageSize);
- }).catch(function (data) {
- toaster.pop("error", "提示", "获取数据列表失败");
- });
- };
- function initDataGrid() {
- //首次加载表格
- $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
- }
- setColumnDefs();
- initDataGrid();
- //展示详情
- $scope.showInfoDetail = function (title, content) {
- $scope.infoDetail = {title: title, content: content};
- $("#detailInfoPanel").modal();
- };
- $scope.closeDetailInfoPanel = function () {
- $("#detailInfoPanel").modal("hide");
- };
- /********************链接拷贝面板***********************/
- var copyLinkData = $scope.copyLinkData = {};
- var currentDomain = location.protocol + "//" + location.host;
- //生成推广链接
- $scope.openLinkPanel = function () {
- var entity = getOneRow();
- if (!entity) {
- return
- }
- $("#copyLinkPanel").modal();
- //经销商注册链接
- var url = currentDomain + "/dealerAccess?agentId=" + entity.id;
- copyLinkData.link1 = url;
- // 个人主页链接
- var url = currentDomain + "/userLogin?agentId=" + entity.id + "&redirect=" + encodeURIComponent("/user/index.html#/user/me");
- copyLinkData.link2 = url;
- // 用户地图链接
- var url = currentDomain + "/userLogin?agentId=" + entity.id + "&redirect=" + encodeURIComponent("/user/index.html#/user/index");
- copyLinkData.link3 = url;
- // 用户扫码
- var url = currentDomain + "/userLogin?agentId=" + entity.id + "&redirect=" + encodeURIComponent("/user/index.html#/dev");
- copyLinkData.link4 = url;
- };
- // 关闭链接生成器
- $scope.closeCopyLinkPanel = function () {
- $("#copyLinkPanel").modal("hide");
- };
- var clipboard;
- //事件绑定
- $timeout(function () {
- //在弹窗绑定 COPY组件
- clipboard = new ClipboardJS('.copyLinkBtn');
- clipboard.on('success', function (e) {
- e.clearSelection();
- toaster.pop("info", "提示", "复制成功");
- $scope.$apply();
- });
- clipboard.on('error', function (e) {
- toaster.pop("info", "提示", "请选择“拷贝”进行复制!");
- $scope.$apply();
- });
- });
- $scope.$on("$destroy", function () {
- if (clipboard) {
- clipboard.destroy();
- console.log("clipboard destroy");
- }
- });
- // 必须先声明,否则ui-select无法双绑
- $scope.dialogData = {};
- //添加
- $scope.add = function () {
- //重置表单状态
- $scope.agentsForm.$setPristine();
- $scope.agentsForm.$setUntouched();
- $scope.dialogName = "代理商开户";
- $scope.dialogData = {isNew: true,};
- $("#agentsPanel").modal();
- };
- //编辑
- $scope.edit = function () {
- //重置表单状态
- $scope.agentsForm.$setPristine();
- $scope.agentsForm.$setUntouched();
- $scope.dialogName = "编辑代理商信息";
- var row = getOneRow();
- if (!row) {
- return
- }
- $scope.dialogData = $.extend({}, row);//非深度克隆的优点是:如果不小心取消了,下次编辑时,子对象的数据还在
- $("#agentsPanel").modal();
- };
- //编辑
- $scope.editOtherAPI = function () {
- //重置表单状态
- $scope.otherAPIForm.$setPristine();
- $scope.otherAPIForm.$setUntouched();
- var row = getOneRow();
- if (!row) {
- return
- }
- $scope.dialogFireData = $.extend(true, {id: row.id}, row.ZJFirePlatform);
- $("#otherAPIForm").modal();
- };
- $scope.saveOtherAPIForm = function () {
- if ($scope.otherAPIForm.$invalid) {
- return;
- }
- var url = "/manager/editAgentZJFirePlatform";
- $http({
- method: 'POST',
- url: url,
- data: $scope.dialogFireData
- }).then(function (response) {
- $('#otherAPIForm').modal('hide');
- $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
- }, function (response) {
- toaster.pop("error", "提示", "保存失败!");
- });
- }
- $scope.editBanner = function () {
- //重置表单状态
- $scope.bannerForm.$setPristine();
- $scope.bannerForm.$setUntouched();
- $scope.dialogName = "编辑代理商Banner";
- var row = getOneRow();
- if (!row) {
- return
- }
- $scope.dialogData = $.extend({bannerImgList: []}, row);//非深度克隆的优点是:如果不小心取消了,下次编辑时,子对象的数据还在
- $("#bannerForm").modal();
- };
- //编辑密码 默认123456
- $scope.editPassword = function () {
- //重置表单状态
- $scope.passwordForm.$setPristine();
- $scope.passwordForm.$setUntouched();
- var row = getOneRow();
- if (!row) {
- return
- }
- $scope.passwordData = $.extend({password: 123456}, row);
- $("#passwordPanel").modal();
- };
- //解锁经销商的登录限制,如密码输错后导致的锁
- $scope.unlock = function () {
- var row = getOneRow();
- if (!row) {
- return
- }
- var url = "/manager/unlockAgent";
- $http({
- method: 'POST',
- url: url,
- data: {
- id: row.id
- }
- }).then(function (response) {
- toaster.pop("info", "提示", "解锁成功!")
- $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
- }, function (response) {
- toaster.pop("error", "提示", "解锁失败!");
- });
- }
- //提交表单保存
- $scope.saveData = function () {
- var url = "";
- if ($scope.dialogData.id == null) {
- url = "/manager/addAgents";
- } else {
- url = "/manager/editAgents";
- }
- var data = {
- nickname: $scope.dialogData.nickname,
- username: $scope.dialogData.username,
- annualTrafficCost: parseFloat($scope.dialogData.annualTrafficCost),//最低流量卡年费
- withdrawFeeRatio: parseFloat($scope.dialogData.withdrawFeeRatio),
- managerProfitShare: parseFloat($scope.dialogData.managerProfitShare),
- };
- if ($scope.dialogData.id != null) {
- data.id = $scope.dialogData.id
- } else {
- //新建
- data.password = MD5.createHash($scope.dialogData.password + '');
- }
- $http({
- method: 'POST',
- url: url,
- data: data
- }).then(function (response) {
- $('#agentsPanel').modal('hide');//弹窗消失
- $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
- }, function (response) {
- toaster.pop("error", "提示", "保存失败!");
- });
- };
- /*****************公众号*********************/
- $scope.editWechat = function () {
- //重置表单状态
- $scope.wechatForm.$setPristine();
- $scope.wechatForm.$setUntouched();
- var row = getOneRow();
- if (!row) {
- return
- }
- $scope.dialogData = $.extend({user: {}, dealer: {}}, row);//非深度克隆的优点是:如果不小心取消了,下次编辑时,子对象的数据还在
- $("#wechatForm").modal();
- }
- $scope.saveWechat = function () {
- var url = "/manager/bind_wechat_cust";
- var data = {};
- // 防止为空没填报错
- $scope.dialogData.dealer = $scope.dialogData.dealer || {};
- $scope.dialogData.user = $scope.dialogData.user || {};
- //编辑
- $.extend(data, {
- 'id': $scope.dialogData.id,
- customizedDealerGzhAllowable: $scope.dialogData.customizedDealerGzhAllowable,
- dealer: {
- appid: $scope.dialogData.dealer.appid,
- secret: $scope.dialogData.dealer.secret,
- templateIdMap: $scope.dialogData.dealer.templateIdMap,
- },
- customizedUserGzhAllowable: $scope.dialogData.customizedUserGzhAllowable,
- user: {
- appid: $scope.dialogData.user.appid,
- secret: $scope.dialogData.user.secret,
- templateIdMap: $scope.dialogData.user.templateIdMap,
- },
- })
- $http({
- method: 'POST',
- url: url,
- data: data
- }).then(function (response) {
- $('#wechatForm').modal('hide');//弹窗消失
- $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
- }, function (response) {
- toaster.pop("error", "提示", "操作失败!");
- });
- };
- /*****************资金池*********************/
- $scope.cashPoolWechat = function () {
- //重置表单状态
- $scope.cashPoolWechatForm.$setPristine();
- $scope.cashPoolWechatForm.$setUntouched();
- var row = getOneRow();
- if (!row) {
- return
- }
- $scope.dialogData = $.extend({wechatPayApp: {}}, row);//非深度克隆的优点是:如果不小心取消了,下次编辑时,子对象的数据还在
- $("#cashPoolWechatForm").modal();
- };
- $scope.cashPoolAlipay = function () {
- //重置表单状态
- $scope.cashPoolAlipayForm.$setPristine();
- $scope.cashPoolAlipayForm.$setUntouched();
- var row = getOneRow();
- if (!row) {
- return
- }
- $scope.dialogData = $.extend({aliPayApp: {}}, row);//非深度克隆的优点是:如果不小心取消了,下次编辑时,子对象的数据还在
- $("#cashPoolAlipayForm").modal();
- };
- $scope.changeFile = function (files,key) {
- if (files.length) {
- var file = files[0];
- var reader = new FileReader();
- // 文件不能大于1M
- if (file.size > 1000 * 1024) {
- toaster.pop("info", "提示", "文件太大,请重新选择");
- } else {
- reader.onload = function() {
- if(reader.result) {
- var text = reader.result
- $scope.dialogData.wechatPayApp[key] = btoa(text)
- $scope.$apply();
- }
- };
- reader.readAsText(file);
- }
- }
- }
- $scope.saveCashPoolAlipay = function () {
- var url = "/manager/bind_ali_app";
- var data = {};
- // 防止未空没填报错
- $scope.dialogData.aliPayApp = $scope.dialogData.aliPayApp || {};
- //编辑
- $.extend(data, {
- 'id': $scope.dialogData.id,
- customizedAlipayCashflowAllowable: $scope.dialogData.customizedAlipayCashflowAllowable,
- aliPayApp: {
- appid: $scope.dialogData.aliPayApp.appid,
- alipayPublicKeyContent: $scope.dialogData.aliPayApp.alipayPublicKeyContent,
- app_private_key_path: $scope.dialogData.aliPayApp.app_private_key_path,
- appPublicKeyContent: $scope.dialogData.aliPayApp.appPublicKeyContent,
- shadow: $scope.dialogData.aliPayApp.shadow,
- public_key_path: $scope.dialogData.aliPayApp.public_key_path
- }
- })
- $http({
- method: 'POST',
- url: url,
- data: data
- }).then(function (response) {
- $('#cashPoolAlipayForm').modal('hide');//弹窗消失
- $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
- }, function (response) {
- toaster.pop("error", "提示", "保存失败!");
- });
- }
- //修改密码提交
- $scope.savePassword = function () {
- //表单未校验通过不能提交
- if ($scope.passwordForm.$invalid) {
- return;
- }
- var url = "/manager/editAgentPassword";
- var password = MD5.createHash($scope.passwordData.password + '');
- $http({
- method: 'POST',
- url: url,
- data: {
- id: $scope.passwordData.id,
- password: password,
- }
- }).then(function (response) {
- $('#passwordPanel').modal('hide');//弹窗消失
- $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
- }, function (response) {
- toaster.pop("error", "提示", "修改密码失败!");
- });
- };
- /***************** 分配厂商的设备类型弹窗**********************/
- $scope.editDeviceType = function () {
- var entity = getOneRow();
- if (!entity) {
- return
- }
- if (entity.isPrimary) {
- toaster.pop("warning", "提示", "该角色是主代理商,不能配置!");
- return
- }
- $("#editDeviceTypePanel").modal();
- $scope.dialogName = entity.nickname + "配置设备类型";
- $("#dealerDevList").modal();
- // todo 由于ui-grid 之前隐藏,表格渲染有问题
- setTimeout(function () {
- // 刷新设备
- $scope.$broadcast("initDriverCodeList", {id: entity.id, role: "agent"});
- }, 100);
- };
- $scope.closeDeviceConfig = function (entity) {
- $("#editDeviceTypePanel").modal('hide');
- };
- }]);
|