<template>
	<el-container>
		<el-header>
			<div class="left-panel">
				<el-select
					v-model="query.type"
					clearable
					style="width: 120px; margin-left: 2px"
					placeholder="出入库类型"
					@change="handleQuery"
				>
					<el-option
						v-for="item in cateOptions"
						:key="item.id"
						:label="item.name"
						:value="item.id"
					></el-option>
				</el-select>
				<el-select
					v-model="query.state"
					clearable
					style="width: 120px; margin-left: 2px"
					placeholder="状态"
					@change="handleQuery"
				>
					<el-option
						v-for="item in stateOptions"
						:key="item.id"
						:label="item.name"
						:value="item.id"
					></el-option>
				</el-select>
			</div>
			<div class="right-panel">
				<el-input
					v-model="query.search"
					placeholder="编号"
					clearable
					style="margin-right: 5px"
				></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" stripe>
				<el-table-column type="index" width="50" />
				<el-table-column
					label="记录编号"
					prop="number"
				></el-table-column>
				<el-table-column label="出/入库类型">
					<template #default="scope">
						{{ typeDict[scope.row.type] }}
					</template>
				</el-table-column>
				<el-table-column label="记录状态">
					<template #default="scope">
						{{ stateDict[scope.row.state] }}
					</template>
				</el-table-column>
				<el-table-column label="出/入库日期" prop="inout_date">
				</el-table-column>

				<el-table-column label="创建人" prop="create_by_name">
				</el-table-column>
				<el-table-column label="创建时间" prop="create_time">
				</el-table-column>
				<el-table-column
					label="操作"
					fixed="right"
					align="center"
					width="150px"
				>
					<template #default="scope">
						<el-button
							link
							type="primary"
							@click="table_detail(scope.row)"
						>
							查看
						</el-button>
					</template>
				</el-table-column>
			</scTable>
		</el-main>
	</el-container>
	<record-dialog
		ref="showDrawer"
		v-if="visibleDrawer"
		:type="type"
		:cate="cate"
		:mioId="mioId"
		@closed="visibleDrawer = false"
	>
	</record-dialog>
</template>
<script>
import recordDialog from "./mioitem.vue";

export default {
	name: "mio",
	components: {
		recordDialog,
	},
	data() {
		return {
			stateDict: {
				10: "创建中",
				20: "已提交",
			},
			stateOptions: [
				{ id: 10, name: "创建中" },
				{ id: 20, name: "已提交" },
			],
			typeDict: {
				do_out: "生产领料",
				sale_out: "销售发货",
				pur_in: "采购入库",
				do_in: "生产入库",
			},
			cateOptions: [
				{ id: "do_out", name: "生产领料" },
				{ id: "sale_out", name: "销售发货" },
				{ id: "pur_in", name: "采购入库" },
				{ id: "do_in", name: "生产入库" },
			],
			dialog: {
				record: false,
			},
			visibleDrawer: false,
			query: {
				search: "",
			},
			form: {},
			apiObj: this.$API.inm.mio.list,
			selection: [],
			type: "",
			mioId: "",
		};
	},
	methods: {
		//查看
		table_detail(row) {
			this.type = row.type;
			this.mioId = row.id;
			this.visibleDrawer = true;
			this.$nextTick(() => {
				this.$refs.showDrawer.open('show');
			});
		},
		handleQuery() {
			this.$refs.table.queryData(this.query);
		},
		resetQuery() {
			this.query = {};
		},
	},
};
</script>
