AttentionModel.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import { createAction, NavigationActions } from '../../utils'
  2. import * as authService from '../../services/auth'
  3. export default {
  4. namespace: 'attention',
  5. state: {
  6. attentData: [],
  7. isRefreshing: false,
  8. },
  9. reducers: {
  10. attentionListReducer(state, { payload }) {
  11. return { ...state, ...payload }
  12. },
  13. updateReducer(state, { payload }) {
  14. return { ...state, ...payload }
  15. },
  16. // shopIdsReducer(state, { payload }) {
  17. // return { ...state, ...payload };
  18. // }
  19. },
  20. effects: {
  21. // 查看关注列表
  22. *getAttentionList(action, { call, put }) {
  23. try {
  24. let attentData = []
  25. yield put(
  26. createAction('attentionListReducer')({
  27. isRefreshing: true,
  28. })
  29. )
  30. const attention = yield call(() =>
  31. authService.checkAttention({ customer: CUSTOMERINFO.id })
  32. )
  33. if (attention && attention.data) {
  34. attention.data.map(item => {
  35. if (item.storelist) {
  36. attentData = attentData.concat(item.storelist)
  37. }
  38. })
  39. yield put(
  40. createAction('attentionListReducer')({ attentData: attentData })
  41. )
  42. }
  43. } catch (error) {
  44. yield put(
  45. createAction('attentionListReducer')({
  46. isRefreshing: false,
  47. })
  48. )
  49. console.log(
  50. error,
  51. '-----error的完整信息' + '\n' + error.response.data.message,
  52. '-----相关错误信息'
  53. )
  54. }
  55. },
  56. // 添加关注
  57. *addAttention(action, { call, put }) {
  58. try {
  59. const attentionAdd = yield call(() =>
  60. authService.addAttention(action.payload)
  61. )
  62. yield put(createAction('getAttentionList')())
  63. } catch (error) {
  64. console.log(
  65. error,
  66. '-----error的完整信息' + '\n' + error.response.data.message,
  67. '-----相关错误信息'
  68. )
  69. }
  70. },
  71. // 删除关注商品行
  72. *delAttention(action, { call, put }) {
  73. try {
  74. const delAttent = yield call(() =>
  75. authService.delAttention({
  76. customer: CUSTOMERINFO.id,
  77. id: action.payload,
  78. })
  79. )
  80. yield put(createAction('getAttentionList')())
  81. } catch (error) {
  82. console.log(
  83. error,
  84. '-----error的完整信息' + '\n' + error.response.data.message,
  85. '-----相关错误信息'
  86. )
  87. }
  88. },
  89. // 删除关注商品行
  90. *delAttentionByGoodsId(action, { call, put }) {
  91. try {
  92. const delAttent = yield call(() =>
  93. authService.delAttentionByGood({
  94. customer: CUSTOMERINFO.id,
  95. goodsId: action.payload.goodsId,
  96. saleOrg: action.payload.saleOrg,
  97. })
  98. )
  99. yield put(createAction('getAttentionList')())
  100. } catch (error) {
  101. console.log(
  102. error,
  103. '-----error的完整信息' + '\n' + error.response.data.message,
  104. '-----相关错误信息'
  105. )
  106. }
  107. },
  108. // 删除关注商品行
  109. *updateAttention(action, { call, put }) {
  110. try {
  111. yield put(
  112. createAction('updateReducer')({
  113. attentData: action.payload.attentData,
  114. })
  115. )
  116. } catch (error) {
  117. console.log(
  118. error,
  119. '-----error的完整信息' + '\n' + error.response.data.message,
  120. '-----相关错误信息'
  121. )
  122. }
  123. },
  124. },
  125. }