import model from "../tools/model.js"
import tools from '@/tools/tools.js'
import config from '@/config.js'
// Action 包含异步操作（请求API方法）、回调函数提交mutaions更改state数据状态，使之可以异步
export default {
	//配置接口
	getHomeConfig({
		commit,
		dispatch
	}) {
		return model.getHomeConfig({
			time: tools.getDate("start")
		}).then(res => {
			console.log("配置接口", res.data)
			commit('changeConfig', res.data)
			return res.data
		})
	},
	// 用户信息
	getUserInfo({
		commit,
		dispatch
	}) {
		return model.getHomeUserInfo({}).then(res => {
			if (res.code != 0) {
				tools.msg(res.msg)
				return
			}
			if (res.data.weight == 0 || res.data.weight == null || res.data.weight == "") {
				commit('changeUserInfo', {
					isEditInfo: true,
					aud_id: ""
				})
			} else {
				commit('changeUserInfo', res.data)
			}
			dispatch("getCountFoodInfo", {
				aud_id: res.data.aud_id,
				time: tools.getDate("start")
			})
			return res.data
		});
	},
	// 计食器信息
	getCountFoodInfo({
		commit
	}, account) {
		return model.getCountFoodInfo(account).then(res => {
			if (res.code == 0) {
				commit('changeCountFoodInfo', res.data)
			}
			return res.data
		});
	},
}