<template>
	<el-container>
		<el-header>
			<div class="left-panel">
				<el-select
					v-model="query.warehouse"
					clearable
					placeholder="所在仓库"
					@change="handleQuery"
					style="width: 150px"
				>
					<el-option
						v-for="item in warehouseOptions"
						: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
				:params="params"
			>
				<el-table-column type="index" width="50" />
				<el-table-column label="物料批次" prop="batch">
				</el-table-column>
				<el-table-column label="物料名称" prop="material_name">
				</el-table-column>
				<!-- <el-table-column label="规格型号">
					<template #default="scope">
						{{ scope.row.specification }} {{ scope.row.model }}
					</template>
				</el-table-column> -->
				<el-table-column label="仓库" prop="warehouse_name">
				</el-table-column>
				<el-table-column label="物料存量" prop="count">
				</el-table-column>
				<el-table-column label="有效期" prop="expiration_date">
				</el-table-column>
				<el-table-column label="更新时间" prop="update_time">
				</el-table-column>
				<el-table-column width="90">
					<template #default="scope">
						<el-button @click="printMaterial(scope.row)" type="text">物料标签</el-button>
					</template>
				</el-table-column>
			</scTable>
		</el-main>
		<print-dialog
			v-if="print_m"
			ref="printmaterial"
			:mId="wmId"
			:mtype="wmtype"
			:apiObj="apiObjPrint"
		></print-dialog>
	</el-container>
</template>
<script>
import printDialog from "./../template/printmaterial.vue";
export default {
	name: "materials",
	components: {
		printDialog
	},
	data() {
		return {
			apiObj: this.$API.inm.warehouse.batch,
			params: { count__gte: 1, material__type__in: "30" },
			selection: [],
			query: {},
			warehouseOptions: [],
			wmtype:0,
			print_m:false,
			materialsVisible:false,
			apiObjPrint:this.$API.cm.labelmat.fromMb,
			wmId:'',
		};
	},
	mounted() {
		this.getWarehouse();
	},
	methods: {
		getWarehouse() {
			this.$API.inm.warehouse.list.req({ page: 0 }).then((res) => {
				this.warehouseOptions = res;
			});
		},
		handleQuery() {
			this.$refs.table.queryData(this.query);
		},
		resetQuery() {
			this.query = {};
		},
		//打印物料标签
		printMaterial(row){
			let that = this;
			that.wmId = row.id;
			that.wmtype = row.material_.type;
			that.print_m = true;
			this.$nextTick(() => {
			    this.$refs.printmaterial.open();
			})
		},
	},
};
</script>
