'use strict';
/**
* controller for User Profile Example
*/
app.controller('informationCtr', ["$rootScope", "$scope", "$state", "$timeout", "$interval", "$modal", "SweetAlert", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_user_data", "api_login", "api_configure_data", "api_solution", "api_wechatfile", function ($rootScope, $scope, $state, $timeout, $interval, $modal, SweetAlert, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_user_data, api_login, api_configure_data, api_solution, api_wechatfile) {
$scope.langs = i18nService.getAllLangs();
$scope.lang = 'zh-cn';
i18nService.setCurrentLang($scope.lang);
var loginUser = $rootScope.user;
$scope.xinzeng = false;
$scope.shanchu = false;
$scope.bianji = false;
$scope.fabu = false;
$scope.chehui = false;
for (var i = 0; i < loginUser.menu.length; i++) {
if (loginUser.menu[i].link == "fuwuzhinanliebiao_xinzeng") {
$scope.xinzeng = true
}
if (loginUser.menu[i].link == "fuwuzhinanliebiao_shanchu") {
$scope.shanchu = true
}
if (loginUser.menu[i].link == "fuwuzhinanliebiao_bianji") {
$scope.bianji = true
}
if (loginUser.menu[i].link == "fuwuzhinanliebiao_fabu") {
$scope.fabu = true
}
if (loginUser.menu[i].link == "fuwuzhinanliebiao_chehui") {
$scope.chehui = true
}
}
//$scope.allright=false;
//$scope.allrightnot=true;
$scope.gridOptions = {};
$scope.gridOptions.data = 'myData';
$scope.gridOptions.enableColumnResizing = true;
$scope.gridOptions.enableFiltering = true;
$scope.gridOptions.enableGridMenu = true;
$scope.gridOptions.enableRowSelection = true;
$scope.gridOptions.showGridFooter = true;
$scope.gridOptions.showColumnFooter = false;
$scope.gridOptions.fastWatch = true;
$scope.gridOptions.useExternalFiltering = true;
$scope.gridOptions.useExternalPagination = true;
$scope.gridOptions.paginationPageSizes = [10, 20, 50, 100];
$scope.gridOptions.paginationPageSize = 10;
$scope.gridOptions.multiSelect = true;
$scope.gridOptions.rowTemplate = "
";
$scope.gridOptions.rowIdentity = function (row) {
return row.id;
};
$scope.gridOptions.getRowIdentity = function (row) {
return row.id;
};
//remote data
$scope.gridOptions.columnDefs = [{
name: 'item',
displayName: '序号',
enableFiltering: false,
width: 50
},
{
name: 'title',
displayName: '标题',
width: '25%',
enableFiltering: false
},
{
name: 'serviceType.name',
displayName: '分类',
width: '13%',
enableFiltering: false
},
{
name: 'createUser.name',
displayName: '创建人',
width: '8%',
enableFiltering: false
},
{
name: 'createUser.dept.dept',
displayName: '发布科室',
width: '10%',
enableFiltering: false
},
{
name: 'createTime',
displayName: '创建时间',
width: '10%',
minWidth:'140',
enableFiltering: false,
cellTemplate: '' +
'
{{grid.appScope.transferTime(row.entity.createTime)}}
' +
'
'
},
{
name: 'status',
displayName: '状态',
width: '8%',
enableFiltering: false,
cellTemplate: '' +
'
{{grid.appScope.getStatus(row.entity.status)}}
' +
'
'
},
{
minWidth: '310',
name: '操作',
enableFiltering: false,
cellTemplate: '' +
'
编辑' +
'
删除' +
'
查看' +
'
发布' +
'
撤回' +
'
'
},
];
$scope.transferTime = function(time) {
return moment(time).format('YYYY-MM-DD HH:mm');
}
// 状态名转化
$scope.getStatus = function (data) {
if (data == 1) {
return "已发布"
} else if (data == 2) {
return "暂存"
} else if (data == 3) {
return "已撤回"
}
}
// 撤回显示隐藏
$scope.showChehui = function (data) {
// console.log(data);
if (data.status == 1) {
return true
} else {
return false
}
}
// 发布显示隐藏
$scope.showFabu = function (data) {
if (data.status == 2 || data.status == 3) {
return true
} else {
return false
}
}
// 查看显示隐藏
$scope.showChakan = function (data) {
// if(data.status==1||data.status==2){
return true
// }else{
// return false
// }
}
// 删除显示隐藏
$scope.showShanchu = function (data) {
if (data.status == 2 || data.status == 3) {
return true
} else {
return false
}
}
// 编辑显示隐藏
$scope.showBianji = function (data) {
if (data.status == 2 || data.status == 3) {
return true
} else {
return false
}
}
$scope.open = function ($event) {
$event.preventDefault();
$event.stopPropagation();
$scope.opened = !$scope.opened;
};
$scope.endOpen = function ($event) {
$event.preventDefault();
$event.stopPropagation();
$scope.startOpened = false;
$scope.endOpened = !$scope.endOpened;
};
$scope.startOpen = function ($event) {
$event.preventDefault();
$event.stopPropagation();
$scope.endOpened = false;
$scope.startOpened = !$scope.startOpened;
};
// 获取创建人
$scope.getCreateUser = function () {
api_configure_data.fetchDataList("user", {
"idx": 0,
"sum": 1000,
"user":{
"simple": true,
engineer: 1,
}
}).then(function (res) {
$scope.createUserData = res.list
})
}
$scope.getCreateUser()
// 发布
$scope.release = function (data) {
var modalInstance = $modal.open({
templateUrl: 'assets/views/delete.html',
controller: function ($scope, scope, $modalInstance, api_bpm_data) {
$scope.title = '服务指南发布';
$scope.connect = '确定要发布此服务指南?';
$scope.ok = function () {
$modalInstance.close(data);
};
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
},
size: 'sm',
resolve: {
scope: function () {
return $scope;
}
}
});
modalInstance.result.then(function (selectedItem) {
if (selectedItem) {
selectedItem.status = 1;
delete selectedItem.item;
api_solution.updData('serviceGuide', {
"serviceGuide": selectedItem
}).then(function (response) {
if (response.data) {
SweetAlert.swal({
title: "发布成功!",
type: "success",
confirmButtonColor: "#007AFF"
}, function () {
$scope.myData = _.reject($scope.myData, function (o) {
return _.includes(selectedItem, o.id);
});
$scope.gridOptions.totalItems = $scope.gridOptions.totalItems - selectedItem.length;
$scope.refreshData('expand-right', $scope.jry_fileData);
});
} else {
SweetAlert.swal({
title: "操作异常!",
text: "系统异常,请稍后重试,或者联系管理员!",
type: "error"
});
}
})
}
})
}
$scope.minTime = "";
$scope.maxTime = "";
// 新增
$scope.addData = function () {
$state.go('app.system.form', {
formKey: 'serviceGuideForm',
service: 'api_solution'
});
}
//列表操作按钮-查看
// $scope.onDblClick = function(data) {
// var modelfile = { model: { serviceGuide: data } };
// $state.go('app.system.form_editor', { formKey: 'serviceGuideDetail', service: 'api_solution', model: JSON.stringify(modelfile) });
// };
$scope.seeDetail = function (data) {
var modelfile = {
model: {
serviceGuide: data
}
};
$state.go('app.system.form_editor', {
formKey: 'serviceGuideDetail',
service: 'api_solution',
model: JSON.stringify(modelfile)
});
};
//列表操作按钮-编辑
$scope.saveData = function (data) {
var modelData = {
model: {
serviceGuide: data
}
};
$state.go('app.system.form', {
formKey: 'serviceGuideEdi',
service: 'api_solution',
model: JSON.stringify(modelData),
'isServiceGuideEdit': "true"
});
};
// 搜索
$scope.searchData = function () {
if ($scope.minTime) {
$scope.jry_fileData.serviceGuide.startTime = moment($scope.minTime).format("YYYY-MM-DD HH:mm:ss")
}
if ($scope.maxTime) {
$scope.jry_fileData.serviceGuide.endTime = moment($scope.maxTime).format("YYYY-MM-DD HH:mm:ss")
}
$scope.refreshData('expand-right', $scope.jry_fileData);
}
// 清空
$scope.clean = function () {
delete $scope.jry_fileData.serviceGuide.title;
delete $scope.jry_fileData.serviceGuide.serviceType;
delete $scope.jry_fileData.serviceGuide.startTime;
$scope.minTime = "";
delete $scope.jry_fileData.serviceGuide.endTime;
$scope.maxTime = "";
delete $scope.jry_fileData.serviceGuide.createUser;
$scope.refreshData('expand-right', $scope.jry_fileData);
}
// 撤回
$scope.withdraw = function (data) {
var modalInstance = $modal.open({
templateUrl: 'assets/views/delete.html',
controller: function ($scope, scope, $modalInstance, api_bpm_data) {
$scope.title = '服务指南撤回';
$scope.connect = '确定要撤回此服务指南?';
$scope.ok = function () {
$modalInstance.close(data);
};
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
},
size: 'sm',
resolve: {
scope: function () {
return $scope;
}
}
});
modalInstance.result.then(function (selectedItem) {
if (selectedItem) {
console.log(selectedItem);
delete selectedItem.item;
selectedItem.status = 3;
api_solution.updData("serviceGuide", {
"serviceGuide": selectedItem
}).then(function (res) {
if (res.data) {
SweetAlert.swal({
title: "撤回成功!",
type: "success",
confirmButtonColor: "#007AFF"
})
$scope.refreshData('expand-right', $scope.jry_fileData);
} else {
SweetAlert.swal({
title: "操作异常!",
text: "系统异常,请稍后重试,或者联系管理员!",
type: "error"
});
}
})
}
})
}
// 删除
$scope.removeData = function (data) {
var modalInstance = $modal.open({
templateUrl: 'assets/views/delete.html',
controller: function ($scope, scope, $modalInstance, api_bpm_data) {
var rmvList = [];
$scope.title = '服务指南删除';
$scope.connect = '确定要删除此服务指南?';
// angular.forEach(scope.selected.items, function(item) {
// rmvList.push(item.id);
// });
rmvList.push(data.id);
$scope.ok = function () {
$modalInstance.close(rmvList);
};
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
},
size: 'sm',
resolve: {
scope: function () {
return $scope;
}
}
});
modalInstance.result.then(function (selectedItem) {
if (selectedItem) {
if (selectedItem.length > 0) {
api_solution.rmvData('serviceGuide', selectedItem).then(function (response) {
if (response.data) {
SweetAlert.swal({
title: "删除成功!",
type: "success",
confirmButtonColor: "#007AFF"
}, function () {
$scope.myData = _.reject($scope.myData, function (o) {
return _.includes(selectedItem, o.id);
});
$scope.selected = {
items: []
};
$scope.gridOptions.totalItems = $scope.gridOptions.totalItems - selectedItem.length;
// $scope.gridApi.grid.selection.selectedCount = 0;
$scope.refreshData('expand-right', $scope.jry_fileData);
});
} else {
SweetAlert.swal({
title: "操作异常!",
text: "系统异常,请稍后重试,或者联系管理员!",
type: "error"
});
}
})
}
}
})
}
$scope.selected = {
items: []
}
$scope.editted = {
items: []
}
$scope.jry_fileData = {
"idx": 0,
"sum": 10,
"serviceGuide": {}
}
$scope.gridOptions.onRegisterApi = function (gridApi) {
$scope.gridApi = gridApi;
gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
// var filtersData = $scope.memoryfilterData;
// filtersData.idx = newPage - 1;
$scope.jry_fileData.idx = newPage - 1;
// filtersData.sum = pageSize;
$scope.jry_fileData.sum = pageSize;
// defaultFilterData = filtersData;
$scope.refreshData('expand-right', $scope.jry_fileData);
});
};
// api_solution.jry_fetchDataList("serviceGuide",{"idx":0,"sum":10}).then(function(res){
// console.log(res)
// })
$scope.serviceGuideType = [];
// 获取分类
$scope.getType = function () {
var data = {
key: "service_type",
type: "list"
}
api_wechatfile.getDictionary(data).then(function (res) {
$scope.serviceGuideType = res
})
}
$scope.getType()
$scope.ldloading = {};
//获取数据
$scope.refreshData = function (style, filterData) {
$scope.ldloading[style.replace('-', '_')] = true;
if (angular.isUndefined(filterData)) {
filterData = defaultFilterData;
}
if (angular.isDefined($scope.searchTypes)) {
filterData['searchType'] = $scope.searchTypes;
}
$scope.myData = [];
// filterData['flag'] = -1;
// console.log("filterData=" + JSON.stringify(filterData))
api_solution.jry_fetchDataList('serviceGuide', filterData).then(function (data) {
var myData = Restangular.stripRestangular(data);
$scope.gridOptions.totalItems = myData.totalNum;
$scope.myData = myData.list;
for (var i = 0; i < $scope.myData.length; i++) {
$scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum;
$scope.myData[i]['createTime'] = moment($scope.myData[i]['createTime']).format('YYYY-MM-DD HH:mm:ss')
}
$scope.ldloading[style.replace('-', '_')] = false;
// console.log("$scope.myData="+JSON.stringify($scope.myData))
}, function () {
$scope.ldloading[style.replace('-', '_')] = false;
});
};
//获取数据
$scope.refreshData2 = function (style, filterData) {
$scope.ldloading[style.replace('-', '_')] = true;
if (angular.isUndefined(filterData)) {
filterData = defaultFilterData;
}
if (angular.isDefined($scope.searchTypes)) {
filterData['searchType'] = $scope.searchTypes;
}
// $scope.myData = [];
// filterData['flag'] = -1;
// console.log("filterData=" + JSON.stringify(filterData))
api_solution.jry_fetchDataList('serviceGuide', filterData).then(function (data) {
var myData = Restangular.stripRestangular(data);
$scope.gridOptions.totalItems = myData.totalNum;
$scope.myData = myData.list;
for (var i = 0; i < $scope.myData.length; i++) {
$scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum;
$scope.myData[i]['createTime'] = moment($scope.myData[i]['createTime']).format('YYYY-MM-DD HH:mm:ss')
}
$scope.ldloading[style.replace('-', '_')] = false;
// console.log("$scope.myData="+JSON.stringify($scope.myData))
}, function () {
$scope.ldloading[style.replace('-', '_')] = false;
});
};
$scope.timer = $interval(function () {
$scope.refreshData2('expand-right', $scope.jry_fileData);
}, $rootScope.refreshTime);
$scope.$on('$destroy', function () {
$interval.cancel($scope.timer)
})
$scope.refreshData('expand-right', $scope.jry_fileData);
}]);