HeaderModels.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. import { createAction, NavigationActions } from '../../utils'
  2. import * as authService from '../../services/auth'
  3. import { accAdd, ScaleUtil } from '../../utils/utils'
  4. import { PaginationUtil } from '../../utils/PaginationUtil'
  5. export default {
  6. namespace: 'mine_header',
  7. state: {
  8. creditData: [],
  9. // 信用余额总数
  10. creditBalance: 0,
  11. isRefreshing: false,
  12. totalPages: 2,
  13. // 0:隐藏footer 1:已加载完成,没有更多数据 2 :显示加载中
  14. showFoot: 0,
  15. // 费用余额
  16. Balance: {},
  17. // 费用当前可用余额
  18. CastDdlData: 0,
  19. // 费用列表
  20. castData: [],
  21. // 费用详情
  22. castDetail: [],
  23. // 费用对账数据
  24. castAmtData: {},
  25. castAmtcontent: [],
  26. maxBalData: [],
  27. },
  28. reducers: {
  29. creditReducer(state, { payload }) {
  30. return { ...state, ...payload }
  31. },
  32. castReducer(state, { payload }) {
  33. return { ...state, ...payload }
  34. },
  35. castDetailReducer(state, { payload }) {
  36. return { ...state, ...payload }
  37. },
  38. castAmountReducer(state, { payload }) {
  39. return { ...state, ...payload }
  40. },
  41. CastDdlBalReducer(state, { payload }) {
  42. return { ...state, ...payload }
  43. },
  44. MaxBalanceReducer(state, { payload }) {
  45. return { ...state, ...payload }
  46. },
  47. },
  48. effects: {
  49. //信用
  50. *CreditSaga(action, { call, put }) {
  51. try {
  52. let creditData = []
  53. const hotdata = yield call(() =>
  54. authService.getCredit({ customerId: action.payload.customer })
  55. )
  56. if (hotdata && hotdata.data && hotdata.data.length > 0) {
  57. // 数据重组成需要的数据结构
  58. const mapObj = {}
  59. let creditBalance = 0
  60. hotdata.data.sort((a, b) => a - b)
  61. creditBalance = hotdata.data[0].creditBalance
  62. for (let item of hotdata.data) {
  63. mapObj[item.saleOrgName]
  64. ? mapObj[item.saleOrgName].push(item)
  65. : (mapObj[item.saleOrgName] = [].concat(item))
  66. }
  67. for (let val of Object.keys(mapObj)) {
  68. arrObj = {}
  69. arrObj.saleOrg = val
  70. arrObj.financialOrg = mapObj[val][0].organizationName
  71. arrObj.data = mapObj[val]
  72. creditData.push(arrObj)
  73. }
  74. creditBalance = ScaleUtil(creditBalance, CURRENCY.currencyAmountScale)
  75. yield put(
  76. createAction('creditReducer')({
  77. creditData: creditData,
  78. creditBalance: creditBalance,
  79. })
  80. )
  81. }
  82. } catch (error) {
  83. console.log(
  84. error,
  85. '-----error的完整信息' + '\n' + error.response.data.message,
  86. '-----相关错误信息'
  87. )
  88. }
  89. },
  90. //费用
  91. *CastSaga(action, { call, put }) {
  92. try {
  93. let foot = 0,
  94. search = {}
  95. if (action.payload.forUse !== 'slipOn') {
  96. yield put(
  97. createAction('castReducer')({
  98. isRefreshing: true,
  99. })
  100. )
  101. } else {
  102. yield put(
  103. createAction('castReducer')({
  104. showFoot: 2,
  105. })
  106. )
  107. }
  108. search = { ...action.payload.pageInfo, ...action.payload.searchInfo }
  109. const hotdata = yield call(() => authService.getCasts(search))
  110. const balance = yield call(() =>
  111. authService.getCastsBalance(action.payload.searchInfo)
  112. )
  113. if (hotdata && hotdata.data) {
  114. if (action.payload.pageInfo.page >= hotdata.data.totalPages) {
  115. foot = 1
  116. }
  117. yield put(
  118. createAction('castReducer')({
  119. castData: action.payload.castData.concat(hotdata.data.content),
  120. totalPages: hotdata.data.totalPages,
  121. isRefreshing: false,
  122. showFoot: foot,
  123. Balance: balance.data,
  124. })
  125. )
  126. }
  127. } catch (error) {
  128. yield put(
  129. createAction('castReducer')({
  130. isRefreshing: false,
  131. showFoot: 1,
  132. })
  133. )
  134. console.log(
  135. error,
  136. '-----error的完整信息' + '\n' + error.response.data.message,
  137. '-----相关错误信息'
  138. )
  139. }
  140. },
  141. // 费用详情
  142. *CastDetailSaga(action, { call, put }) {
  143. try {
  144. const hotdata = yield call(() =>
  145. authService.getCastsDetail(action.payload)
  146. )
  147. if (hotdata && hotdata.data) {
  148. yield put(
  149. createAction('castDetailReducer')({
  150. castDetail: hotdata.data,
  151. })
  152. )
  153. }
  154. } catch (error) {
  155. console.log(
  156. error,
  157. '-----error的完整信息' + '\n' + error.response.data.message,
  158. '-----相关错误信息'
  159. )
  160. }
  161. },
  162. // 费用对账
  163. *CastAmountSaga(action, { call, put }) {
  164. try {
  165. let foot = 0
  166. const search = {}
  167. if (action.payload.forUse !== 'slipOn') {
  168. yield put(
  169. createAction('castAmountReducer')({
  170. isRefreshing: true,
  171. })
  172. )
  173. } else {
  174. yield put(
  175. createAction('castAmountReducer')({
  176. showFoot: 2,
  177. })
  178. )
  179. }
  180. search = { ...action.payload.pageInfo, ...action.payload.searchInfo }
  181. const hotdata = yield call(() => authService.getCastsAmount(search))
  182. if (hotdata && hotdata.data) {
  183. if (action.payload.pageInfo.page >= hotdata.data.results.totalPages) {
  184. foot = 1
  185. }
  186. yield put(
  187. createAction('castAmountReducer')({
  188. castAmtData: hotdata.data,
  189. castAmtContent: action.payload.castAmt.concat(
  190. hotdata.data.results.content
  191. ),
  192. totalPages: hotdata.data.results.totalPages,
  193. isRefreshing: false,
  194. showFoot: foot,
  195. })
  196. )
  197. }
  198. } catch (error) {
  199. yield put(
  200. createAction('castAmountReducer')({
  201. isRefreshing: false,
  202. showFoot: 1,
  203. })
  204. )
  205. console.log(
  206. error,
  207. '-----error的完整信息' + '\n' + error.response.data.message,
  208. '-----相关错误信息'
  209. )
  210. }
  211. },
  212. // 费用当前可用余额
  213. *CastBalSaga(action, { call, put }) {
  214. try {
  215. const hotdata = yield call(() =>
  216. authService.CastDdlBalance(action.payload)
  217. )
  218. if (hotdata && hotdata.data) {
  219. yield put(
  220. createAction('CastDdlBalReducer')({
  221. CastDdlData: hotdata.data,
  222. })
  223. )
  224. }
  225. } catch (error) {
  226. console.log(
  227. error,
  228. '-----error的完整信息' + '\n' + error.response.data.message,
  229. '-----相关错误信息'
  230. )
  231. }
  232. },
  233. //
  234. // 费用当前可用余额
  235. *MaxBalanceSaga(action, { call, put }) {
  236. try {
  237. const hotdata = yield call(() =>
  238. authService.getMaxBalance(action.payload)
  239. )
  240. if (hotdata && hotdata.data) {
  241. yield put(
  242. createAction('MaxBalanceReducer')({
  243. maxBalData: hotdata.data,
  244. })
  245. )
  246. }
  247. } catch (error) {
  248. console.log(
  249. error,
  250. '-----error的完整信息' + '\n' + error.response.data.message,
  251. '-----相关错误信息'
  252. )
  253. }
  254. },
  255. },
  256. }