import { createAction, NavigationActions } from '../../utils' import * as authService from '../../services/auth' export default { namespace: 'orderedit', state: { castRateData: {}, promData: {}, mutualRelationShip: [], creditData: [], }, reducers: { CastRateReducer(state, { payload }) { return { ...state, ...payload } }, PromReducer(state, { payload }) { return { ...state, ...payload } }, CreditCheckReducer(state, { payload }) { return { ...state, ...payload } }, }, effects: { // 促销政策 *getProm(action, { call, put }) { try { const supConfirm = {} if ( action.payload.promInfo && !action.payload.promInfo.isPrimaryChannel ) { const suppilerList = yield call(() => authService.getsupplier({ customer: CUSTOMERINFO.id }) ) if ( suppilerList && suppilerList.data && suppilerList.data.length > 0 ) { suppilerList = suppilerList.data.filter( data => data.id == action.payload.promInfo.saleOrgId ) if (suppilerList && suppilerList.length == 1) { supConfirm.isPrimaryChannel = suppilerList[0].isPrimaryChannel } } } // 把互斥关系存在内存里,当返回不为null,将互斥关系覆盖 action.payload.promInfo.orderType = 'reqOrder'; const promdata = yield call(() => authService.promServer({ ...action.payload.promInfo, ...supConfirm }) ) if ( promdata && promdata.data && Object.keys(promdata.data).length > 0 && promdata.data.reqOrderItems.length > 0 ) { yield put( createAction('PromReducer')({ promData: promdata.data, }) ) } } catch (error) { console.log(error, '下单寻促销政策报错') } }, // 检查信用 *getCreditCheck(action, { call, put }) { try { // console.log(action); const creditCheck = yield call(() => authService.castCheck(action.payload.searchInfo) ) // console.log(creditCheck); if ( creditCheck && creditCheck.data && creditCheck.data.creditData && creditCheck.data.creditData.length > 0 ) { yield put( createAction('CreditCheckReducer')({ creditData: creditCheck.data.creditData, }) ) } } catch (error) { console.log(error, '下单检查信用报错') } }, // 冲抵比率 *getCastRate(action, { call, put }) { try { // console.log(action); const castdata = yield call(() => authService.castRate(action.payload.castInfo) ) if (castdata && castdata.data) { yield put( createAction('CastRateReducer')({ castRateData: castdata.data, }) ) } } catch (error) { console.log(error, '下单获取冲抵比率及最大冲抵值报错') } }, }, }