| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- import { tianpanDashboard, tianpanMemberDetail, tianpanCompatibility, tianpanAnnualEnergy, tianpanDailyFortune, tianpanRelatedItems } from '@/utils/api.js'
- export default {
- namespaced: true,
- state: {
- dashboard: null,
- memberDetail: null,
- compatibility: null,
- annualEnergy: null,
- dailyFortune: null,
- relatedItems: null,
- loading: false,
- error: null,
- currentYear: new Date().getFullYear(),
- daysAhead: 7
- },
- mutations: {
- SET_DASHBOARD(state, v) { state.dashboard = v },
- SET_MEMBER_DETAIL(state, v) { state.memberDetail = v },
- SET_COMPATIBILITY(state, v) { state.compatibility = v },
- SET_ANNUAL_ENERGY(state, v) { state.annualEnergy = v },
- SET_DAILY_FORTUNE(state, v) { state.dailyFortune = v },
- SET_RELATED_ITEMS(state, v) { state.relatedItems = v },
- SET_LOADING(state, v) { state.loading = v },
- SET_ERROR(state, v) { state.error = v },
- SET_YEAR(state, v) { state.currentYear = v }
- },
- actions: {
- loadDashboard({ commit, state }) {
- commit('SET_LOADING', true)
- commit('SET_ERROR', null)
- const familyId = uni.getStorageSync('familyId')
- if (!familyId) {
- commit('SET_LOADING', false)
- return Promise.reject(new Error('no familyId'))
- }
- return tianpanDashboard({ familyId: familyId, year: state.currentYear, daysAhead: state.daysAhead })
- .then(function(res) {
- if (res && res.code === 0) {
- commit('SET_DASHBOARD', res.data)
- }
- })
- .catch(function(e) {
- commit('SET_ERROR', e.message)
- })
- .finally(function() {
- commit('SET_LOADING', false)
- })
- },
- switchYear({ commit, dispatch }, year) {
- commit('SET_YEAR', year)
- return dispatch('loadDashboard')
- },
- loadMemberDetail({ commit }, payload) {
- return tianpanMemberDetail(payload.memberId, { memberType: payload.memberType || 'family_member' })
- .then(function(res) {
- if (res && res.code === 0) {
- commit('SET_MEMBER_DETAIL', res.data)
- return res.data
- }
- return null
- })
- },
- loadCompatibility({ commit }, payload) {
- return tianpanCompatibility(payload).then(function(res) {
- if (res && res.code === 0) {
- commit('SET_COMPATIBILITY', res.data)
- return res.data
- }
- return null
- })
- },
- loadAnnualEnergy({ commit }, payload) {
- return tianpanAnnualEnergy(payload).then(function(res) {
- if (res && res.code === 0) {
- commit('SET_ANNUAL_ENERGY', res.data)
- return res.data
- }
- return null
- })
- },
- loadDailyFortune({ commit }, payload) {
- return tianpanDailyFortune(payload).then(function(res) {
- if (res && res.code === 0) {
- commit('SET_DAILY_FORTUNE', res.data)
- return res.data
- }
- return null
- })
- },
- loadRelatedItems({ commit }, payload) {
- return tianpanRelatedItems(payload).then(function(res) {
- if (res && res.code === 0) {
- commit('SET_RELATED_ITEMS', res.data)
- return res.data
- }
- return null
- })
- }
- },
- getters: {
- members: function(state) {
- return state.dashboard && state.dashboard.members ? state.dashboard.members : []
- },
- relationships: function(state) {
- return state.dashboard && state.dashboard.relationships ? state.dashboard.relationships : []
- },
- familyWuxing: function(state) {
- return state.dashboard && state.dashboard.familyWuxing ? state.dashboard.familyWuxing : null
- },
- familyName: function(state) {
- return state.dashboard && state.dashboard.familyName ? state.dashboard.familyName : ''
- }
- }
- }
|