OptionalModels.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. import { createAction, NavigationActions } from '../../utils'
  2. import * as authService from '../../services/auth'
  3. export default {
  4. namespace: 'optional',
  5. state: {
  6. optDataByGoodId: [],
  7. optDataByIds: [],
  8. optionalReturn: [],
  9. goodsBoom: [],
  10. // isRefreshing: false,
  11. // totalPages: 2,
  12. // // 0:隐藏footer 1:已加载完成,没有更多数据 2 :显示加载中
  13. // showFoot: 0
  14. colorGroups: [],
  15. colorData: [],
  16. goodsPriceByColor: [],
  17. goodsOpt: [],
  18. },
  19. reducers: {
  20. optionalByGoodIdReducer(state, { payload }) {
  21. return { ...state, ...payload }
  22. },
  23. optionalByIdsReducer(state, { payload }) {
  24. return { ...state, ...payload }
  25. },
  26. saveOptionalReducer(state, { payload }) {
  27. return { ...state, ...payload }
  28. },
  29. getBoomReducer(state, { payload }) {
  30. return { ...state, ...payload }
  31. },
  32. getColorGroupsReducer(state, {payload}) {
  33. return {...state, ...payload}
  34. },
  35. getColorByGroupsReducer(state, {payload}) {
  36. return {...state, ...payload}
  37. },
  38. getPriceByColorIdReducer(state, {payload}) {
  39. return {...state, ...payload}
  40. },
  41. saveGoodsOptReducer(state, {payload}) {
  42. return {...state, ...payload}
  43. }
  44. },
  45. effects: {
  46. // 获取选配信息 ByGoodId
  47. *optionalByGoodIdSaga(action, { call, put }) {
  48. let returnData = []
  49. try {
  50. const hotdata = yield call(() =>
  51. authService.getOptionalByGoodId(action.payload)
  52. )
  53. if (hotdata && hotdata.data) {
  54. returnData = hotdata.data
  55. }
  56. yield put(
  57. createAction('optionalByGoodIdReducer')({
  58. optDataByGoodId: returnData,
  59. })
  60. )
  61. } catch (error) {
  62. yield put(
  63. createAction('optionalByGoodIdReducer')({
  64. optDataByGoodId: returnData,
  65. })
  66. )
  67. console.log(
  68. error,
  69. '-----error的完整信息' + '\n' + error.response.data.message,
  70. '-----相关错误信息'
  71. )
  72. }
  73. },
  74. // 获取选配信息 ByIds
  75. *optionalByIds(action, { call, put }) {
  76. try {
  77. const hotdata = yield call(() =>
  78. authService.getOptionalByIds({ ids: action.payload })
  79. )
  80. if (hotdata && hotdata.data) {
  81. yield put(
  82. createAction('optionalByIdsReducer')({
  83. optDataByIds: hotdata.data,
  84. })
  85. )
  86. }
  87. } catch (error) {
  88. console.log(
  89. error,
  90. '-----error的完整信息' + '\n' + error.response.data.message,
  91. '-----相关错误信息'
  92. )
  93. }
  94. },
  95. // 保存选配
  96. *saveOptionalSaga(action, { call, put }) {
  97. try {
  98. const hotdata = yield call(() =>
  99. authService.saveOptional(action.payload)
  100. )
  101. if (hotdata && hotdata.data) {
  102. yield put(
  103. createAction('saveOptionalReducer')({
  104. optionalReturn: hotdata.data,
  105. })
  106. )
  107. }
  108. } catch (error) {
  109. console.log(
  110. error,
  111. '-----error的完整信息' + '\n' + error.response.data.message,
  112. '-----相关错误信息'
  113. )
  114. }
  115. },
  116. // 获取Boom信息
  117. *getBoomInfo(action, { call, put }) {
  118. try {
  119. const hotdata = yield call(() =>
  120. authService.getBoomInfo({ parentGoodId: action.payload })
  121. )
  122. if (hotdata && hotdata.data) {
  123. yield put(
  124. createAction('getBoomReducer')({
  125. goodsBoom: hotdata.data,
  126. })
  127. )
  128. }
  129. } catch (error) {
  130. console.log(
  131. error,
  132. '-----error的完整信息' + '\n' + error.response.data.message,
  133. '-----相关错误信息'
  134. )
  135. }
  136. },
  137. //获取颜色选配分组
  138. *getColorGroups(action, { call, put}) {
  139. try {
  140. const hotdata = yield call(() =>
  141. authService.getColorGroups({})
  142. )
  143. if(hotdata && hotdata.data) {
  144. yield put(
  145. createAction('getColorGroupsReducer')({
  146. colorGroups : hotdata.data
  147. })
  148. )
  149. }
  150. } catch (error) {
  151. console.log(
  152. error,
  153. '-----error的完整信息' + '\n' + error.response.data.message,
  154. '-----相关错误信息'
  155. )
  156. }
  157. },
  158. //根据颜色分组查询颜色
  159. *getColorByGroups(action, { call, put}) {
  160. try {
  161. const hotdata = yield call(() =>
  162. authService.getColorByGroups(action.payload)
  163. )
  164. console.log(hotdata);
  165. if(hotdata && hotdata.data) {
  166. yield put(
  167. createAction('getColorByGroupsReducer')({
  168. colorData : hotdata.data
  169. })
  170. )
  171. }
  172. } catch (error) {
  173. console.log(
  174. error,
  175. '-----error的完整信息' + '\n' + error.response.data.message,
  176. '-----相关错误信息'
  177. )
  178. }
  179. },
  180. //根据色卡号查询商品调色价格
  181. *getPriceByColorId(action, { call, put}) {
  182. try {
  183. const hotdata = yield call(() =>
  184. authService.getPriceByColorId(action.payload)
  185. )
  186. if(hotdata && hotdata.data) {
  187. yield put(
  188. createAction('getPriceByColorIdReducer')({
  189. goodsPriceByColor : hotdata.data
  190. })
  191. )
  192. }
  193. } catch (error) {
  194. console.log(
  195. error,
  196. '-----error的完整信息' + '\n' + error.response.data.message,
  197. '-----相关错误信息'
  198. )
  199. }
  200. },
  201. //保存调色商品配置
  202. *saveGoodsOpt(action, { call, put}) {
  203. try {
  204. const hotdata = yield call(() =>
  205. authService.saveGoodsOpt(action.payload)
  206. )
  207. if(hotdata && hotdata.data) {
  208. yield put(
  209. createAction('saveGoodsOptReducer')({
  210. goodsOpt : hotdata.data
  211. })
  212. )
  213. }
  214. } catch (error) {
  215. console.log(
  216. error,
  217. '-----error的完整信息' + '\n' + error.response.data.message,
  218. '-----相关错误信息'
  219. )
  220. }
  221. }
  222. },
  223. }