import { getaddress, getordermessage, postorder } from "@/api/login"

const state = {
	addressmessage: [],
	ordermessage: {}
}

const mutations = {
	GETADDRESS(state, addressmessage) {
		state.addressmessage = addressmessage
	},
	GETORDER(state, ordermessage) {
		state.ordermessage = ordermessage
	}
}

const actions = {
	// 获取当用户地址信息 根据token
	async getaddress({ commit }) {
		let result = await getaddress()
		// 获取信息成功
		if (result.code == 200) {
			console.log(result);
			commit("GETADDRESS", result.data)
			return '获取信息成功'
		} else {
			return Promise.reject(new Error("获取信息失败"))
		}
	},
	// 根据token获取订单交易页信息
	async getordermessage({ commit }) {
		let result = await getordermessage()
		if (result.code == 200) {
			commit("GETORDER", result.data)
			return "获取订单交易信息成功"
		} else {
			return Promise.reject(new Error("获取订单交易信息失败"))
		}
	}
}

const getters = {
	// 简化接口数据
	detailArrayList(state) {
		return state.ordermessage.detailArrayList || []
	}
}


export default {
	state,
	mutations,
	actions,
	getters
}