<template>
	<el-container>
		<el-header>
			<div class="left-panel"></div>
			<div class="right-panel">
                <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-input v-model="query.material_name" 
					placeholder="产品名称" 
					clearable 
					style="width: 200px;"
				></el-input>
				<el-input v-model="query.batch" 
					placeholder="批次号" 
					clearable 
					style="width: 200px;"
				></el-input>
				<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="product" label="生产数据" style="height: 100%;">
					<el-container v-if="activeName=='product'">
						<el-main>
							<scTable
							   v-if="showTable"
								ref="table1"
								:data="tableData"
								row-key="id"
								hidePagination
								hideDo
								stripe
							>
								<el-table-column type="index" width="50"  fixed="left"/>
								<el-table-column label="员工" prop="员工" fixed="left">	
								</el-table-column>
								<el-table-column label="物料名" prop="物料名" fixed="left">	
								</el-table-column>
								<el-table-column label="总切片数" prop="总切片数" fixed="left">	
								</el-table-column>
								<el-table-column label="暗点" align="center">
									<template #default="scope">
										<span v-if="scope.row.暗点不合格">{{ scope.row.暗点不合格.含?scope.row.暗点不合格.含:'' }}</span>
									</template>
								</el-table-column>
								<el-table-column label="暗点重" align="center">
									<template #default="scope">
										<span v-if="scope.row.暗点重">{{ scope.row.暗点重.含?scope.row.暗点重.含:'' }}</span>
									</template>
								</el-table-column>
								<el-table-column label="黑网轻" align="center">
									<template #default="scope">
										<span v-if="scope.row.黑网轻">{{ scope.row.黑网轻.含?scope.row.黑网轻.含:'' }}</span>
									</template>
								</el-table-column>
								<el-table-column label="黑网重" align="center">
									<template #default="scope">
										<span v-if="scope.row.黑网重">{{ scope.row.黑网重.含?scope.row.黑网重.含:'' }}</span>
									</template>
								</el-table-column>
								<el-table-column label="黑网废" align="center">
									<template #default="scope">
										<span v-if="scope.row.黑网废">{{ scope.row.黑网废.含?scope.row.黑网废.含:'' }}</span>
									</template>
								</el-table-column>
								<el-table-column label="白网轻" align="center">
									<template #default="scope">
										<span v-if="scope.row.白网轻">{{ scope.row.白网轻.含?scope.row.白网轻.含:'' }}</span>
									</template>
								</el-table-column>
								<el-table-column label="白网重" align="center">
									<template #default="scope">
										<span v-if="scope.row.白网重">{{ scope.row.白网重.含?scope.row.白网重.含:'' }}</span>
									</template>
								</el-table-column>
								<el-table-column label="小网轻" align="center">
									<template #default="scope">
										<span v-if="scope.row.小网轻">{{ scope.row.小网轻.含?scope.row.小网轻.含:'' }}</span>
									</template>
								</el-table-column>
								<el-table-column label="小网重" align="center">
									<template #default="scope">
										<span v-if="scope.row.小网重">{{ scope.row.小网重.含?scope.row.小网重.含:'' }}</span>
									</template>
								</el-table-column>
								<el-table-column label="小网废" align="center">
									<template #default="scope">
										<span v-if="scope.row.小网废">{{ scope.row.小网废.含?scope.row.小网废.含:'' }}</span>
									</template>
								</el-table-column>
								<el-table-column label="分辨率" align="center">
									<template #default="scope">
										<span v-if="scope.row.分辨率">{{ scope.row.分辨率.含?scope.row.分辨率.含:'' }}</span>
									</template>
								</el-table-column>
								<el-table-column label="S畸变" align="center">
									<template #default="scope">
										<span v-if="scope.row.S畸变不合格">{{ scope.row.S畸变不合格.含?scope.row.S畸变不合格.含:'' }}</span>
									</template>
								</el-table-column>
								<el-table-column label="弓形畸变" align="center">
									<template #default="scope">
										<span v-if="scope.row.弓形畸变不合格">{{ scope.row.弓形畸变不合格.含?scope.row.弓形畸变不合格.含:'' }}</span>
									</template>
								</el-table-column>
							</scTable>
						</el-main>
					</el-container>
				</el-tab-pane>
				<el-tab-pane name="luhao" label="炉号统计" style="height: 100%;">
					<el-container v-if="activeName=='luhao'">
						<el-main>
							<scTable
							   v-if="showTable"
								ref="table2"
								: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>{{ scope.row.总生产数 }}</span>
									</template>
								</el-table-column>
								<el-table-column label="暗点" align="center">
									<template #default="scope">
										<span v-if="scope.row.暗点不合格">{{ scope.row.暗点不合格.含?scope.row.暗点不合格.含:'' }}</span>
									</template>
								</el-table-column>
								<el-table-column label="暗点重" align="center">
									<template #default="scope">
										<span v-if="scope.row.暗点重">{{ scope.row.暗点重.含?scope.row.暗点重.含:'' }}</span>
									</template>
								</el-table-column>
								<el-table-column label="黑网轻" align="center">
									<template #default="scope">
										<span v-if="scope.row.黑网轻">{{ scope.row.黑网轻.含?scope.row.黑网轻.含:'' }}</span>
									</template>
								</el-table-column>
								<el-table-column label="黑网重" align="center">
									<template #default="scope">
										<span v-if="scope.row.黑网重">{{ scope.row.黑网重.含?scope.row.黑网重.含:'' }}</span>
									</template>
								</el-table-column>
								<el-table-column label="黑网废" align="center">
									<template #default="scope">
										<span v-if="scope.row.黑网废">{{ scope.row.黑网废.含?scope.row.黑网废.含:'' }}</span>
									</template>
								</el-table-column>
								<el-table-column label="白网轻" align="center">
									<template #default="scope">
										<span v-if="scope.row.白网轻">{{ scope.row.白网轻.含?scope.row.白网轻.含:'' }}</span>
									</template>
								</el-table-column>
								<el-table-column label="白网重" align="center">
									<template #default="scope">
										<span v-if="scope.row.白网重">{{ scope.row.白网重.含?scope.row.白网重.含:'' }}</span>
									</template>
								</el-table-column>
								<el-table-column label="小网轻" align="center">
									<template #default="scope">
										<span v-if="scope.row.小网轻">{{ scope.row.小网轻.含?scope.row.小网轻.含:'' }}</span>
									</template>
								</el-table-column>
								<el-table-column label="小网废" align="center">
									<template #default="scope">
										<span v-if="scope.row.小网废">{{ scope.row.小网废.含?scope.row.小网废.含:'' }}</span>
									</template>
								</el-table-column>
								<el-table-column label="分辨率" align="center">
									<template #default="scope">
										<span v-if="scope.row.分辨率">{{ scope.row.分辨率.含?scope.row.分辨率.含:'' }}</span>
									</template>
								</el-table-column>
								<el-table-column label="S畸变" align="center">
									<template #default="scope">
										<span v-if="scope.row.S畸变不合格">{{ scope.row.S畸变不合格.含?scope.row.S畸变不合格.含:'' }}</span>
									</template>
								</el-table-column>
								<el-table-column label="弓形畸变" align="center">
									<template #default="scope">
										<span v-if="scope.row.弓形畸变不合格">{{ scope.row.弓形畸变不合格.含?scope.row.弓形畸变不合格.含:'' }}</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: 'product',
			query:{
				end_date:'',
				start_date:'',
  				select_cols: "",
				mgroup_name: "扭转",
				testmgroup_name: "扭后检测",
				material_name: "",
				batch: "",
			},
			end_date:'',
			start_date:'',
			mgruops:[],
			tableData:[],
			detailRow:[],
			params:{cate:'热压'},
		};
	},
    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 = {},biStr = '';
			let query =that.query;
			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.query.material_name==''||that.query.material_name==null){
				delete query.material_name;
			}else{
				query.material_name = that.query.material_name;
			}
			if(that.query.batch==''||that.query.batch==null){
				delete query.batch;
			}else{
				query.batch = that.query.batch;
			}
			params.query = query;
			if(that.activeName=='product'){
				biStr = 'product_defect_pb_m';
			}else{
				biStr = 'product_defect_equip_mlogbw';
			}
			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];
						}
					}
				})
				that.$nextTick(() => {
					console.log('data',data);
					that.tableData = data;
					that.showTable=true;
                })
			});
        },
		handleQuery2(){
			let that = this;
            that.getData();
		},
		filterName(value, row) {
			return row.物料名 == value;
		},
		handleClick(e){
			let that = this;
			that.query.end_date = that.end_date;
			that.query.start_date =  that.start_date;
			that.activeName = e.props.name;
			that.showTable=false;
			that.getData();
		},
		handleNumClick(row){
			let that = this;
			that.userName = row.设备编号;
			that.visible = true;
			that.detailRow = row.切片编号列表;
		},
	},
};
</script>
<style scoped>
</style>
