$(function () { var companyId = $.getUrlParam("cid") initTimeCombobox = function () { loadYearList("year") //加载年combobox loadMonthList("month") //加载月combobox loadYearList("year1") //加载年combobox loadMonthList("month1") //加载月combobox $("#month").combobox("enable") $("#month1").combobox("enable") } initTimeCombobox() //type combox选择事件 $("#type").combobox({ valueField: "value", textField: "text", onSelect: function (record) { if (record.value == 1) { $("#month").combobox("enable") } else { $("#month").combobox("disable") } }, }) //type combox选择事件 $("#type1").combobox({ valueField: "value", textField: "text", onSelect: function (record) { if (record.value == 1) { $("#month1").combobox("enable") } else { $("#month1").combobox("disable") } }, }) $("#selectEnergy").linkbutton({ onClick: function () { loadEnergyDataGrid() }, }) $("#selectProductEnergy").linkbutton({ onClick: function () { loadData() }, }) $("#exportProductEnergy").linkbutton({ onClick: function () { exportProductEnergy() }, }) $("#exportEnergy").linkbutton({ onClick: function () { exportEnergy() }, }) loadEnergyDataGrid = function () { var columns = [ [ { field: "productName", title: "产品名称", rowspan: 2, width: 120, align: "right" }, { field: "tpe", title: "电量(kW.h)", rowspan: 2, width: 120, align: "right" }, { field: "yield", title: "产量", rowspan: 2, width: 100, align: "right" }, ], [ { field: "consumption", title: "单耗", width: 100, align: "right" }, { field: "mom", title: "环比(%)", width: 80, align: "right" }, ], ] var type = $("#type1").combobox("getValue") var time = $("#year1").combobox("getValue") if (type == 1) { var month = $("#month1").combobox("getValue") time += "-" + (month < 10 ? "0" + month.toString() : month.toString()) columns[0].push({ title: "产品单耗", colspan: 3, width: 300 }) columns[1].push({ field: "an", title: "同比(%)", width: 80, align: "right" }) } else { columns[0].push({ title: "产品单耗", colspan: 2, width: 300 }) } //请求加载产品单耗数据,填充datagrid ajax({ url: "/web/pline/energy/getEnergy/" + time + ".json", beforeSend: function (XHR) { $("#energyTableDiv").mask("数据加载中...") }, success: function (data) { $("#energyTableDiv").unmask() $("#energyTable").datagrid({ data: data.data, rownumbers: true, columns: columns, onLoadError: function () { alert("载入数据发生错误,可能是由于您的登录已失效。
请刷新后再试。") }, }) }, }) } //产品电量数据加载 loadData = function () { var type = $("#type").combobox("getValue") var time = $("#year").combobox("getValue") if (type == 1) { var month = $("#month").combobox("getValue") time += "-" + (month < 10 ? "0" + month.toString() : month.toString()) } ajax({ url: "/web/pline/energy/getProductEnergy/" + time + ".json", method: "post", beforeSend: function (XHR) { $("#pieContainer").mask("数据加载中...") $("#lineContainer").mask("数据加载中...") $("#energyTabDiv").mask("数据加载中...") }, success: function (data) { $("#pieContainer").unmask() $("#lineContainer").unmask() $("#energyTabDiv").unmask() fillPieChart(data.data.pieChartData) if (type == 1) { fillLineChart(data.data.lineChartData) } else { fillMonthLineChart(data.data.lineChartData) } init_energyTab(type, data.data.dataGridData) }, }) } loadData() //默认加载当前数据 loadEnergyDataGrid() //表一excel导出 exportProductEnergy = function () { var type = $("#type").combobox("getValue") var time = $("#year").combobox("getValue") if (type == 1) { var month = $("#month").combobox("getValue") time += "-" + (month < 10 ? "0" + month.toString() : month.toString()) } var param var p = $.query.toString() if (p.indexOf("?") != -1) { param = p } else { param = "?" + p } var url = "/web/machineshop/energy/" + time + "/exportEnergyOfProduct.json" + param $("#formdata").val(JSON.stringify($("#energyTab").datagrid("getData"))) $("#mainForm").attr("action", url) $("#mainForm").attr("method", "post") $("#mainForm").submit() } //表二excel导出 exportEnergy = function () { var type = $("#type1").combobox("getValue") var time = $("#year1").combobox("getValue") if (type == 1) { var month = $("#month1").combobox("getValue") time += "-" + (month < 10 ? "0" + month.toString() : month.toString()) } var param var p = $.query.toString() if (p.indexOf("?") != -1) { param = p } else { param = "?" + p } var url = "/web/machineshop/energy/" + time + "/exportEnergy.json" + param $("#formdata").val(JSON.stringify($("#energyTable").datagrid("getData"))) $("#mainForm").attr("action", url) $("#mainForm").attr("method", "post") $("#mainForm").submit() } }) //窗口大小变化时延时刷新图表大小 $(window).resize(function () { var width = $(window).width() ;(width = (width / 10) * 6 - 30), $("#lineContainer").width(width) })