<template>
	<el-container>
		<el-header>
			<div class="left-panel">
				<el-button type="primary" @click="tomio" v-auth="'mio.do'"
					>领料</el-button
				>
				<el-button type="primary" @click="tomio" v-auth="'mio.do'"
					>入库</el-button
				>
			</div>
			<div class="right-panel">
				<!-- <el-button type="primary" @click="materialsChoses('wm')"
					>选择物料</el-button
				> -->
				<el-input
					style="margin-right: 5px"
					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"
				hidePagination
				:params="params"
			>
				<el-table-column
					label="#"
					type="index"
					width="50"
				></el-table-column>
				<el-table-column
					label="物料名称"
					prop="material_name"
					min-width="120"
				></el-table-column>
				<el-table-column
					label="批次号"
					prop="batch"
					min-width="120"
				></el-table-column>
				<el-table-column
					label="所属部门"
					prop="belong_dept_name"
				></el-table-column>
				<el-table-column
					label="数量"
					prop="count"
					min-width="80"
				></el-table-column>
				<el-table-column
					label="不合格标记"
					prop="notok_sign_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="180"
				>
					<template #default="scope">
						<el-button
							link
							size="small"
							@click="table_edit(scope.row)"
							v-auth="'mgroup.update'"
							type="primary"
							>编辑</el-button
						>
						<el-divider direction="vertical"></el-divider>
						<el-popconfirm
							title="确定删除吗？"
							@confirm="table_del(scope.row, scope.$index)"
						>
							<template #reference>
								<el-button
									link
									size="small"
									v-auth="'mgroup.delete'"
									type="danger"
									>删除</el-button
								>
							</template>
						</el-popconfirm>
					</template>
				</el-table-column> -->
			</scTable>
		</el-main>
		<el-dialog title="选择物料" v-model="materialsVisible" width="90%">
			<materials
				style="height: 500px"
				:materialType="materialType"
				ref="materialsChose"
				@choseChange="choseChange"
			></materials>
		</el-dialog>
	</el-container>
</template>
<script>
import materials from "./../mtm/materials.vue";
export default {
	props: {
		mgroupName: {
			type: String,
			default: "",
		},
	},
	components: {
		materials,
	},
	name: "wmaterial",
	data() {
		return {
			apiObj: null,
			params: {
				mgroupx: "",
			},
			query: {},
			dialog: {
				save: false,
				permission: false,
			},
			tableData: [],
			selection: [],
			queryWm: {
				search: "",
				material: "",
			},
			materialType: "wm",
			visibleDrawer: false,
		};
	},
	mounted() {
		let that = this;
		that.$API.mtm.mgroup.list
			.req({ page: 0, search: that.mgroupName })
			.then((res) => {
				if (res.length != 1) {
					that.$message.error("获取工段错误");
					return;
				}
				that.mgroupId = res[0].id;
				that.params.mgroupx = res[0].id;
				that.apiObj = that.$API.wpm.wmaterial.list;
			});
	},
	methods: {
		materialsChoses(str) {
			this.materialType = str;
			this.materialsVisible = true;
		},
		choseChange(data) {
			this.queryWm.material = data;
			this.$refs.table_wm.queryData(this.queryWm);
			this.materialsVisible = false;
		},
		tomio() {
			this.$router.push({ name: "halfgood_mio" });
		},
		//表格选择后回调事件
		selectionChange(selection) {
			this.selection = selection;
		},
		//搜索
		handleQuery() {
			this.$refs.table.queryData(this.query);
		},
		//本地更新数据
		handleSaveSuccess(data, mode) {
			this.dialog.save = true;
			this.$refs.table.refresh();
		},
	},
};
</script>
<style scoped></style>
