health-score.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * 健康积分/等级状态模块
  3. * P2-1 身份重塑系统
  4. */
  5. import api from '@/utils/api.js'
  6. var healthScoreStore = {
  7. state: {
  8. scoreInfo: null,
  9. timeline: [],
  10. scoreLoading: false
  11. },
  12. mutations: {
  13. setScoreInfo: function(state, info) {
  14. state.scoreInfo = info
  15. state.scoreLoading = false
  16. },
  17. setTimeline: function(state, list) {
  18. state.timeline = list
  19. },
  20. setScoreLoading: function(state) {
  21. state.scoreLoading = true
  22. }
  23. },
  24. actions: {
  25. fetchScoreInfo: function({ commit }, memberId) {
  26. if (!memberId) return
  27. commit('setScoreLoading')
  28. api.getHealthScoreInfo({ memberId: memberId }).then(function(res) {
  29. if (res.code === 200) {
  30. commit('setScoreInfo', res.data)
  31. } else {
  32. commit('setScoreLoading')
  33. }
  34. }).catch(function() {})
  35. },
  36. fetchTimeline: function({ commit }, memberId) {
  37. if (!memberId) return
  38. api.getHealthTimeline({ memberId: memberId }).then(function(res) {
  39. if (res.code === 200) {
  40. commit('setTimeline', res.data || [])
  41. }
  42. }).catch(function() {})
  43. }
  44. }
  45. }
  46. export default healthScoreStore