"use strict";
/**
* controller for User Profile Example
*/
app.controller("integralCtrl", [
"$rootScope",
"$scope",
"$state",
"$timeout",
"$interval",
"$modal",
"SweetAlert",
"i18nService",
"uiGridConstants",
"uiGridGroupingConstants",
"Restangular",
"api_bpm_schedule",
"api_bpm_data",
"api_wechatfile",
"api_configure_data",
"api_simple",
"moment",
function (
$rootScope,
$scope,
$state,
$timeout,
$interval,
$modal,
SweetAlert,
i18nService,
uiGridConstants,
uiGridGroupingConstants,
Restangular,
api_bpm_schedule,
api_bpm_data,
api_wechatfile,
api_configure_data,
api_simple,
moment
) {
$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;
$scope.zantingzhixing = false;
for (var i = 0; i < loginUser.menu.length; i++) {
if (loginUser.menu[i].link == "xunjianjihua_xinzeng") {
$scope.xinzeng = true;
}
if (loginUser.menu[i].link == "xunjianjihua_shanchu") {
$scope.shanchu = true;
}
if (loginUser.menu[i].link == "xunjianjihua_bianji") {
$scope.bianji = true;
}
if (loginUser.menu[i].link == "xunjianjihua_zantingzhixing") {
$scope.zantingzhixing = true;
}
}
$scope.isIncidentManager = false;
loginUser.role.forEach(v=>{
if(v.rolecode === 'incident manager'){
$scope.isIncidentManager = true;
}
})
var defaultFilterData = {
idx: 0,
sum: 10,
};
var inspectPlanParameter = {
idx: 0,
sum: 10,
operation: "",
status: "",
inspection: {
inspectionTypeDTO: {
id: "",
},
},
};
//本地存储
sessionStorage.inspectPlanParameter = JSON.stringify(inspectPlanParameter);
$scope.memoryfilterData = {
idx: 0,
sum: 10,
};
// $scope.isMask = false;
$scope.gridOptions = {};
$scope.gridOptions.data = "myData";
$scope.gridOptions.enableColumnResizing = true;
$scope.gridOptions.enableFiltering = false;
$scope.gridOptions.enableGridMenu = true;
$scope.gridOptions.enableRowSelection = true;
$scope.gridOptions.showGridFooter = true;
$scope.gridOptions.showColumnFooter = false;
$scope.gridOptions.useExternalFiltering = false;
$scope.gridOptions.useExternalPagination = true;
$scope.gridOptions.paginationPageSizes = [10, 20, 50, 100];
$scope.gridOptions.paginationPageSize = 10;
$scope.gridOptions.multiSelect = true;
// $scope.gridOptions.enableSelectionBatchEvent = true; //使用批量使用事件
//行鼠标悬浮变色功能
// $scope.gridOptions.rowTemplate = '
';
// $scope.gridOptions.rowTemplate =
// '';
$scope.gridOptions.rowIdentity = function (row) {
return row.id;
};
$scope.gridOptions.getRowIdentity = function (row) {
return row.id;
};
//待审核的才能批量审核
$scope.gridOptions.isRowSelectable = function (row,i) {
console.log(row);
if (row.entity.auditState.value == 0) {
return true;
} else {
return false;
}
};
$scope.transfer = function (status) {
if (status === "正常") {
return "执行中";
} else if (status === "停止") {
return "暂停中";
}
};
$scope.gridOptions.columnDefs = [
{
name: "item",
displayName: "序号",
width: 50,
enableFiltering: false,
},
{
name: "description",
displayName: "故障描述",
width: "10%",
enableFiltering: true,
cellTemplate:
'{{row.entity.incident?row.entity.incident.description:""}}
',
},
{
name: "category",
displayName: "故障现象",
width: "10%",
enableFiltering: false,
cellTemplate:
'{{row.entity.incident?row.entity.incident.category.category:""}}
',
},
{
name: "handlerUserName",
displayName: "处理人",
width: "140",
enableFiltering: false,
},
{
name: "planEndTime",
displayName: "登记时间",
width: "200",
enableFiltering: false,
cellTemplate:
'{{row.entity.addTime | date:"yyyy-MM-dd HH:mm:ss"}}
',
},
{
name: "sourceScore",
displayName: "原工时",
width: "109",
enableFiltering: false,
},
{
name: "currentScore",
displayName: "最终工时",
width: "11%",
enableFiltering: false,
},
{
name: "updateReason",
displayName: "升级原因",
width: "12%",
enableFiltering: false,
},
{
name: "auditState.desc",
displayName: "审核状态",
width: "15%",
enableFiltering: false,
},
{
minWidth: "230",
name: "操作",
enableFiltering: false,
cellTemplate:
'' +
// '
' +
'
查看事件' +
'
审核' +
// '
编辑' +
// '
' +
// '
执行中' +
// '
暂停中' +
"
",
},
// { name: 'planTime2', displayName: '截止时间', width: 160, enableFiltering: false },
];
$scope.transferTime = function (time) {
return moment(time).format("YYYY-MM-DD HH:mm");
};
//新增数据
$scope.addData = function () {
$state.go("app.inspection.editor", {
formKey: "inspectionform",
service: "api_bpm_data",
});
};
$scope.inspectdata = {};
//跳转到编辑列表
$scope.selectRowFunction = function (data) {
var datas = delete data.item;
datas = delete data.style;
datas = delete data.runStatus;
var filedata = {
model: {
incidentIntegral: data,
},
};
$state.go("app.inspection.editor", {
formKey: "inspectionform",
service: "api_bpm_data",
model: JSON.stringify(filedata),
});
};
// 批量审核liaomingming
$scope.batchReview = function(){
SweetAlert.swal({
title: "提示",
text: "您是需要批量审核通过吗?",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "确认",
cancelButtonText: "取消",
closeOnConfirm: true,
closeOnCancel: true
}, function (isConfirm) {
if (isConfirm) {
console.log($scope.selected.items);
api_wechatfile.getDictionary({"key":"incident_integral_state","type":"list"}).then(function(res){
var auditState = res.find(v=>v.value == 1);
var postData = angular.copy($scope.selected.items);
postData.forEach(v=>{
v.auditState = auditState;
})
api_simple.addListData('incidentIntegral', postData).then(function (response) {
console.log(response)
if (response.status == 200) {
SweetAlert.swal({
title: "审核通过!",
confirmButtonColor: "#007AFF",
type: "success"
});
$scope.refreshData('expand-right', $scope.fileData);
} else {
SweetAlert.swal({
title: "操作失败",
text: "操作失败, 请稍后再试!",
type: "error"
});
}
});
})
}
});
}
//跳转到查看列表
$scope.seeFunction = function (data) {
var filedata = {
model: {
incidentIntegral: data,
},
};
$state.go("app.inspection.form", {
formKey: "inspection__detailform",
service: "api_bpm_data",
model: JSON.stringify(filedata),
});
};
//跳转到查看列表
$scope.lookFunction = function (data) {
var filedata = {
model: {
incidentIntegral: data,
},
};
$state.go("app.inspection.form", {
formKey: "inspection__detailform",
service: "api_bpm_data",
model: JSON.stringify(filedata),
});
};
//巡检暂停/恢复
$scope.runFunction = function (data) {
var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
var upData = {};
upData.id = data.id;
upData.operation = 1;
var modalInstance = $modal.open({
// templateUrl: 'assets/views/inspect/changRun.html',
templateUrl: "assets/views/delete.html",
// size: "sm",
controller: function ($scope, $modalInstance) {
$scope.isRunFunction = true;
var status = "";
if (data.status.name == "正常") {
$scope.title = "暂停巡检计划";
$scope.connect = "确定要暂停该巡检计划?";
// $scope.textLog = "是否暂停该巡检计划";
} else if (data.status.name == "停止") {
$scope.title = "开始巡检计划";
$scope.connect = "确定要开始该巡检计划?";
// $scope.textLog = "是否开始该巡检计划";
}
$scope.ok = function () {
// var groupdata = "123";
// $modalInstance.dismiss('cancel');
if (data.status.name == "正常") {
upData.status = "停止";
// data.style = "fa fa-pause";
} else if (data.status.name == "停止") {
upData.status = "正常";
// data.style = "fa fa-play";
}
sessionStorage.inspectPlanParameter = JSON.stringify(filterData);
// $modalInstance.close(upData);
$modalInstance.close(data);
};
$scope.cancel = function () {
$modalInstance.dismiss("cancel");
};
},
size: "sm",
});
modalInstance.result.then(function (result) {
if (result) {
// if(result.status=="停止"){
// result.status={"id":$scope.statusData[1].id}
// }else{
// result.status={"id":$scope.statusData[2].id}
// }
// var upData = {
// "inspection":{
// "id": result.id,
// "operation": result.operation,
// "status": result.status
// }
// };
if (result.status.value == "1") {
result.status.id = $scope.statusData[1].id;
} else if (result.status.value == "2") {
result.status.id = $scope.statusData[0].id;
}
var toData = {
inspection: result,
};
api_bpm_data.updData("inspection", toData).then(
function (response) {
var myData = Restangular.stripRestangular(response);
if (myData.status == 200) {
var showData = {
idx: filterData.idx,
sum: filterData.sum,
inspection: {
inspectionTypeDTO: {
id: "",
},
},
};
if (
filterData.inspection &&
filterData.inspection.inspectionTypeDTO &&
filterData.inspection.inspectionTypeDTO.id
) {
showData.inspection.inspectionTypeDTO.id =
filterData.inspection.inspectionTypeDTO.id;
} else {
showData.inspection.inspectionTypeDTO.id = -1;
}
$scope.refreshData("expand-right", $scope.fileData);
}
},
function () {
// $scope.ldloading[style.replace('-', '_')] = false;
}
);
}
});
};
// $scope.newincident = function(data) {
// $state.go('app.incident.editor', {});
// };
//行删除
$scope.removeData = function () {
console.log($scope.selected.items);
var modalInstance = $modal.open({
templateUrl: "assets/views/delete.html",
controller: function ($scope, $modalInstance) {
// $scope.textLog = "是否删除巡检计划";
$scope.title = "巡检计划删除";
$scope.connect = "确定要删除巡检计划?";
$scope.ok = function () {
$modalInstance.close("start");
};
$scope.cancel = function () {
$modalInstance.dismiss("cancel");
};
},
size: "sm",
});
modalInstance.result.then(
function (result) {
if (result) {
if ($scope.selected.items.length != 0) {
$rootScope.isMask = true;
}
var rmvList = [];
angular.forEach($scope.selected.items, function (item) {
rmvList.push(item.id);
});
if (rmvList.length > 0) {
api_bpm_data
.rmvData("inspection", rmvList)
.then(function (response) {
if (response.status == 200) {
$rootScope.isMask = false;
SweetAlert.swal(
{
title: "删除成功!",
type: "success",
confirmButtonColor: "#007AFF",
},
function () {
$scope.myData = _.reject($scope.myData, function (o) {
return _.includes(rmvList, o.id);
});
$scope.selected = {
items: [],
};
}
);
$scope.gridApi.selection.clearSelectedRows();
var filterData = JSON.parse(
sessionStorage.inspectPlanParameter
);
var showData = {
idx: filterData.idx,
sum: filterData.sum,
inspection: {
inspectionTypeDTO: {
id: "",
},
},
};
if (
filterData.inspection &&
filterData.inspection.inspectionTypeDTO &&
filterData.inspection.inspectionTypeDTO.id
) {
showData.inspection.inspectionTypeDTO.id =
filterData.inspection.inspectionTypeDTO.id;
} else {
showData.inspection.inspectionTypeDTO.id = -1;
}
$scope.refreshData("expand-right", $scope.fileData);
//取消遮罩层
// $scope.isMask = false;
} else {
$rootScope.isMask = false;
SweetAlert.swal({
title: "操作异常!",
text: "系统异常,请稍后重试,或者联系管理员!",
type: "error",
});
}
});
}
}
},
function () {
// $scope.ldloading[style.replace('-', '_')] = false;
}
);
};
$scope.selected = {
items: [],
};
$scope.editted = {
items: [],
};
$scope.testRow = [];
$scope.gridOptions.onRegisterApi = function (gridApi) {
//导入gridApi对象
$scope.gridApi = gridApi;
//分页选项
gridApi.pagination.on.paginationChanged(
$scope,
function (newPage, pageSize) {
var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
var filtersData = {};
filtersData.idx = newPage - 1;
filtersData.sum = pageSize;
$scope.pageNum = $scope.gridApi.pagination.getPage() - 1;
// console.log(pp);
filterData.idx = $scope.pageNum;
$scope.fileData.idx = newPage - 1;
$scope.fileData.sum = pageSize;
sessionStorage.inspectPlanParameter = JSON.stringify(filterData);
$scope.refreshData("expand-right", $scope.fileData);
}
);
//勾选行事件
gridApi.selection.on.rowSelectionChanged($scope, function (data) {
if (data.isSelected) {
$scope.selected.items.push(data.entity);
} else {
//objs:需要遍历的集合 data:遍历时当前的数据 index:遍历时当前索引
//array:需要遍历的集合,每次遍历时都会把objs原样的传一次。
//angular.forEach(objs, function(data,index,array)
angular.forEach(
$scope.selected.items,
function (ObjIndex, index, destObj) {
// console.log(ObjIndex);
// console.log(index);
// console.log(destObj);
if (ObjIndex.id == data.entity.id) {
destObj.splice(index, 1);
}
}
);
}
});
//批量全选
gridApi.selection.on.rowSelectionChangedBatch(
$scope,
function (rows, event) {
// if ($scope.selected.items.length != 0) {
// $scope.selected.items = [];
angular.forEach(rows, function (ObjIndex, index, destObj) {
if (ObjIndex.isSelected) {
$scope.selected.items.push(ObjIndex.entity);
} else {
$scope.selected.items = [];
// $scope.selected.items.splice(index, 1);
}
});
// } else {
// }
// $scope.mySelectedRows = $scope.gridApi.selection.getSelectedRows();
// if ($scope.selected.items.length == 0) {
// $scope.selected.items = $scope.mySelectedRows;
// } else if ($scope.mySelectedRows.length == 0) {
// for (var i = 0; i < $scope.selected.items.length; i++) {
// for (var j = 0; j < rows.length; j++) {
// if ($scope.selected.items[i].id == rows[j].entity.id) {
// $scope.selected.items.splice(i, 1);
// }
// }
// }
// } else {
// angular.forEach($scope.mySelectedRows, function(item) {
// $scope.selected.items.push(item);
// });
// }
}
);
//列过滤事件
gridApi.core.on.filterChanged($scope, function () {
var grid = this.grid;
var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
angular.forEach(grid.columns, function (item) {
if (item.enableFiltering) {
if (
angular.isDefined(item.filters[0].term) &&
item.filters[0].term != ""
) {
if (angular.isUndefined(filterData["inspection"])) {
filterData["inspection"] = {};
}
filterData["inspection"]["title"] = item.filters[0].term;
}
}
});
sessionStorage.inspectPlanParameter = JSON.stringify(filterData);
$scope.refreshData("expand-right", filterData);
});
};
// //刷新按钮
// $scope.reload = function() {
// var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
// var showData = {
// "idx": filterData.idx,
// "sum": filterData.sum,
// "inspection": {
// "inspectionTypeDTO": {
// "id": ""
// }
// }
// }
// if (filterData.inspection && filterData.inspection.inspectionTypeDTO && filterData.inspection.inspectionTypeDTO.id) {
// showData.inspection.inspectionTypeDTO.id = filterData.inspection.inspectionTypeDTO.id
// } else {
// showData.inspection.inspectionTypeDTO.id = -1
// }
// $scope.refreshData('expand-right', showData);
// }
//审核
$scope.toAudit = function (data) {
$modal.open({
templateUrl: 'assets/views/incident/tpl/toAudit.tpl.html',
controller: function ($scope, scope, $modalInstance, modelData, currentUserId, Alert, api_wechatfile,api_bpm_data) {
$scope.msg = `由${data.handlerUserName}处理的事件由工时${data.sourceScore}改为工时${data.currentScore},发起原因为:${data.updateReason||''}`;
$scope.ok = function () {
api_wechatfile.getDictionary({"key":"incident_integral_state","type":"list"}).then(function(res){
var auditState = res.find(v=>v.value == 1);
var postData = {
incidentIntegral: {
id:modelData.id,
incidentId:modelData.incidentId,
auditState:auditState,
handlerUser:modelData.handlerUser,
handlerUserName:modelData.handlerUserName,
sourceScore:modelData.sourceScore,
currentScore:modelData.currentScore,
updateReason:modelData.updateReason||undefined,
}
}
$modalInstance.close('success');
api_bpm_data.addData('incidentIntegral', postData).then(function (response) {
console.log(response)
if (response.status == 200) {
Alert.swal({
title: "审核通过!",
confirmButtonColor: "#007AFF",
type: "success"
});
scope.refreshData('expand-right', $scope.fileData);
} else {
Alert.swal({
title: "操作失败",
text: "操作失败, 请稍后再试!",
type: "error"
});
}
});
})
}
// 调整工时
$scope.time = function(){
$modalInstance.close('success');
$modal.open({
templateUrl: 'assets/views/incident/tpl/toAuditTime.tpl.html',
controller: function ($scope, $modalInstance, modelData, currentUserId, Alert,api_wechatfile,api_bpm_data) {
console.log(modelData,loginUser);
$scope.searchList = {time:''};
$scope.list = [];
api_wechatfile.getDictionary({"key":"incident_complexity","type":"list"}).then(function(res){
$scope.list = res;
})
$scope.ok = function () {
if (!$scope.searchList.time){
Alert.swal({
title: "操作失败",
text: "请填写工时!",
type: "error"
});
return;
}
api_wechatfile.getDictionary({"key":"incident_integral_state","type":"list"}).then(function(res){
var auditState = res.find(v=>v.value == 1);
var postData = {
incidentIntegral: {
id:modelData.id,
incidentId:modelData.incidentId,
auditState:auditState,
handlerUser:modelData.handlerUser,
handlerUserName:modelData.handlerUserName,
sourceScore:modelData.sourceScore,
currentScore:modelData.currentScore,
updateReason:modelData.updateReason||undefined,
}
}
$modalInstance.close('success');
api_bpm_data.addData('incidentIntegral', postData).then(function (response) {
console.log(response)
if (response.status == 200) {
Alert.swal({
title: "审核通过!",
confirmButtonColor: "#007AFF",
type: "success"
});
scope.refreshData('expand-right', $scope.fileData);
} else {
Alert.swal({
title: "操作失败",
text: "操作失败, 请稍后再试!",
type: "error"
});
}
});
})
}
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
}
},
size: 'sm',
resolve: {
modelData: function () {
return data;
},
currentUserId: function () {
return loginUser.id;
},
Alert: function () {
return SweetAlert;
},
api_wechatfile: function () {
return api_wechatfile;
},
api_bpm_data: function () {
return api_bpm_data;
},
}
});
}
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
}
},
size: 'sm',
resolve: {
scope: function () {
return $scope;
},
modelData: function () {
return data;
},
currentUserId: function () {
return loginUser.id;
},
Alert: function () {
return SweetAlert;
},
api_wechatfile: function () {
return api_wechatfile;
},
api_bpm_data: function () {
return api_bpm_data;
}
}
});
};
//查看
$scope.toDetail = function (data) {
console.log(data,$rootScope.isFuwutai);
if($rootScope.isFuwutai){
//角色是服务台人员
$state.go('app.incident.detail', {
formKey: 'incident_back',
pdKey: 'incident',
dataId: data.id,
taskId: data.taskId,
processInstanceId: data.processInstanceId
});
}else{
window.open(location.origin+'/#/app/incident/detail/incident_back/incident/'+data.id+'/'+data.taskId+'/'+data.processInstanceId+'//');
}
};
//重置按钮
$scope.reload = function () {
// var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
// var data={
// "idx":filterData.idx,
// "sum":filterData.sum
// }
// $scope.inspectdata={};
if(!$scope.isIncidentManager){
$scope.fileData.incidentIntegral = {handlerUser:$rootScope.user.id}
}else{
$scope.fileData.incidentIntegral = {};
}
$scope.try_async_load();
$scope.refreshData("expand-right", $scope.fileData);
};
//数据刷新
$scope.refreshData = function (style, filterData) {
$scope.ldloading[style.replace("-", "_")] = true;
if (angular.isUndefined(filterData)) {
filterData = defaultFilterData;
}
$scope.myData = [];
var filterDataClone = angular.copy(filterData)
if(filterDataClone.incidentIntegral&&filterDataClone.incidentIntegral.startTime){
filterDataClone.incidentIntegral.startTime = moment(filterDataClone.incidentIntegral.startTime).format('YYYY-MM-DD 00:00:00');
}
if(filterDataClone.incidentIntegral&&filterDataClone.incidentIntegral.endTime){
filterDataClone.incidentIntegral.endTime = moment(filterDataClone.incidentIntegral.endTime).format('YYYY-MM-DD 23:59:59');
}
if(filterDataClone.incidentIntegral&&filterDataClone.incidentIntegral.handlerUser){
filterDataClone.incidentIntegral.handlerUser = filterDataClone.incidentIntegral.handlerUser.id;
}
if(!$scope.isIncidentManager){
filterDataClone.incidentIntegral.handlerUser = $rootScope.user.id;
}
api_bpm_data.fetchDataList("incidentIntegral", filterDataClone).then(
function (data) {
var myData = Restangular.stripRestangular(data);
$scope.gridOptions.totalItems = myData.totalNum;
if (angular.isArray(myData.list)) {
$scope.myData = myData.list;
for (var i = 0; i < $scope.myData.length; i++) {
$scope.myData[i]["item"] =
i + 1 + filterData.idx * filterData.sum;
if ($scope.myData[i].doing + $scope.myData[i].completed != 0) {
$scope.myData[i].percent = (
($scope.myData[i].completed * 100) /
($scope.myData[i].doing + $scope.myData[i].completed)
).toFixed(1);
} else if ($scope.myData[i].completed == 0) {
$scope.myData[i].percent = "0.0";
} else {
$scope.myData[i].percent = "0.0";
}
}
console.log($scope.myData);
for (var i = 0; i < $scope.myData.length; i++) {
if ($scope.myData[i].status == "正常") {
$scope.myData[i].style = "fa fa-play";
} else if ($scope.myData[i].status == "停止") {
$scope.myData[i].style = "fa fa-pause";
}
$scope.myData[i].runStatus = $scope.transfer(
$scope.myData[i].status
);
}
} else {
SweetAlert.swal({
title: "数据为空",
text: myData.data,
type: "warning",
});
}
$scope.ldloading[style.replace("-", "_")] = false;
},
function () {
$scope.ldloading[style.replace("-", "_")] = false;
}
);
};
$scope.refreshData2 = function (style, filterData) {
$scope.ldloading[style.replace("-", "_")] = true;
if (angular.isUndefined(filterData)) {
filterData = defaultFilterData;
}
var filterDataClone = angular.copy(filterData)
if(filterDataClone.incidentIntegral&&filterDataClone.incidentIntegral.startTime){
filterDataClone.incidentIntegral.startTime = moment(filterDataClone.incidentIntegral.startTime).format('YYYY-MM-DD 00:00:00');
}
if(filterDataClone.incidentIntegral&&filterDataClone.incidentIntegral.endTime){
filterDataClone.incidentIntegral.endTime = moment(filterDataClone.incidentIntegral.endTime).format('YYYY-MM-DD 23:59:59');
}
if(filterDataClone.incidentIntegral&&filterDataClone.incidentIntegral.handlerUser){
filterDataClone.incidentIntegral.handlerUser = filterDataClone.incidentIntegral.handlerUser.id;
}
if(!$scope.isIncidentManager){
filterDataClone.incidentIntegral.handlerUser = $rootScope.user.id;
}
// $scope.myData = [];
api_bpm_data.fetchDataList("incidentIntegral", filterDataClone).then(
function (data) {
var myData = Restangular.stripRestangular(data);
$scope.gridOptions.totalItems = myData.totalNum;
if (angular.isArray(myData.list)) {
$scope.myData = myData.list;
for (var i = 0; i < $scope.myData.length; i++) {
$scope.myData[i]["item"] =
i + 1 + filterData.idx * filterData.sum;
if ($scope.myData[i].doing + $scope.myData[i].completed != 0) {
$scope.myData[i].percent = (
($scope.myData[i].completed * 100) /
($scope.myData[i].doing + $scope.myData[i].completed)
).toFixed(1);
} else if ($scope.myData[i].completed == 0) {
$scope.myData[i].percent = "0.0";
} else {
$scope.myData[i].percent = "0.0";
}
}
console.log($scope.myData);
for (var i = 0; i < $scope.myData.length; i++) {
if ($scope.myData[i].status == "正常") {
$scope.myData[i].style = "fa fa-play";
} else if ($scope.myData[i].status == "停止") {
$scope.myData[i].style = "fa fa-pause";
}
$scope.myData[i].runStatus = $scope.transfer(
$scope.myData[i].status
);
}
} else {
SweetAlert.swal({
title: "数据为空",
text: myData.data,
type: "warning",
});
}
$scope.ldloading[style.replace("-", "_")] = false;
},
function () {
$scope.ldloading[style.replace("-", "_")] = false;
}
);
};
$scope.ldloading = {};
//树形控件点击事件
$scope.my_tree_handler = function (branch) {
var filterData = JSON.parse(sessionStorage.inspectPlanParameter);
filterData.inspection.inspectionTypeDTO.id = branch.id;
sessionStorage.inspectPlanParameter = JSON.stringify(filterData);
var showData = {
idx: filterData.id,
sum: filterData.sum,
inspection: {
inspectionTypeDTO: {
id: branch.id,
},
},
};
// $scope.refreshData('expand-right', showData);
};
$scope.fileData = {
idx: 0,
sum: 10,
incidentIntegral: {},
};
$scope.onFilterCallback = function (data) {
$scope.fileData.inspection.inspectionTypeDTO = {
id: data.id,
};
};
$scope.inspecttype = {};
$scope.searchinspe = function (item) {
$scope.refreshData("expand-right", $scope.fileData);
};
//树形控件加载
$scope.my_tree = {};
$scope.try_async_load = function () {
$scope.my_data = [];
$scope.doing_async = true;
api_bpm_data
.fetchDataList("inspectionType", {
idx: 0,
sum: 1000,
})
.then(function (response) {
if (response.status == 200) {
var data = response.list;
var objects = [];
for (var i = 0; i < data.length; i++) {
var object = {};
object.id = data[i].id;
if (data[i].parent && data[i].parent.id != 0) {
object.parent = data[i].parent.id;
}
object.label = data[i].type;
objects.push(object);
}
$scope.my_data = convertParentToChildList(objects);
$scope.tree_data = angular.copy($scope.my_data);
if ($scope.my_data.length > 0) {
$scope.doing_async = false;
}
// return $scope.my_tree.expand_all()
} else {
SweetAlert.swal({
title: "系统错误!",
text: "请刷新重试!",
type: "error",
});
}
});
};
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];
//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;
}
// 获取状态
$scope.getStatusDictroy = function () {
var data = {
key: "incident_integral_state",
type: "list",
};
api_wechatfile.getDictionary(data).then(function (res) {
$scope.statusData = res;
});
};
$scope.getStatusDictroy();
// 获取执行人
$scope.getExecuteUser = function () {
api_configure_data
.fetchDataList("user", {
idx: 0,
sum: 1000,
user: {
roledata: {
rolecode: "inspectman",
},
simple: true,
engineer: 1,
},
})
.then(function (res) {
$scope.executeUserData = res.list;
});
};
$scope.getExecuteUser();
// 获取处理人
$scope.getCreateUser = function (keyword = '') {
api_configure_data
.fetchDataList("user", {
idx: 0,
sum: 1000,
"user": {
"name": keyword,
'selectType': "pinyin_qs",
engineer: 1,
}
})
.then(function (res) {
$scope.createUserData = res.list;
});
};
$scope.getCreateUser();
$scope.open = function ($event) {
$event.preventDefault();
$event.stopPropagation();
$scope.opened = !$scope.opened;
};
$scope.endOpen = function ($event) {
$event.preventDefault();
$event.stopPropagation();
$scope.startOpened = false;
$scope.endOpened = !$scope.endOpened;
};
$scope.startOpen = function ($event) {
$event.preventDefault();
$event.stopPropagation();
$scope.endOpened = false;
$scope.startOpened = !$scope.startOpened;
};
function convertParentToChildList(data) {
var treeMap = {};
var list = [];
convertListToTree(data, treeMap);
angular.forEach(treeMap, function (item) {
list.push(item);
});
return list;
}
$scope.refresh = function () {
var jry_filterData = JSON.parse(sessionStorage.inspectPlanParameter);
var intervalData = {};
if ($scope.inspectdata.type) {
$scope.inspectdata.inspectionTypeDTO = $scope.inspectdata.type.id;
}
if ($scope.inspectdata.createTime) {
$scope.inspectdata.createTime = moment(
$scope.inspectdata.createTime
).format("YYYY-MM-DD");
}
intervalData.idx = jry_filterData.idx;
intervalData.sum = jry_filterData.sum;
intervalData.inspection = $scope.inspectdata;
$scope.refreshData("expand-right", intervalData);
};
$scope.try_async_load();
$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);
});
},
]);
app.factory("inspectListMobileCtrlTree", [
"api_bpm_data",
function (api_bpm_data) {
function convertListToTree(data, treeMap) {
var idToNodeMap = {};
var root = null;
var parentNode = null;
for (var i = 0; i < data.length; i++) {
var datum = data[i];
datum.children = [];
idToNodeMap[datum.id] = datum;
if (typeof datum.parent === "undefined" || datum.parent == null) {
root = datum;
treeMap[datum.id] = root;
} else {
parentNode = idToNodeMap[datum.parent];
delete datum.parent;
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;
}
var forEachEelement = function forEachEelement(response) {
var objects = [];
angular.forEach(response.list, function (ObjIndex, index, destObj) {
var object = {};
object.id = ObjIndex.id;
object.label = ObjIndex.type;
if (ObjIndex.parent && ObjIndex.parent.id != 0) {
object.parent = ObjIndex.parent.id;
}
if (ObjIndex.formUiEdit) {
object.formUiEdit = ObjIndex.formUiEdit;
}
if (ObjIndex.formUiName) {
object.formUiName = ObjIndex.formUiName;
}
if (ObjIndex.processKey) {
object.processKey = ObjIndex.processKey;
}
if (ObjIndex.formUiStart) {
object.formUiStart = ObjIndex.formUiStart;
}
objects.push(object);
});
var my_data = convertParentToChildList(objects);
var tree_data = angular.copy(my_data);
return {
my_data: my_data,
tree_data: tree_data,
};
};
return forEachEelement;
},
]);