<template>
	<el-drawer
		v-model="visible"
		title="检验记录"
		:size="'90%'"
		destroy-on-close
		@closed="$emit('closed')"
	>
		<el-container>
			<el-main>
				<scTable
					ref="drawer_table"
					:apiObj="apiObj"
					row-key="id"
					stripe
					:params="paramsObj"
				>
					<el-table-column type="expand">
						<template #default="props">
							<el-descriptions title="不合格列表" :column="5" border>
								<el-descriptions-item label="划伤" width="150px">
									{{props.row.count_notok_json.count_n_hs}}
								</el-descriptions-item>
								<el-descriptions-item label="挫伤" width="150px">
									{{props.row.count_notok_json.count_n_hs}}
								</el-descriptions-item>
								<el-descriptions-item label="杂质" width="150px">
									{{props.row.count_notok_json.count_n_zz}}
								</el-descriptions-item>
								<el-descriptions-item label="条纹" width="150px">
									{{props.row.count_notok_json.count_n_tw}}
								</el-descriptions-item>
								<el-descriptions-item label="锥度大" width="150px">
									{{props.row.count_notok_json.count_n_zdd}}
								</el-descriptions-item>
								<el-descriptions-item label="短" width="150px">
									{{props.row.count_notok_json.count_n_d}}
								</el-descriptions-item>
								<el-descriptions-item label="炸纹" width="150px">
									{{props.row.count_notok_json.count_n_zw}}
								</el-descriptions-item>
								<el-descriptions-item label="断裂" width="150px">
									{{props.row.count_notok_json.count_n_dl}}
								</el-descriptions-item>
								<el-descriptions-item label="气泡" width="150px">
									{{props.row.count_notok_json.count_n_qp}}
								</el-descriptions-item>
								<el-descriptions-item label="不亮" width="150px">
									{{props.row.count_notok_json.count_n_bl}}
								</el-descriptions-item>
								<el-descriptions-item label="横纹" width="150px">
									{{props.row.count_notok_json.count_n_hw}}
								</el-descriptions-item>
								<el-descriptions-item label="有皮" width="150px">
									{{props.row.count_notok_json.count_n_yp}}
								</el-descriptions-item>
								<el-descriptions-item label="爆皮" width="150px">
									{{props.row.count_notok_json.count_n_bp}}
								</el-descriptions-item>
								<el-descriptions-item label="色差" width="150px">
									{{props.row.count_notok_json.count_n_sc}}
								</el-descriptions-item>
								<el-descriptions-item label="直径大" width="150px">
									{{props.row.count_notok_json.count_n_zjd}}
								</el-descriptions-item>
								<el-descriptions-item label="直径小" width="150px">
									{{props.row.count_notok_json.count_n_zjx}}
								</el-descriptions-item>
								<el-descriptions-item label="气线" width="150px">
									{{props.row.count_notok_json.count_n_qx}}
								</el-descriptions-item>
								<el-descriptions-item label="结石" width="150px">
									{{props.row.count_notok_json.count_n_js}}
								</el-descriptions-item>
								<el-descriptions-item label="椭圆度大" width="150px">
									{{props.row.count_notok_json.count_n_tydd}}
								</el-descriptions-item>
								<el-descriptions-item label="水雾" width="150px">
									{{props.row.count_notok_json.count_n_sw}}
								</el-descriptions-item>
								<el-descriptions-item label="壁厚偏差大" width="150px">
									{{props.row.count_notok_json.count_n_bhpcd}}
								</el-descriptions-item>
								<el-descriptions-item label="弯" width="150px">
									{{props.row.count_notok_json.count_n_wq}}
								</el-descriptions-item>
							</el-descriptions>
						</template>
					</el-table-column>
					<!-- <el-table-column type="expand" v-if="deptName=='7车间'">
						<template #default="props">
							<el-descriptions title="不合格列表" :column="5" border>
								<el-descriptions-item label="炸纹" width="150px">
									{{props.row.count_notok_json.count_n_zw}}
								</el-descriptions-item>
								<el-descriptions-item label="炸头" width="150px">
									{{props.row.count_notok_json.count_n_zt}}
								</el-descriptions-item>
								<el-descriptions-item label="条纹" width="150px">
									{{props.row.count_notok_json.count_n_tw}}
								</el-descriptions-item>
								<el-descriptions-item label="气泡" width="150px">
									{{props.row.count_notok_json.count_n_qp}}
								</el-descriptions-item>
								<el-descriptions-item label="扁" width="150px">
									{{props.row.count_notok_json.count_n_b}}
								</el-descriptions-item>
								<el-descriptions-item label="其他" width="150px">
									{{props.row.count_notok_json.count_n_qt}}
								</el-descriptions-item>
							</el-descriptions>
						</template>
					</el-table-column> -->
					<!-- <el-table-column type="expand" v-if="deptName=='10车间'">
						<template #default="props">
							<el-descriptions title="不合格列表" :column="5" border>
								<el-descriptions-item label="椭圆/弯曲" width="150px">
									{{props.row.count_notok_json.count_n_wq}}
								</el-descriptions-item>
								<el-descriptions-item label="条纹" width="150px">
									{{props.row.count_notok_json.count_n_tw}}
								</el-descriptions-item>
								<el-descriptions-item label="断裂" width="150px">
									{{props.row.count_notok_json.count_n_dl}}
								</el-descriptions-item>
								<el-descriptions-item label="偏壁" width="150px">
									{{props.row.count_notok_json.count_n_pb}}
								</el-descriptions-item>
								<el-descriptions-item label="大小头" width="150px">
									{{props.row.count_notok_json.count_n_dxt}}
								</el-descriptions-item>
								<el-descriptions-item label="结石" width="150px">
									{{props.row.count_notok_json.count_n_js}}
								</el-descriptions-item>
								<el-descriptions-item label="气线" width="150px">
									{{props.row.count_notok_json.count_n_qx}}
								</el-descriptions-item>
								<el-descriptions-item label="其他" width="150px">
									{{props.row.count_notok_json.count_n_qt}}
								</el-descriptions-item>
							</el-descriptions>
						</template>
					</el-table-column> -->
					<el-table-column label="检验类型">
						<template #default="scope">
							<el-tag v-if="scope.row.type2 == 10">
								{{ type2_[scope.row.type2] }}
							</el-tag>
							<el-tag v-else type="success">
								{{ type2_[scope.row.type2] }}
							</el-tag>
						</template>
					</el-table-column>
					<el-table-column label="物料批次" prop="batch">
					</el-table-column>
					<el-table-column label="总数" prop="count">
					</el-table-column>
					<el-table-column label="检验数">
						<template #default="scope">
							<span v-if="scope.row.type2 == 10">{{ scope.row.count_sampling }}</span>
							<span v-else>{{ scope.row.count }}</span>
						</template>
					</el-table-column>
					<el-table-column label="合格数">
						<template #default="scope">
							<span v-if="scope.row.type2 == 10">{{ scope.row.count_sampling_ok }}</span>
							<span v-else>{{ scope.row.count_ok }}</span>
						</template>
					</el-table-column>
					<el-table-column label="不合格数" prop="count_notok">
					</el-table-column>
					<el-table-column label="合格率">
						<template #default="scope">
							<span v-if="scope.row.type2 == 10">{{ (scope.row.count_sampling_ok/scope.row.count_sampling*100).toFixed(2) }}%</span>
							<span v-else>{{ (scope.row.count_ok/scope.row.count*100).toFixed(2) }}%</span>
						</template>
					</el-table-column>
					<el-table-column label="检验日期" prop="test_date">
					</el-table-column>
					<el-table-column label="检验人" prop="test_user_name">
					</el-table-column>
					<el-table-column label="操作" fixed="right" align="right" width="55">
						<template #default="scope">
							<el-link type="primary" v-if="scope.row.submit_time==null" @click.stop="testSubmit(scope.row)" v-auth="'ftestwork.submit'">提交</el-link>
							<el-link type="warning" v-else @click.stop="testRevoke(scope.row)">撤回</el-link>
						</template>
					</el-table-column>
				</scTable>
			</el-main>
		</el-container>
	</el-drawer>
</template>
<script>
export default {
	emits: ["closed"],
	props: {
		deptName: { type: String, default: "" },
		wm: { type: String, default: "" },
	},
	data() {
		return {
			visible: false,
			apiObj: null,
			paramsObj: {},
			form: {},
			type2_: {
				10: "抽检",
				20: "全检",
			},
			isSaveing: false,
		};
	},
	mounted() {},
	methods: {
		open() {
			this.visible = true;
			this.paramsObj.wm = this.wm;
			this.apiObj = this.$API.qm.ftestwork.list;
			return this;
		},
		table_del(row){
			this.$API.qm.ftestwork.delete.req(row.id).then((res) => {
				this.$refs.drawer_table.fetch();
			});
		},
		testSubmit(row) {
			let that = this;
		    that.$API.qm.ftestwork.submit.req(row.id).then((res) => {
				that.$message.success("操作成功");
				that.$refs.drawer_table.fetch();
			})	
		},
		testRevoke(row) {
		    let that = this;
		    that.$API.qm.ftestwork.revoke.req(row.id).then((res) => {
				that.$message.success("操作成功");
				that.$refs.drawer_table.fetch();
			})	
		}
	},
};
</script>
