410 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			Vue
		
	
	
	
			
		
		
	
	
			410 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			Vue
		
	
	
	
| <template>
 | ||
| 	<div class="app-container">
 | ||
| 		<el-header>
 | ||
| 			<div class="left-panel">
 | ||
| 				<el-date-picker
 | ||
| 					v-model="query.year_s"
 | ||
| 					type="year"
 | ||
| 					value-format="YYYY"
 | ||
| 					format="YYYY"
 | ||
| 					placeholder="查询年份"
 | ||
| 					class="headerSearch"
 | ||
| 				/>
 | ||
| 				<el-button
 | ||
| 					type="primary"
 | ||
| 					icon="el-icon-search"
 | ||
| 					@click="handleQuery"
 | ||
| 				></el-button>
 | ||
| 				<el-button
 | ||
| 					type="primary"
 | ||
| 					@click="exportExcel()"
 | ||
| 					:loading="exportLoading"
 | ||
| 					v-auth="'export_excel'"
 | ||
| 					>导出xlsx
 | ||
| 				</el-button>
 | ||
| 				<el-button type="primary" @click="handlePrint">打印 </el-button>
 | ||
| 			</div>
 | ||
| 		</el-header>
 | ||
| 		<el-card style="margin-top: 5px">
 | ||
| 			<div class="printWrap">
 | ||
| 				<div ref="print" id="myReport" class="printContainer">
 | ||
| 					<table
 | ||
| 						border="1"
 | ||
| 						cellspacing="0"
 | ||
| 						:key="timeStamp"
 | ||
| 						id="myTable"
 | ||
| 						class="myTable"
 | ||
| 						width="1600"
 | ||
| 					>
 | ||
| 						<thead class="myTableHead">
 | ||
| 							<tr>
 | ||
| 								<th colspan="16">煤磨工序班组月度对比分析</th>
 | ||
| 							</tr>
 | ||
| 							<tr>
 | ||
| 								<th rowspan="2">月份</th>
 | ||
| 								<th rowspan="2">班组</th>
 | ||
| 								<th rowspan="2">总产量(t)</th>
 | ||
| 								<th rowspan="2">台时产量(t/h)</th>
 | ||
| 								<th rowspan="2">运转率(%)</th>
 | ||
| 								<th colspan="2">质量</th>
 | ||
| 								<th colspan="7">单位产品电耗</th>
 | ||
| 								<th rowspan="2">得分</th>
 | ||
| 								<th rowspan="2">排名</th>
 | ||
| 							</tr>
 | ||
| 							<tr>
 | ||
| 								<th>细度(%)</th>
 | ||
| 								<th>水分(%)</th>
 | ||
| 								<!-- <th>煤磨排风机主电机(kW·h/t)</th> -->
 | ||
| 								<th>当期值(kW·h/t)</th>
 | ||
| 								<th>目标值(kW·h/t)</th>
 | ||
| 								<th>当期与目标值差值(kW·h/t)</th>
 | ||
| 								<th>环期值(kW·h/t)</th>
 | ||
| 								<th>当期与环期差值(kW·h/t)</th>
 | ||
| 								<th>环比增长率(%)</th>
 | ||
| 								<th>同比增长率(%)</th>
 | ||
| 							</tr>
 | ||
| 						</thead>
 | ||
| 						<tr v-for="(item, index) in tableDatas" :key="index">
 | ||
| 							<td
 | ||
| 								v-for="(item0, index0) in item"
 | ||
| 								:key="index0"
 | ||
| 								class="numCell"
 | ||
| 							>
 | ||
| 								{{ item0 }}
 | ||
| 							</td>
 | ||
| 						</tr>
 | ||
| 					</table>
 | ||
| 				</div>
 | ||
| 			</div>
 | ||
| 		</el-card>
 | ||
| 	</div>
 | ||
| </template>
 | ||
| <script>
 | ||
