"use strict"; /** * controller for User Profile Example */ app.controller("hospitalCtrl", [ "$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); 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 == "hospital_add") { $scope.xinzeng = true; } if (loginUser.menu[i].link == "hospital_del") { $scope.shanchu = true; } if (loginUser.menu[i].link == "hospital_edit") { $scope.bianji = 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 = false; // $scope.gridOptions.rowTemplate = // '
'; $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: "parent.hosName", displayName: "父级院区", width: "25%", enableFiltering: false, }, { name: "hosName", displayName: "院区名称", width: "25%", enableFiltering: false, }, { name: "hosNo", displayName: "院区编码", width: "25%", enableFiltering: false, }, { name: "操作", cellTemplate: '", enableFiltering: false, }, ]; $scope.transferDept = function (data) { if (data) { return data; } else { return "无"; } }; // // 区域 // $scope.getArea = function () { // var fildata = { // "idx": 0, // "sum": 1000 // }; // 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/hospitalchange.html", controller: function ($scope, scope, $modalInstance, api_user_data) { $scope.hospital = selectdata; $scope.title = "院区编辑"; $scope.hospitalList = []; api_user_data.fetchDataList("branch", { "idx":0,"sum":10 }) .then(function (data) { $scope.hospitalList = Restangular.stripRestangular(data).list.filter(v=>(v.id != selectdata.id && (v.children.length > 0||(v.children.length === 0 && Restangular.stripRestangular(data).list.length === 1)))); }); $scope.cancel = function () { $modalInstance.dismiss("cancel"); }; $scope.savercode = function (hospital) { if (hospital && hospital.hosName && hospital.hosNo) { var fildata = { branch: { uuid:hospital.uuid, parent:hospital.parent, id: hospital.id, hosName: hospital.hosName, hosNo: hospital.hosNo, deleteFlag: 0, }, }; api_user_data .updData("branch", fildata) .then(function (response) { if (response) { if (response.status == 200) { SweetAlert.swal( { title: "修改成功!", type: "success", }, function () { scope.refreshData("expand-right", scope.fileData); } ); } else if (response.status == 500) { SweetAlert.swal( { title: "修改失败!", text: "该院区已存在", type: "error", }, function () { scope.refreshData("expand-right", scope.fileData); } ); } else { SweetAlert.swal( { title: "修改失败!", type: "error", }, function () { scope.refreshData("expand-right", scope.fileData); } ); } $modalInstance.close(); } else { SweetAlert.swal( { title: "修改失败!", 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/hospitalchange.html", controller: function ($scope, $modalInstance, api_user_data) { $scope.title = "院区新增"; $scope.cancel = function () { $modalInstance.dismiss("cancel"); }; $scope.hospital = { hosName: "", hosNo: "", parent:undefined }; $scope.hospitalList = []; api_user_data.fetchDataList("branch", { "idx":0,"sum":10 }) .then(function (data) { $scope.hospitalList = Restangular.stripRestangular(data).list.filter(v=>(v.children.length > 0||(v.children.length === 0 && Restangular.stripRestangular(data).list.length === 1))); if($scope.hospitalList.length){ $scope.hospital.parent = $scope.hospitalList[0]; } }); $scope.savercode = function (hospital) { if (hospital && hospital.hosName && hospital.hosNo) { $modalInstance.close(hospital); } else { SweetAlert.swal( { title: "新增失败!", text: "请填写必填项!", type: "error", confirmButtonColor: "#DD6B55", }, function () {} ); } }; }, }); modalInstance.result.then(function (selectedItem) { if (selectedItem.hosName && selectedItem.hosNo) { var fildata = { branch: { parent:selectedItem.parent, hosName: selectedItem.hosName, hosNo: selectedItem.hosNo, deleteFlag: 0, }, }; api_user_data.addData("branch", 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 (rmData) { var modalInstance = $modal.open({ templateUrl: "assets/views/incident/tpl/acceptTask.tpl.html", controller: function ($scope, scope, $modalInstance, api_bpm_data) { var rmvList = []; $scope.title = "院区删除"; $scope.connect = "确定要删除此院区?"; rmvList.push(rmData); $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); api_user_data .rmvData("branch", [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.selected = { items: [], }; $scope.editted = { items: [], }; $scope.gridOptions.onRegisterApi = function (gridApi) { $scope.gridApi = gridApi; 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, branch: {}, }; $scope.ldloading = {}; $scope.refreshData = function (style, filterData) { $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("branch", 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.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("branch", 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 () { delete $scope.fileData.branch.dept; delete $scope.fileData.branch.address; delete $scope.fileData.branch.phone; delete $scope.fileData.branch.parent; delete $scope.fileData.branch.area; delete $scope.fileData.branch.place; $scope.refreshData("expand-right", $scope.fileData); }; // 获取单位下拉 $scope.model = {}; $scope.deptData = {}; // $scope.getDeptData=function(){ // var data={ // "idx":0, // "sum":1000 // } // api_user_data.fetchDataList('branch',data).then(function(res){ // $scope.deptData=res.list; // // console.log($scope.deptData) // }) // } // $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); }); }, ]);