123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686 |
- app.controller('placeCtrl', ["$rootScope", "$scope", "$http", "$state", "$timeout", "$interval", "SweetAlert", "$modal", "FileUploader", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_user_data", "api_cmdb2", function ($rootScope, $scope, $http, $state, $timeout, $interval, SweetAlert, $modal, FileUploader, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_user_data, api_cmdb2) {
- $scope.langs = i18nService.getAllLangs();
- $scope.lang = 'zh-cn';
- $scope.cancles = true;
- 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 == "quyudidianguanli_xinzeng") {
- $scope.xinzeng = true
- }
- if (loginUser.menu[i].link == "quyudidianguanli_shanchu") {
- $scope.shanchu = true
- }
- if (loginUser.menu[i].link == "quyudidianguanli_bianji") {
- $scope.bianji = true
- }
- }
- var fildata = {
- "idx": 0,
- "sum": 1000
- };
- $scope.choice = false;
- $scope.backcolor = [];
- $scope.outhospital = [];
- $scope.outarea = [];
- $scope.outplace = [];
- $scope.pla = {};
- $scope.areaid = {};
- $scope.areaname = "";
- $scope.area = {};
- $scope.areaplace = true;
- $scope.freshenHospital = function () {
- api_user_data.fetchDataList('branch', fildata).then(function (response) {
- if (response) {
- if (response.status = 200) {
- $scope.outhospital = response.list;
- }
- }
- })
- }
- $scope.freshenHospital();
- $scope.freshenarea = function () {
- api_user_data.fetchDataList('area', fildata).then(function (response) {
- if (response) {
- if (response.status = 200) {
- if (!$scope.outarea.length&&response.list.length) {
- $scope.ckickrow(response.list[0]);
- }
- $scope.outarea = response.list;
- }
- }
- })
- }
- $scope.freshenarea();
-
- $scope.freshenplace = function (id) {
- if (id) {
- var fildata = {
- "idx": 0,
- "sum": 1000,
- "place": {
- "area": {
- "id": id
- }
- }
- };
- api_user_data.fetchDataList('place', fildata).then(function (response) {
- if (response) {
- if (response.status = 200) {
- $scope.outplace = response.list;
- }
- }
- })
- }
- }
-
- $scope.ckickrow = function (data) {
- $scope.choice = false;
- $scope.areaid = data.id;
- $scope.areaname = data.area;
- $scope.areaplace = true;
- $scope.areaData = data;
- if (data.id) {
- $scope.freshenplace(data.id);
- // var fildata={"idx":0,"sum":1000,"place":{areaId:data.id}};
- // api_user_data.fetchDataList('place',fildata).then(function(response){
- // if(response){
- // if(response.status=200){
- // $scope.outplace= response.list;
- // }
- // }
- // })
- } else { }
- }
- // 置空区域下的地点
- $scope.clear = function () {
- $scope.areaname = ''
- $scope.outplace = []
- }
- $scope.clickplace = function (pla) {
- $scope.areaplace = false;
- $scope.pla = pla
- }
- // 编辑区域
- $scope.editArea = function (data) {
- var modalInstance = $modal.open({
- templateUrl: 'assets/views/system/tpl/area.html',
- controller: function ($scope, scope, $modalInstance, api_user_data) {
- $scope.title = "修改区域";
- $scope.cancel = function () {
- $modalInstance.dismiss('cancel');
- };
- $scope.outhospital = scope.outhospital;
- $scope.areaName = data.area;
- $scope.search = {hospital:{id:data.branch,hosName:data.branchName}};
- $scope.ok = function (areaName) {
- // if (areaName != data.area) {
- if ($scope.areaName && $scope.search.hospital.id) {
- $modalInstance.close({areaName:areaName,hospital:$scope.search.hospital});
- } else {
- SweetAlert.swal({
- title: "修改失败!",
- text: "名称不能为空",
- type: "error"
- })
- }
- // } else {
- // $modalInstance.dismiss('cancel');
- // }
- }
- },
- resolve: {
- scope: function () {
- return $scope;
- }
- }
- });
- modalInstance.result.then(function (selectedItem) {
- if (selectedItem) {
- var fildata = {
- "area": {
- "id": data.id,
- "deleteFlag": 0,
- "area": selectedItem.areaName,
- branch: selectedItem.hospital.id,
- branchName: selectedItem.hospital.hosName
- }
- }
- api_user_data.updData('area', fildata).then(function (response) {
- if (response) {
- if (response.status == 200) {
- SweetAlert.swal({
- title: "修改成功!",
- type: "success"
- }, function () {
- $scope.freshenarea()
- })
- } else {
- SweetAlert.swal({
- title: "修改失败!",
- text: response.msg || '',
- type: "error"
- })
- }
- }
- })
- }
- })
- }
- // 新增区域
- $scope.addArea = function (state) {
- var modalInstance = $modal.open({
- templateUrl: 'assets/views/system/tpl/area.html',
- controller: function ($scope, scope, $modalInstance, api_user_data) {
- $scope.title = "新增区域";
- $scope.areaName = "";
- $scope.search = {hospital:{}};
- $scope.outhospital = scope.outhospital;
- $scope.cancel = function () {
- $modalInstance.dismiss('cancel');
- };
- $scope.ok = function (areaName) {
- if ($scope.areaName&&$scope.search.hospital.id) {
- $modalInstance.close({areaName:areaName,hospital:$scope.search.hospital});
- } else {
- SweetAlert.swal({
- title: "新增失败!",
- text: "名称不能为空",
- type: "error"
- })
- }
- }
- },
- resolve: {
- scope: function () {
- return $scope;
- }
- }
- });
- modalInstance.result.then(function (selectedItem) {
- if (selectedItem) {
- var fildata = {
- "area": {
- "area": selectedItem.areaName,
- branch: selectedItem.hospital.id,
- branchName: selectedItem.hospital.hosName
- }
- }
- api_user_data.addData('area', fildata).then(function (response) {
- if (response) {
- if (response.status == 200) {
- SweetAlert.swal({
- title: "新增成功!",
- type: "success"
- }, function () {
- $scope.freshenarea()
- })
- } else {
- SweetAlert.swal({
- title: "新增失败!",
- text: response.msg || '',
- type: "error"
- })
- }
- }
- })
- }
- })
- }
- //删除区域
- $scope.closearea = function (index, data) {
- if (!data.id) {
- $scope.cancles = true;
- $scope.outarea.splice(index, 1);
- } else {
- var rmvList = data;
- var modalInstance = $modal.open({
- templateUrl: 'assets/views/delete.html',
- controller: function ($scope, $modalInstance) {
- $scope.ok = function () {
- $modalInstance.close(data);
- };
- $scope.cancel = function () {
- $modalInstance.dismiss('cancel');
- };
- $scope.title = '区域删除';
- $scope.connect = '是否删除该区域'
- },
- size: 'sm'
- });
- modalInstance.result.then(function (selectedItem) {
- if (selectedItem) {
- if (selectedItem.id) {
- var fildata = [selectedItem.id];
- api_user_data.rmvData('area', fildata).then(function (response) {
- if (response) {
- if (response.status == 200) {
- $scope.outplace = [];
- $scope.areaname = "";
- $scope.outarea.splice(index, 1);
- SweetAlert.swal({
- title: "删除成功!",
- type: "success"
- })
- } else {
- SweetAlert.swal({
- title: "删除失败!",
- text: response.msg || '',
- type: "error"
- })
- }
- }
- })
- }
- }
- })
- }
- }
- // 编辑地点
- $scope.editPlace = function (data) {
- var modalInstance = $modal.open({
- templateUrl: 'assets/views/system/tpl/place.html',
- controller: function ($scope, scope, $modalInstance, api_user_data) {
- $scope.title = "修改地点";
- $scope.check = {
- area: data.area,
- place: data.place
- }
- $scope.outarea = scope.outarea;
- $scope.cancel = function () {
- $modalInstance.dismiss('cancel');
- };
- $scope.ok = function (check) {
- if (check.place != data.place) {
- if (check.place) {
- $modalInstance.close(check);
- } else {
- SweetAlert.swal({
- title: "编辑失败!",
- text: "地点不能为空",
- type: "error"
- })
- }
- } else {
- $modalInstance.dismiss('cancel');
- }
- }
- },
- resolve: {
- scope: function () {
- return $scope;
- }
- }
- });
- modalInstance.result.then(function (check) {
- if (check) {
- var fildata = {
- "place": {
- "place": check.place,
- "area": {
- "id": check.area.id
- },
- "deleteFlag": 0,
- "id": data.id
- }
- }
- api_user_data.updData('place', fildata).then(function (response) {
- if (response) {
- if (response.status == 200) {
- SweetAlert.swal({
- title: "修改成功!",
- type: "success"
- }, function () {
- $scope.freshenplace($scope.areaData.id);
- })
- } else {
- SweetAlert.swal({
- title: "修改失败!",
- text: response.msg || '',
- type: "error"
- })
- }
- }
- })
- }
- })
- }
- // 新增地点
- $scope.addplace = function (area) {
- var modalInstance = $modal.open({
- templateUrl: 'assets/views/system/tpl/place.html',
- controller: function ($scope, scope, $modalInstance, api_user_data) {
- $scope.title = "新增地点";
- if (area !== undefined) {
- $scope.check = { area: area }
- } else {
- $scope.check = {}
- }
- $scope.outarea = scope.outarea;
- $scope.cancel = function () {
- $modalInstance.dismiss('cancel');
- };
- $scope.ok = function (check) {
- if (check && check.area && check.place) {
- console.log(check, 9999)
- $modalInstance.close(check);
- } else {
- SweetAlert.swal({
- title: "新增失败!",
- text: "请填写必填项",
- type: "error"
- })
- }
- }
- },
- resolve: {
- scope: function () {
- return $scope;
- }
- }
- });
- modalInstance.result.then(function (check) {
- if (check) {
- var fildata = {
- "place": {
- "place": check.place
- }
- }
- if (check.area) {
- fildata.place.area = {
- "id": check.area.id
- }
- }
- api_user_data.addData('place', fildata).then(function (response) {
- if (response) {
- if (response.status == 200) {
- SweetAlert.swal({
- title: "新增成功!",
- type: "success"
- }, function () {
- $scope.freshenplace($scope.areaData.id);
- })
- } else {
- SweetAlert.swal({
- title: "新增失败!",
- text: response.msg || '',
- type: "error"
- })
- }
- }
- })
- }
- })
- }
- //删除地点
- $scope.closeplace = function (index, data) {
- if (!data.id) {
- $scope.cancles = true;
- $scope.outplace.splice(index, 1);
- } else {
- var rmvList = data;
- var modalInstance = $modal.open({
- templateUrl: 'assets/views/delete.html',
- controller: function ($scope, $modalInstance) {
- $scope.ok = function () {
- $modalInstance.close(data);
- };
- $scope.cancel = function () {
- $modalInstance.dismiss('cancel');
- };
- $scope.title = '地点删除';
- $scope.connect = '是否删除该地点'
- },
- size: 'sm'
- });
- modalInstance.result.then(function (selectedItem) {
- if (selectedItem) {
- if (selectedItem.id) {
- var fildata = [selectedItem.id];
- api_user_data.rmvData('place', fildata).then(function (response) {
- if (response) {
- if (response.status == 200) {
- $scope.outplace.splice(index, 1);
- SweetAlert.swal({
- title: "删除成功!",
- type: "success"
- })
- } else {
- SweetAlert.swal({
- title: "删除失败!",
- type: "error"
- })
- }
- }
- })
- }
- }
- })
- }
- }
- //导入
- $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.importData().getRequestedUrl(),
- });
- 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', defaultFilterData);
- });
- } 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.push({
- 'filename': item.file.name
- });
- item.formData.push({
- 'type': "areaPlace"
- });
- 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.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 = "areaPlace";
- // var month = 0;
- $http({
- url: api_user_data.downDataModel("areaPlace", 0).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 = "区域地点.xlsx";
- document.body.appendChild(a);
- a.click();
- }).error(function (data, status, headers, config) {
- console.log(data);
- });
- }
- // });
- // }
- // 2021
- //导入模板
- $scope.importDataTpl = function () {
- var wt_url = api_user_data.importData1('areaPlace').getRequestedUrl();
- var form = new FormData();
- var file = document.getElementById("importTplIpt").files[0];
- form.append('filename', file.name)
- form.append('file', file);
- console.log(document.getElementById("importTplIpt").files)
- $http({
- method: 'POST',
- url: wt_url,
- data: form,
- headers: { 'Content-Type': undefined },
- transformRequest: angular.identity
- }).success(function (data) {
- document.getElementById("importTplIpt").outerHTML = document.getElementById("importTplIpt").outerHTML;
- if (data.status == 200) {
- SweetAlert.swal({
- title: "导入成功",
- confirmButtonColor: "#007AFF",
- type: "success"
- }, function (flag) {
- $scope.freshenarea();
- $scope.freshenplace();
- });
- } else {
- SweetAlert.swal({
- title: "导入失败",
- text: data.error,
- type: "error"
- });
- }
- }).error(function (data) {
- document.getElementById("importTplIpt").outerHTML = document.getElementById("importTplIpt").outerHTML;
- SweetAlert.swal({
- title: "导入失败",
- text: data.error,
- type: "error"
- });
- })
- };
- //导出模板
- $scope.exportDataTpl = function () {
- var wt_url = api_cmdb2.exportData1("downDataModels/operationSystem", {}).getRequestedUrl()
- $http({
- url: wt_url,
- method: 'POST',
- headers: {
- 'Accept': '*/*'
- },
- responseType: 'arraybuffer'
- }).success(function (data, status, headers, config) {
- var fileName = headers("Content-Disposition").split(";")[1].split("filename=")[1];
- var file = new Blob([data], {
- type: 'application/vnd.ms-excel'
- });
- var fileURL = URL.createObjectURL(file);
- var a = document.createElement('a');
- a.href = fileURL;
- a.target = '_blank';
- a.download = decodeURIComponent(fileName);
- document.body.appendChild(a);
- a.click();
- }).error(function (data, status, headers, config) { });
- };
- }]);
|