lottery.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import axios from '~/plugins/axios'
  2. export const actions = {
  3. // 获取用户信息
  4. getUserInfo ({ commit }, params = {}) {
  5. commit('lotteryInfo/REQUEST_USER_INFO')
  6. return axios.get('/lottery/userInfo', {params})
  7. .then(response => {
  8. commit('lotteryInfo/GET_USER_INFO_SUCCESS', response.data)
  9. }, err => {
  10. commit('lotteryInfo/GET_USER_INFO_FAILURE', err)
  11. })
  12. },
  13. // 获取下一等级
  14. getNextLevel ({ commit }, params = {}) {
  15. commit('lotteryInfo/REQUEST_NEXT_LEVEL')
  16. return axios.get('/lottery/user/activityItems', {params})
  17. .then(response => {
  18. commit('lotteryInfo/GET_NEXT_LEVEL_SUCCESS', response.data)
  19. }, err => {
  20. commit('lotteryInfo/GET_NEXT_LEVEL_FAILURE', err)
  21. })
  22. },
  23. // 获取活动参与者中奖记录
  24. getWinningRecord ({ commit }, params = {}) {
  25. commit('lotteryInfo/REQUEST_WIN_RECORD')
  26. return axios.get('/lottery/user/winninghistories', {params})
  27. .then(response => {
  28. commit('lotteryInfo/GET_WIN_RECORD_SUCCESS', response.data)
  29. }, err => {
  30. commit('lotteryInfo/GET_WIN_RECORD_FAILURE', err)
  31. })
  32. },
  33. // 获取个人中奖记录
  34. getOwnWinningRecord ({ commit }, params = {}) {
  35. commit('lotteryInfo/REQUEST_OWN_WIN_RECORD')
  36. return axios.get('/lottery/user/winninghistories/one', {params})
  37. .then(response => {
  38. commit('lotteryInfo/GET_OWN_WIN_RECORD_SUCCESS', response.data)
  39. }, err => {
  40. commit('lotteryInfo/GET_OWN_WIN_RECORD_FAILURE', err)
  41. })
  42. },
  43. // 获取当前等级对应奖品
  44. currentGradePrizes ({ commit }, params = {}) {
  45. let resItems = []
  46. commit('lotteryInfo/REQUEST_CURRENT_GRADE_PRIZES')
  47. return axios.get('/lottery/user/prizes', {params})
  48. .then(res => {
  49. // if (res.data.data) {
  50. // resItems = res.data
  51. // for (let i = 0; i < resItems.data.length; i++) {
  52. // resItems.data[i].$index = i
  53. // resItems.code = 200
  54. // resItems.success = true
  55. // }
  56. // console.log(resItems, 'resItems')
  57. // commit('lotteryInfo/GET_CURRENT_GRADE_PRIZES_SUCCESS', resItems)
  58. // }
  59. resItems = res.data
  60. for (let i = 0; i < resItems.data.length; i++) {
  61. resItems.data[i].$index = i
  62. resItems.code = 200
  63. resItems.success = true
  64. }
  65. commit('lotteryInfo/GET_CURRENT_GRADE_PRIZES_SUCCESS', resItems)
  66. }, err => {
  67. commit('lotteryInfo/GET_CURRENT_GRADE_PRIZES_FAILURE', err)
  68. })
  69. },
  70. // 抽奖
  71. getOwnLotteryInfo ({ commit }, params = {}) {
  72. commit('lotteryInfo/REQUEST_OWN_LOTTERY_INFO')
  73. return axios.get('/lottery/user/draw', {params})
  74. .then(response => {
  75. commit('lotteryInfo/GET_OWN_LOTTERY_INFO_SUCCESS', response.data)
  76. }, err => {
  77. commit('lotteryInfo/GET_OWN_LOTTERY_INFO_FAILURE', err)
  78. })
  79. }
  80. }