AccountModels.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import { createAction, NavigationActions } from '../../utils'
  2. import * as authService from '../../services/auth'
  3. export default {
  4. namespace: 'mine_account',
  5. state: {
  6. accountData: [],
  7. accountBalance: 0,
  8. isRefreshing: false,
  9. totalPages: 2,
  10. // 0:隐藏footer 1:已加载完成,没有更多数据 2 :显示加载中
  11. showFoot: 0,
  12. },
  13. reducers: {
  14. accountReducer(state, { payload }) {
  15. return { ...state, ...payload }
  16. },
  17. accBalanceReducer(state, { payload }) {
  18. return { ...state, ...payload }
  19. },
  20. },
  21. effects: {
  22. // 账户余额
  23. *AccountSagas(action, { call, put }) {
  24. try {
  25. let foot = 0,
  26. search = {}
  27. if (action.payload.forUse !== 'slipOn') {
  28. yield put(
  29. createAction('castReducer')({
  30. isRefreshing: true,
  31. })
  32. )
  33. } else {
  34. yield put(
  35. createAction('castReducer')({
  36. showFoot: 2,
  37. })
  38. )
  39. }
  40. customerinfo = { search_EQ_customer: CUSTOMERINFO.id }
  41. search = {
  42. ...action.payload.pageInfo,
  43. ...action.payload.searchInfo,
  44. ...customerinfo,
  45. }
  46. const hotdata = yield call(() => authService.getBalanceChange(search))
  47. if (hotdata && hotdata.data) {
  48. if (action.payload.pageInfo.page >= hotdata.data.totalPages) {
  49. foot = 1
  50. }
  51. yield put(
  52. createAction('accountReducer')({
  53. accountData: action.payload.accountReturn.concat(
  54. hotdata.data.content
  55. ),
  56. isRefreshing: false,
  57. totalPages: hotdata.data.totalPages,
  58. isRefreshing: false,
  59. showFoot: foot,
  60. })
  61. )
  62. } else {
  63. yield put(
  64. createAction('accountReducer')({
  65. isRefreshing: false,
  66. })
  67. )
  68. }
  69. } catch (error) {
  70. yield put(
  71. createAction('accountReducer')({
  72. isRefreshing: false,
  73. showFoot: 1,
  74. })
  75. )
  76. console.log(
  77. error,
  78. '-----error的完整信息' + '\n' + error.response.data.message,
  79. '-----相关错误信息'
  80. )
  81. }
  82. },
  83. // 账户 预付余额
  84. *getAccountBalance(action, { call, put }) {
  85. try {
  86. let search = {},
  87. customerinfo = { customerId: CUSTOMERINFO.id }
  88. search = {
  89. ...action.payload.searchInfo,
  90. ...customerinfo,
  91. }
  92. const hotdata = yield call(() => authService.getPrepayBalance(search))
  93. if (hotdata && hotdata.data) {
  94. yield put(
  95. createAction('accBalanceReducer')({
  96. accountBalance: hotdata.data,
  97. })
  98. )
  99. }
  100. } catch (error) {
  101. console.log(
  102. error,
  103. '-----error的完整信息' + '\n' + error.response.data.message,
  104. '-----相关错误信息'
  105. )
  106. }
  107. },
  108. },
  109. }