123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- import { createAction, NavigationActions } from '../../utils'
- import * as authService from '../../services/auth'
- import { accAdd, ScaleUtil } from '../../utils/utils'
- import { PaginationUtil } from '../../utils/PaginationUtil'
- export default {
- namespace: 'mine_header',
- state: {
- creditData: [],
- // 信用余额总数
- creditBalance: 0,
- isRefreshing: false,
- totalPages: 2,
- // 0:隐藏footer 1:已加载完成,没有更多数据 2 :显示加载中
- showFoot: 0,
- // 费用余额
- Balance: {},
- // 费用当前可用余额
- CastDdlData: 0,
- // 费用列表
- castData: [],
- // 费用详情
- castDetail: [],
- // 费用对账数据
- castAmtData: {},
- castAmtcontent: [],
- maxBalData: [],
- },
- reducers: {
- creditReducer(state, { payload }) {
- return { ...state, ...payload }
- },
- castReducer(state, { payload }) {
- return { ...state, ...payload }
- },
- castDetailReducer(state, { payload }) {
- return { ...state, ...payload }
- },
- castAmountReducer(state, { payload }) {
- return { ...state, ...payload }
- },
- CastDdlBalReducer(state, { payload }) {
- return { ...state, ...payload }
- },
- MaxBalanceReducer(state, { payload }) {
- return { ...state, ...payload }
- },
- },
- effects: {
- //信用
- *CreditSaga(action, { call, put }) {
- try {
- let creditData = []
- const hotdata = yield call(() =>
- authService.getCredit({ customerId: action.payload.customer })
- )
- if (hotdata && hotdata.data && hotdata.data.length > 0) {
- // 数据重组成需要的数据结构
- const mapObj = {}
- let creditBalance = 0
- hotdata.data.sort((a, b) => a - b)
- creditBalance = hotdata.data[0].creditBalance
- for (let item of hotdata.data) {
- mapObj[item.saleOrgName]
- ? mapObj[item.saleOrgName].push(item)
- : (mapObj[item.saleOrgName] = [].concat(item))
- }
- for (let val of Object.keys(mapObj)) {
- arrObj = {}
- arrObj.saleOrg = val
- arrObj.financialOrg = mapObj[val][0].organizationName
- arrObj.data = mapObj[val]
- creditData.push(arrObj)
- }
- creditBalance = ScaleUtil(creditBalance, CURRENCY.currencyAmountScale)
- yield put(
- createAction('creditReducer')({
- creditData: creditData,
- creditBalance: creditBalance,
- })
- )
- }
- } catch (error) {
- console.log(
- error,
- '-----error的完整信息' + '\n' + error.response.data.message,
- '-----相关错误信息'
- )
- }
- },
- //费用
- *CastSaga(action, { call, put }) {
- try {
- let foot = 0,
- search = {}
- if (action.payload.forUse !== 'slipOn') {
- yield put(
- createAction('castReducer')({
- isRefreshing: true,
- })
- )
- } else {
- yield put(
- createAction('castReducer')({
- showFoot: 2,
- })
- )
- }
- search = { ...action.payload.pageInfo, ...action.payload.searchInfo }
- const hotdata = yield call(() => authService.getCasts(search))
- const balance = yield call(() =>
- authService.getCastsBalance(action.payload.searchInfo)
- )
- if (hotdata && hotdata.data) {
- if (action.payload.pageInfo.page >= hotdata.data.totalPages) {
- foot = 1
- }
- yield put(
- createAction('castReducer')({
- castData: action.payload.castData.concat(hotdata.data.content),
- totalPages: hotdata.data.totalPages,
- isRefreshing: false,
- showFoot: foot,
- Balance: balance.data,
- })
- )
- }
- } catch (error) {
- yield put(
- createAction('castReducer')({
- isRefreshing: false,
- showFoot: 1,
- })
- )
- console.log(
- error,
- '-----error的完整信息' + '\n' + error.response.data.message,
- '-----相关错误信息'
- )
- }
- },
- // 费用详情
- *CastDetailSaga(action, { call, put }) {
- try {
- const hotdata = yield call(() =>
- authService.getCastsDetail(action.payload)
- )
- if (hotdata && hotdata.data) {
- yield put(
- createAction('castDetailReducer')({
- castDetail: hotdata.data,
- })
- )
- }
- } catch (error) {
- console.log(
- error,
- '-----error的完整信息' + '\n' + error.response.data.message,
- '-----相关错误信息'
- )
- }
- },
- // 费用对账
- *CastAmountSaga(action, { call, put }) {
- try {
- let foot = 0
- const search = {}
- if (action.payload.forUse !== 'slipOn') {
- yield put(
- createAction('castAmountReducer')({
- isRefreshing: true,
- })
- )
- } else {
- yield put(
- createAction('castAmountReducer')({
- showFoot: 2,
- })
- )
- }
- search = { ...action.payload.pageInfo, ...action.payload.searchInfo }
- const hotdata = yield call(() => authService.getCastsAmount(search))
- if (hotdata && hotdata.data) {
- if (action.payload.pageInfo.page >= hotdata.data.results.totalPages) {
- foot = 1
- }
- yield put(
- createAction('castAmountReducer')({
- castAmtData: hotdata.data,
- castAmtContent: action.payload.castAmt.concat(
- hotdata.data.results.content
- ),
- totalPages: hotdata.data.results.totalPages,
- isRefreshing: false,
- showFoot: foot,
- })
- )
- }
- } catch (error) {
- yield put(
- createAction('castAmountReducer')({
- isRefreshing: false,
- showFoot: 1,
- })
- )
- console.log(
- error,
- '-----error的完整信息' + '\n' + error.response.data.message,
- '-----相关错误信息'
- )
- }
- },
- // 费用当前可用余额
- *CastBalSaga(action, { call, put }) {
- try {
- const hotdata = yield call(() =>
- authService.CastDdlBalance(action.payload)
- )
- if (hotdata && hotdata.data) {
- yield put(
- createAction('CastDdlBalReducer')({
- CastDdlData: hotdata.data,
- })
- )
- }
- } catch (error) {
- console.log(
- error,
- '-----error的完整信息' + '\n' + error.response.data.message,
- '-----相关错误信息'
- )
- }
- },
- //
- // 费用当前可用余额
- *MaxBalanceSaga(action, { call, put }) {
- try {
- const hotdata = yield call(() =>
- authService.getMaxBalance(action.payload)
- )
- if (hotdata && hotdata.data) {
- yield put(
- createAction('MaxBalanceReducer')({
- maxBalData: hotdata.data,
- })
- )
- }
- } catch (error) {
- console.log(
- error,
- '-----error的完整信息' + '\n' + error.response.data.message,
- '-----相关错误信息'
- )
- }
- },
- },
- }
|