import request from '@/utils/request'

/** 接口 */
const Api = {
	skuList: '/api/wms/sku/list',
	lineCodeList: '/api/sys/dict/data/list',
    skuTypeList: '/api/wms/skuCategory/list',
	inventoryList: '/api/wms/pda/inventoryList',
	getSkuByCode: '/api/wms/pda/getSkuByCode',
}

//获取获取单个物料 
export async function getSkuByCode(skuCode ){	
	return await request({
		url: Api.getSkuByCode + '/' + skuCode,
		method: 'GET'
	})
}

//获取库存列表 
export async function getInventoryList(dictType ){	
	var dictionary =[];
	let responseData = await request({
		url: Api.inventoryList,
		data:dictType,
		method: 'get'
	}).then(response => {
		dictionary = response.data;
		dictionary.map((item) => {
			item.text = item.skuCode+item.skuName
			item.value = item.skuCode
		});
	}).catch((e)=>{
		console.log("获取库存列表数据时出现异常",e)
	});
	return dictionary
}

//获取物料信息 适配于 uni-select 下拉值数据中需要text字段的渲染
export async function getSkuDictionary(dictType ){	
	var dictionary =[];
	let responseData = await request({
		url: Api.skuList,
		data:dictType,
		method: 'get'
	}).then(response => {
		dictionary = response.data;
		dictionary.map((item) => {
			item.text = item.skuCode+item.skuName
			item.value = item.skuCode
		});
	}).catch((e)=>{
		console.log("获取物料下拉值数据时出现异常",e)
	});
	return dictionary
}
export async function getSkuTypes(){	
	var dictionary =[];
	let responseData = await request({
		url: Api.skuTypeList,
		method: 'get'
	}).then(response => {
		dictionary = response.data;
		dictionary.map((item) => {
			item.text = item.categoryName
			item.value = item.categoryCode
		});
	}).catch((e)=>{
		console.log("获取物料分类下拉值数据时出现异常",e)
	});
	return dictionary
}
export async function getLineCodes(){	
	var dictionary =[];
	let responseData = await request({
		url: Api.lineCodeList,
		data:{code:"lineCodes"},
		method: 'get'
	}).then(response => {
		dictionary = response.data;
		dictionary.map((item) => {
			item.text = item.label
			item.value = item.value
		});
	}).catch((e)=>{
		console.log("获取线体下拉值数据时出现异常",e)
	});
	return dictionary
}