| export default {
 | ||
| 	data() {
 | ||
| 		return {
 | ||
| 			timeStamp: 0,
 | ||
| 			query: {
 | ||
| 				year_s: "",
 | ||
| 				page: 0,
 | ||
| 				type: "month_st",
 | ||
| 				mgroup: "",
 | ||
| 			},
 | ||
| 			tableDatas: [],
 | ||
| 			goalDatas: [],
 | ||
| 			tableName:'煤磨工序生产报告',
 | ||
| 		};
 | ||
| 	},
 | ||
| 	mounted() {
 | ||
| 		let that = this;
 | ||
| 		var myDate = new Date();
 | ||
| 		let year = myDate.getFullYear();
 | ||
| 		that.query.year_s = year;
 | ||
| 		//月目标
 | ||
| 		let paramsGoal = {};
 | ||
| 		paramsGoal.page = 0;
 | ||
| 		this.$API.mtm.mgroup.list
 | ||
| 			.req({page:0, search:"煤磨"})
 | ||
| 			.then((res) =>{
 | ||
| 				that.query.mgroup = res[0].id;
 | ||
| 				let params = {};
 | ||
| 				params.page = 0;
 | ||
| 				params.year = year;
 | ||
| 				params.mgroup = that.query.mgroup;
 | ||
| 				this.$API.mtm.goal.list.req(params).then((res) => {
 | ||
| 					// let data = [];
 | ||
| 					if (res.length > 0) {
 | ||
| 						res.forEach((item) => {
 | ||
| 						    if (item.goal_cate_name == "单位产品分布电耗(kW·h/t)") {
 | ||
| 						        that.getGoalData();
 | ||
| 						    }
 | ||
| 						})
 | ||
| 					}
 | ||
| 				});
 | ||
| 			});
 | ||
| 	},
 | ||
| 	
 | ||
| 	methods: {
 | ||
| 		getGoalData() {
 | ||
| 			const self = this;
 | ||
| 			let params = {};
 | ||
| 			params.page = 0;
 | ||
| 			params.year = self.query.year_s;
 | ||
| 			params.mgroup = self.query.mgroup;
 | ||
| 			this.$API.mtm.goal.list.req(params).then((res) => {
 | ||
| 				if (res.length > 0) {
 | ||
| 						res.forEach((item) => {
 | ||
| 						    if (item.goal_cate_name == "单位产品分布电耗(kW·h/t)") {
 | ||
| 						        this.getData(item);
 | ||
| 						    }
 | ||
| 						})
 | ||
| 					}
 | ||
| 			})
 | ||
| 			.catch((error) => {
 | ||
|             console.error('获取目标数据失败:', error);
 | ||
|         });
 | ||
| 		},
 | ||
| 		getData(goalData) {
 | ||
| 			let that = this;
 | ||
| 			let query0 = {};
 | ||
| 			query0.page = 0;
 | ||
| 			query0.type = "month_st";
 | ||
| 			query0.year_s = that.query.year_s - 1;
 | ||
| 			query0.mgroup = that.query.mgroup;
 | ||
| 			let wrapArr = [],
 | ||
| 				wrapArr0 = [],
 | ||
| 				compareArr0 = [],
 | ||
| 				month_obj = {},
 | ||
| 				wrapArrs = [];
 | ||
| 			this.$API.enm.enstat.req(query0).then((res0) => {
 | ||
| 				let data0 = res0;
 | ||
| 				if (data0.length > 0) {
 | ||
| 					data0.forEach((item0) => {
 | ||
| 						//先按月份排序,再按班组排序
 | ||
| 						let month = item0.month_s;
 | ||
| 						if (!wrapArr0[month]) {
 | ||
| 							wrapArr0[month] = [];
 | ||
| 						}
 | ||
| 						wrapArr0[month].push(item0);
 | ||
| 					});
 | ||
| 				} else { console.log('No data received.');}
 | ||
| 			}).then(() => {
 | ||
| 				this.$API.enm.enstat.req(that.query).then((res) => {
 | ||
| 					//今年的值
 | ||
| 					let data = res;
 | ||
| 					if (data.length > 0) {
 | ||
| 						data.forEach((item) => {
 | ||
| 							//先按月份排序,再按班组排序
 | ||
| 							let compareArr = [];
 | ||
| 							compareArr.push(item.month_s);
 | ||
| 							compareArr.push(item.team_name);
 | ||
| 							compareArr.push(item.elec_consume_unit);
 | ||
| 							compareArr0.push(compareArr);
 | ||
| 							if (!month_obj[item.month_s]) {
 | ||
| 								month_obj[item.month_s] = [];
 | ||
| 							}
 | ||
| 							month_obj[item.month_s].push(
 | ||
| 								{
 | ||
| 								team:item.team_name, 
 | ||
| 								production_hour: item.production_hour,
 | ||
| 								run_rate:item.run_rate,
 | ||
| 								xidu:item.出磨煤粉_细度_rate_pass,
 | ||
| 								coal_powder:item.出磨煤粉_水分_rate_pass,
 | ||
| 								elec:item.elec_consume_unit,
 | ||
| 								}
 | ||
| 							);
 | ||
| 
 | ||
| 						});
 | ||
| 						data.forEach((item) => {
 | ||
| 							//先按月份排序,再按班组排序
 | ||
| 							let n = item.month_s;
 | ||
| 							let arr = [];
 | ||
| 							let time = "" + item.year_s + "." + item.month_s;
 | ||
| 							arr.push(time);
 | ||
| 							arr.push(item.team_name);
 | ||
| 							arr.push(item.total_production);
 | ||
| 							arr.push(item.production_hour);
 | ||
| 							arr.push(item.run_rate);
 | ||
| 							//质量
 | ||
| 							arr[5] =
 | ||
| 								item.出磨煤粉_细度_rate_pass !== undefined && item.出磨煤粉_细度_rate_pass !== null
 | ||
| 									? item.出磨煤粉_细度_rate_pass
 | ||
| 									: 0;
 | ||
| 
 | ||
| 							arr[6] =
 | ||
| 								item.出磨煤粉_水分_rate_pass !== undefined && item.出磨煤粉_水分_rate_pass !== null
 | ||
| 									? item.出磨煤粉_水分_rate_pass
 | ||
| 									: 0;
 | ||
| 									//设备
 | ||
| 							// arr[7] =
 | ||
| 							// 	item.煤磨排风机主电机_consume_unit
 | ||
| 							// 	!== undefined && item.煤磨排风机主电机_consume_unit
 | ||
| 							// 	!== null
 | ||
| 							// 		? item.煤磨排风机主电机_consume_unit
 | ||
| 							// 		: 0;
 | ||
| 							let keyVale = "goal_val_" + n;
 | ||
| 							arr[7] = item.elec_consume_unit; //当期值(kW·h/t)
 | ||
| 							arr[8] = goalData[keyVale]; //目标值(kW·h/t)//需要接口获取
 | ||
| 							arr[9] = (arr[7] - arr[8]).toFixed(2); //当期与目标差值(kW·h/t)
 | ||
| 							let ind_pre = 0,
 | ||
| 							huanqi = 0;
 | ||
| 								if (item.month_s == 1) {
 | ||
| 									ind_pre = 12;
 | ||
| 									// 循环遍历数组wrapArr0[ind_pre],找到item.name与 wrapArr0 数组中相同的名字
 | ||
| 									if (wrapArr0[ind_pre]) {
 | ||
| 										wrapArr0[ind_pre].forEach((item0) => {
 | ||
| 											if (item0.team_name == item.team_name) {
 | ||
| 												huanqi = item0.elec_consume_unit;
 | ||
| 											}
 | ||
| 										});
 | ||
| 									}
 | ||
| 								
 | ||
| 							} else {
 | ||
| 								// 如果 wrapArr数组长度大于0,那么循环遍历wrapArr数组,找到与item.month_s相差1的元素 而 item.name相同,并赋值给huanbi
 | ||
| 								compareArr0.forEach((item0) => {
 | ||
| 									if (item0[0] == item.month_s - 1 && item0[1] == item.team_name) {
 | ||
| 										huanqi = item0[2];
 | ||
| 								}
 | ||
| 							})
 | ||
| 							}
 | ||
| 							arr[10] = huanqi; //环期值(kW·h/t)上个月的值
 | ||
| 							let huanqicha = 0;
 | ||
| 							if (huanqi !== "/") {
 | ||
| 								huanqicha = (arr[7] - arr[10]).toFixed(2);
 | ||
| 							} else {
 | ||
| 								huanqicha = 0;
 | ||
| 							}
 | ||
| 							arr[11] = huanqicha; //当期与环期差值(kW·h/t)
 | ||
| 							// arr[13] =
 | ||
| 							if (arr[12] !=="/" && arr[10]!=0 && arr[11] !=0 && arr[11] !== "undefined"){
 | ||
| 								arr[12] = ((arr[11]/arr[10])*100).toFixed(2);
 | ||
| 							}else{
 | ||
| 								arr[12] = "/"; //环比增长率(%)= 当期与环期差值(kW·h/t)/环期值(kW·h/t)*100%
 | ||
| 							}
 | ||
| 							arr[13] = 0; //同比增长率(%)
 | ||
| 							// arr[15] = 0.0; //得分
 | ||
| 							arr[14] = 0;
 | ||
| 							if (month_obj[n]) {
 | ||
| 							    const monthData = month_obj[n];
 | ||
| 								const itemValue = item.elec_consume_unit; // 单位产品电耗的值
 | ||
| 								const sortedData = monthData.sort((a, b) => parseFloat(b.elec) - parseFloat(a.elec));
 | ||
| 								const index = sortedData.findIndex(obj => parseFloat(obj.elec) === parseFloat(itemValue));	
 | ||
| 								let elec_score = 0;							
 | ||
| 								if (index === 0){
 | ||
| 									elec_score= 5;
 | ||
| 								} else if (index === 1) {
 | ||
| 									elec_score= 8;
 | ||
| 								} else if (index === 2) {
 | ||
| 									elec_score= 10;
 | ||
| 								} else if (index === 3) {
 | ||
| 									elec_score= 15;
 | ||
| 								}
 | ||
| 								arr[14] += elec_score;
 | ||
| 
 | ||
| 								// const run_rate_itemValue = item.run_rate; // 运转率的值
 | ||
| 								// const run_rate_sortedData = monthData.sort((a, b) => parseFloat(b.run_rate) - parseFloat(a.run_rate));
 | ||
| 								// const run_rate_index = run_rate_sortedData.findIndex(obj => parseFloat(obj.run_rate) === parseFloat(run_rate_itemValue));
 | ||
| 								// let run_rate_score = 0;
 | ||
| 								// if (run_rate_index === 0){
 | ||
| 								// 	run_rate_score= 20;
 | ||
| 								// } else if (run_rate_index === 1) {
 | ||
| 								// 	run_rate_score= 15;
 | ||
| 								// } else if (run_rate_index === 2) {
 | ||
| 								// 	run_rate_score= 5;
 | ||
| 								// } else if (run_rate_index === 3) {
 | ||
| 								// 	run_rate_score= 0;
 | ||
| 								// }
 | ||
| 								// arr[15] += run_rate_score;
 | ||
| 
 | ||
| 								const production_hour_itemValue = item.production_hour; // 台时产量的值
 | ||
| 								const production_hour_sortedData = monthData.sort((a, b) => parseFloat(b.production_hour) - parseFloat(a.production_hour));
 | ||
| 								const production_hour_index = production_hour_sortedData.findIndex(obj => parseFloat(obj.production_hour) === parseFloat(production_hour_itemValue));
 | ||
| 								let production_hour_score = 0;
 | ||
| 								if (production_hour_index === 0){
 | ||
| 									production_hour_score= 10;
 | ||
| 								} else if (production_hour_index === 1) {
 | ||
| 									production_hour_score= 8;
 | ||
| 								} else if (production_hour_index === 2) {
 | ||
| 									production_hour_score= 6;
 | ||
| 								} else if (production_hour_index === 3) {
 | ||
| 									production_hour_score= 4;
 | ||
| 								}
 | ||
| 								arr[14] += production_hour_score;
 | ||
| 
 | ||
| 								const xidu_itemValue = item.出磨煤粉_细度_rate_pass; // 出磨煤粉细度的值
 | ||
| 								const xidu_sortedData = monthData.sort((a, b) => parseFloat(b.xidu) - parseFloat(a.xidu));
 | ||
| 								const xidu_index = xidu_sortedData.findIndex(obj => parseFloat(obj.xidu) === parseFloat(xidu_itemValue));
 | ||
| 								let xidu_score = 0;
 | ||
| 								if (xidu_index === 0){
 | ||
| 									xidu_score= 8;
 | ||
| 								} else if (xidu_index === 1) {
 | ||
| 									xidu_score= 6;
 | ||
| 								} else if (xidu_index === 2) {
 | ||
| 									xidu_score= 5;
 | ||
| 								} else if (xidu_index === 3) {
 | ||
| 									xidu_score= 3;
 | ||
| 								}
 | ||
| 								arr[14] += xidu_score;
 | ||
| 
 | ||
| 								const coal_powder_itemValue = item.出磨煤粉_水分_rate_pass; // 出磨煤粉水分的值
 | ||
| 								const coal_powder_sortedData = monthData.sort((a, b) => parseFloat(b.coal_powder) - parseFloat(a.coal_powder));
 | ||
| 								const coal_powder_index = coal_powder_sortedData.findIndex(obj => parseFloat(obj.coal_powder) === parseFloat(coal_powder_itemValue));
 | ||
| 								let coal_powder_score = 0;
 | ||
| 								if (coal_powder_index === 0){
 | ||
| 									coal_powder_score= 7;
 | ||
| 								} else if (coal_powder_index === 1) {
 | ||
| 									coal_powder_score= 4;
 | ||
| 								} else if (coal_powder_index === 2) {
 | ||
| 									coal_powder_score= 3;
 | ||
| 								} else if (coal_powder_index === 3) {
 | ||
| 									coal_powder_score= 2;
 | ||
| 								}
 | ||
| 								arr[14] += coal_powder_score;
 | ||
| 								arr[14] += 60;
 | ||
| 							}
 | ||
| 							wrapArr.push(arr);
 | ||
| 						});
 | ||
| 						// 深拷贝数组,防止原始数据被修改
 | ||
| 						const sortArr = [...wrapArr];
 | ||
| 						// 将数组按每4个元素进行分组
 | ||
| 						const groupSize = 4;
 | ||
| 						const groupedArr = [];
 | ||
| 						for (let i = 0; i < sortArr.length; i += groupSize) {
 | ||
| 							groupedArr.push(sortArr.slice(i, i + groupSize));
 | ||
| 							}
 | ||
| 						groupedArr.forEach(group => {
 | ||
| 							group.sort((a, b) => b[b.length - 1] - a[a.length - 1]); // 按最后一项值排序(忽略排名)
 | ||
| 							// 为每个分组内的元素计算排名
 | ||
| 							let currentRank = 1;
 | ||
| 							let previousValue = null;
 | ||
| 							group.forEach((item, index) => {
 | ||
| 								if (previousValue !== item[item.length - 1]) {
 | ||
| 									currentRank = index + 1;
 | ||
| 									previousValue = item[item.length - 1];  // 保留上一个排名
 | ||
| 									  // 当前排名为索引加1
 | ||
| 								}
 | ||
| 								item.push(`${currentRank}名`);
 | ||
| 							});
 | ||
| 								});
 | ||
| 						// 扁平化分组数组
 | ||
| 						const flattenedArr = groupedArr.flat();
 | ||
| 						// 将排序并添加排名后的数据赋值给 tableDatas
 | ||
| 						that.tableDatas = flattenedArr;
 | ||
| 						}
 | ||
| 							});
 | ||
| 						});			
 | ||
| 		},
 | ||
| 		handleQuery() {
 | ||
| 			this.tableDatas = [];
 | ||
| 			this.getGoalData();
 | ||
| 		},
 | ||
| 		itemClick(type, item) {
 | ||
| 			this.type = type;
 | ||
| 			this.asynDialog = true;
 | ||
| 		},
 | ||
| 		itemClick1(type, item) {
 | ||
| 			this.chartShow = false;
 | ||
| 			this.$API.bi.dataset.exec.req("3322567213885833216").then((res) => {
 | ||
| 				this.myOption = JSON.parse(res.echart_options);
 | ||
| 				debugger;
 | ||
| 				this.chartShow = true;
 | ||
| 			});
 | ||
| 		},
 | ||
| 		handlePrint() {
 | ||
| 			this.$PRINT("#myReport");
 | ||
| 		},
 | ||
| 		exportExcel() {
 | ||
| 			this.exportLoading = true;
 | ||
| 			this.$XLSX("#myTable", this.tableName);
 | ||
| 			this.exportLoading = false;
 | ||
| 		},
 | ||
| 	},
 | ||
| };
 | ||
| </script>
 | ||
| <style scoped>
 | ||
| .printWrap {
 | ||
| 	width: 100%;
 | ||
| 	overflow-x: scroll;
 | ||
| }
 | ||
| </style>
 |