emsApplication/applications/WebConfigure/web/js/script/historyChartConfigCtrl.js

324 lines
14 KiB
JavaScript
Raw Normal View History

2024-05-24 12:19:45 +08:00
angular.module('nurseApp')
.controller('historyChartConfigCtrl',['$scope', 'KpiService', 'balert',
function($scope, KpiService, balert){
// iView版本 历史图表
$scope.currentLocation = window.location.hash;
$scope.cutSelect = function(url){
$scope.currentLocation = url;
};
$scope.isSelect = function(url){
return url == $scope.currentLocation ? 'selected' : '';
};
//#region 窗体加载事件
(function(){
loadHistoryChartDistribution();
loadHistoryChartConfig();
})();
// 同KPIID一组
function loadHistoryChartDistribution(kpiid){
KpiService.GetHistoryChartDistribution().then(function(data){
$scope.ChartDistributions = toChartDistributions(data);
if(kpiid) $scope.CDKPIID = kpiid;
else if($scope.ChartDistributions) $scope.CDKPIID = $scope.ChartDistributions[0].KPIID;
$scope.distributionIdChange($scope.CDKPIID);
});
}
function toChartDistributions(data){
var result = [];
if(data){
_.find(data,function(page){
if(result.length > 0){
var temp = _.findWhere(result, {KPIID: page.KPIID});
if(temp) temp.Parts.push(page);
else{
var temp2 = {KPIID: page.KPIID, Parts:[]};
temp2.Parts.push(page);
result.push(temp2);
}
}else{
var temp = {KPIID: page.KPIID, Parts:[]};
temp.Parts.push(page);
result.push(temp);
}
});
}
return result;
}
function loadHistoryChartConfig(key){
KpiService.GetHistoryChartConfig("KPI5.Chart1").then(function(data){
$scope.ChartConfigs = data;
if($scope.ChartConfigs){
$scope.ChartConfig = angular.copy($scope.ChartConfigs[0]);
if(key) $scope.ChartConfig.Key = key;
else $scope.ChartConfig.Key = $scope.ChartConfig.KPIID+"."+$scope.ChartConfig.ID;
}
});
}
//#endregion
//#region 图表页面
// 加载数据
$scope.distributionIdChange = function(kpiid){
$scope.ChartDistribution = {};
if($scope.ChartDistributions && kpiid){
var chartDist = _.findWhere($scope.ChartDistributions, {KPIID: kpiid});
if(chartDist && chartDist.Parts){
$scope.ChartDistribution = {
Table: angular.copy(_.findWhere(chartDist.Parts, {TabType: "Table"})),
Tds: angular.copy(_.where(chartDist.Parts, {TabType: "Td"}))
};
}
}
console.log($scope.ChartDistribution);
};
// 新增
$scope.addChartPageClk = function(){
var prompt = $scope.languageJson.Prompt;
KpiService.AddedHistoryChartDistribution().then(function(result){
if(result == "Error"){
balert.show('danger',prompt.AddedFailure, 3000);// '新增失败!'
}else{
loadHistoryChartDistribution(result);
balert.show('success',prompt.AddedSucceed, 3000);//'新增成功!'
}
});
};
// 删除
$scope.delChartPageClk = function(kpiid){
var prompt = $scope.languageJson.Prompt;
KpiService.RemoveHistoryChartDistribution(kpiid).then(function(result){
if(result == "Error"){
balert.show('danger',prompt.RemoveFailure, 3000);// '删除失败!'
}else{
loadHistoryChartDistribution();
balert.show('success',prompt.RemoveSucceed, 3000);// '删除成功!'
}
});
};
// 新增图表(TD)
$scope.addChartPageTdClk = function(){
if($scope.ChartDistribution){
if($scope.ChartDistribution.Tds == undefined) $scope.ChartDistribution.Tds = [];
var kpiid = $scope.ChartDistribution.Table.KPIID;
$scope.ChartDistribution.Tds.push({
KPIID: kpiid,
ID: "Chart1",
TdCount: "",
TrCount: "",
Colspan: "",
Rowspan: "",
TabClass: "",
TabStyle: "text-align:center;cursor:default;",
TabType: "Td",
Visible: "false",
Location: "1,1",
HtmlFile: ""
});
}
};
// 删除图表(TD)
$scope.delChartPageTdClk = function($index){
if($scope.ChartDistribution){
$scope.ChartDistribution.Tds.splice($index, 1);
}
};
// 修改
$scope.updChartPageClk = function(){
if($scope.ChartDistribution){
var prompt = $scope.languageJson.Prompt;
KpiService.ModifyHistoryChartDistribution($scope.ChartDistribution).then(function(result){
if(result == "Error"){
balert.show('danger',prompt.ModifyFailure, 3000);// '修改失败!'
}else{
loadHistoryChartDistribution($scope.ChartDistribution.Table.KPIID);
balert.show('success',prompt.ModifySucceed, 3000);// '修改成功!'
}
});
}
};
// 生成页面
$scope.reloadChartPageClk = function(){
if($scope.ChartDistribution){
var prompt = $scope.languageJson.Prompt;
KpiService.CreateHistoryChartPage($scope.ChartDistribution).then(function(result){
if(result == "Error"){
balert.show('danger',prompt.OperateFailure, 3000);// '操作失败!'
}else{
balert.show('success',prompt.OperateSucceed, 3000);// '操作成功!'
}
});
}
};
//#endregion
//#region 图表配置
// 加载数据
$scope.chartKeyChange = function(key){
if($scope.ChartConfigs){
_.find($scope.ChartConfigs, function(item){
if((item.KPIID+'.'+item.ID) == key){
$scope.ChartConfig = angular.copy(item);
$scope.ChartConfig.Key = $scope.ChartConfig.KPIID+"."+$scope.ChartConfig.ID;
}
});
}
};
// 删除
$scope.delChartCfgClk = function(kpiid, id){
var prompt = $scope.languageJson.Prompt;
KpiService.RemoveHistoryChartConfig(kpiid, id).then(function(result){
if(result == "Error"){
balert.show('danger',prompt.RemoveFailure, 3000);// '删除失败!'
}else{
loadHistoryChartConfig();
balert.show('success',prompt.RemoveSucceed, 3000);//'删除成功!'
}
});
};
// 修改
$scope.modifyChartConfigClk = function(){
if($scope.ChartConfig){
var prompt = $scope.languageJson.Prompt;
KpiService.ModifyHistoryChartConfig($scope.ChartConfig).then(function(result){
if(result == "Error"){
balert.show('danger',prompt.ModifyFailure, 3000);//'修改失败!'
}else{
loadHistoryChartConfig($scope.ChartConfig.Key);
balert.show('success',prompt.ModifySucceed, 3000);//'修改成功!'
}
});
}
};
// 配置生效
$scope.reloadChartConfigClk = function(){
$scope.loading = true;
KpiService.ReloadHistoryChartData().then(function(result){
$scope.loading = false;
});
};
//#endregion
}
])
.controller('kpiCtrl', ['$scope','$stateParams', '$element', 'KpiService', '$http',
function ($scope, $stateParams, $element, KpiService, $http) {
var charType = new Array();
// 加载HTML文件
function loadHtml(){
var kpiNo = $stateParams.id;
$http.get("data/KPI" + kpiNo + ".html").success(function (data) {
$element.html(data);
setTdHeight();
addedChartDiv();
loadChartData(kpiNo);
});
}
loadHtml();
//设置td的高度
function setTdHeight() {
var bodyHeight = $("#page-wrapper").height();
var tdHeight = bodyHeight / parseInt($("#layouttable").attr("vertical")) - 30;
$(".tabKpi tr").each(function () {
if (!!$(this).attr('style'))
return true;
$(this).children("td").each(function () {
var realHeight = parseInt($(this).attr("vertical")) * tdHeight;
if(isNaN(realHeight)) realHeight = tdHeight;
$(this).height(realHeight);
});
});
}
// 加载画布的id
function addedChartDiv() {
$element.find("table tr").each(function () {
$(this).children("td").each(function () {
var charId = $(this).text();
if (charId != 'GTCHART') {
charType.push(charId);
if (charId.indexOf("[") != -1)
charId = charId.split("[")[0];
var div = "<div class='charts_div'><a class='charts_a' id='" + charId + "'></a></div>";
$(this).html(div);
}
});
});
}
// 获取图表数据
function loadChartData(kpiNo){
KpiService.GetHistoryChartConfig(kpiNo).then(function(chartConfig){
$scope.ChartConfig = getChartConfigByNo(chartConfig,kpiNo);
if($scope.ChartConfig){
//console.log(chartConfig);
$element.find("table tr").each(function () {
$(this).children("td").each(function () {
var charId = $(this).children("div").children("a").attr("id");
KpiService.GetHistoryChartData(kpiNo, charId).then(function(option){
//console.log(charId, chartConfig.ChartType, option);
loadChartOption(charId, $scope.ChartConfig.ChartType, option);
});
});
});
}
});
}
function getChartConfigByNo(chartConfig, no){
var kpiid = "KPI"+no;
if(chartConfig){
return _.findWhere(chartConfig, {KPIID: kpiid});
}
return {};
}
// 加载图表
var index = 0;
function loadChartOption(charId, chartType, optionData){
var sysStyle = localStorage.getItem("systemStyle");
var colorArr = ["#068cfd", "#1dc0c5", "#fc794f", "#3a546d", "#73C0DE", "#EE6666", "#5470C6"];
if(chartType == "Bar" || chartType == "Line"){
$http.get("data/BarCharts.json").success(function (option) {
var myOption = echarts.init($("#" + charId)[0]);
// 赋值数据
if(optionData && optionData.series){
option.title.text = optionData.title.text;
option.xAxis[0].name = optionData.xAxis.name;
option.xAxis[0].data = angular.fromJson(optionData.xAxis.data);
option.yAxis[0].name = optionData.yAxis.name;
var optSeries = option.series[0]
option.series = [];
for(var i = 0;i < optionData.series.length;i++){
var series = angular.copy(optSeries);
series.type = optionData.series[i].type;
series.data = angular.fromJson(optionData.series[i].data);
option.series.push(series);
}
}
// 风格切换
if (sysStyle == "White") {
option.title.textStyle.color = "#464952";
if(option.legend) option.legend.textStyle.color = "#464952";
option.xAxis[0].axisLabel.textStyle.color = "#464952";
option.yAxis[0].axisLabel.textStyle.color = "#464952";
_.find(option.series,function(ser){
ser.itemStyle.normal.label.textStyle.color = "#464952";
});
}
// 多条颜色
option.color = [colorArr[index]];
if (index >= colorArr.length) index = 0;
else index++;
//console.log(angular.toJson(option));
myOption.setOption(option, true);
});
}
}
}
]);