<template>
	<el-container>
		<el-header>
			<div class="left-panel"></div>
			<div class="right-panel">
				<el-select
				 	v-if="activeName=='gongxu'"
					v-model="query2.process_name"
					placeholder="选择工序"
					clearable
					filterable
				>
					<el-option
						v-for="item in processList"
						:key="item"
						:label="item"
						:value="item">
					</el-option>
				</el-select>
                <el-date-picker
					v-model="query.start_date"
					type="date"
					value-format="YYYY-MM-DD"
					placeholder="开始时间"
					style="width: 150px"
				/>
				<el-date-picker
					v-model="query.end_date"
					type="date"
					value-format="YYYY-MM-DD"
					placeholder="结束时间"
					style="margin-left: 2px; width: 150px"
				/>
				<el-button
					type="primary"
					icon="el-icon-search"
					@click="handleQuery2"
				></el-button>
			</div>
		</el-header>
		<el-main class="nopadding">
			<el-tabs type="border-card" v-model="activeName" @tab-click="handleClick" style="height: 100%;" lazy>
				<el-tab-pane name="luhao" label="炉号统计" style="height: 100%;">
					<el-container v-if="activeName=='luhao'">
						<el-main>
							<scTable
							   v-if="showTable"
								ref="table3"
								:data="tableData"
								row-key="id"
								hidePagination
								hideDo
								stripe
							>
								<el-table-column type="index" width="50"  fixed="left"/>
								<el-table-column label="炉号" prop="设备编号">
								</el-table-column>
								<el-table-column label="总数">
									<template #default="scope">
										<!--  @click="handleNumClick(scope.row)"  -->
										<span v-if="scope.row.总切片数">{{ scope.row.总切片数 }}</span>
										<span v-else>{{ scope.row.总生产数 }}</span>
									</template>
								</el-table-column>
								<el-table-column label="黑网重">
									<template #default="scope">
										<span v-if="scope.row.黑网重">{{scope.row.黑网重.含}}</span>
										<span v-else>0</span>
									</template>
								</el-table-column>
								<el-table-column label="白网重">
									<template #default="scope">
										<span v-if="scope.row.白网重">{{scope.row.白网重.含}}</span>
										<span v-else>0</span>
									</template>
								</el-table-column>
								<el-table-column label="小网重">
									<template #default="scope">
										<span v-if="scope.row.小网重">{{scope.row.小网重.含}}</span>
										<span v-else>0</span>
									</template>
								</el-table-column>
								<el-table-column label="分辨率">
									<template #default="scope">
										<span v-if="scope.row.分辨率">{{scope.row.分辨率.含}}</span>
										<span v-else>0</span>
									</template>
								</el-table-column>
								<el-table-column label="炸纹">
									<template #default="scope">
										<span v-if="scope.row.炸纹">{{scope.row.炸纹.含}}</span>
										<span v-else>0</span>
									</template>
								</el-table-column>
								<el-table-column label="炸废">
									<template #default="scope">
										<span v-if="scope.row.炸废">{{scope.row.炸废.含}}</span>
										<span v-else>0</span>
									</template>
								</el-table-column>
								<el-table-column label="S畸变">
									<template #default="scope">
										<span v-if="scope.row.S畸变">{{scope.row.S畸变.含}}</span>
										<span v-else>0</span>
									</template>
								</el-table-column>
								<el-table-column label="弓形畸变">
									<template #default="scope">
										<span v-if="scope.row.弓形畸变">{{scope.row.弓形畸变.含}}</span>
										<span v-else>0</span>
									</template>
								</el-table-column>
							</scTable>
						</el-main>
					</el-container>
				</el-tab-pane>
				<el-tab-pane name="muju" label="模具号统计" style="height: 100%;">
					<el-container v-if="activeName=='muju'">
						<el-main>
							<scTable
							   v-if="showTable"
								ref="table4"
								:data="tableData"
								row-key="id"
								hidePagination
								hideDo
								stripe
							>
								<el-table-column type="index" width="50"  fixed="left"/>
								<el-table-column label="模具号" prop="模具号">
									<template #default="scope">
										<span>{{scope.row.模具号}}</span>
										<span v-if="scope.row.横压!==null">{{scope.row.横压}}</span>
									</template>
								</el-table-column>
								<el-table-column label="总数" prop="总切片数">
								</el-table-column>
								<el-table-column label="黑网重">
									<template #default="scope">
										<span v-if="scope.row.黑网重">{{scope.row.黑网重.含}}</span>
										<span v-else>0</span>
									</template>
								</el-table-column>
								<el-table-column label="白网重">
									<template #default="scope">
										<span v-if="scope.row.白网重">{{scope.row.白网重.含}}</span>
										<span v-else>0</span>
									</template>
								</el-table-column>
								<el-table-column label="小网重">
									<template #default="scope">
										<span v-if="scope.row.小网重">{{scope.row.小网重.含}}</span>
										<span v-else>0</span>
									</template>
								</el-table-column>
								<el-table-column label="分辨率">
									<template #default="scope">
										<span v-if="scope.row.分辨率">{{scope.row.分辨率.含}}</span>
										<span v-else>0</span>
									</template>
								</el-table-column>
								<el-table-column label="炸纹">
									<template #default="scope">
										<span v-if="scope.row.炸纹">{{scope.row.炸纹.含}}</span>
										<span v-else>0</span>
									</template>
								</el-table-column>
								<el-table-column label="炸废">
									<template #default="scope">
										<span v-if="scope.row.炸废">{{scope.row.炸废.含}}</span>
										<span v-else>0</span>
									</template>
								</el-table-column>
								<el-table-column label="S畸变">
									<template #default="scope">
										<span v-if="scope.row.S畸变">{{scope.row.S畸变.含}}</span>
										<span v-else>0</span>
									</template>
								</el-table-column>
								<el-table-column label="弓形畸变">
									<template #default="scope">
										<span v-if="scope.row.弓形畸变">{{scope.row.弓形畸变.含}}</span>
										<span v-else>0</span>
									</template>
								</el-table-column>
							</scTable>
						</el-main>
					</el-container>
				</el-tab-pane>
				<el-tab-pane name="gongxu" label="工序统计" style="height: 100%;">
					<el-container v-if="activeName=='gongxu'">
						<el-main>
							<scTable
							   v-if="showTable"
								ref="table5"
								:data="tableData"
								row-key="id"
								hidePagination
								hideDo
								stripe
							>
								<el-table-column type="index" width="50"  fixed="left"/>
								<el-table-column label="操作人" prop="员工">
								</el-table-column>
								<el-table-column label="总数" prop="总切片数">
								</el-table-column>
								<el-table-column label="黑网重">
									<template #default="scope">
										<span v-if="scope.row.黑网重">{{scope.row.黑网重.含}}</span>
										<span v-else>0</span>
									</template>
								</el-table-column>
								<el-table-column label="白网重">
									<template #default="scope">
										<span v-if="scope.row.白网重">{{scope.row.白网重.含}}</span>
										<span v-else>0</span>
									</template>
								</el-table-column>
								<el-table-column label="小网重">
									<template #default="scope">
										<span v-if="scope.row.小网重">{{scope.row.小网重.含}}</span>
										<span v-else>0</span>
									</template>
								</el-table-column>
								<el-table-column label="分辨率">
									<template #default="scope">
										<span v-if="scope.row.分辨率">{{scope.row.分辨率.含}}</span>
										<span v-else>0</span>
									</template>
								</el-table-column>
								<el-table-column label="炸纹">
									<template #default="scope">
										<span v-if="scope.row.炸纹">{{scope.row.炸纹.含}}</span>
										<span v-else>0</span>
									</template>
								</el-table-column>
								<el-table-column label="炸废">
									<template #default="scope">
										<span v-if="scope.row.炸废">{{scope.row.炸废.含}}</span>
										<span v-else>0</span>
									</template>
								</el-table-column>
								<el-table-column label="S畸变">
									<template #default="scope">
										<span v-if="scope.row.S畸变">{{scope.row.S畸变.含}}</span>
										<span v-else>0</span>
									</template>
								</el-table-column>
								<el-table-column label="弓形畸变">
									<template #default="scope">
										<span v-if="scope.row.弓形畸变">{{scope.row.弓形畸变.含}}</span>
										<span v-else>0</span>
									</template>
								</el-table-column>
							</scTable>
						</el-main>
					</el-container>
				</el-tab-pane>
				<el-tab-pane name="total" label="总统计" style="height: 100%;">
					<el-container v-if="activeName=='total'">
						<el-main>
							<scTable
							   v-if="showTable"
								ref="table4"
								:data="tableData"
								row-key="id"
								hidePagination
								hideDo
								stripe
							>
								<el-table-column type="index" width="50"  fixed="left"/>
								<el-table-column label="总数" prop="总切片数">
								</el-table-column>
								<el-table-column label="黑网重">
									<template #default="scope">
										<span v-if="scope.row.黑网重">{{scope.row.黑网重.含}}</span>
										<span v-else>0</span>
									</template>
								</el-table-column>
								<el-table-column label="白网重">
									<template #default="scope">
										<span v-if="scope.row.白网重">{{scope.row.白网重.含}}</span>
										<span v-else>0</span>
									</template>
								</el-table-column>
								<el-table-column label="小网重">
									<template #default="scope">
										<span v-if="scope.row.小网重">{{scope.row.小网重.含}}</span>
										<span v-else>0</span>
									</template>
								</el-table-column>
								<el-table-column label="分辨率">
									<template #default="scope">
										<span v-if="scope.row.分辨率">{{scope.row.分辨率.含}}</span>
										<span v-else>0</span>
									</template>
								</el-table-column>
								<el-table-column label="炸纹">
									<template #default="scope">
										<span v-if="scope.row.炸纹">{{scope.row.炸纹.含}}</span>
										<span v-else>0</span>
									</template>
								</el-table-column>
								<el-table-column label="炸废">
									<template #default="scope">
										<span v-if="scope.row.炸废">{{scope.row.炸废.含}}</span>
										<span v-else>0</span>
									</template>
								</el-table-column>
								<el-table-column label="S畸变">
									<template #default="scope">
										<span v-if="scope.row.S畸变">{{scope.row.S畸变.含}}</span>
										<span v-else>0</span>
									</template>
								</el-table-column>
								<el-table-column label="弓形畸变">
									<template #default="scope">
										<span v-if="scope.row.弓形畸变">{{scope.row.弓形畸变.含}}</span>
										<span v-else>0</span>
									</template>
								</el-table-column>
							</scTable>
						</el-main>
					</el-container>
				</el-tab-pane>
			</el-tabs>
		</el-main>
		<el-drawer v-model="visible" :title="userName+'板段列表'" size="50%" direction="rtl" append-to-body destroy-on-close>
			<el-card shadow="never">
				<div v-for="(item,index) in detailRow" :key="item" style="height:22px;border-bottom: 1px solid #efefef;">
					<span style="margin-right:10px;width: 18px;display: inline-block;">{{ index+1 }} </span>
					{{ item }}
				</div>
			</el-card>
		</el-drawer>
	</el-container>
