DetailModels.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import { createAction, NavigationActions } from '../../utils'
  2. import * as authService from '../../services/auth'
  3. export default {
  4. namespace: 'detail',
  5. state: {
  6. detailDatas: [],
  7. detailPicts: [],
  8. detailSpec: {},
  9. questSuccess: false,
  10. },
  11. reducers: {
  12. pictureReducer(state, { payload }) {
  13. return { ...state, ...payload }
  14. },
  15. specReducer(state, { payload }) {
  16. return { ...state, ...payload }
  17. },
  18. },
  19. effects: {
  20. // 进入详情
  21. *gotoDetail(action, { call, put }) {
  22. try {
  23. const hotdata = yield call(() =>
  24. authService.getPicture({ id: action.payload.item.id })
  25. )
  26. const hotdetaildata = yield call(() =>
  27. authService.getDetailAuth({
  28. id: action.payload.item.id,
  29. customer: CUSTOMERINFO.id,
  30. supplier: action.payload.item.saleOrgId,
  31. })
  32. )
  33. if (hotdata && hotdata.data) {
  34. let pictures = []
  35. hotdata.data.map(items => pictures.push(items.fileUrl))
  36. yield put(
  37. createAction('pictureReducer')({
  38. detailPicts: pictures,
  39. detailDatas: hotdetaildata.data,
  40. })
  41. )
  42. yield put(
  43. NavigationActions.navigate({
  44. routeName: 'CommodityTab',
  45. params: action.payload.userFor,
  46. })
  47. )
  48. }
  49. } catch (error) {
  50. console.log(
  51. error,
  52. '-----获取商品列表及图片并进入详情的完整信息' +
  53. '\n' +
  54. '相关错误信息---->:' +
  55. error.response.data.message
  56. )
  57. }
  58. },
  59. //获取商品详情
  60. *getDetail(action, { call, put }) {
  61. try {
  62. let pictures = [],
  63. questSuccess = false
  64. const hotdata = yield call(() =>
  65. authService.getDetailAuth(action.payload.inFo)
  66. )
  67. if (action.payload.useFor == 'specification') {
  68. const pictureData = yield call(() =>
  69. authService.getPicture({ id: action.payload.inFo.id })
  70. )
  71. pictureData.data.map(item => pictures.push(item.fileUrl))
  72. }
  73. if (hotdata && hotdata.data && Object.keys(hotdata.data).length > 0) {
  74. if (action.payload.useFor == 'specification') {
  75. questSuccess = true
  76. yield put(
  77. createAction('pictureReducer')({
  78. detailDatas: hotdata.data,
  79. detailPicts: pictures,
  80. questSuccess: questSuccess,
  81. })
  82. )
  83. } else {
  84. yield put(
  85. createAction('pictureReducer')({
  86. detailDatas: hotdata.data,
  87. })
  88. )
  89. }
  90. if (action.payload.useFor == 'specification') {
  91. action.payload.refresh._refreshdata(
  92. hotdata.data.salePrice || hotdata.data.basePrice,
  93. pictures[0]
  94. )
  95. }
  96. }
  97. } catch (error) {
  98. console.log(
  99. error,
  100. '-----获取商品详情的完整信息' +
  101. '\n' +
  102. '相关错误信息---->:' +
  103. error.response.data.message
  104. )
  105. }
  106. },
  107. //商品规格
  108. *getSpec(action, { call, put }) {
  109. try {
  110. const hotdata = yield call(() =>
  111. authService.getSpecification(action.payload)
  112. )
  113. if (hotdata && Object.keys(hotdata).length > 0) {
  114. yield put(
  115. createAction('specReducer')({
  116. detailSpec: hotdata.data,
  117. })
  118. )
  119. }
  120. } catch (error) {
  121. yield put(
  122. createAction('specReducer')({
  123. detailSpec: {},
  124. })
  125. )
  126. console.log(
  127. error,
  128. '-----商品规格的完整信息' +
  129. '\n' +
  130. '相关错误信息---->:' +
  131. error.response.data.message
  132. )
  133. }
  134. },
  135. },
  136. }