tianpan.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import { tianpanDashboard, tianpanMemberDetail, tianpanCompatibility, tianpanAnnualEnergy, tianpanDailyFortune, tianpanRelatedItems } from '@/utils/api.js'
  2. export default {
  3. namespaced: true,
  4. state: {
  5. dashboard: null,
  6. memberDetail: null,
  7. compatibility: null,
  8. annualEnergy: null,
  9. dailyFortune: null,
  10. relatedItems: null,
  11. loading: false,
  12. error: null,
  13. currentYear: new Date().getFullYear(),
  14. daysAhead: 7
  15. },
  16. mutations: {
  17. SET_DASHBOARD(state, v) { state.dashboard = v },
  18. SET_MEMBER_DETAIL(state, v) { state.memberDetail = v },
  19. SET_COMPATIBILITY(state, v) { state.compatibility = v },
  20. SET_ANNUAL_ENERGY(state, v) { state.annualEnergy = v },
  21. SET_DAILY_FORTUNE(state, v) { state.dailyFortune = v },
  22. SET_RELATED_ITEMS(state, v) { state.relatedItems = v },
  23. SET_LOADING(state, v) { state.loading = v },
  24. SET_ERROR(state, v) { state.error = v },
  25. SET_YEAR(state, v) { state.currentYear = v }
  26. },
  27. actions: {
  28. loadDashboard({ commit, state }) {
  29. commit('SET_LOADING', true)
  30. commit('SET_ERROR', null)
  31. return tianpanDashboard({ year: state.currentYear, daysAhead: state.daysAhead })
  32. .then(function(res) {
  33. if (res && res.code === 200) {
  34. commit('SET_DASHBOARD', res.data)
  35. }
  36. })
  37. .catch(function(e) {
  38. commit('SET_ERROR', e.message)
  39. })
  40. .finally(function() {
  41. commit('SET_LOADING', false)
  42. })
  43. },
  44. switchYear({ commit, dispatch }, year) {
  45. commit('SET_YEAR', year)
  46. return dispatch('loadDashboard')
  47. },
  48. loadMemberDetail({ commit }, payload) {
  49. return tianpanMemberDetail(payload.memberId, { memberType: payload.memberType || 'family_member' })
  50. .then(function(res) {
  51. if (res && res.code === 200) {
  52. commit('SET_MEMBER_DETAIL', res.data)
  53. return res.data
  54. }
  55. return null
  56. })
  57. },
  58. loadCompatibility({ commit }, payload) {
  59. return tianpanCompatibility(payload).then(function(res) {
  60. if (res && res.code === 200) {
  61. commit('SET_COMPATIBILITY', res.data)
  62. return res.data
  63. }
  64. return null
  65. })
  66. },
  67. loadAnnualEnergy({ commit }, payload) {
  68. return tianpanAnnualEnergy(payload).then(function(res) {
  69. if (res && res.code === 200) {
  70. commit('SET_ANNUAL_ENERGY', res.data)
  71. return res.data
  72. }
  73. return null
  74. })
  75. },
  76. loadDailyFortune({ commit }, payload) {
  77. return tianpanDailyFortune(payload).then(function(res) {
  78. if (res && res.code === 200) {
  79. commit('SET_DAILY_FORTUNE', res.data)
  80. return res.data
  81. }
  82. return null
  83. })
  84. },
  85. loadRelatedItems({ commit }, payload) {
  86. return tianpanRelatedItems(payload).then(function(res) {
  87. if (res && res.code === 200) {
  88. commit('SET_RELATED_ITEMS', res.data)
  89. return res.data
  90. }
  91. return null
  92. })
  93. }
  94. },
  95. getters: {
  96. members: function(state) {
  97. return state.dashboard && state.dashboard.members ? state.dashboard.members : []
  98. },
  99. relationships: function(state) {
  100. return state.dashboard && state.dashboard.relationships ? state.dashboard.relationships : []
  101. },
  102. familyWuxing: function(state) {
  103. return state.dashboard && state.dashboard.familyWuxing ? state.dashboard.familyWuxing : null
  104. },
  105. familyName: function(state) {
  106. return state.dashboard && state.dashboard.familyName ? state.dashboard.familyName : ''
  107. }
  108. }
  109. }