diff --git a/src/views/statistics/inm_statistics.vue b/src/views/statistics/inm_statistics.vue index 45c573b7..8e8d44ae 100644 --- a/src/views/statistics/inm_statistics.vue +++ b/src/views/statistics/inm_statistics.vue @@ -41,7 +41,21 @@

产品交付统计

- + + + + + + +
@@ -188,6 +202,7 @@ export default { end_date: "", currentYear: "", currentMonth: "", + materialName: "", xAxisOrigin: [], xAxisData: [], typeOptions: ["月", "年"], @@ -227,20 +242,10 @@ export default { tableData2: [], firstWeekNum: 1, endWeekNum: 4, - monthList: [ - "一月", - "二月", - "三月", - "四月", - "五月", - "六月", - "七月", - "八月", - "九月", - "十月", - "十一月", - "十二月", - ], + monthList: ["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"], + materialItem:{}, + paramsMaterial:{type__in : "10"}, + apiObjMaterial:this.$API.mtm.material.list, }; }, mounted() { @@ -251,16 +256,12 @@ export default { let days = new Date(year, month, 0).getDate(); that.currentYear = year; that.currentMonth = month; + that.firstWeekNum = that.getWeekOfYear(year,month,1); + that.endWeekNum = that.getWeekOfYear(year,month,days); + month = month < 10 ? "0" + month : month; that.start_date = year + "-" + month + "-01"; - that.end_date = - year + "-" + month + "-" + new Date(year, month, 0).getDate(); - let month1 = month; - if (month1 < 10) { - month1 = "0" + month1; - } - that.queryDate = year + "-" + month1; - that.firstWeekNum = that.getWeekOfYear(new Date(that.start_date)); - that.endWeekNum = that.getWeekOfYear(new Date(that.end_date)); + that.end_date =year + "-" + month + "-" + days; + that.queryDate = year + "-" + month; let duration = that.endWeekNum - that.firstWeekNum + 1; for (let i = 1; i <= duration; i++) { that.xAxisOrigin.push("第" + i + "周"); @@ -272,17 +273,16 @@ export default { that.rightHeight = height - 115; that.getTable(); that.setChart("bachart1", that.basicOption); - this.getSaleOption(); + // this.getSaleOption(); }, methods: { setChart(name, option = null) { // 根据name 渲染数据, option需填写,否则option为模拟数据 - var myChart = echarts.getInstanceByDom( - document.getElementById(name) - ); - if (myChart == undefined) { - myChart = echarts.init(document.getElementById(name), "T"); + var myChart = echarts.getInstanceByDom(document.getElementById(name)); + if (myChart != null) { + myChart.dispose(); // 销毁之前的实例 } + myChart = echarts.init(document.getElementById(name), "T"); if (option == null) { option = Object.assign({}, this.basicOption); } @@ -296,24 +296,13 @@ export default { console.log(value); this.queryDate = ""; }, - getWeekOfYear(date) { - var target = new Date( - date.getFullYear(), - date.getMonth(), - date.getDate() - ); // 创建目标日期对象 - var firstDayOfYear = new Date(target.getFullYear(), 0, 1); // 创建当前年份第一天的日期对象 - if (target.getTime() == firstDayOfYear.getTime()) { - return 1; - } else { - return Math.ceil( - (target - - firstDayOfYear + - 8 * (firstDayOfYear.getTimezoneOffset() / 480)) / - 604800000 - ); - } - // 计算两者之间相隔的周数并返回结果 + getWeekOfYear(a,b,c) { + var date1 = new Date(a, parseInt(b) - 1, c), //当前日期   + date2 = new Date(a, 0, 1), //当年第一天   + // d是当前日期是今年第多少天   + d = Math.round((date1.valueOf() - date2.valueOf()) / 86400000); + // d + 当前年的第一天的周差距的和在除以7就是本年第几周   + return Math.ceil((d + (date2.getDay() + 1 - 1)) / 7); }, materialSaleChange() { this.getSaleData(); @@ -331,8 +320,6 @@ export default { //交付物料 getSaleData() { let that = this; - let option = deepCopy(that.basicOption); - option.xAxis.data = that.xAxisData; let exec = that.queryType == "月" ? "saleOutWeek" : "saleOutMonth"; let obj = { query: { @@ -343,26 +330,14 @@ export default { }, }; that.$API.bi.dataset.exec.req(exec, obj).then((res) => { - console.log("getSaleData", res); - option.series.data = []; - if (res.data2.ds0) { - let data = res.data2.ds0; - that.tableData1 = data; - if (data.length > 0) { - let seriesData = []; - data.forEach((item) => { - if (that.queryType == "月") { - let index = item.周 - that.firstWeekNum; - seriesData[index] = item.数量; - } else { - let index = item.月 - 1; - seriesData[index] = item.数量; - } - }); - option.series.data = seriesData; - } + if (res.data2.ds0&&res.data2.ds0.length>0) { + that.tableData1 = res.data2.ds0; + that.setChartData(res.data2.ds0); + }else{ + let option = deepCopy(that.basicOption); + option.xAxis.data = that.xAxisData; + that.setChart("bachart1",option); } - that.setChart("bachart1", option); }); }, getTable() { @@ -379,7 +354,9 @@ export default { that.tableData2 = []; if (res.data2.ds0) { let data = res.data2.ds0; + that.tableData1 = data; that.tableData2 = data; + that.setChartData(data); } }); }, @@ -387,48 +364,33 @@ export default { let that = this; if (this.queryType == "月") { if (this.queryDate !== "" && this.queryDate !== null) { - this.start_date = this.queryDate + "-01"; - let arr = this.queryDate.split("-"); - this.end_date = - this.queryDate + - "-" + - new Date(arr[0], arr[1], 0).getDate(); - this.firstWeekNum = this.getWeekOfYear( - new Date(this.start_date) - ); - this.endWeekNum = this.getWeekOfYear( - new Date(this.end_date) - ); - let duration = this.endWeekNum - this.firstWeekNum + 1; + let arr = that.queryDate.split("-"); + let year = arr[0]; + let month = arr[1]; + let days = new Date(year, month, 0).getDate(); + that.start_date = that.queryDate + "-01"; + that.end_date =that.queryDate +"-" +days; + that.firstWeekNum = that.getWeekOfYear(year,month,1); + that.endWeekNum = that.getWeekOfYear(year,month,days); + let duration = that.endWeekNum - that.firstWeekNum + 1; let xAxisData = []; for (let i = 1; i <= duration; i++) { xAxisData.push("第" + i + "周"); } that.xAxisData = xAxisData; } else { - this.start_date = - this.currentYear + "-" + this.currentMonth + "-01"; - this.end_date = - this.currentYear + - "-" + - this.currentMonth + - "-" + - new Date( - this.currentYear, - this.currentMonth, - 0 - ).getDate(); - let date = new Date(this.start_date); - this.firstWeekNum = this.getWeekOfYear(date); - this.xAxisData = this.xAxisOrigin; + that.start_date =that.currentYear + "-" + that.currentMonth + "-01"; + that.end_date =that.currentYear +"-" +that.currentMonth +"-" +new Date(that.currentYear,that.currentMonth,0).getDate(); + that.firstWeekNum = that.getWeekOfYear(that.currentYear,that.currentMonth,1); + that.xAxisData = that.xAxisOrigin; } } else { - if (this.queryDate !== "" && this.queryDate !== null) { - this.start_date = this.queryDate + "-01-01"; - this.end_date = this.queryDate + "-12-31"; + if (that.queryDate !== "" && that.queryDate !== null) { + that.start_date = that.queryDate + "-01-01"; + that.end_date = that.queryDate + "-12-31"; } else { - this.start_date = this.currentYear + "-01-01"; - this.end_date = this.currentYear + "-12-31"; + that.start_date = that.currentYear + "-01-01"; + that.end_date = that.currentYear + "-12-31"; } that.xAxisData = that.monthList; } @@ -437,6 +399,39 @@ export default { that.getSaleData(); } }, + setChartData(data){ + let that = this; + let option = deepCopy(that.basicOption); + option.xAxis.data = that.xAxisData; + option.series=[]; + let materials = [],seriesData = []; + data.forEach((item) => { + if(materials.indexOf(item.物料名) == -1){ + materials.push(item.物料名); + } + }) + materials.forEach((item) => { + let obj = {}; + obj.name = item; + obj.type = "bar"; + obj.stack = "Ad"; + obj.barWidth = "15px"; + obj.data = [0,0,0,0,0,0,0,0,0,0,0,0]; + seriesData.push(obj); + }) + data.forEach((item) => { + let index = 0;let indexY = 0; + if (that.queryType == "月") { + index = item.周 - that.firstWeekNum; + } else { + index = item.月 - 1; + } + indexY = materials.indexOf(item.物料名); + seriesData[indexY].data[index] = item.数量; + }); + option.series = seriesData; + that.setChart("bachart1", option); + }, handleExport(val) { this.exportLoading = true; let id = "#exportDiv" + val; diff --git a/src/views/statistics/material_statistics.vue b/src/views/statistics/material_statistics.vue index 1a2ba481..f5210432 100644 --- a/src/views/statistics/material_statistics.vue +++ b/src/views/statistics/material_statistics.vue @@ -43,6 +43,7 @@

采购统计

{{ scope.row.data.棒料成型_count_n_qp }} + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -472,59 +267,14 @@ {{ scope.row.data.六车间_粗中细磨_合格率 }} - - - - - - - - - - - - - - - - + - - - - - - - - - - - - @@ -532,54 +282,19 @@ {{ scope.row.data.六车间_粗中细磨_count_n_yp }} - + - + - + - - - - - - - - - - - - - - - - - - - - - @@ -608,36 +323,6 @@ {{ scope.row.data.六车间_粗中细磨_count_n_hs }} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -920,66 +415,21 @@ {{ scope.row.data.六车间中检_count_n_bl }} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -621,41 +427,21 @@ {{ scope.row.data.六车间中检_count_n_hs }} - - - - - - - - - - - - - + - + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + +