SearchResult.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. console.log("listData==============>",listData)
  73. yield put(
  74. createAction('commodityList')({
  75. listDatas: action.payload.actionData.concat(
  76. listData.data.content
  77. ),
  78. totalPages: listData.data.totalPages,
  79. isRefreshing: false,
  80. showFoot: foot,
  81. // Searchval: action.payload.Searchval
  82. })
  83. )
  84. if (
  85. action.payload.comeFrom !== 'CommodityShowbase' &&
  86. action.payload.comeFrom !== 'Filter'
  87. )
  88. yield put(
  89. NavigationActions.navigate({
  90. routeName: 'CommodityShowbase',
  91. })
  92. )
  93. }
  94. } catch (error) {
  95. yield put(
  96. createAction('commodityList')({
  97. isRefreshing: false,
  98. showFoot: 1,
  99. })
  100. )
  101. console.log(
  102. error,
  103. 'models/commodity/SearchResult-searchGoodsAll-listDatas(1、所有商品查询)'
  104. )
  105. }
  106. },
  107. // 2、根据商品分类查询商品
  108. *searchGoodsByCate(action, { call, put }) {
  109. try {
  110. yield put(createAction('categoryData')({ GoodsFlag: true }))
  111. const listData = yield call(() =>
  112. authService.searchCommodityList({
  113. ...action.payload.searchVal,
  114. search_EQ_isEnable: 1,
  115. })
  116. )
  117. if (listData && listData.data && listData.data.content) {
  118. yield put(
  119. createAction('categoryData')({
  120. GoodsList: listData.data.content,
  121. GoodsState: true,
  122. GoodsFlag: false,
  123. })
  124. )
  125. }
  126. } catch (error) {
  127. yield put(
  128. createAction('categoryData')({
  129. GoodsState: false,
  130. GoodsFlag: false,
  131. })
  132. )
  133. console.log(
  134. error,
  135. 'models/commodity/SearchResult-searchGoodsByCate-GoodsList(2、根据商品分类查询商品)'
  136. )
  137. }
  138. },
  139. // //商品列表
  140. // *getCommodityList(action, { call, put }) {
  141. // try {
  142. // console.log(action, 9991);
  143. // const listData = yield call(() =>
  144. // authService.getCommodityList(action.payload.Searchval)
  145. // );
  146. // console.log(listData, 888811);
  147. // if (listData) {
  148. // yield put(
  149. // createAction("commodityList")({
  150. // listDatas: listData.data,
  151. // Searchval: action.payload.Searchval
  152. // })
  153. // );
  154. // if (action.payload.comeFrom != "CommodityShowbase")
  155. // yield put(
  156. // NavigationActions.navigate({
  157. // routeName: "CommodityShowbase"
  158. // })
  159. // );
  160. // }
  161. // } catch (error) {
  162. // console.log(error,'-----error的完整信息'+'\n'+error. response.data.message,'-----相关错误信息');
  163. // }
  164. // }
  165. },
  166. }