app.controller('agentsManageCtrl', ['$scope', '$http', '$stateParams', "$state", '$timeout', 'uiGridConstants', 'i18nService', 'FileUploader', 'toaster', 'md5', function ($scope, $http, $stateParams, $state, $timeout, uiGridConstants, i18nService, FileUploader, toaster, MD5) {
i18nService.setCurrentLang("zh-cn");
var managerId = $stateParams.managerId;
var moniAppId = $stateParams.moniAppId;// 根据是否有监督号查询代理商
$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);
}
});
}
};
//枚举常量
$scope.enum = {};
$scope.enum.adShow = [
{value: "", label: "广告状态"},
{value: false, label: "无广告"},
{value: true, label: "有广告"}
];
$scope.enum.forceFollowGzh = [
{value: "", label: "-强制关注状态-"},
{value: "yes", label: "强制关注"},
{value: "no", label: "不强制关注"},
];
$scope.enum.forceFollowGzhForDealer = [
{value: "", label: "-经销商的是否允许关注-"},
{value: "never", label: "永不强制关注公众号"},
{value: "free", label: "自由选择"},
];
$scope.enum.platformSupport = [
{value: "", label: "-客服接管状态-"},
{value: "yes", label: "用平台客服"},
{value: "no", label: "不用"},
{value: "never", label: "用自己的"},
];
$scope.enum.beforeChargeUnpay = [
{value: "", label: "-使用前充值-"},
{value: "yes", label: "是"},
{value: "no", label: "否"},
{value: "never", label: "永不"},
{value: "free", label: "自由选择"},
];
var managerDefault = {"nickname": "厂商"}
//查询条件
var condition = $scope.condition = {
adShow: $.extend({}, $scope.enum.adShow[0]),
forceFollowGzh: $.extend({}, $scope.enum.forceFollowGzh[0]),
forceFollowGzhForDealer: $.extend({}, $scope.enum.forceFollowGzhForDealer[0]),
beforeChargeUnpay: $.extend({}, $scope.enum.beforeChargeUnpay[0]),
managerDefault: managerDefault,
managerList: [
managerDefault
],
manager: managerDefault,
searchKey: ""
};
var searchTimer = null;
//事件
$scope.event = {
statusChange: function (key, item) {
condition[key].value = item.value;
condition[key].label = item.label;
this.search()
},
managerInit: function ($event) {
var searchKey = $event ? $event.target.value : "";
$timeout.cancel(searchTimer);
searchTimer = $timeout(function () {
$http.get('/superadmin/getManagerList', {
params: {
pageSize: 1000,
pageIndex: 1,
searchKey: searchKey,
}
}).then(function (data) {
data = data.data
$scope.condition.managerList = data.data.dataList;
}).catch(function (data) {
toaster.pop("error", "提示", "搜索失败");
});
}, 500);//延迟搜索,否则请求太频繁
},
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", "提示", "生成失败!");
});
},
};
// 初始化一次
$scope.event.managerInit();
function setColumnDefs() {
$scope.gridOptions.columnDefs = [
{
field: 'nickname', displayName: '代理商名称',
cellTemplate: '
{{row.entity.nickname}}
',
},
{field: 'username', displayName: '用户名'},
{
field: 'dateTimeAdded',
displayName: '注册时间',
cellTemplate: ''
},
{
field: 'dealerTotal',
displayName: '经销商总数',
cellTemplate: ''
},
{
field: 'annualTrafficCost',
displayName: '流量年费下限',
cellTemplate: ''
},
{
field: 'trafficCardCost',
displayName: '流量卡成本',
cellTemplate: ''
},
{
field: 'productName',
displayName: '产品名称',
},
{
field: 'moniApps',
displayName: '监督号',
cellTemplate: '{{item.appName}};
'
},
{
field: 'moniApps',
displayName: '监督号位置',
cellTemplate: '{{item.name}};
'
},
{
field: 'forceFollowGzh',
displayName: '强制关注状态',
},
{
field: 'forceFollowGzhForDealer',
displayName: '经销商的是否允许关注',
minWidth: 180,
},
// {
// field: 'beforeChargeUnpay',
// displayName: '使用前充值',
// },
{
field: 'detail',
displayName: '详细信息',
cellTemplate: '{{row.entity.detail}}
'
},
{
field: 'operation',
displayName: '操作',
enableFiltering: false,
enableSorting: false,
enableHiding: false,//禁止在列选择器中隐藏
enableColumnMenu: false,// 是否显示列头部菜单按钮
minWidth: 300,
cellTemplate: '' +
'' +
'' +
// '' +
'' +
'' +
'
'
},
];
var fields = $scope.gridOptions.columnDefs;
for (var index in fields) {
var item = fields[index];
if (item && item['minWidth'] == null) {
item['minWidth'] = 120;
}
}
}
$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 = {
adShow: condition.adShow.value,
forceFollowGzh: condition.forceFollowGzh.value,
forceFollowGzhForDealer: condition.forceFollowGzhForDealer.value,
beforeChargeUnpay: condition.beforeChargeUnpay.value,
pageSize: pageSize,
pageIndex: curPage
};
if (condition.searchKey != "") {
params.searchKey = condition.searchKey
}
// 路由参数也可能有managerId
if (managerId) {
params.managerId = managerId
}
// 也可以直接根据筛选条件进行查询,优先级高
if (condition.manager.id && condition.manager.id != "") {
params.managerId = condition.manager.id
}
// 路由参数也可能有moniAppId
if (moniAppId) {
params.moniAppId = moniAppId
}
$scope.gridOptionsLoading = true;
$http.get('/superadmin/getAgentsDetailList', {
params: params
}).then(function (data) {
data = data.data
$scope.gridOptionsLoading = false;
$scope.setPagingData(data, curPage, pageSize);
}).catch(function (data) {
toaster.pop("error", "提示", "获取数据列表失败");
});
};
function initDataGrid() {
//首次加载表格
$scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
}
setColumnDefs();
initDataGrid();
//封号|解封
$scope.ban = function (entity, targetStatus) {
var url = "/superadmin/toggleAgentStatus";
$.confirm({
content: '确定这样操作?',
buttons: {
ok: {
btnClass: 'btn-red',
action: function () {
$http({
method: 'POST',
url: url,
data: {
id: entity.id,
normal: targetStatus
}
}).then(function (response) {
entity.normal = targetStatus;
console.log(response);
if (response.data.result) {
toaster.pop("success", "提示", "修改状态成功!");
} else {
toaster.pop("error", "提示", "修改状态失败!");
}
}, function (response) {
toaster.pop("error", "提示", "修改状态失败!");
});
}
},
}
});
};
// 解除5次错误限制
$scope.unfreeze = function (entity) {
var entity = getOneRow();
if (!entity) {
return
}
var url = "/superadmin/unfreeze";
$http({
method: 'POST',
url: url,
data: {
role: "agent",
id: entity.id,
}
}).then(function (response) {
if (response.data.result) {
toaster.pop("success", "提示", "解除限制成功!");
} else {
toaster.pop("error", "提示", "解除限制失败!");
}
}, function (response) {
toaster.pop("error", "提示", "解除限制失败!");
});
};
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]
}
/********************链接拷贝面板***********************/
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");
}
});
//查看经销商
$scope.checkDealer = function (entity) {
$state.go('app.user.dealer', {
agentId: entity.id,
managerId: ""
}, {
reload: true
});
};
//查看设备
$scope.checkDevice = function (entity) {
$state.go('app.dev.devManage', {
managerId: "",
agentId: entity.id,
dealerId: "",
searchKey: "",
}, {
reload: true
});
};
//展示详情
$scope.showInfoDetail = function (title, content) {
$scope.infoDetail = {title: title, content: content};
$("#detailInfoPanel").modal();
};
$scope.closeDetailInfoPanel = function () {
$("#detailInfoPanel").modal("hide");
};
// 必须先声明,否则ui-select无法双绑
$scope.dialogData = {};
// 配置特性
$scope.editFeature = function () {
var entity = getOneRow();
if (!entity) {
return
}
$scope.dialogData = {
id: entity.id,
featureList: entity.featureList,
specialFeature: entity.specialFeature,
};
$("#featureForm").modal();
}
$scope.saveFeature = function () {
if ($scope.featureForm.$invalid) {
toaster.pop("warning", "提示", "请填写正确的数据");
return
}
$.confirm({
content: '确定要变更特性?',
buttons: {
ok: {
btnClass: 'btn-red',
action: function () {
var url = "/superadmin/editAgentFeature";
$http({
method: 'POST',
url: url,
data: $scope.dialogData
}).then(function (response) {
//保存成功 弹窗消失
$('#featureForm').modal('hide');
if (response.data.result) {
toaster.pop("info", "提示", "成功")
$scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
}
}, function (response) {
toaster.pop("error", "提示", "保存失败!");
});
}
},
}
});
};
//广告开关
$scope.selectedIds = []
function getSelectRows() {
var rows = $scope.gridApi.selection.getSelectedRows();
if (rows.length === 0) {
toaster.pop("info", "提示", "请选择数据!");
return false;
}
var ids = [];
for (var i = 0; i < rows.length; i++) {
ids.push(rows[i].id);
}
$scope.selectedIds = ids;
return ids
}
$scope.editAdShow = function () {
$scope.dialogData = {};
if (getSelectRows()) {
$("#editAdForm").modal();
}
}
$scope.saveAdEdit = function () {
var ids = $scope.selectedIds
if ($scope.editAdForm.$invalid) {
toaster.pop("warning", "提示", "请填写正确的数据");
return
}
$http({
method: 'POST',
url: '/superadmin/editAdShow',
data: {ids: ids, adShow: $scope.dialogData.adShow, role: "agent"}
}).then(function (response) {
initDataGrid();
$('#editAdForm').modal('hide');
toaster.pop("success", "提示", "保存成功!");
}, function (response) {
toaster.pop("error", "提示", "保存失败!");
});
}
//流量卡配置
$scope.editCardShow = function () {
$scope.dialogData = {};
if (getSelectRows()) {
$("#editCardForm").modal();
}
}
$scope.saveCardEdit = function () {
var ids = $scope.selectedIds
if ($scope.editCardForm.$invalid) {
toaster.pop("warning", "提示", "请填写正确的数据");
return
}
$http({
method: 'POST',
url: '/superadmin/setTrafficCardCost',
data: {ids: ids, cost: $scope.dialogData.cost}
}).then(function (response) {
initDataGrid();
$('#editCardForm').modal('hide');
}, function (response) {
toaster.pop("error", "提示", "保存失败!");
});
}
// 编辑代理商
$scope.editAgents = function (entity) {
var entity = getOneRow();
if (!entity) {
return
}
$scope.dialogData = entity;
$("#agentsForm").modal();
}
$scope.saveAgents = function () {
if ($scope.agentsForm.$invalid) {
toaster.pop("warning", "提示", "请填写正确的数据");
return
}
$http({
method: 'POST',
url: '/superadmin/editUserInfo',
data: {
role: 'agent',
id: $scope.dialogData.id,
'info': {
username: $scope.dialogData.username,
isChangingPaymentGateway: $scope.dialogData.isChangingPaymentGateway,
maxPayLimit: $scope.dialogData.maxPayLimit,
}
}
}).then(function (response) {
initDataGrid();
$('#agentsForm').modal('hide');
}, 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: {}, dealer_sub: {}, user_sub: {}}, row);//非深度克隆的优点是:如果不小心取消了,下次编辑时,子对象的数据还在
$("#wechatForm").modal();
}
$scope.saveWechat = function () {
var url = "/superadmin/bind_wechat_cust";
var data = {};
// 防止为空没填报错
$scope.dialogData.dealer = $scope.dialogData.dealer || {};
$scope.dialogData.dealer_sub = $scope.dialogData.dealer_sub || {};
$scope.dialogData.user = $scope.dialogData.user || {};
$scope.dialogData.user_sub = $scope.dialogData.user_sub || {};
//编辑
$.extend(data, {
'id': $scope.dialogData.id,
customizedDealerGzhAllowable: $scope.dialogData.customizedDealerGzhAllowable,
customizedDealerSubGzhAllowable: $scope.dialogData.customizedDealerSubGzhAllowable,
dealer: {
appid: $scope.dialogData.dealer.appid,
secret: $scope.dialogData.dealer.secret,
templateIdMap: $scope.dialogData.dealer.templateIdMap,
name: $scope.dialogData.dealer.name,
companyName: $scope.dialogData.dealer.companyName
},
dealer_sub: {
appid: $scope.dialogData.dealer_sub.appid,
secret: $scope.dialogData.dealer_sub.secret,
templateIdMap: $scope.dialogData.dealer_sub.templateIdMap,
name: $scope.dialogData.dealer_sub.name,
companyName: $scope.dialogData.dealer_sub.companyName
},
customizedUserGzhAllowable: $scope.dialogData.customizedUserGzhAllowable,
customizedUserSubGzhAllowable: $scope.dialogData.customizedUserSubGzhAllowable,
user: {
appid: $scope.dialogData.user.appid,
secret: $scope.dialogData.user.secret,
templateIdMap: $scope.dialogData.user.templateIdMap,
name: $scope.dialogData.user.name,
companyName: $scope.dialogData.user.companyName
},
user_sub: {
appid: $scope.dialogData.user_sub.appid,
secret: $scope.dialogData.user_sub.secret,
templateIdMap: $scope.dialogData.user_sub.templateIdMap,
name: $scope.dialogData.user_sub.name,
companyName: $scope.dialogData.user_sub.companyName
},
})
$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.moniApps = []
$http.get('/superadmin/getMoniApps', {
params: {
pageSize: 1000,
pageIndex: 1
}
}).then(function (res) {
var payload = res.data.payload;
$scope.moniApps = payload.dataList;
}).catch(function (data) {
toaster.pop("error", "提示", "获取监督号列表失败");
});
$scope.moniConfig = function () {
var ids = getSelectRows()
if (ids) {
$("#moniConfigForm").modal();
$scope.dialogData = {}
for (var key in $scope.moniApps) {
var item = $scope.moniApps[key]
$scope.dialogData[item.appId] = false
}
}
};
$scope.setMoniAppId = function (appId) {
var data = {
agentIds: $scope.selectedIds,
moniApp: [],
}
// 单个保存
if (appId) {
data.moniApp.push({
appId: appId,
switch: $scope.dialogData[appId] || false,// 默认为false
})
} else {
var tempApp = []
for (var key in $scope.dialogData) {
tempApp.push({
appId: key,
switch: $scope.dialogData[key] || false,// 默认为false
})
}
data.moniApp = tempApp
}
$http({
method: 'POST',
url: "/superadmin/editMoniAppForAgents",
data: data
}).then(function (response) {
toaster.pop("success", "提示", "保存成功!");
$scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
//批量保存关闭弹窗
if (!appId) {
$('#moniConfigForm').modal('hide');//弹窗消失
}
}, function (response) {
toaster.pop("error", "提示", "保存失败!");
});
};
/**监督号展现位置**/
$scope.moniPoint = []
$http.get('/superadmin/getMoniPointList', {
params: {
pageSize: 1000,
pageIndex: 1
}
}).then(function (res) {
var payload = res.data.payload;
$scope.moniPoint = payload.dataList;
}).catch(function (data) {
toaster.pop("error", "提示", "获取监督号展现位置列表失败");
});
$scope.moniPointConfig = function () {
var ids = getSelectRows()
if (ids) {
$("#moniPointForm").modal();
$scope.dialogData = {}
for (var key in $scope.moniPoint) {
var item = $scope.moniPoint[key]
$scope.dialogData[item.key] = false
}
}
};
$scope.setMoniPoint = function (pointKey) {
var data = {
agentIds: $scope.selectedIds,
moniPoint: [],
}
// 单个保存
if (pointKey) {
data.moniPoint.push({
key: pointKey,
switch: $scope.dialogData[pointKey] || false,// 默认为false
})
} else {
var tempApp = []
for (var key in $scope.dialogData) {
tempApp.push({
key: key,
switch: $scope.dialogData[key] || false,// 默认为false
})
}
data.moniPoint = tempApp
}
$http({
method: 'POST',
url: "/superadmin/editMoniPointForAgents",
data: data
}).then(function (response) {
toaster.pop("success", "提示", "保存成功!");
$scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
//批量保存关闭弹窗
if (!pointKey) {
$('#moniPointForm').modal('hide');//弹窗消失
}
}, function (response) {
toaster.pop("error", "提示", "保存失败!");
});
};
// 强制关注公众号
$scope.forceFollowGzh = function () {
$scope.dialogData = {};
var rows = getSelectRows()
if (rows) {
$("#editGzhForm").modal();
}
}
$scope.saveGzg = function () {
var ids = $scope.selectedIds
if ($scope.editGzhForm.$invalid) {
toaster.pop("warning", "提示", "请填写正确的数据");
return
}
$http({
method: 'POST',
url: '/superadmin/editAgentForceFollowGzh',
data: {
ids: ids,
forceFollowGzh: $scope.dialogData.forceFollowGzh,
forceFollowGzhForDealer: $scope.dialogData.forceFollowGzhForDealer
}
}).then(function (response) {
initDataGrid();
$('#editGzhForm').modal('hide');
toaster.pop("success", "提示", "保存成功!");
}, function (response) {
toaster.pop("error", "提示", "保存失败!");
});
}
$scope.editSupporter = function () {
$scope.dialogData = {};
var rows = getSelectRows()
if (rows) {
$("#editSupporterForm").modal();
}
}
$scope.saveSuporter = function () {
var ids = $scope.selectedIds
if ($scope.editSupporterForm.$invalid) {
toaster.pop("warning", "提示", "请填写正确的数据");
return
}
$http({
method: 'POST',
url: '/superadmin/editSupporterForAgents',
data: {
ids: ids,
platformSupport: $scope.dialogData.platformSupport
}
}).then(function (response) {
initDataGrid();
$('#editSupporterForm').modal('hide');
toaster.pop("success", "提示", "保存成功!");
}, function (response) {
toaster.pop("error", "提示", "保存失败!");
});
}
// 使用前充值
$scope.openSaveBeforeCharge = function () {
$scope.dialogData = {};
var rows = getSelectRows()
if (rows) {
$("#beforeChargeUnpayForm").modal();
}
}
$scope.saveBeforeChargeUnpay = function () {
var ids = $scope.selectedIds
if ($scope.beforeChargeUnpayForm.$invalid) {
toaster.pop("warning", "提示", "请填写正确的数据");
return
}
$http({
method: 'POST',
url: '/superadmin/editDealerBeforeChargeUnpay',
data: {ids: ids, beforeChargeUnpay: $scope.dialogData.beforeChargeUnpay}
}).then(function (response) {
initDataGrid();
$('#beforeChargeUnpayForm').modal('hide');
toaster.pop("success", "提示", "保存成功!");
}, function (response) {
toaster.pop("error", "提示", "保存失败!");
});
}
//编辑密码 默认123456
$scope.editPassword = function () {
//重置表单状态
$scope.passwordForm.$setPristine();
$scope.passwordForm.$setUntouched();
var rows = $scope.gridApi.selection.getSelectedRows();
if (rows.length == 0) {
toaster.pop("info", "提示", "请选择数据!");
return;
}
if (rows.length > 1) {
toaster.pop("info", "提示", "只能选中编辑一条数据");
return;
}
var item = rows[0];
$scope.passwordData = $.extend({password: 123456}, item);
$("#passwordPanel").modal();
};
//修改密码提交
$scope.savePassword = function () {
//表单未校验通过不能提交
if ($scope.passwordForm.$invalid) {
return;
}
var url = "/superadmin/changeAgentPassword"
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.setDisclaimer = function () {
var entity = getOneRow();
if (!entity) {
return
}
$state.go('app.user.disclaimer', {
agentId: entity.id,
agentName: entity.nickname,
});
}
$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');
};
}]);