app.controller('complaintOrderCtrl', ['$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');
$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);//翻页是强制刷新
}
});
}
};
let stateMap = {
'': '-请选择-',
PENDING: '未处理',
PROCESSING: '正在处理',
PROCESSED: '处理完成',
}
let stateList = []
for (let key in stateMap) {
stateList.push({
value: key,
label: stateMap[key]
})
}
//枚举常量
$scope.enum = {
stateMap: stateMap,
stateList: stateList
};
var searchType = $scope.enum.searchType = [
{value: 'complaintId', label: "按投诉订单查询", desc: '输入用户投诉订单'},
];
//查询条件
var condition = $scope.condition = {
stateFilter: stateList[0],
searchType: searchType[0],
searchKey: '',
};
//查询条件
$scope.query = {
startTime: moment().format("YYYY-MM-DD"),
endTime: moment().format("YYYY-MM-DD"),
};
//事件
$scope.event = {
statusChange: function (key, item) {
condition[key] = {}
condition[key].value = item.value;
condition[key].label = item.label;
condition[key].desc = item.desc;
},
search: function () {
// 就在当前 厂商|代理商|经销商的域下进行搜索
if (condition.searchKey === "") {
$scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize, true);
} else {
$scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize);
}
},
};
$scope.getStateText = function (value) {
return stateMap[value]
}
function setColumnDefs() {
$scope.gridOptions.columnDefs = [
{
field: 'complaint_id',
displayName: '投诉订单号',
},
{
field: 'complaint_time',
displayName: '投诉时间',
},
{
field: 'complainted_mchid',
displayName: '用户投诉商户号',
},
{
field: 'complaint_state',
displayName: '投诉状态',
cellTemplate: `
{{ grid.appScope.getStateText(row.entity.complaint_state)}}
`
},
{
field: 'complaint_detail', displayName: '投诉详情',
cellTemplate: '{{row.entity.complaint_detail}}
'
},
{
field: 'payer_phone',
displayName: '用户联系方式',
},
{
field: 'complaint_order_info', displayName: '订单详情',
cellTemplate: '{{row.entity.complaint_order_info}}
'
},
{field: 'complaint_full_refunded', displayName: '是否已退款',},
{field: 'incoming_user_response', displayName: '是否有新回复',},
{
field: 'user_complaint_times', displayName: '投诉次数',
cellTemplate: `{{row.entity.user_complaint_times}}
`
},
{
field: 'operation',
displayName: '操作',
enableFiltering: false,
enableSorting: false,
enableHiding: false,//禁止在列选择器中隐藏
enableColumnMenu: false,// 是否显示列头部菜单按钮
minWidth: 100,
cellTemplate: '' +
'' +
'' +
'
'
},
];
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, force) {
if ($scope.gridOptionsLoading) {
return;
}
var params = {
pageSize: pageSize,
pageIndex: curPage,
};
var query = $scope.query;
params.startTime = query.startTime
params.endTime = query.endTime
console.log(condition.searchType)
if (condition.searchKey !== "") {
params[condition.searchType.value] = condition.searchKey
}
if (condition.stateFilter.value) {
params.stateFilter = condition.stateFilter.value
}
$scope.gridOptionsLoading = true;
$http.get('/superadmin/getUserComplaintList', {
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.reply = function (entity) {
var url = "/superadmin/replyComplaint";
$.confirm({
content: '',
title: "回复用户",
buttons: {
ok: {
btnClass: 'btn-red',
action: function () {
var remark = $('#replyRemark').val()
if (!remark) {
return false
}
$http({
method: 'POST',
url: url,
data: {
complainted_mchid: entity.complainted_mchid,
complaint_id: entity.complaint_id,
remark: remark,
}
}).then(function (response) {
if (response.data.result) {
toaster.pop("success", "提示", "回复成功!");
} else {
toaster.pop("error", "提示", "回复失败!");
}
$scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
}, function (response) {
toaster.pop("error", "提示", "回复失败!");
});
}
},
}
});
};
$scope.submitComplaint = function (entity) {
var url = "/superadmin/submitComplaint";
$.confirm({
content: '确定提交投诉处理?',
buttons: {
ok: {
btnClass: 'btn-red',
action: function () {
$http({
method: 'POST',
url: url,
data: {
complainted_mchid: entity.complainted_mchid,
complaint_id: entity.complaint_id,
}
}).then(function (response) {
if (response.data.result) {
toaster.pop("success", "提示", "提交成功!");
} else {
toaster.pop("error", "提示", "提交失败!");
}
$scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
}, function (response) {
toaster.pop("error", "提示", "提交失败!");
});
}
},
}
});
};
$scope.showInfoDetailInfo = function (title, key, content) {
var detail = content[key]
$scope.infoDetail = {title: title, content: detail};
$(".devManageMain #detailInfoPanel").modal();
};
$scope.closeDetailPanel = function () {
$(".devManageMain #detailInfoPanel").modal("hide");
};
}]);