'use strict'; /** * controller for User Profile Example */ app.controller('deptlistCtrl', ["$rootScope", "$scope", "$state", "$timeout", "$interval", "$modal", "SweetAlert", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_user_data", function($rootScope, $scope, $state, $timeout, $interval, $modal, SweetAlert, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_user_data) { $scope.langs = i18nService.getAllLangs(); $scope.lang = 'zh-cn'; i18nService.setCurrentLang($scope.lang); $scope.jry_user = JSON.parse(localStorage.getItem('jry_user')); $scope.jry_user_duty = null; if($scope.jry_user&&$scope.jry_user.duty){ $scope.jry_user_duty = $scope.jry_user.duty; } var loginUser = $rootScope.user; $scope.xinzeng=false; $scope.shanchu=false; $scope.bianji=false; for(var i=0;i"; $scope.gridOptions.rowIdentity = function(row) { return row.id; }; $scope.gridOptions.getRowIdentity = function(row) { return row.id; }; $scope.gridOptions.columnDefs = [{ name: 'item', displayName: '序号', width: 50, enableFiltering: false }, { name: 'branchName', displayName: '院区', width: '10%', enableFiltering: false }, { name: 'dept', displayName: '科室', width: '10%', enableFiltering: false }, { name: 'pcode', displayName: '科室编码', width: '10%', enableFiltering: false }, { name: 'parent.dept', displayName: '父级科室', width: '10%', enableFiltering: false, cellTemplate: '
' + '
{{grid.appScope.transferDept(row.entity.parent.dept)}}
' + '
' }, { name: 'phone', displayName: '科室电话', width: '20%', enableFiltering: false }, { name: 'area', displayName: '区域地点', width: '20%', enableFiltering: false, cellTemplate: '
' + '
{{row.entity.place.area.area+""+row.entity.place.place}} {{row.entity.address}}
' + '
' }, { name: '操作', cellTemplate: '
' + // '' + // ''+ '编辑' + '
', enableFiltering: false }, ]; $scope.transferDept=function(data){ if(data){ return data }else{ return "无" } } $scope.changeBranch = function(branchObj){ delete $scope.fileData.department.area; delete $scope.fileData.department.place; $scope.getArea(branchObj.id); } // 院区 $scope.getBranch = function () { var fildata = { "idx": 0, "sum": 1000 }; api_user_data.fetchDataList('branch', fildata).then(function (res) { $scope.branchData=res.list; if($scope.jry_user_duty){ $scope.fileData.department.branch = $scope.branchData.find(v=>v.id == $scope.jry_user_duty.branch) } }) } $scope.getBranch(); // 区域 $scope.getArea = function (branchId) { var fildata = { "idx": 0, "sum": 1000, "area":{} }; if(branchId){ fildata.area.branch = branchId; }else if($scope.jry_user_duty){ fildata.area.branch=$scope.jry_user_duty.branch } api_user_data.fetchDataList('area', fildata).then(function (res) { $scope.areaData=res.list; }) } $scope.getArea(); // 选择区域带出地点 $scope.changeArea=function(item){ $scope.getPlace(item.id) } // 地点 $scope.getPlace = function (areaId) { var fildata = { "idx": 0, "sum": 1000, place: {area: {id: areaId}}, }; api_user_data.fetchDataList('place', fildata).then(function (res) { $scope.placeData=res.list; }) } $scope.saveData = function(selectdata) { console.log(selectdata) var modalInstance = $modal.open({ templateUrl: 'assets/views/system/tpl/deptchange.html', controller: function($scope, scope, $modalInstance, api_user_data) { $scope.deptdata = {}; $scope.deptdata = angular.copy(selectdata); if($scope.deptdata.place){ $scope.deptdata.area = $scope.deptdata.place.area; } if($scope.deptdata.branch && $scope.deptdata.branchName){ $scope.deptdata.branchObj = {id:$scope.deptdata.branch,hosName:$scope.deptdata.branchName} } $scope.areaData=scope.areaData $scope.deptchoice = {}; $scope.title = '科室修改'; $scope.deptdata.phone = $scope.deptdata.phone || ''; $scope.deptPhones = $scope.deptdata.phone.split(',').map(v => ({id: ++$scope.deptsPhoneId, phone: v})); $scope.deptsPhoneId = 1; $scope.isAddDeptsPhone = !($scope.deptdata.phone); // 新添加科室号码 $scope.addDeptPhone = function() { $scope.deptPhones.push({ id: ++$scope.deptsPhoneId, phone: "" }); $scope.deptsPhoneChange(); } // 删除新添加科室号码 $scope.removeDeptPhone = function(index) { $scope.deptPhones.splice(index, 1); $scope.deptsPhoneChange(); } //监听科室电话输入事件 $scope.deptsPhoneChange = function(e, phone) { if (e !== undefined && phone !== undefined) { phone.phone = e; } // -------------判断添加按钮是否禁用 start $scope.isAddDeptsPhone = $scope.deptPhones.some((item) => item.phone.trim() === ""); // -------------判断添加按钮是否禁用 end } var filterData = { "idx": 0, "sum": 9999 }; $scope.getDeptData=function(keyword = ''){ var postData = { "idx": 0, "sum": 20, department: { dept:keyword, selectType: "pinyin_qs", searchType: "quickStart", } }; api_user_data.fetchDataList('department',postData).then(function(data){ $scope.deptchoice = Restangular.stripRestangular(data).list; }) } $scope.getDeptData(); $scope.branchchoice = {}; api_user_data.fetchDataList('branch', filterData).then(function(data) { $scope.branchchoice = Restangular.stripRestangular(data).list; }) $scope.cancel = function() { $modalInstance.dismiss('cancel'); }; $scope.changeArea=function(item,isFirst=false){ if(!isFirst){ $scope.deptdata.place = ''; } var postData={ idx: 0, sum: 1000 } if(item){ postData.place={area: {id: item.id}} } api_user_data.fetchDataList('place', postData).then(function(data) { $scope.placeData = Restangular.stripRestangular(data).list; }) } $scope.changeArea(selectdata.area,true) $scope.changeBranch=function(item,isFirst=false){ if(!isFirst){ $scope.deptdata.area = ''; $scope.deptdata.place = ''; } var postData={ idx: 0, sum: 1000 } if(item){ postData.area={branch: item.id} } api_user_data.fetchDataList('area', postData).then(function(data) { $scope.areaData = Restangular.stripRestangular(data).list; }) } $scope.changeBranch({id:selectdata.branch,hosName:selectdata.branchName},true) $scope.savercode = function(deptdata) { let phones = $scope.deptPhones.filter(v => v.phone.trim() !== '').map(v => v.phone).join(','); if (deptdata&&deptdata.dept&&phones&&deptdata.area&&deptdata.place&&deptdata.branchObj&&deptdata.pcode){ var fildata = { "department": { "id": deptdata.id, area:{id:deptdata.area.id},place:{id:deptdata.place.id,area:{id:deptdata.area.id}},"deleteFlag":0,"phone":phones, "dept": deptdata.dept,branch:deptdata.branchObj.id, pcode: deptdata.pcode,address:deptdata.address } } if (deptdata.parent) { fildata.department.parent= { id: deptdata.parent.id } } // console.log(fildata) api_user_data.updData('department', fildata).then(function(response) { if (response) { if (response.status == 200) { SweetAlert.swal({ title: "修改成功!", type: "success" }, function() { scope.refreshData('expand-right', scope.fileData); }) } else { SweetAlert.swal({ title: "修改失败!", text: response.error, type: "error" }, function() { scope.refreshData('expand-right', scope.fileData); }) } $modalInstance.close(); }else{ SweetAlert.swal({ title: "修改失败!", text: response.error, type: "error" }, function() { scope.refreshData('expand-right', scope.fileData); }) } }) }else{ SweetAlert.swal({ title: "修改失败!", text: "请填写必填项!", type: "error", confirmButtonColor: "#DD6B55" }, function () { }); } } }, resolve: { scope: function() { return $scope; } } }); } $scope.addData = function() { var modalInstance = $modal.open({ templateUrl: 'assets/views/system/tpl/deptchange.html', controller: function($scope, $modalInstance, api_user_data) { $scope.deptdata = {}; var filterData = { "idx": 0, "sum": 9999 }; $scope.title = '科室新增'; $scope.deptPhones = [{id: 1, phone: ""}]; $scope.deptsPhoneId = 1; $scope.isAddDeptsPhone = true; // 新添加科室号码 $scope.addDeptPhone = function() { $scope.deptPhones.push({ id: ++$scope.deptsPhoneId, phone: "" }); $scope.deptsPhoneChange(); } // 删除新添加科室号码 $scope.removeDeptPhone = function(index) { $scope.deptPhones.splice(index, 1); $scope.deptsPhoneChange(); } //监听科室电话输入事件 $scope.deptsPhoneChange = function(e, phone) { if (e !== undefined && phone !== undefined) { phone.phone = e; } // -------------判断添加按钮是否禁用 start $scope.isAddDeptsPhone = $scope.deptPhones.some((item) => item.phone.trim() === ""); // -------------判断添加按钮是否禁用 end } $scope.getDeptData=function(keyword = ''){ var postData = { "idx": 0, "sum": 20, department: { dept:keyword, selectType: "pinyin_qs", searchType: "quickStart", } }; api_user_data.fetchDataList('department',postData).then(function(data){ $scope.deptchoice = Restangular.stripRestangular(data).list; }) } $scope.getDeptData(); api_user_data.fetchDataList('branch', filterData).then(function(data) { $scope.branchchoice = Restangular.stripRestangular(data).list; }) // api_user_data.fetchDataList('area', filterData).then(function(data) { // $scope.areaData = Restangular.stripRestangular(data).list; // }) // api_wechatfile.getDictionary('department').then(function(data) { // $scope.deptchoice = Restangular.stripRestangular(data).list; // }) $scope.cancel = function() { $modalInstance.dismiss('cancel'); }; $scope.savercode = function(deptdata) { deptdata.phones = $scope.deptPhones.filter(v => v.phone.trim() !== '').map(v => v.phone).join(','); if (deptdata&&deptdata.dept&&deptdata.phones&&deptdata.area&&deptdata.place&&deptdata.branchObj&&deptdata.pcode){ $modalInstance.close(deptdata); }else{ SweetAlert.swal({ title: "新增失败!", text: "请填写必填项!", type: "error", confirmButtonColor: "#DD6B55" }, function () { }); } }; $scope.changeBranch=function(item){ $scope.deptdata.area = ''; $scope.deptdata.place = ''; var postData={ idx: 0, area: {branch: item.id}, sum: 1000 } api_user_data.fetchDataList('area', postData).then(function(data) { $scope.areaData = Restangular.stripRestangular(data).list; }) } $scope.changeArea=function(item){ $scope.deptdata.place = ''; var postData={ idx: 0, place: {area: {id: item.id}}, sum: 1000 } api_user_data.fetchDataList('place', postData).then(function(data) { $scope.placeData = Restangular.stripRestangular(data).list; }) } } }); modalInstance.result.then(function(selectedItem) { if (selectedItem.dept&&selectedItem.phones&&selectedItem.area&&selectedItem.place&&selectedItem.branchObj&&selectedItem.pcode) { // angular.forEach($scope.myData,function(item){ // if(item.dept==selectedItem.parent.dept){ // selectedItem.parent.id=item.id; // } // }) var fildata = { "department": { "phone": selectedItem.phones,"area":{id:selectedItem.area.id},"place":{id:selectedItem.place.id,"area":{id:selectedItem.area.id}}, "dept": selectedItem.dept,branch:selectedItem.branchObj.id,pcode:selectedItem.pcode,address:selectedItem.address } } if (selectedItem.parent) { fildata.department.parent= { "id": selectedItem.parent.id } } // console.log(fildata) api_user_data.addData('department', fildata).then(function(response) { if (response) { if (response.status == 200) { SweetAlert.swal({ title: "新增成功!", type: "success" }, function() { $scope.refreshData('expand-right', $scope.fileData); }) } else { SweetAlert.swal({ title: "新增失败!", text: response.msg, type: "error" }) } } }) } else{ SweetAlert.swal({ title: "新增失败!", text: "请填写必填项!", type: "error", confirmButtonColor: "#DD6B55" }, function () { }); } }); } $scope.removeData = function() { var modalInstance = $modal.open({ // templateUrl: 'assets/views/delete.html', templateUrl: 'assets/views/incident/tpl/acceptTask.tpl.html', controller: function($scope, scope, $modalInstance, api_bpm_data) { var rmvList = []; $scope.title = '科室删除'; $scope.connect = '确定要删除此科室?'; rmvList.push(scope.selected.items); $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) { console.log(selectedItem); if (selectedItem[0].children.length>0) { SweetAlert.swal({ title: "该科室存在子类科室", text: "请先删除该科室子类科室!", type: "error" }); } else { api_user_data.rmvData('department', [selectedItem[0].id]).then(function(response) { if (response.status == 200) { 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.fileData); }); } else { SweetAlert.swal({ title: "操作异常!", text: "系统异常,请稍后重试,或者联系管理员!", type: "error" }); } }) } } } }) } // $scope.removeData = function() { // var rmvList = [$scope.selected.items.id] // if (rmvList.length > 0) { // api_user_data.rmvData('department', rmvList).then(function(response) { // if (response.status == 200) { // SweetAlert.swal({ // title: "删除成功!", // type: "success", // confirmButtonColor: "#007AFF" // }, function() { // $scope.myData = _.reject($scope.myData, function(o) { return _.includes(rmvList, o.id); }); // $scope.selected = { // items: [] // }; // }); // } 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; $scope.fileData.idx=newPage - 1; $scope.fileData.sum=pageSize; defaultFilterData = filtersData; $scope.refreshData('expand-right', $scope.fileData); }); gridApi.selection.on.rowSelectionChanged($scope, function(scope) { scope.grid.appScope.selected.items = scope.entity }); }; var defaultFilterData = { "idx": 0, "sum": 10 }; $scope.memoryfilterData = { "idx": 0, "sum": 10 } $scope.fileData={ "idx":0, "sum":10, "department":{branch:$scope.jry_user_duty?$scope.jry_user_duty.branch:undefined} } $scope.ldloading = {}; $scope.refreshData = function(style, postData) { var filterData = angular.copy(postData); if(typeof filterData.department.branch == 'object'){ filterData.department.branch = filterData.department.branch.id } $scope.selected.items = {}; $scope.ldloading[style.replace('-', '_')] = true; if (angular.isUndefined(filterData)) { filterData = defaultFilterData; } $scope.myData = []; $scope.selected = { items: [] }; if ($scope.gridApi) { $scope.gridApi.grid.selection.selectedCount = 0; } api_user_data.fetchDataList('department', 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, postData) { var filterData = angular.copy(postData); if(typeof filterData.department.branch == 'object'){ filterData.department.branch = filterData.department.branch.id } $scope.selected.items = {}; $scope.ldloading[style.replace('-', '_')] = true; if (angular.isUndefined(filterData)) { filterData = defaultFilterData; } // $scope.myData = []; $scope.selected = { items: [] }; if ($scope.gridApi) { $scope.gridApi.grid.selection.selectedCount = 0; } api_user_data.fetchDataList('department', 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.searchData=function(){ $scope.refreshData('expand-right', $scope.fileData); } // 清空 $scope.clean=function(){ if($scope.jry_user_duty){ $scope.fileData.department.branch = {id:$scope.jry_user_duty.branch,hosName:$scope.jry_user_duty.branchName} } delete $scope.fileData.department.dept; delete $scope.fileData.department.address; delete $scope.fileData.department.phone; delete $scope.fileData.department.parent; delete $scope.fileData.department.area; delete $scope.fileData.department.place; $scope.refreshData('expand-right', $scope.fileData); } // 获取父级科室下拉 $scope.model={}; $scope.deptData={}; $scope.getDeptData=function(keyword = ''){ var data = { "idx": 0, "sum": 20, department: { dept:keyword, selectType: "pinyin_qs", searchType: "quickStart", } }; api_user_data.fetchDataList('department',data).then(function(res){ $scope.deptData=res.list||[]; }) } $scope.getDeptData(); $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) }); }]);