app.controller('joinDevManageCtrl', ['$scope', '$filter', '$http', '$stateParams', '$timeout', 'uiGridConstants', 'i18nService', 'toaster', function ($scope, $filter, $http, $stateParams, $timeout, uiGridConstants, i18nService, toaster) {
i18nService.setCurrentLang("zh-cn");
moment.locale('zh-cn');
var dealerId = $stateParams.dealerId || "";
$scope.startTimeOpen = false;
$scope.endTimeOpen = false;
$scope.timeChange = function (newDate, oldDate) {
$scope.startTimeOpen = false;
$scope.endTimeOpen = false;
};
$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, true);//翻页是强制刷新
}
});
}
};
//查询条件
var condition = $scope.condition = {
dealerId: dealerId
};
//查询条件
$scope.query = {
startTime: moment().format("YYYY-MM-DD"),
endTime: moment().format("YYYY-MM-DD"),
};
//枚举常量
$scope.enum = {
joinStatus: [
{name: '厂家加盟', value: 'factoryJoined', className: 'text-danger'},
{name: '可被经销商加盟', value: 'factoryAllowed', className: 'text-warning-dker'},
{name: '经销商加盟', value: 'joinerJoined', className: 'text-success'},
]
};
//事件
$scope.ngEvent = {
quickTime: function (event, passDay) {
$scope.query.startTime = moment().add(-(passDay - 1), "day").format("YYYY-MM-DD");
$scope.query.endTime = moment().format("YYYY-MM-DD");
},
};
//事件
$scope.event = {
search: function () {
if (condition.searchKey === "") {
$scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize);
} else {
$scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize);
}
}
};
function setColumnDefs() {
$scope.gridOptions.columnDefs = [
{
field: 'logicalCode',
displayName: '设备编号',
width: 100,
},
{
field: 'joinerName',
displayName: '加盟商',
width: 140,
},
{
field: 'address',
displayName: '设备地址',
},
{
field: 'joinMoney',
displayName: '加盟费',
},
{
field: 'joinScale',
displayName: '加盟商分成',
cellTemplate: '
{{row.entity.joinScale}}%
'
},
{
field: 'totalPay',
displayName: '最近总收入',
},
{
field: 'joinStatus',
displayName: '加盟状态',
cellTemplate: '{{grid.appScope.formatterStatus(row.entity.joinStatus)}}
'
},
];
var fields = $scope.gridOptions.columnDefs;
for (var index in fields) {
var item = fields[index];
if (item && item['minWidth'] == null) {
item['minWidth'] = 100;
}
}
}
$scope.setPagingData = function (data) {
var pagedData = data.data.dataList;
$scope.myData = pagedData;
$scope.gridOptions.totalItems = data.data.total;
};
$scope.getPagedDataAsync = function (curPage, pageSize) {
if ($scope.gridOptionsLoading) {
return;
}
var params = {
pageSize: pageSize,
pageIndex: curPage,
};
if (condition.searchKey !== "") {
params.searchKey = condition.searchKey
}
if (condition.dealerId !== "") {
params.dealerId = condition.dealerId
}
if ($scope.query.startTime !== "") {
params.startDate = $scope.query.startTime
}
if ($scope.query.endTime !== "") {
params.endDate = $scope.query.endTime
}
$scope.gridOptionsLoading = true;
$http.get('/manager/getDevDetailListForJoiner', {
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();
var dialogData = $scope.dialogData = {};
$scope.formatterStatus = function (status) {
var list = $scope.enum.joinStatus;
for (var index in list) {
var item = list[index];
if (item.value === status) {
return item.name;
}
}
};
$scope.formatterStatusStyle = function (status) {
var list = $scope.enum.joinStatus;
for (var index in list) {
var item = list[index];
if (item.value === status) {
return item.className;
}
}
};
//规则配置
$scope.ruleEdit = function () {
var rows = $scope.gridApi.selection.getSelectedRows();
if (rows.length === 0) {
toaster.pop("info", "提示", "请选择数据!");
return false;
}
var ids = []
var data = {}
if (rows.length > 1) {
for (var index in rows) {
ids.push(rows[index].logicalCode)
}
data = {
logicalCode: ids,
}
} else {
var row = rows[0]
data = {
logicalCode: [row.logicalCode],
joinStatus: row.joinStatus,
joinMoney: parseFloat(row.joinMoney),
joinScale: parseFloat(row.joinScale),
}
}
$scope.dialogData = data;
$("#joinRuleEdit").modal();
}
$scope.saveJoinRule = function () {
//表单未校验通过不能提交
if ($scope.joinRuleEdit.$invalid) {
return;
}
var data = $scope.dialogData
var url = "/manager/setDevJoinStatus";
$http({
method: 'POST',
url: url,
data: data
}).then(function (response) {
$('#joinRuleEdit').modal('hide');//弹窗消失
if (response.data.result === 1) {
toaster.pop("success", "提示", "保存成功!")
$scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
}
}, function (response) {
toaster.pop("error", "提示", "保存失败了!");
});
}
$scope.joinStatusEdit = function () {
var rows = $scope.gridApi.selection.getSelectedRows();
if (rows.length === 0) {
toaster.pop("info", "提示", "请选择数据!");
return false;
}
var ids = []
var data = {}
if (rows.length > 1) {
for (var index in rows) {
ids.push(rows[index].logicalCode)
}
data = {
logicalCode: ids,
}
} else {
var row = rows[0]
data = {
logicalCode: [row.logicalCode],
joinStatus: row.joinStatus,
}
}
$scope.dialogData = data;
$("#joinStatusForm").modal();
}
$scope.saveJoinStatusForm = function () {
//表单未校验通过不能提交
if ($scope.joinStatusForm.$invalid) {
return;
}
var data = $scope.dialogData
var url = "/manager/setDevJoinStatus";
$http({
method: 'POST',
url: url,
data: data
}).then(function (response) {
$('#joinStatusForm').modal('hide');//弹窗消失
if (response.data.result === 1) {
toaster.pop("success", "提示", "保存成功!")
$scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
}
}, function (response) {
toaster.pop("error", "提示", "保存失败了!");
});
}
}]);