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, '-----相关错误信息' ) } }, }, }