import http from '@/request/index.js';
// 上架详情
export const state = {
	groundDetailsData: [], //上架详情数据
	groundTitleData: {
		idPendList: 0, // 当前单号待上架数量
		idAlreadyList: 0 // 当前单号已上架数量
	},
	detailsData: {} // 上架明细数据
};
export const mutations = {
	DetailsData(state, data) {
		state.groundDetailsData = data
	},
	setTitleData(state, data) {
		state.groundTitleData = data
	},
	setDetaisData(state, data) {
		console.log(data, '上架的明细');
		state.detailsData = data
	},
}
export const actions = {
	getDetails({
		commit,
		rootState
	}) {
		return new Promise((resolve, reject) => {
			http('groundDetails.getList', {
				stroomId: "1770106310000422914"
			}, '加载中').then(res => {
				if (res.code == "0" && res.success == "true") {
					commit('DetailsData', res.data);
					let pend = 0;
					let already = 0;
					if (res.data.length > 0) {
						res.data.forEach((item) => {

						})
					}
				} else {
					commit('DetailsData', []);
				}
			}).catch(e => {
				reject(e)
			})
		})
	},
	getdetilsCont({
		commit,
		rootState
	}, date) {
		return new Promise((resolve, reject) => {
			http('groundDetails.detailsCont', {
				id_instock: rootState.groundData.length > 0 && rootState.groundData[0].id_instock ||
					"rkd0000117",
				...date
			}, '加载中').then(res => {
				if (res.code == "0" && res.success == "true") {
					commit('setDetaisData', {
						[date['id_material']]: res.data
					});

				} else {
					commit('setDetaisData', {});
				}
			}).catch(e => {
				reject(e)
			})
		})
	}
}