SearchResult.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import { createAction, NavigationActions } from '../../utils'
  2. import * as authService from '../../services/auth'
  3. export default {
  4. namespace: 'search',
  5. state: {
  6. listDatas: [],
  7. GoodsList: [],
  8. Searchval: '',
  9. // GoodList状态
  10. GoodsState: true,
  11. // 分类列表List刷新标识
  12. GoodsFlag: false,
  13. // 分页用
  14. isRefreshing: false,
  15. totalPages: 2,
  16. // 0:隐藏footer 1:已加载完成,没有更多数据 2 :显示加载中
  17. showFoot: 0,
  18. },
  19. reducers: {
  20. commodityList(state, { payload }) {
  21. return { ...state, ...payload }
  22. },
  23. categoryData(state, { payload }) {
  24. return { ...state, ...payload }
  25. },
  26. },
  27. effects: {
  28. /**
  29. * info 1、所有商品查询
  30. * --------------------------------------
  31. * isNew 是否新品 - Boolean
  32. * productLineId 产品线Id - String
  33. * keyWord 产品编码名称 - String
  34. * goodsCategoryIds 商品分类IDs - String
  35. * organizationId 组织 - String
  36. *
  37. * ?
  38. * search_customerId //客户Id (必须)
  39. * search_customerRankCode=01 //客户档案关系(必须) 01-一级 02-二级
  40. * --------------------------------------
  41. * 根据上述条件筛选
  42. */
  43. *searchGoodsAll(action, { call, put }) {
  44. try {
  45. let foot = 0,
  46. search = {}
  47. if (action.payload.forUse !== 'slipOn') {
  48. yield put(
  49. createAction('commodityList')({
  50. isRefreshing: true,
  51. })
  52. )
  53. } else {
  54. yield put(
  55. createAction('commodityList')({
  56. showFoot: 2,
  57. })
  58. )
  59. }
  60. search = {
  61. ...action.payload.pageInfo,
  62. ...action.payload.searchInfo,
  63. search_EQ_isEnable: 1,
  64. }
  65. const listData = yield call(() =>
  66. authService.searchCommodityList(search)
  67. )
  68. if (listData && listData.data && listData.data.content) {
  69. if (action.payload.pageInfo.page >= listData.data.totalPages) {
  70. foot = 1
  71. }
  72. yield put(
  73. createAction('commodityList')({
  74. listDatas: action.payload.actionData.concat(
  75. listData.data.content
  76. ),
  77. totalPages: listData.data.totalPages,
  78. isRefreshing: false,
  79. showFoot: foot,
  80. // Searchval: action.payload.Searchval
  81. })
  82. )
  83. if (
  84. action.payload.comeFrom !== 'CommodityShowbase' &&
  85. action.payload.comeFrom !== 'Filter'
  86. )
  87. yield put(
  88. NavigationActions.navigate({
  89. routeName: 'CommodityShowbase',
  90. })
  91. )
  92. }
  93. } catch (error) {
  94. yield put(
  95. createAction('commodityList')({
  96. isRefreshing: false,
  97. showFoot: 1,
  98. })
  99. )
  100. console.log(
  101. error,
  102. 'models/commodity/SearchResult-searchGoodsAll-listDatas(1、所有商品查询)'
  103. )
  104. }
  105. },
  106. // 2、根据商品分类查询商品
  107. *searchGoodsByCate(action, { call, put }) {
  108. try {
  109. yield put(createAction('categoryData')({ GoodsFlag: true }))
  110. const listData = yield call(() =>
  111. authService.searchCommodityList({
  112. ...action.payload.searchVal,
  113. search_EQ_isEnable: 1,
  114. })
  115. )
  116. if (listData && listData.data && listData.data.content) {
  117. yield put(
  118. createAction('categoryData')({
  119. GoodsList: listData.data.content,
  120. GoodsState: true,
  121. GoodsFlag: false,
  122. })
  123. )
  124. }
  125. } catch (error) {
  126. yield put(
  127. createAction('categoryData')({
  128. GoodsState: false,
  129. GoodsFlag: false,
  130. })
  131. )
  132. console.log(
  133. error,
  134. 'models/commodity/SearchResult-searchGoodsByCate-GoodsList(2、根据商品分类查询商品)'
  135. )
  136. }
  137. },
  138. // //商品列表
  139. // *getCommodityList(action, { call, put }) {
  140. // try {
  141. // console.log(action, 9991);
  142. // const listData = yield call(() =>
  143. // authService.getCommodityList(action.payload.Searchval)
  144. // );
  145. // console.log(listData, 888811);
  146. // if (listData) {
  147. // yield put(
  148. // createAction("commodityList")({
  149. // listDatas: listData.data,
  150. // Searchval: action.payload.Searchval
  151. // })
  152. // );
  153. // if (action.payload.comeFrom != "CommodityShowbase")
  154. // yield put(
  155. // NavigationActions.navigate({
  156. // routeName: "CommodityShowbase"
  157. // })
  158. // );
  159. // }
  160. // } catch (error) {
  161. // console.log(error,'-----error的完整信息'+'\n'+error. response.data.message,'-----相关错误信息');
  162. // }
  163. // }
  164. },
  165. }