"use strict"; /** * controller for User Profile Example */ app.controller("responsibilityDeptlistCtrl", [ "$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 == "responsibilityDept_add") { $scope.xinzeng = true; } if (loginUser.menu[i].link == "responsibilityDept_del") { $scope.shanchu = true; } if (loginUser.menu[i].link == "responsibilityDept_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: "branchName", displayName: "院区", width: "20%", enableFiltering: false, }, { name: "parent.dept", displayName: "父级科室", width: "20%", enableFiltering: false, }, { name: "dept", displayName: "责任科室", width: "20%", enableFiltering: false, }, { name: "phone", displayName: "科室电话", width: "20%", enableFiltering: false, }, { name: "操作", cellTemplate: '", enableFiltering: false, }, ]; $scope.transferDept = function (data) { if (data) { return data; } else { return "无"; } }; $scope.saveData = function (selectdata) { console.log(selectdata); var modalInstance = $modal.open({ templateUrl: "assets/views/system/tpl/responsibilityDeptchange.html", controller: function ($scope, scope, $modalInstance, api_user_data) { $scope.summaryOrderList = [ {id: 1, name: '是', value: 1}, {id: 2, name: '否', value: 0} ] $scope.deptdata = { uuid:selectdata.uuid, id: selectdata.id, dept: selectdata.dept, phone: selectdata.phone, branch: { id: selectdata.branch, hosName: selectdata.branchName }, parent:selectdata.parent, addSummary: $scope.summaryOrderList.find(v => v.value == selectdata.addSummary) || $scope.summaryOrderList.find(v => v.value == 0), supportZero: $scope.summaryOrderList.find(v => v.value == selectdata.supportZero) || $scope.summaryOrderList.find(v => v.value == 0), }; $scope.branchList = []; $scope.title = "责任科室修改"; $scope.parentList = []; $scope.changeBranch = function(keyword=''){ api_user_data.fetchDataList("dutyDepartment", { "idx":0,"sum":10,"dutyDepartment":{dept: keyword, selectType: "pinyin_qs"} }) .then(function (data) { $scope.parentList = Restangular.stripRestangular(data).list.filter(v=>v.id != selectdata.id); }); } api_user_data.fetchDataList("dutyDepartment", { "idx":0,"sum":10 }) .then(function (data) { $scope.parentList = Restangular.stripRestangular(data).list.filter(v=>v.id != selectdata.id); }); api_user_data .fetchDataList("branch", { idx: 0, sum: 100 }) .then(function (data) { $scope.branchList = Restangular.stripRestangular(data).list; }); $scope.cancel = function () { $modalInstance.dismiss("cancel"); }; // 保存 $scope.savercode = function (deptdata) { if ( deptdata && deptdata.dept && deptdata.phone && deptdata.branch && deptdata.addSummary && deptdata.supportZero ) { var fildata = { dutyDepartment: { uuid:deptdata.uuid, id: deptdata.id, deleteFlag: 0, phone: deptdata.phone, dept: deptdata.dept, branch: deptdata.branch.id, parent:deptdata.parent, addSummary: deptdata.addSummary.value, supportZero: deptdata.supportZero.value, }, }; api_user_data .updData("dutyDepartment", 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/responsibilityDeptchange.html", controller: function ($scope, $modalInstance, api_user_data) { $scope.summaryOrderList = [ {id: 1, name: '是', value: 1}, {id: 2, name: '否', value: 0} ] $scope.deptdata = { dept: "", phone: "", branch: "", parent:'', addSummary: $scope.summaryOrderList.find(v => v.value == 0), supportZero: $scope.summaryOrderList.find(v => v.value == 0), }; $scope.title = "责任科室新增"; $scope.parentList = []; $scope.changeBranch = function(keyword=''){ api_user_data.fetchDataList("dutyDepartment", { "idx":0,"sum":10,"dutyDepartment":{dept: keyword, selectType: "pinyin_qs"} }) .then(function (data) { $scope.parentList = Restangular.stripRestangular(data).list; }); } api_user_data .fetchDataList("branch", { idx: 0, sum: 100 }) .then(function (data) { $scope.branchList = Restangular.stripRestangular(data).list; }); $scope.cancel = function () { $modalInstance.dismiss("cancel"); }; // 保存 $scope.savercode = function (deptdata) { if ( deptdata && deptdata.dept && deptdata.phone && deptdata.branch && deptdata.addSummary && deptdata.supportZero ) { $modalInstance.close(deptdata); } else { SweetAlert.swal( { title: "新增失败!", text: "请填写必填项!", type: "error", confirmButtonColor: "#DD6B55", }, function () {} ); } }; }, }); modalInstance.result.then(function (selectedItem) { if (selectedItem.dept && selectedItem.phone && selectedItem.branch && selectedItem.addSummary && selectedItem.supportZero) { var fildata = { dutyDepartment: { phone: selectedItem.phone, dept: selectedItem.dept, branch: selectedItem.branch.id, parent:selectedItem.parent?selectedItem.parent:undefined, addSummary: selectedItem.addSummary.value, supportZero: selectedItem.supportZero.value, }, }; api_user_data .addData("dutyDepartment", 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 && selectedItem[0].children.length > 0) { SweetAlert.swal({ title: "该科室存在子类科室", text: "请先删除该科室子类科室!", type: "error", }); } else { api_user_data .rmvData("dutyDepartment", [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.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, dutyDepartment: {}, }; $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; } filterData = angular.copy(filterData); if(filterData.dutyDepartment.branch){ filterData.dutyDepartment.branch = filterData.dutyDepartment.branch.id; } api_user_data.fetchDataList("dutyDepartment", 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; } filterData = angular.copy(filterData); if(filterData.dutyDepartment.branch){ filterData.dutyDepartment.branch = filterData.dutyDepartment.branch.id; } api_user_data.fetchDataList("dutyDepartment", 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.dutyDepartment.dept; delete $scope.fileData.dutyDepartment.phone; delete $scope.fileData.dutyDepartment.branch; $scope.refreshData("expand-right", $scope.fileData); }; // 获取院区下拉 $scope.model = {}; $scope.branchData = []; $scope.getDeptData = function () { var data = { idx: 0, sum: 1000, }; api_user_data.fetchDataList("branch", data).then(function (res) { $scope.branchData = 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); }); }, ]);