<template>
	<el-container>
		<el-header>
			<div class="left-panel">
				<el-button type="primary" v-loading="exportLoading" icon="el-icon-download" @click="exportExcel">导出</el-button>
			</div>
			<div class="right-panel">
				<el-select
					v-model="query.mgroup"
					clearable
					style="width: 150px"
				>
					<el-option
						v-for="item in mgroupOption"
						:key="item.id"
						:label="item.name"
						:value="item.id"
					>
					</el-option>
				</el-select>
				<el-date-picker
					v-model="query.handle_date"
					type="date"
					placeholder="选择日期"
					value-format="YYYY-MM-DD"
					style="width: 150px"
				/>
				<el-input
					v-model="query.search"
					placeholder="批次号"
					clearable
					style="width: 150px"
				></el-input>
				<el-button type="primary" @click="materialsChoses()"
					>选择物料</el-button
				>
				<el-button
					type="primary"
					icon="el-icon-search"
					@click="handleQuery"
					>查询</el-button
				>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable
				ref="table"
				:apiObj="apiObj"
				row-key="id"
				:params = "params"
				stripe
				id="myTable"
				:query="query"
			>
				<!-- <el-table-column type="index" width="50" /> -->
				<el-table-column
					label="物料"
					prop="material_name"
					show-overflow-tooltip
					min-width="120"
				>
				</el-table-column>
				<el-table-column label="检验数" prop="count">
				</el-table-column>
				<el-table-column label="抽检数" prop="count_sampling">
				</el-table-column>
				<el-table-column label="合格数" prop="count_ok">
				</el-table-column>
				<el-table-column label="不合格数" prop="count_notok">
				</el-table-column>
				<el-table-column label="不合格原因及数量" align="center">
					<el-table-column label="厚度" prop="count_n_hd">
						<template #default="scope">{{scope.row.count_notok_json.count_n_hd}}</template>
					</el-table-column>
					<el-table-column label="气泡" prop="count_n_qp">
						<template #default="scope">{{scope.row.count_notok_json.count_n_qp}}</template>
					</el-table-column>
					<el-table-column label="水纹" prop="count_n_swen">
						<template #default="scope">{{scope.row.count_notok_json.count_n_swen}}</template>
					</el-table-column>
					<el-table-column label="崩边" prop="count_n_bb">
						<template #default="scope">{{scope.row.count_notok_json.count_n_bb}}</template>
					</el-table-column>
					<el-table-column label="划伤" prop="count_n_hs">
						<template #default="scope">{{scope.row.count_notok_json.count_n_hs}}</template>
					</el-table-column>
					<el-table-column label="麻点" prop="count_n_md">
						<template #default="scope">{{scope.row.count_notok_json.count_n_md}}</template>
					</el-table-column>
					<el-table-column label="线痕" prop="count_n_xh">
						<template #default="scope">{{scope.row.count_notok_json.count_n_xh}}</template>
					</el-table-column>
					<el-table-column label="产品外径" prop="count_n_wj">
						<template #default="scope">{{scope.row.count_notok_json.count_n_wj}}</template>
					</el-table-column>
					<el-table-column label="产品圆度" prop="count_n_yd">
						<template #default="scope">{{scope.row.count_notok_json.count_n_yd}}</template>
					</el-table-column>
					<el-table-column label="产品同心度" width="90">
						<template #default="scope">{{scope.row.count_notok_json.count_n_txd}}</template>
					</el-table-column>
				</el-table-column>
				<el-table-column label="抽检时间" prop="submit_time" width="150">
				</el-table-column>
				<el-table-column label="操作" width="60" fixed="right">
					<template #default="scope">
						<el-button
							type="text"
							size="small"
							 @click="handlePrint(scope.row)"
							>打印</el-button
						>
					</template>
				</el-table-column>
			</scTable>
		</el-main>
		<el-dialog title="选择物料" v-model="materialsVisible" width="90%">
			<materials
				style="height: 500px"
				ref="materialsChose"
				@choseChange="choseChange"
			></materials>
		</el-dialog>
		<el-dialog v-model="printVisible" width="1200px">
			<print :baseData="rowItem" type="ptest_cj" @closePrint="printVisible=false"/>
		</el-dialog>
	</el-container>
</template>
<script>
import print from "./../setting/print/A4.vue";
import materials from "./../mtm/materials.vue";
export default {
	components: {
		materials,print
	},
	name: "rparty",
	data() {
		return {
			params:{
				type2:10
			},
			apiObj: this.$API.qm.ftestwork.list,
			query: {
				search: "",
				material: "",
				mgroup: "",
				handle_date: "",
			},
			selection: [],
			state_: {
				10: "",
				20: "",
			},
			rowItem:{},
			mgroupOption: [],
			printVisible:false,
			exportLoading:false,
			materialsVisible: false,
		};
	},
	mounted() {
		this.getMgroup();
	},
	methods: {
		materialsChoses() {
			this.materialsVisible = true;
		},
		choseChange(data) {
			this.query.material = data;
			this.$refs.table.queryData(this.query);
			this.materialsVisible = false;
		},
		getMgroup() {
			this.$API.mtm.mgroup.list.req({ page: 0 }).then((res) => {
				this.mgroupOption = res;
			});
		},
		handleQuery() {
			this.$refs.table.queryData(this.query);
		},
		resetQuery() {
			this.query = {};
		},
		//打印
		handlePrint(row){
			this.rowItem = row;
			this.printVisible = true;
		},
		exportExcel() {
            this.exportLoading = true;
            this.$XLSX('#myTable',"过程抽检表")
            this.exportLoading = false;
        },
	},
};
</script>
