"use strict"; /** * controller for User Profile Example */ app.controller("commonFaultSymptomslistCtrl", [ "$rootScope", "$scope", "$state", "$timeout", "$interval", "$modal", "SweetAlert", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_user_data", 'api_bpm_data', function ( $rootScope, $scope, $state, $timeout, $interval, $modal, SweetAlert, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_user_data, api_bpm_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: "content", displayName: "别名", width: "30%", enableFiltering: false, }, { name: "category.category", displayName: "故障现象", width: "30%", enableFiltering: false, }, { name: "操作", cellTemplate: '", enableFiltering: false, }, ]; $scope.transferDept = function (data) { if (data) { return data; } else { return "无"; } }; function selectItem(pmodel, childrens) { if (angular.isArray(pmodel)) { angular.forEach(pmodel, function (index) { if (index && index.id) { angular.forEach(childrens, function (item) { if (item.id == index.id) { item.selected = true; } if (item && item.children) { selectItem(pmodel, item.children); } }); } }); } else { if (pmodel && pmodel.id) { angular.forEach(childrens, function (item, index) { if (item.id == pmodel.id) { item.selected = true; } if (item && item.children) { selectItem(pmodel, item.children); } }); } } } $scope.saveData = function (selectdata) { console.log(selectdata); var modalInstance = $modal.open({ templateUrl: "assets/views/system/tpl/commonFaultSymptomschange.html", controller: function ($scope, scope, $modalInstance, api_user_data,api_bpm_data) { selectdata.category.selected = true; $scope.deptdata = { id: selectdata.id, content: selectdata.content, category: selectdata.category }; $scope.categoryList = []; $scope.title = "常用故障现象修改"; // -------------------- $scope.select_treedata = []; $scope.try_async_load = function (s, fn) { if (s) { var filterKeyword = s.filterKeyword; } var postData = { idx: 0, sum: 1000, }; if (filterKeyword) { postData.incidentcategory = { selectType: "pinyin_qs", category: filterKeyword, }; } $scope.my_data = []; $scope.doing_async = true; api_bpm_data .fetchDataList("incidentcategory", postData) .then(function (response) { if (response.status == 200) { var data = response.list; if (filterKeyword) { data.forEach((e) => { e.isExpanded = true; }); var li = transform(data).children; console.log(li); fn(li); return; } else { var objects = []; for (var i = 0; i < data.length; i++) { var object = {}; object.id = data[i].id; object.parent = data[i].parent; object.category = data[i].category; object.isExpanded = true; objects.push(object); } $scope.my_data = convertParentToChildList(objects); $scope.select_treedata = angular.copy($scope.my_data); } if ($scope.my_data.length > 0) { $scope.doing_async = false; } selectItem(selectdata.category,$scope.select_treedata); $scope.deptdata.category = selectdata.category; } else { SweetAlert.swal({ title: "系统错误!", text: "请刷新重试!", type: "error", }); } }); }; $scope.try_async_load(); // -------------------- $scope.cancel = function () { $modalInstance.dismiss("cancel"); }; // 保存 $scope.savercode = function (deptdata) { if ( deptdata && deptdata.content && deptdata.category ) { var fildata = { incidentCategoryContent: { id: deptdata.id, deleteFlag: 0, content: deptdata.content, category: deptdata.category, }, }; api_user_data .updData("incidentCategoryContent", 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; }, }, }); }; 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 var parentNode = 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? 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.addData = function () { var modalInstance = $modal.open({ templateUrl: "assets/views/system/tpl/commonFaultSymptomschange.html", controller: function ($scope, $modalInstance, api_user_data,api_bpm_data) { $scope.deptdata = { content: "", category: "", }; $scope.title = "常用故障现象新增"; // -------------------- $scope.select_treedata = []; $scope.try_async_load = function (s, fn) { if (s) { var filterKeyword = s.filterKeyword; } var postData = { idx: 0, sum: 1000, }; if (filterKeyword) { postData.incidentcategory = { selectType: "pinyin_qs", category: filterKeyword, }; } $scope.my_data = []; $scope.doing_async = true; api_bpm_data .fetchDataList("incidentcategory", postData) .then(function (response) { if (response.status == 200) { var data = response.list; if (filterKeyword) { data.forEach((e) => { e.isExpanded = true; }); var li = transform(data).children; console.log(li); fn(li); return; } else { var objects = []; for (var i = 0; i < data.length; i++) { var object = {}; object.id = data[i].id; object.parent = data[i].parent; object.category = data[i].category; object.isExpanded = true; objects.push(object); } $scope.my_data = convertParentToChildList(objects); $scope.select_treedata = angular.copy($scope.my_data); } if ($scope.my_data.length > 0) { $scope.doing_async = false; } } else { SweetAlert.swal({ title: "系统错误!", text: "请刷新重试!", type: "error", }); } }); }; $scope.try_async_load(); // -------------------- $scope.cancel = function () { $modalInstance.dismiss("cancel"); }; // 保存 $scope.savercode = function (deptdata) { if ( deptdata && deptdata.content && deptdata.category ) { $modalInstance.close(deptdata); } else { SweetAlert.swal( { title: "新增失败!", text: "请填写必填项!", type: "error", confirmButtonColor: "#DD6B55", }, function () {} ); } }; }, }); modalInstance.result.then(function (selectedItem) { if (selectedItem.content && selectedItem.category) { var fildata = { incidentCategoryContent: { content: selectedItem.content, category: selectedItem.category, }, }; api_user_data .addData("incidentCategoryContent", 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("incidentCategoryContent", [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, incidentCategoryContent: {}, }; $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); api_user_data.fetchDataList("incidentCategoryContent", 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.incidentCategoryContent.category) { filterData.incidentCategoryContent.category = filterData.incidentCategoryContent.category.id; } api_user_data.fetchDataList("incidentCategoryContent", 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.incidentCategoryContent.content; delete $scope.fileData.incidentCategoryContent.category; $scope.getCategoryData(); $scope.refreshData("expand-right", $scope.fileData); }; // 获取院区下拉 $scope.model = {}; $scope.categoryData = []; $scope.getCategoryData = function (s, fn) { if (s) { var filterKeyword = s.filterKeyword; } var postData = { idx: 0, sum: 1000, }; if (filterKeyword) { postData.incidentcategory = { selectType: "pinyin_qs", category: filterKeyword, }; } $scope.my_data = []; $scope.doing_async = true; api_bpm_data .fetchDataList("incidentcategory", postData) .then(function (response) { if (response.status == 200) { var data = response.list; if (filterKeyword) { data.forEach((e) => { e.isExpanded = true; }); var li = transform(data).children; console.log(li); fn(li); return; } else { var objects = []; for (var i = 0; i < data.length; i++) { var object = {}; object.id = data[i].id; object.parent = data[i].parent; object.category = data[i].category; object.isExpanded = true; objects.push(object); } $scope.my_data = convertParentToChildList(objects); $scope.categoryData = angular.copy($scope.my_data); } if ($scope.my_data.length > 0) { $scope.doing_async = false; } } else { SweetAlert.swal({ title: "系统错误!", text: "请刷新重试!", type: "error", }); } }); }; $scope.getCategoryData(); $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); }); }, ]);