<template>
	<el-container>
		<el-header>
			<div class="left-panel">
				<el-button type="primary" v-auth="'handover.create'" @click="table_add(20)">
					返工交接</el-button>
			</div>
			<div class="right-panel">
				<el-input
					style="margin-right: 5px;width: 250px"
					v-model="query.search"
					placeholder="名称"
					clearable
				></el-input>
				<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"
				:query="query"
			>
			<el-table-column label="状态" prop="state" width="100" >
				<template #default="scope">
					<el-tag :type="wmState[scope.row.state]?.type">
						{{wmState[scope.row.state]?.text}}
						</el-tag>
					</template>
				</el-table-column>
				<el-table-column
					label="物料名称"
					prop="material_name"
					min-width="150"
				>
					<template #default="scope">
						{{ scope.row.material_name }}
						<span v-if="scope.row.material_origin != null"
							>（{{ scope.row.material_origin_name }}）</span
						>
					</template>
				</el-table-column>
				<el-table-column
					label="批次号"
					prop="batch"
					min-width="120"
				></el-table-column>
				<el-table-column
					label="部门/工段"
					prop="belong_dept_name"
				>
				<template #default="scope">
					{{scope.row.belong_dept_name}}/{{scope.row.mgroup_name}}
				</template>
				</el-table-column>
				<el-table-column
					label="数量"
					prop="count"
					min-width="80"
				></el-table-column>
				<el-table-column
					label="不合格标记"
					prop="defect_name"
				></el-table-column>
				<el-table-column
					label="创建时间"
					prop="create_time"
					width="150"
				></el-table-column>
				<!-- <el-table-column
					label="操作"
					fixed="right"
					align="center"
					width="70"
				>
					<template #default="scope">
						<el-link type="primary" v-auth="'handover.create'" @click="table_add(20,scope.row)">交接</el-link>
					</template>	
				</el-table-column> -->
			</scTable>
		</el-main>
		<save-dialog
			v-if="dialog.save"
			ref="saveDialog"
			:type="type"
			:mgroupName="mgroupName"
			:mgroupId="mgroupId"
			@success="handleSaveSuccess"
			@closed="dialog.save = false"
		>
		</save-dialog>
	</el-container>
</template>
<script>
import saveDialog from "../wpm_gx/handover_form.vue";
import { wmState } from "@/utils/enum.js";
export default {
	components: {
		saveDialog
	},
	name: "wmaterial",
	data() {
		return {
			wmState,
			apiObj: this.$API.wpm.wmaterial.list,
			params: {
				state : 50,
				state_all: 1
			},
			dialog: {
				save: false,
			},
			query:{
				search:''
			},
			type:20,
			mgroupName:'废品库',
			mgroupId:'',
		};
	},
	mounted() {
		let that = this;
		that.$API.mtm.mgroup.list.req({ page: 0}).then((res) => {
			that.mgroupOptions = res;
			res.forEach(item=>{
				if(item.name=="废品库"){
					that.mgroupId = item.id;
				}
			})
		});
	},
	methods: {
		
		//添加
		table_add(type) {
			this.dialog.save = true;
			this.type = type;
			this.$nextTick(() => {
				this.$refs.saveDialog.open("add");
			});
		},
		//搜索
		handleQuery() {
			this.$refs.table.queryData(this.query);
		},
		
	},
};
</script>
<style scoped></style>
