<template>
	<view class="factoryBox">
		<zxz-uni-data-select filterable v-model="warehouseCode" dataKey="label" placeholder="请选择库存地点" dataValue="value"
			:localdata="warehouseData" @change="onWarehouseChange" />
	</view>
</template>

<script>
	export default {
		model: {
			prop: "value",
			event: "update",
		},
		props: {
			value: {
				type: String,
				default: "",
			},
			options: {
				type: Array,
				default: () => ([])
			}
		},
		data() {
			return {
				warehouseData: [],
			};
		},
		computed: {
			warehouseCode: {
				get() {
					return this.value;
				},
				set(v) {
					this.$emit("update", v);
				},
			},
		},
		created() {
			this.getDepotLists();
		},
		methods: {
			onWarehouseChange(e) {
				this.$emit("change", e);
			},
			getDepotLists() {
				this.$u.api.sapApi
					.sapDict({
						FIELDNAME: "T001L",
					})
					.then((res) => {
						if (res) {
							// 过滤当前工厂下的库存地点
							this.warehouseData = res
								.filter((ele) => ele.WERKS == this.vuex_user_factory)
								.map((item) => {
									item.label = item.LGORT + "-" + item.LGOBE;
									item.value = item.LGORT;
									return item;
								})
								this.warehouseData.unshift(...this.options)
						} else {
							this.warehouseData = [];
						}
					});
			},
		},
	};
</script>

<style lang="scss">
	.factoryBox {
		padding: 10rpx 20rpx 0;

		.item-select {
			margin-bottom: 20rpx;
		}
	}
</style>
