<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-button
					type="primary"
					icon="el-icon-search"
					@click="handleQuery"
				></el-button>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable
				ref="table"
				:data="tableData"
				id="exportDiv"
				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.总切片数" @click="handleClick(scope.row)" style="color:#0052d9;">{{ scope.row.总切片数 }}</span>
						<span v-else @click="handleClick(scope.row)" style="color:#0052d9;">{{ 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.暗点不合格.含/scope.row.总切片数)*100).toFixed(2) }}%</span>
						<span v-else>0%</span>
					</template>
				</el-table-column>
				<el-table-column label="放大率不合格">
					<template #default="scope">
						<span v-if="scope.row['放大率￠16mm不合格']">{{scope.row['放大率￠16mm不合格'].含}}</span>
						<span v-else>0</span>
					</template>
				</el-table-column>
				<el-table-column label="放大率不合格占比">
					<template #default="scope">
						<span v-if="scope.row['放大率￠16mm不合格']">{{((scope.row['放大率￠16mm不合格'].含/scope.row.总切片数)*100).toFixed(2) }}%</span>
						<span v-else>0%</span>
					</template>
				</el-table-column>
			</scTable>
			<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-main>
	</el-container>
</template>

<script>
export default {
	name: "workerTimes",
	data() {
		return {
			visible:false,
			userName:'',
			query:{
				end_date:'',
				start_date:'',
  				// select_cols: ",ls.板段编号列表,ls.切片编号列表"
			},
			tableData:[],
			detailRow:[],
			nameFilters:[],
		};
	},
    mounted() {
        let that = this;
        let date = new Date();
        that.query.end_date = that.$TOOL.dateFormat2(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 = {};
            params.query = that.query;
			that.$API.bi.dataset.exec.req('product_defect_equip_bdgy', 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(() => {
					that.tableData = data;
                })
			});
        },
		deptChange(){
			this.getData();
		},
		filterName(value, row) {
			return row.物料名 == value;
		},
		handleClick(row){
			let that = this;
			that.userName = row.员工;
			that.visible = true;
			that.detailRow = row.切片编号列表;
		},
		handleQuery(){
			let that = this;
			console.log('that.query',that.query)
			that.getData();
		},
	},
};
</script>

<style scoped>
</style>
