123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686 |
- 'use strict';
- /**
- * controller for User Profile Example
- */
- app.controller('noticeCtrl', ["$rootScope", "$scope", "$state", "$timeout", "$interval", "$modal", "SweetAlert", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_user_data", "api_login", "api_configure_data", function ($rootScope, $scope, $state, $timeout, $interval, $modal, SweetAlert, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_user_data, api_login, api_configure_data) {
- $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 == "gonggaoliebiao_xinzeng") {
- $scope.xinzeng = true
- }
- if (loginUser.menu[i].link == "gonggaoliebiao_shanchu") {
- $scope.shanchu = true
- }
- if (loginUser.menu[i].link == "gonggaoliebiao_bianji") {
- $scope.bianji = true
- }
- if (loginUser.menu[i].link == "gonggaoliebiao_fabu") {
- $scope.fabu = true
- }
- if (loginUser.menu[i].link == "gonggaoliebiao_chehui") {
- $scope.chehui = 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 = "<div ng-dblclick=\"grid.appScope.onDblClick(row.entity)\" ng-repeat=\"(colRenderIndex, col) in colContainer.renderedColumns track by col.uid\" ui-grid-one-bind-id-grid=\"rowRenderIndex + '-' + col.uid + '-cell'\" class=\"ui-grid-cell\" ng-class=\"{ 'ui-grid-row-header-cell': col.isRowHeader }\" role=\"{{col.isRowHeader ? 'rowheader' : 'gridcell'}}\" ui-grid-cell></div>";
- $scope.gridOptions.rowIdentity = function (row) {
- return row.id;
- };
- $scope.gridOptions.getRowIdentity = function (row) {
- return row.id;
- };
- $scope.transferRole = function (roles) {
- var tempValue = "";
- angular.forEach(roles, function (item) {
- if (tempValue != "") {
- tempValue = tempValue + "/";
- }
- tempValue = tempValue + item.role;
- })
- return tempValue;
- }
- $scope.transferStatus = function (flag) {
- return (flag == 0) ? "有效" : "无效";
- }
- $scope.transfergroup = function (group) {
- var groupData = '';
- angular.forEach(group, function (item) {
- if (groupData == '') {
- groupData = item.groupName;
- } else {
- groupData = groupData + "/" + item.groupName;
- }
- })
- return groupData;
- }
- //remote data
- $scope.gridOptions.columnDefs = [{
- name: 'item',
- displayName: '序号',
- enableFiltering: false,
- width: 50
- },
- {
- name: 'title',
- displayName: '标题',
- width: '25%',
- enableFiltering: false
- },
- {
- name: 'createUser.name',
- displayName: '创建人',
- width: '8%',
- enableFiltering: false
- },
- // { name: 'areaDTO.area', displayName: '区域', width: '8%', enableFiltering: false },
- // { name: 'placeDTO.place', displayName: '地点', width: '8%', enableFiltering: false },
- {
- name: 'dept.dept',
- displayName: '发布科室',
- width: '10%',
- enableFiltering: false
- },
- {
- name: 'statusName',
- displayName: '状态',
- width: '10%',
- enableFiltering: false
- },
- {
- name: 'createTime',
- displayName: '创建时间',
- width: '16%',
- enableFiltering: false,
- cellTemplate: '<div>' +
- '<div class="ui-grid-cell-contents" style="cursor:pointer;text-align:center">{{grid.appScope.transferTime(row.entity.createTime)}}</div>' +
- '</div>'
- },
- // { name: 'content', displayName: '内容', enableFiltering: false }
- // '<div class="links cl-effect-1">' +
- // '<a ng-click="grid.appScope.selectRowFunction(row.entity)" tooltip="编辑" tooltip-placement="left"><i class="fa fa-pencil-square-o"></i></a>'+
- // '</div>' , width:100, enableFiltering:false}
- {
- name: '操作',
- enableFiltering: false,
- minWidth: "300",
- cellTemplate: '<div class="links cl-effect-1 pull-left ui-grid-cell-contents">' +
- '<a ng-click="grid.appScope.saveData(row.entity)" ng-show="grid.appScope.showBianji(row.entity)&&grid.appScope.bianji">编辑</a>' +
- '<a ng-click="grid.appScope.removeData(row.entity)" ng-show="grid.appScope.showShanchu(row.entity)&&grid.appScope.shanchu">删除</a>' +
- '<a ng-click="grid.appScope.seeData(row.entity)">查看</a>' +
- '<a ng-click="grid.appScope.release(row.entity)" ng-show="grid.appScope.showFabu(row.entity)&&grid.appScope.fabu">发布</a>' +
- '<a ng-click="grid.appScope.withdraw(row.entity)" ng-show="grid.appScope.showChehui(row.entity)&&grid.appScope.chehui">撤回</a>' +
- '</div>'
- },
- ];
- $scope.transferTime = function(time) {
- return moment(time).format('YYYY-MM-DD HH:mm');
- }
- // 查看显示隐藏
- $scope.showChehui = function (data) {
- if (data.statusName == "已发布") {
- return true
- } else {
- return false
- }
- }
- // 发布显示隐藏
- $scope.showFabu = function (data) {
- if (data.statusName == "暂存" || data.statusName == "已撤销") {
- return true
- } else {
- return false
- }
- }
- // // 查看显示隐藏
- // $scope.showChakan=function(data){
- // if(data.statusName=="已发布"){
- // return true
- // }else{
- // return false
- // }
- // }
- // 删除显示隐藏
- $scope.showShanchu = function (data) {
- if (data.statusName == "暂存" || data.statusName == "已撤销") {
- return true
- } else {
- return false
- }
- }
- // 编辑显示隐藏
- $scope.showBianji = function (data) {
- if (data.statusName == "暂存" || data.statusName == "已撤销") {
- return true
- } else {
- return false
- }
- }
- //区域地点过滤
- $scope.key = {};
- api_user_data.fetchDataList('area', {
- "idx": 0,
- "sum": 1000
- }).then(function (response) {
- if (response) {
- if (response.status = 200) {
- $scope.outarea = response.list;
- }
- }
- })
- $scope.onChangearea = function (data) {
- delete $scope.key.place;
- if ($scope.memoryfilterData.incident) {
- delete $scope.memoryfilterData.incident.place;
- }
- var fildata = {
- "idx": 0,
- "sum": 1000,
- "place": {
- areaId: data.area.id
- }
- };
- api_user_data.fetchDataList('place', fildata).then(function (response) {
- if (response) {
- if (response.status = 200) {
- $scope.outplace = response.list;
- }
- }
- })
- };
- $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.saveData = function (data) {
- var modelData = {
- model: {
- notice: data
- }
- };
- $state.go('app.system.form', {
- formKey: 'noticeEdi',
- service: 'api_user_data',
- model: JSON.stringify(modelData),
- 'isNoticeEdit': "true"
- });
- };
- //列表操作按钮-查看
- // $scope.onDblClick = function(data) {
- // var modelfile = { model: { notice: data } };
- // $state.go('app.system.form_editor', { formKey: 'noticeDetail', service: 'api_user_data', model: JSON.stringify(modelfile) });
- // };
- $scope.seeData = function (data) {
- var modelfile = {
- model: {
- notice: data
- }
- };
- $state.go('app.system.form_editor', {
- formKey: 'noticeDetail',
- service: 'api_user_data',
- model: JSON.stringify(modelfile)
- });
- };
- //列表操作按钮-新增
- $scope.addData = function () {
- // console.log(loginUser)
- var modelData = {
- model: {
- notice: {
- dept: {
- id: loginUser.dept.id
- }
- }
- }
- };
- $state.go('app.system.form', {
- formKey: 'noticeEditor',
- service: 'api_user_data',
- model: JSON.stringify(modelData)
- });
- }
- // 发布
- $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) {
- // console.log(selectedItem);
- selectedItem.status = 1;
- delete selectedItem.item;
- delete selectedItem.statusName;
- api_user_data.updData('notice', {
- "notice": 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.searchData = function () {
- if ($scope.minTime) {
- $scope.jry_fileData.notice.createTime = moment($scope.minTime).format("YYYY-MM-DD HH:mm:ss")
- }
- if ($scope.maxTime) {
- $scope.jry_fileData.notice.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.notice.title;
- delete $scope.jry_fileData.notice.createTime;
- $scope.minTime = "";
- delete $scope.jry_fileData.notice.endTime;
- $scope.maxTime = "";
- delete $scope.jry_fileData.notice.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);
- selectedItem.status = 2;
- delete selectedItem.item;
- delete selectedItem.statusName;
- api_user_data.updData('notice', {
- "notice": 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.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_user_data.rmvData('notice', 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,
- "notice": {}
- }
- $scope.gridOptions.onRegisterApi = function (gridApi) {
- $scope.gridApi = gridApi;
- // gridApi.edit.on.afterCellEdit($scope,function(rowEntity, colDef, newValue, oldValue){
- // // console.log(rowEntity);
- // });
- 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);
- });
- // gridApi.selection.on.rowSelectionChanged($scope, function(scope) {
- // console.log("ok");
- // var j = 0;
- // for (var i = 0; i <= scope.grid.appScope.selected.items.length; i++) {
- // if (scope.grid.appScope.selected.items[i] == scope.entity) {
- // j++;
- // break;
- // }
- // }
- // // console.log("j="+j)
- // if (j == 1) {
- // scope.grid.appScope.selected.items.splice(i, 1);
- // } else {
- // scope.grid.appScope.selected.items.push(scope.entity)
- // }
- // });
- // gridApi.selection.on.rowSelectionChangedBatch($scope, function(rows) {
- // var selectitem = [];
- // selectitem = angular.copy($scope.selected.items);
- // for (var j = 0; j < rows.length; j++) {
- // if (rows[j].isSelected == true) {
- // selectitem.push(rows[j].entity);
- // } else {
- // delete selectitem[j];
- // // rows.splice(j, 1);
- // }
- // }
- // $scope.selected.items = [];
- // for (var i = 0; i < selectitem.length; i++) {
- // if (selectitem[i]) {
- // $scope.selected.items.push(selectitem[i]);
- // }
- // }
- // });
- gridApi.core.on.filterChanged($scope, function () {
- var grid = this.grid;
- // var filtersData = {
- // idx: 0,
- // sum: 10
- // };
- var filtersData = $scope.memoryfilterData;
- angular.forEach(grid.columns, function (item) {
- if (item.enableFiltering) {
- if (angular.isDefined(item.filters[0].term) && item.filters[0].term != '') {
- if (angular.isUndefined(filtersData['user'])) {
- filtersData['notice'] = {};
- // filtersData['user']['flag'] = -1;
- filtersData['notice'][item.field] = item.filters[0].term;
- } else {
- // filtersData.user.flag = -1;
- filtersData.notice[item.field] = item.filters[0].term;
- }
- // filtersData['user']['flag'] = -1;
- // filtersData['user'][item.field] = item.filters[0].term;
- }
- }
- });
- $scope.memoryfilterData = filtersData;
- $scope.refreshData('expand-right', filtersData);
- });
- };
- var defaultFilterData = {
- "idx": 0,
- "sum": 10
- };
- $scope.memoryfilterData = {
- "idx": 0,
- "sum": 10
- }
- $scope.ldloading = {};
- $scope.refresh = function (style, filterData) {
- $scope.selected = {
- items: []
- };
- if ($scope.gridApi) {
- // $scope.gridApi.grid.options.paginationCurrentPage = 0;
- // $scope.gridApi.grid.selection.selectedCount = 0;
- }
- $scope.refreshData('expand-right', defaultFilterData);
- }
- //获取数据
- $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_user_data.fetchDataList('notice', 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'] = $scope.myData[i]['createTime'].split('.')[0];
- if ($scope.myData[i].status == 1) {
- $scope.myData[i]["statusName"] = "已发布"
- } else if ($scope.myData[i].status == 2) {
- $scope.myData[i]["statusName"] = "已撤销"
- } else if ($scope.myData[i].status == 3) {
- $scope.myData[i]["statusName"] = "暂存"
- }
- }
- $scope.ldloading[style.replace('-', '_')] = false;
- // console.log("$scope.myData="+JSON.stringify($scope.myData))
- }, function () {
- $scope.ldloading[style.replace('-', '_')] = false;
- });
- };
- //获取数据2
- $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;
- }
- // filterData['flag'] = -1;
- // console.log("filterData=" + JSON.stringify(filterData))
- api_user_data.fetchDataList('notice', 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'] = $scope.myData[i]['createTime'].split('.')[0];
- if ($scope.myData[i].status == 1) {
- $scope.myData[i]["statusName"] = "已发布"
- } else if ($scope.myData[i].status == 2) {
- $scope.myData[i]["statusName"] = "已撤销"
- } else if ($scope.myData[i].status == 3) {
- $scope.myData[i]["statusName"] = "暂存"
- }
- }
- $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', defaultFilterData);
- }]);
|