123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562 |
- 'use strict';
- app.controller('grouplistCtrl', ["$rootScope", "$scope", "$state", "$timeout", "$interval", "SweetAlert", "$modal", "Restangular", "api_user_data", "api_configure_data", function($rootScope, $scope, $state, $timeout, $interval, SweetAlert, $modal, Restangular, api_user_data, api_configure_data) {
- var loginUser = $rootScope.user;
- $scope.xinzeng=false;
- $scope.shanchu=false;
- $scope.bianji=false;
- for(var i=0;i<loginUser.menu.length;i++){
- if(loginUser.menu[i].link=="gongzuozuguanli_xinzeng"){
- $scope.xinzeng=true
- }
- if(loginUser.menu[i].link=="gongzuozuguanli_shanchu"){
- $scope.shanchu=true
- }
- if(loginUser.menu[i].link=="gongzuozuguanli_bianji"){
- $scope.bianji=true
- }
- }
- //user tree
- var apple_selected, tree, treedata_avm, treedata_geography;
- var i = 0;
- $scope.bodyHeight = Math.max((window.innerHeight - 290), 500);
- // $(window).resize(function() {
- // $scope.bodyHeight = Math.max((window.innerHeight - 290), 500);
- // });
- $rootScope.isMask = false;
- // //角色仪表权限
- // function dashboardaborad(branch) {
- // $scope.dashboard_tree = angular.copy($scope.dashboard_data);
- // angular.forEach($scope.dashboard_tree, function(index, i) {
- // if (branch.dashboard && branch.dashboard.length > 0) {
- // angular.forEach(branch.dashboard, function(item) {
- // if (index.id == item.id) {
- // $scope.dashboard_tree[i].checks = true;
- // }
- // })
- // }
- // })
- // }
- //组树
- $scope.my_tree = {};
- $scope.my_user = {};
- $scope.try_async_load = function() {
- $scope.group = {};
- $scope.my_user = [];
- $scope.my_data = [];
- $scope.doing_async = true;
- var postData = { "idx": 0, "sum": 1000, group: {} };
- if($rootScope.user.duty){
- // 当前的所属责任科室
- postData.group.duty = $rootScope.user.duty;
- }else if($rootScope.user.branch){
- // 当前的所属院区
- postData.group.branch = $rootScope.user.branch.id;
- }
- api_user_data.fetchDataList('group', postData).then(function(response) {
- $scope.doing_async = false;
- if (response.status == 200) {
- var data = response.list;
- var objects = [];
- for (var i = 0; i < data.length; i++) {
- var object = {};
- // object.id = data[i].id;
- // if (data[i].parent && data[i].parent.id != 0) {
- // object.parent = data[i].parent.id;
- // }
- angular.extend(object, data[i]);
- object.label = object.branchName + '-' + (object.duty ? object.duty.dept : '') + '-' + object.groupName;
- // if (loginUser.id == 1) {
- // objects.push(object);
- // } else {
- // if (object.roletype == 0) {
- // objects.push(object);
- // }
- // }
- objects.push(object);
- }
- $scope.my_data = convertParentToChildList(objects);
- $scope.tree_data = angular.copy($scope.my_data);
- } else {
- SweetAlert.swal({
- title: "系统错误!",
- text: "请刷新重试!",
- type: "error"
- });
- }
- });
- };
- 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.try_async_load();
- //end power
- //tree user
- $scope.try_async_powerload = function(items) {
- if (items) {
- $scope.getbranchs = items.users;
- }
- // $scope.my_power = [];
- var objects = [];
- var selected = [];
- for (var i = 0; i < $scope.getbranchs.length; i++) {
- var object = {};
- angular.extend(object, $scope.getbranchs[i]);
- object.label = object.name;
- objects.push(object);
- }
- selected = angular.copy($scope.tree_user);
- // if (data.length > 0) {
- angular.forEach(selected, function(index, i) {
- angular.forEach(objects, function(item) {
- if (index.id == item.id) {
- selected[i].checks = true;
- }
- })
- })
- $scope.my_user = selected;
- // if ($scope.my_user.length > 0) {
- // $scope.doing_asyncuser = false;
- // }
- };
- //tree admin
- $scope.my_user = [];
- $scope.tile = [];
- $scope.try_async_user = function() {
- var postData = { "idx": 0, "sum": 9999, user: {engineer: 1,} };
- if($rootScope.user.duty){
- // 当前的所属责任科室
- postData.user.duty = $rootScope.user.duty;
- }else if($rootScope.user.branch){
- // 当前的所属院区
- postData.user.branch = $rootScope.user.branch;
- }
- api_user_data.fetchDataList("user", postData).then(function(response) {
- if (response.status == 200) {
- var data = response.list;
- var objects = [];
- for (var i = 0; i < data.length; i++) {
- var object = {};
- // object.id = data[i].id;
- // if (data[i].parent && data[i].parent.id != 0) {
- // object.parent = data[i].parent.id;
- // }
- angular.extend(object, data[i]);
- object.label = object.name;
- objects.push(object);
- }
- $scope.tile = objects;
- $scope.my_user = convertParentToChildList(objects);
- $scope.tree_user = angular.copy($scope.my_user);
- if ($scope.my_user.length > 0) {
- $scope.doing_asyncuser = false;
- }
- } else {
- SweetAlert.swal({
- title: "系统错误!",
- text: "请刷新重试!",
- type: "error"
- });
- }
- });
- };
- $scope.try_async_user();
- //点击角色
- $scope.group = {};
- $scope.change = true;
- $scope.my_tree_handler = function(branch) {
- $scope.group = branch;
- $scope.try_async_powerload(branch);
- $scope.change = false;
- }
- //start remove
- $scope.getbranchs = {};
- $scope.formbranch = function(branchData) {
- $scope.getbranchs = branchData;
- }
- //change right
- $scope.changeData = function() {
- if(!$scope.group.id){
- SweetAlert.swal({
- title: "操作失败",
- text: "请选择需要修改的项!",
- type: "error",
- confirmButtonColor: "#DD6B55"
- });
- return;
- }
- var users = [];
- $rootScope.isMask = true;
- angular.forEach($scope.getbranchs, function(it) {
- users.push({ "id": it.id });
- })
- // var branch = { 'menu': menu };
- // angular.extend(branch, { 'id': $scope.role.id, 'role': $scope.role.role, 'rolecode': $scope.role.rolecode, 'roletype': $scope.role.roletype, 'dashboard': $scope.role.dashboard })
- var fildata = { "group": { "id": $scope.group.id, "groupName": $scope.group.groupName, "users": users, "duty":$scope.group.duty, "branch": $scope.group.branch } }
- // api_user_data.updData('group', fildata).then(function(response) {
- // if (response) {
- // if (response.status == 200) {
- api_user_data.updData('group', fildata).then(function(response) {
- if (response && response.status == 200) {
- $scope.try_async_load();
- SweetAlert.swal({
- title: "提交成功!",
- type: "success",
- confirmButtonColor: "#007AFF"
- }, function() {
- $rootScope.isMask = false;
- });
- } else {
- SweetAlert.swal({
- title: "系统错误",
- text: "系统错误,请稍后重试!",
- type: "error",
- confirmButtonColor: "#DD6B55"
- }, function() {
- $rootScope.isMask = false;
- });
- }
- })
- // $state.go('app.system.form',{formKey:'system_add_menu', service:'api_configure_data', model : JSON.stringify(modelData)});
- }
- // //change menu
- // $scope.choiceMenu = [];
- // $scope.showHandler = function(branch) {
- // $scope.choiceMenu = branch;
- // }
- //add role
- $scope.addRole = function() {
- var modalInstance = $modal.open({
- templateUrl: 'assets/views/system/tpl/group.html',
- controller: function($rootScope, $scope, scope, $modalInstance, api_user_data, api_category) {
- $scope.disableBranch = false;
- $scope.disableDuty = false;
- if($rootScope.user.duty){
- $scope.disableBranch = true;
- $scope.disableDuty = true;
- }else if($rootScope.user.branch){
- $scope.disableBranch = true;
- $scope.disableDuty = false;
- }
- $scope.group = {};
- $scope.hospitalList = [];
- $scope.dutyDeptList = [];
- // 获取院区
- $scope.getHospitals = function(){
- //跨科室转派
- api_category.getOwnBranch({}).then(function (data) {
- if(data.status == 200){
- $scope.hospitalList = data.data || [];
- if($rootScope.user.duty){
- // 当前的所属责任科室
- $scope.group.branch = $scope.hospitalList.find(v=>v.id == $rootScope.user.duty.branch);
- }else if($rootScope.user.branch){
- // 当前的所属院区
- $scope.group.branch = $scope.hospitalList.find(v=>v.id == $rootScope.user.branch.id);
- }
- }else{
- SweetAlert.swal({
- title: "系统错误!",
- text: "请刷新重试!",
- type: "error"
- });
- }
- })
- }
- $scope.getHospitals();
- // 修改院区
- $scope.changeBranch = function(keyword=''){
- $scope.group.duty = undefined;
- $scope.dutyDeptList = [];
- api_category.getOwnDuty({branchId: $scope.group.branch.id}).then(function (data) {
- if(data.status == 200){
- $scope.dutyDeptList = data.data || [];
- if($rootScope.user.duty){
- // 当前的所属责任科室
- $scope.group.duty = $rootScope.user.duty;
- }else if($rootScope.user.branch){
- // 当前的所属院区
- $scope.group.duty = undefined;
- }
- }else{
- SweetAlert.swal({
- title: "系统错误!",
- text: "请刷新重试!",
- type: "error"
- });
- }
- })
- }
- $scope.cancel = function() {
- $modalInstance.dismiss('cancel');
- };
- $scope.ok = function(group) {
- var close = true;
- for (var i = 0; i < scope.my_data.length; i++) {
- if (scope.my_data[i].groupName == group.groupName) {
- close = false;
- $modalInstance.dismiss('cancel');
- SweetAlert.swal({
- title: "修改失败!",
- text: "该组已存在",
- type: "error"
- })
- break;
- } else {}
- }
- if (close) {
- $modalInstance.close(group);
- }
- }
- },
- resolve: {
- scope: function() {
- return $scope;
- }
- }
- });
- modalInstance.result.then(function(selectedItem) {
- if (selectedItem) {
- if(!selectedItem.duty || !selectedItem.branch || !selectedItem.groupName){
- SweetAlert.swal({
- title: "操作失败!",
- text: "请填写必填项!",
- type: "error"
- })
- return;
- }
- var fildata = { "group": { "groupName": selectedItem.groupName,duty:selectedItem.duty } }
- api_user_data.addData('group', fildata).then(function(response) {
- if (response) {
- if (response.status == 200) {
- SweetAlert.swal({
- title: "新增成功!",
- type: "success"
- }, function() {
- $scope.try_async_load();
- })
- } else {
- SweetAlert.swal({
- title: "修改失败!",
- type: "error"
- })
- }
- // $modalInstance.close();
- }
- })
- }
- })
- }
- //change role
- $scope.changeRole = function() {
- if($scope.group.id){
- var modalInstance = $modal.open({
- templateUrl: 'assets/views/system/tpl/group.html',
- controller: function($rootScope, $scope, scope, $modalInstance, api_user_data, api_category) {
- $scope.disableBranch = true;
- $scope.disableDuty = true;
- $scope.group = angular.copy(scope.group);
- $scope.hospitalList = [];
- $scope.dutyDeptList = [];
- // 获取院区
- $scope.getHospitals = function(){
- //跨科室转派
- api_category.getOwnBranch({}).then(function (data) {
- if(data.status == 200){
- $scope.hospitalList = data.data || [];
- $scope.group.branch = $scope.hospitalList.find(v=>v.id == scope.group.branch);
- }else{
- SweetAlert.swal({
- title: "系统错误!",
- text: "请刷新重试!",
- type: "error"
- });
- }
- })
- }
- $scope.getHospitals();
- // 修改院区
- $scope.changeBranch = function(keyword){
- if(keyword === undefined){
- $scope.group.duty = undefined;
- $scope.dutyDeptList = [];
- }
- api_category.getOwnDuty({branchId: scope.group.branch}).then(function (data) {
- if(data.status == 200){
- $scope.dutyDeptList = data.data || [];
- $scope.group.duty = scope.group.duty;
- }else{
- SweetAlert.swal({
- title: "系统错误!",
- text: "请刷新重试!",
- type: "error"
- });
- }
- })
- }
- $scope.cancel = function() {
- $modalInstance.dismiss('cancel');
- };
- $scope.ok = function(item) {
- $modalInstance.close(item);
- }
- },
- resolve: {
- scope: function() {
- return $scope;
- }
- }
- });
- modalInstance.result.then(function(selectedItem) {
- if (selectedItem) {
- if(!selectedItem.duty || !selectedItem.branch || !selectedItem.groupName){
- SweetAlert.swal({
- title: "操作失败!",
- text: "请填写必填项!",
- type: "error"
- })
- return;
- }
- var fildata = { "group": { "id": selectedItem.id, "groupName": selectedItem.groupName, "users": selectedItem.users,duty:selectedItem.duty, "branch": selectedItem.branch.id } }
- api_user_data.updData('group', fildata).then(function(response) {
- if (response) {
- if (response.status == 200) {
- SweetAlert.swal({
- title: "修改成功!",
- type: "success"
- }, function() {
- $scope.try_async_load();
- // $scope.refreshData('expand-right', defaultFilterData);
- })
- } else {
- SweetAlert.swal({
- title: "修改失败!",
- type: "error"
- })
- }
- // $modalInstance.close();
- }
- })
- }
- })
- }else{
- SweetAlert.swal({
- title: "操作失败",
- text: "请选择需要修改的项!",
- type: "error",
- confirmButtonColor: "#DD6B55"
- });
- }
- }
- //remove role
- $scope.removeRole = function() {
- if(!$scope.group.id){
- SweetAlert.swal({
- title: "操作失败",
- text: "请选择需要修改的项!",
- type: "error",
- confirmButtonColor: "#DD6B55"
- });
- return;
- }
- var modalInstance = $modal.open({
- templateUrl: 'assets/views/delete.html',
- controller: function($scope, scope, $modalInstance) {
- var rmvList = [];
- $scope.title = '工作组删除';
- $scope.connect = '确定要删除此工作组?';
- rmvList.push(scope.group.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('group', selectedItem).then(function(response) {
- if (response.data) {
- SweetAlert.swal({
- title: "删除成功!",
- type: "success",
- confirmButtonColor: "#007AFF"
- }, function() {
- $scope.try_async_load();
- });
- } else {
- SweetAlert.swal({
- title: "操作异常!",
- text: "系统异常,请稍后重试,或者联系管理员!",
- type: "error"
- });
- }
- })
- }
- }
- })
- }
- }]);
|