import {
	listArea
} from "@/api/wms/area";
import {
	listShelves
} from "@/api/wms/shelves";
import {
	listLocation
} from "@/api/wms/location";
import {
	listWarehouse
} from "@/api/wms/warehouse";

const warehouse = {
	state: {
		areaOptions: [],
		shelvesOptions: [],
		locationOptions: [],
		warehouseOptions: [],
	},

	mutations: {
		SET_AreaOptions: (state, areaOptions) => {
			state.areaOptions = areaOptions
		},
		SET_ShelvesOptions: (state, shelvesOptions) => {
			state.shelvesOptions = shelvesOptions
		},
		SET_LocationOptions: (state, locationOptions) => {
			state.locationOptions = locationOptions
		},
		SET_WarehouseOptions: (state, warehouseOptions) => {
			state.warehouseOptions = warehouseOptions
		}
	},

	actions: {
		// 获取参数
		GetAreaOptions({
			commit
		}) {
			return new Promise((resolve, reject) => {
				listArea().then(res => {
					commit("SET_AreaOptions", res.rows)
				}).catch(error => {
					reject(error);
				})
			})
		},
		GetShelvesOptions({
			commit
		}) {
			return new Promise((resolve, reject) => {
				listShelves().then(res => {
					commit("SET_ShelvesOptions", res.rows)
				}).catch(error => {
					reject(error);
				})
			})
		},
		GetLocationOptions({
			commit
		}) {
			return new Promise((resolve, reject) => {
				listLocation().then(res => {
					commit("SET_LocationOptions", res.rows)
				}).catch(error => {
					reject(error);
				})
			})
		},
		GetWarehouseOptions({
			commit
		}) {
			return new Promise((resolve, reject) => {
				listWarehouse().then(res => {
					commit("SET_WarehouseOptions", res.rows)
				}).catch(error => {
					reject(error);
				})
			})
		},
	}
}

export default warehouse