123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690 |
- // 'use strict';
- /**
- * controller for User Profile Example
- */
- app.controller('adminUserListCtrl_requ', ["$rootScope", "$scope", "$http", "$state", "FileUploader", "$timeout", "$interval", "$modal", "SweetAlert", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_user_data", function ($rootScope, $scope, $http, $state, FileUploader, $timeout, $interval, $modal, SweetAlert, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_user_data) {
- $scope.langs = i18nService.getAllLangs();
- $scope.lang = 'zh-cn';
- i18nService.setCurrentLang($scope.lang);
- var loginUser = $rootScope.user;
- //$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 = false;
- $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 = false;
- $scope.gridOptions.rowTemplate= "<div ng-dblclick=\"grid.appScope.onDblClick(row)\" 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;
- }
- //remote data
- $scope.gridOptions.columnDefs = [{
- name: 'item',
- displayName: '序号',
- width: 50,
- enableFiltering: false,
- cellTemplate: '<div>' +
- '<div class="ui-grid-cell-contents">{{row.entity.item}}</div>' +
- '</div>'
- },
- {
- name: 'name',
- displayName: '姓名',
- width: '10%',
- enableFiltering: false
- },
- // { name: 'studentNo', displayName: '学工号', width: 120 },
- {
- name: 'account',
- displayName: '工号',
- width: '10%',
- enableFiltering: false
- },
- {
- name: 'weixin',
- displayName: '微信',
- width: '10%',
- minWidth: '120',
- enableFiltering: false
- },
- {
- name: 'dept.dept',
- displayName: '科室',
- width: '12%',
- enableFiltering: false
- },
- {
- name: 'requesterType.name',
- displayName: '职务',
- width: '10%',
- enableFiltering: false
- },
- {
- name: 'phone',
- displayName: '电话',
- width: '12%',
- minWidth: '125',
- enableFiltering: false
- },
- {
- name: 'place.area.area',
- displayName: '区域',
- width: '10%',
- enableFiltering: false
- },
- {
- name: 'place.place',
- displayName: '地点',
- width: '12%',
- enableFiltering: false
- },
- {
- name: '操作',
- cellTemplate: '<div><div class="cl-effect-1 ui-grid-cell-contents pull-left">' +
- // '<a ng-click="grid.appScope.saveData(row.entity)" tooltip="编辑" tooltip-placement="right">' +
- // '<i class="fa fa-pencil-square-o"></i></a>'+
- '<a ng-click="grid.appScope.saveData(row.entity)" class="bianjifont">编辑</a>' +
- '</div></div>',
- enableFiltering: false
- }
- ];
- //导入
- $scope.importopen = function () { //导入触发事件
- var modalInstance = $modal.open({
- templateUrl: 'assets/views/import.html',
- controller: function ($scope, $modalInstance, FileUploader) {
- var importUploader = $scope.importUploader = new FileUploader({
- url: api_user_data.jry_importData().getRequestedUrl(),
- });
- // importUploader.filters.push({
- // name: 'customFilter',
- // fn: function(item /*{File|FileLikeObject}*/ , options) {
- // var type = item.name.slice(item.name.lastIndexOf('.') + 1);
- // //var type = '|' + item.type.slice(item.type.lastIndexOf('/') + 1) + '|';
- // return (type == 'xlsx');
- // }
- // });
- importUploader.filters.push({
- name: 'customFilter',
- fn: function (item /*{File|FileLikeObject}*/ , options) {
- this.queue = [];
- return this.queue.length < 2;
- }
- });
- importUploader.onWhenAddingFileFailed = function (item /*{File|FileLikeObject}*/ , filter, options) {
- console.info('onWhenAddingFileFailed', item, filter, options);
- };
- importUploader.onAfterAddingFile = function (fileItem) {
- console.info('onAfterAddingFile', fileItem);
- };
- importUploader.onAfterAddingAll = function (addedFileItems) {
- console.info('onAfterAddingAll', addedFileItems);
- };
- importUploader.onProgressItem = function (fileItem, progress) {
- console.info('onProgressItem', fileItem, progress);
- };
- importUploader.onProgressAll = function (progress) {
- console.info('onProgressAll', progress);
- };
- importUploader.onSuccessItem = function (fileItem, response, status, headers) {
- if (response.status == 200) {
- SweetAlert.swal({
- title: "导入成功!",
- confirmButtonColor: "#007AFF",
- type: "success"
- }, function () {
- // $scope.ldloading.contract_overlay = false;
- $rootScope.isMask = false;
- $scope.refreshData('expand-right', $scope.fileData);
- });
- } else {
- // $scope.ldloading.contract_overlay = false;
- $rootScope.isMask = false;
- SweetAlert.swal({
- title: "导入失败!",
- text: response.error,
- type: "error"
- })
- }
- console.info('onSuccessItem', fileItem, response, status, headers);
- };
- importUploader.onErrorItem = function (fileItem, response, status, headers) {
- console.info('onErrorItem', fileItem, response, status, headers);
- SweetAlert.swal({
- title: "系统错误!",
- text: "系统错误,请稍候重试!",
- type: "error"
- });
- };
- importUploader.onCancelItem = function (fileItem, response, status, headers) {
- console.info('onCancelItem', fileItem, response, status, headers);
- };
- importUploader.onCompleteItem = function (fileItem, response, status, headers) {
- console.info('onCompleteItem', fileItem, response, status, headers);
- };
- importUploader.onCompleteAll = function () {
- console.info('onCompleteAll');
- };
- $scope.ldloading = {};
- $rootScope.isMask = false;
- $scope.import = function (style) {
- // $scope.ldloading[style.replace('-', '_')] = true;
- $modalInstance.dismiss('cancel');
- $rootScope.isMask = true;
- importUploader.onBeforeUploadItem = function (item) {
- angular.extend(item.headers, $rootScope.getSession());
- // item.formData[0]['filename'] = item.file.name;
- // item.formData[0]['type'] = "requester";
- item.formData.push({
- 'fileName': item.file.name
- });
- item.formData.push({
- 'type': "requester"
- });
- console.info('onBeforeUploadItem', item);
- };
- importUploader.uploadAll();
- }
- $scope.cancel = function () {
- $modalInstance.dismiss('cancel');
- };
- },
- size: 'sm',
- resolve: {
- importUploader: function () {
- return $scope.importUploader;
- }
- }
- });
- modalInstance.result.then(function (selectedItem) {
- if (selectedItem) {}
- })
- }
- //导出
- $scope.openmodel = function () {
- var modalInstance = $modal.open({
- templateUrl: 'assets/views/system/tpl/getdown.html',
- controller: function ($scope, $modalInstance) {
- $scope.key = {};
- $scope.title = '报修人导入模版下载';
- $scope.lable = '下载模版版本';
- $scope.onChange = function (key) {
- $scope.key = key;
- }
- $scope.downmodel = [{
- id: 1,
- name: "EXCEL2003版(xls)"
- }, {
- id: 2,
- name: "EXCEL2007及以上版(xlsx)"
- }]
- $scope.ok = function () {
- $modalInstance.close($scope.key);
- };
- $scope.cancel = function () {
- $modalInstance.dismiss('cancel');
- };
- },
- size: 'sm',
- });
- modalInstance.result.then(function (selectedItem) {
- if (selectedItem) {
- var selectedItemId = "";
- if (selectedItem.id == 2) {
- selectedItemId = ".xlsx";
- }
- var type = "requester";
- var month = 0;
- $http({
- url: api_user_data.downDataModel(type, month).getRequestedUrl(),
- method: 'GET',
- headers: {
- 'Accept': '*/*'
- },
- responseType: 'arraybuffer'
- }).success(function (data, status, headers, config) {
- var file = new Blob([data], {
- // type : 'application/octet-stream'
- type: 'application/vnd.ms-excel'
- });
- //trick to download store a file having its URL
- var fileURL = URL.createObjectURL(file);
- var a = document.createElement('a');
- a.href = fileURL;
- a.target = '_blank';
- a.download = "报修人" + selectedItemId;
- document.body.appendChild(a);
- a.click();
- }).error(function (data, status, headers, config) {
- console.log(data);
- });
- }
- });
- }
- //修改
- $scope.saveData = function (data) {
- if (data.place) {
- var modelData = {
- model: {
- user: {
- "id": data.id,
- "branch": data.branch,
- "account": data.account,
- "name": data.name,
- "gender": data.gender,
- "email": data.email,
- "phone": data.phone,
- "deptName": data.deptName,
- "telephone": data.telephone,
- "dept": data.dept,
- "area": data.place.area,
- "place": data.place,
- "studentNo": data.studentNo,
- "houseNumber": data.houseNumber,
- "requesterType": data.requesterType,
- "weixin": data.weixin,
- engineer: undefined,
- }
- }
- };
- } else {
- var modelData = {
- model: {
- requester: {
- "id": data.id,
- "branch": data.branch,
- "account": data.account,
- "name": data.name,
- "gender": data.gender,
- "email": data.email,
- "phone": data.phone,
- "deptName": data.deptName,
- "telephone": data.telephone,
- "dept": data.dept,
- // "area": data.place.area,
- "place": data.place,
- "studentNo": data.studentNo,
- "houseNumber": data.houseNumber,
- "requesterTypeDTO": data.requesterTypeDTO,
- "weixin": data.weixin,
- engineer: undefined,
- }
- }
- };
- }
- $state.go('app.system.user.requester', {
- formKey: 'system_edit_requester',
- service: 'api_user_data',
- model: JSON.stringify(modelData)
- });
- };
- // 下拉树
- function convertListToTree(data, treeMap) {
- var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
- var root = null; //Initially set our loop to null
- //loop over data
- for (var i = 0; i < data.length; i++) {
- var datum = data[i];
- //each node will have children, so let's give it a "children" poperty
- datum.children = [];
- //add an entry for this node to the map so that any future children can
- //lookup the parent
- idToNodeMap[datum.id] = datum;
- //Does this node have a parent?
- // console.log("datum="+JSON.stringify(datum))
- if (typeof datum.parent === "undefined" || datum.parent === null) {
- //Doesn't look like it, so this node is the root of the tree
- root = datum;
- treeMap[datum.id] = root;
- } else {
- //This node has a parent, so let's look it up using the id
- parentNode = idToNodeMap[datum.parent.id];
- //We don't need this property, so let's delete it.
- // delete datum.parent;
- //Let's add the current node as a child of the parent node.
- parentNode.children.push(datum);
- }
- }
- return root;
- }
- function convertParentToChildList(data) {
- var treeMap = {};
- var list = [];
- convertListToTree(data, treeMap);
- angular.forEach(treeMap, function (item) {
- list.push(item);
- });
- return list;
- }
- $scope.parentdata = {};
- $scope.try_async_load = function () {
- $scope.my_data = [];
- $scope.doing_async = true;
- var data = {
- "idx": 0,
- "sum": 1000
- };
- api_user_data.fetchDataList('department', data).then(function (response) {
- var data = response.list;
- var objects = [];
- $scope.parentdata = data;
- for (var i = 0; i < data.length; i++) {
- var object = {};
- object.id = data[i].id;
- if (angular.isDefined(data[i].parent)) {
- object.parent = data[i].parent;
- }
- if (angular.isDefined(data[i].hasArea)) {
- object.hasArea = data[i].hasArea;
- }
- if (angular.isDefined(data[i].hasSimple)) {
- object.hasSimple = data[i].hasSimple;
- }
- if (angular.isDefined(data[i].group)) {
- object.group = data[i].group;
- }
- if (angular.isDefined(data[i].priority)) {
- object.priority = data[i].priority;
- }
- object.label = data[i].dept;
- // object.actions = data[i][3]; //权限部分
- // object.group = "1";
- // object.user = "2";
- object.state = {
- "opened": true
- };
- object.typeName = "type";
- // if()
- // if (object.actions.indexOf("2") >= 0) { //知识库类型 具有增加权限--系统管理员
- $scope.showAddSolutionType = true;
- // }
- // if (object.actions.indexOf("5") >= 0) { //知识库类型 具有授权权限--系统管理员
- $scope.showReviewKnowledgeType = true;
- // }
- objects.push(object);
- }
- $scope.my_data = convertParentToChildList(objects);
- $scope.tree_data = angular.copy($scope.my_data);
- // if ($scope.my_data.length > 0) {
- $scope.doing_async = false;
- // }
- });
- };
- $scope.try_async_load();
- //新增
- $scope.addData = function () {
- $state.go('app.system.user.requester', {
- formKey: 'system_edit_requester',
- service: 'api_user_data'
- })
- }
- $scope.removeData = function () {
- var modalInstance = $modal.open({
- templateUrl: 'assets/views/delete.html',
- controller: function ($scope, scope, $modalInstance, api_bpm_data) {
- var rmvList = [];
- $scope.title = '报修人删除';
- $scope.connect = '确定要删除此报修人?';
- rmvList.push(scope.selected.items[0].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('user', 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;
- });
- } else {
- SweetAlert.swal({
- title: "操作异常!",
- text: "系统异常,请稍后重试,或者联系管理员!",
- type: "error"
- });
- }
- })
- }
- }
- })
- }
- $scope.selected = {
- items: []
- }
- $scope.editted = {
- items: []
- }
- $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;
- filtersData.sum = pageSize;
- defaultFilterData = filtersData;
- $scope.fileData.idx = newPage - 1;
- $scope.fileData.sum = pageSize;
- $scope.refreshData('expand-right', $scope.fileData);
- });
- // gridApi.selection.on.rowSelectionChanged($scope, function(data) {
- // data.grid.appScope.selected.items = data.entity
- // });
- gridApi.selection.on.rowSelectionChanged($scope, function (data) {
- if (data.isSelected) {
- data.grid.appScope.selected.items[0] = data.entity;
- } else {
- if (data.grid.appScope.selected.items[0].id == data.entity.id) {
- data.grid.appScope.selected.items = [];
- }
- }
- });
- gridApi.core.on.filterChanged($scope, function () {
- var grid = this.grid;
- var filtersData = {
- idx: 0,
- sum: 10
- };
- 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['user'] = {};
- }
- filtersData['user'][item.field] = item.filters[0].term;
- }
- }
- });
- $scope.memoryfilterData = filtersData;
- $scope.refreshData('expand-right', $scope.fileData);
- });
- };
- 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', $scope.fileData);
- }
- $scope.fileData = {
- "idx": 0,
- "sum": 10,
- "user": {
- }
- };
- // 搜索
- $scope.searchData = function () {
- $scope.refreshData('expand-right', $scope.fileData);
- }
- // 清空
- $scope.clean = function () {
- delete $scope.fileData.user.name;
- delete $scope.fileData.user.account;
- delete $scope.fileData.user.dept;
- $scope.try_async_load();
- $scope.refreshData('expand-right', $scope.fileData);
- }
- $scope.onFilterCallback = function (data) {
- // console.log(data);
- $scope.fileData.user.dept = data;
- }
- $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 = [];
- // if ($scope.gridApi) {
- // $scope.gridApi.grid.options.paginationCurrentPage = 0;
- // $scope.gridApi.grid.selection.selectedCount = 0;
- // }
- filterData.user.engineer = 0;
- api_user_data.fetchDataList('user', 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.ldloading[style.replace('-', '_')] = false;
- }, 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 = [];
- // if ($scope.gridApi) {
- // $scope.gridApi.grid.options.paginationCurrentPage = 0;
- // $scope.gridApi.grid.selection.selectedCount = 0;
- // }
- filterData.user.engineer = 0;
- api_user_data.fetchDataList('user', 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.ldloading[style.replace('-', '_')] = false;
- }, function () {
- $scope.ldloading[style.replace('-', '_')] = false;
- });
- };
- $scope.refreshData('expand-right', $scope.fileData);
- $scope.timer = $interval(function () {
- $scope.refreshData2('expand-right', $scope.fileData);
- }, $rootScope.refreshTime);
- $scope.$on('$destroy', function () {
- $interval.cancel($scope.timer)
- });
- }]);
|