</template>
<script>
export default {
	name: "workHoursRY",
	data() {
		return {
			visible:false,
			showTable:false,
			userName:'',
			activeName: 'luhao',
			query1:{
				number_contains:'',
				time_gte:'',
				time_lte:'',
			},
			query2:{
				process_name:'压板出炉',
			},
			query:{
				end_date:'',
				start_date:'',
  				select_cols: ""
			},
			end_date:'',
			start_date:'',
			mgruops:[],
			tableData:[],
			detailRow:[],
			processList:['装模','装炉','压板出炉','脱膜测量'],
		};
	},
    mounted() {
        let that = this;
        let date = new Date();
        that.end_date = that.query.end_date = that.$TOOL.dateFormat2(date);
		that.start_date = that.query.start_date =  that.query.end_date.split('-')[0] + '-' + that.query.end_date.split('-')[1] + '-01';
		that.getData();
	},
	methods: {
        getData(){
            let that = this;
            let params = {},query ={testmgroup_name:'扭转'},biStr = '';
			if(that.query.start_date==''||that.query.start_date==null){
				that.query.start_date = query.start_date = that.start_date;
			}else{
				query.start_date = that.query.start_date;
			}
			if(that.query.end_date==''||that.query.end_date==null){
				that.query.end_date = query.end_date = that.end_date;
			}else{
				query.end_date = that.query.end_date;
			}
			if(that.activeName=='luhao'){
				query.select_cols = that.query.select_cols;
				params.query = query;
				biStr = 'product_defect_equip_mpjc';
			}else if(that.activeName=='muju'){
				query.select_cols = "";
				params.query = query;
				biStr = 'product_defect_model';
			}else if(that.activeName=='gongxu'){
				query.process_name = that.query2.process_name;
				params.query = query;
				biStr = 'product_defect_reya';
			}else if(that.activeName=='total'){
				params.query = query;
				biStr = 'product_defect_sg';
			}
			console.log('params',params);
			that.$API.bi.dataset.exec.req(biStr, params).then((res) => {
				let data = res.data2.ds0;
				data.forEach(item=>{
					if(item.缺陷分布!==null){
						let defect = JSON.parse(item.缺陷分布);
						for(let key in defect){
							item[key]=defect[key];
						}
					}
				})
				console.log('data',data);
				that.$nextTick(() => {
					that.tableData = data;
					that.showTable=true;
                })
			});
        },
		handleQuery2(){
			let that = this;
            that.getData();
		},
		handleClick(e){
			let that = this;
			that.query.end_date = that.end_date;
			that.query.start_date =  that.start_date;
			this.activeName = e.props.name;
			this.showTable=false;
			this.getData();
		},
		handleNumClick(row){
			let that = this;
			that.userName = row.设备编号;
			that.visible = true;
			that.detailRow = row.切片编号列表;
		},
	},
};
</script>
<style scoped>
</style>
