123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- import { createAction, NavigationActions } from '../../utils'
- import * as authService from '../../services/auth'
- import deviceStorage from '../../utils/storage'
- import { accMul } from '../../utils/utils'
- export default {
- namespace: 'shoppingcart',
- state: {
- ShopList: [],
- isDelete: false,
- TotalNum: 0,
- addShopFlag: false,
- isRefreshing: false,
- shopListIds: [],
- },
- reducers: {
- getShopListReducer(state, { payload }) {
- return { ...state, ...payload }
- },
- getShopTotalNum(state, { payload }) {
- return { ...state, ...payload }
- },
- shopIdsReducer(state, { payload }) {
- return { ...state, ...payload }
- },
- addShopReducer(state, { payload }) {
- return { ...state, ...payload }
- },
- deleteShopReducer(state, { payload }) {
- return { ...state, ...payload }
- },
- },
- effects: {
- // 查看购物车
- *getShoppingList(action, { call, put }) {
- // console.log(action, 112938);
- try {
- yield put(
- createAction('getShopListReducer')({
- isRefreshing: true,
- })
- )
- let newShopdata = [],
- TotalNum = 0,
- shopListIds = []
- const shopList = yield call(() =>
- authService.getShopList(action.payload)
- )
- // console.log(shopList, 19999999);
- if (shopList && shopList.data) {
- if (
- Object.keys(shopList.data).indexOf('code') &&
- Object.keys(shopList.data)[
- Object.keys(shopList.data).indexOf('code') == 'timeOut'
- ]
- ) {
- } else {
- if (shopList.data.length > 0) {
- shopList.data.map(item => {
- newShopdata.push({
- isPrimaryChannel: item.isPrimaryChannel,
- saleOrgCode: item.isPrimaryChannel,
- saleOrgId: item.saleOrgId,
- saleOrgName: item.saleOrgName,
- supplierCode: item.supplierCode,
- supplierId: item.supplierId,
- supplierName: item.supplierName,
- totalAmount: item.totalAmount,
- data: item.cartlist,
- })
- TotalNum = TotalNum + item.cartlist.length
- })
- } else {
- newShopdata = []
- }
- newShopdata.map(item =>
- item.data.map(data => shopListIds.push(data.goodsId))
- )
- }
- yield put(
- createAction('getShopListReducer')({
- ShopList: newShopdata,
- TotalNum: TotalNum,
- isRefreshing: false,
- })
- )
- yield put(
- createAction('shopIdsReducer')({ shopListIds: shopListIds })
- )
- }
- } catch (error) {
- yield put(
- createAction('getShopListReducer')({
- isRefreshing: false,
- })
- )
- console.log(
- error,
- '-----error的完整信息' + '\n' + error.response.data.message,
- '-----相关错误信息'
- )
- }
- },
- // 添加购物车
- *addShop(action, { call, put }) {
- try {
- const shopAddVal = yield call(() =>
- authService.addShopCart(action.payload)
- )
- let shopFlag = false
- if (shopAddVal) {
- shopFlag = true
- yield put(
- createAction('addShopReducer')({
- addShopFlag: shopFlag,
- })
- )
- yield put(
- createAction('getShoppingList')({
- params: {
- customer: CUSTOMERINFO.id,
- },
- })
- )
- }
- } catch (error) {
- console.log(
- error,
- '-----error的完整信息' + '\n' + error.response.data.message,
- '-----相关错误信息'
- )
- }
- },
- //清空购物车
- *emptyCart(action, { call, put }) {
- try {
- yield call(() => {
- authService.clearShopCart(action.payload)
- }
- )
- yield put(
- createAction('getShopListReducer')({
- isDelete: true,
- edited: false,
- ShopList: [],
- TotalNum: 0,
- Amount: 0
- })
- )
- } catch (error) {
- console.log(
- error,
- '-----error的完整信息' + '\n' + error.response.data.message,
- '-----相关错误信息'
- )
- }
- },
- // 删除购物车商品行
- *deleteShop(action, { call, put }) {
- // console.log(action, 112938);
- try {
- let newShopdata = [],
- TotalNum = 0
- const shopList = yield call(() =>
- authService.delShopCart(action.payload)
- )
- if (shopList && shopList.data) {
- // shopList.data.map(item => {
- // newShopdata.push({
- // isPrimaryChannel: item.isPrimaryChannel,
- // saleOrgCode: item.isPrimaryChannel,
- // saleOrgId: item.saleOrgId,
- // saleOrgName: item.saleOrgName,
- // supplierCode: item.supplierCode,
- // supplierId: item.supplierId,
- // supplierName: item.supplierName,
- // totalAmount: item.totalAmount,
- // data: item.cartlist
- // });
- // TotalNum = TotalNum + item.cartlist.length;
- // });
- yield put(
- createAction('getShopListReducer')({
- isDelete: true,
- // ShopList: newShopdata,
- // TotalNum: TotalNum
- })
- )
- }
- } catch (error) {
- console.log(
- error,
- '-----error的完整信息' + '\n' + error.response.data.message,
- '-----相关错误信息'
- )
- }
- },
- // 修改购物车数量
- *editShop(action, { call, put }) {
- try {
- let newItem = {}
- action.payload.item.orderNum = action.payload.cbNumber
- newItem = action.payload.item
- yield call(() => authService.editShopCart(newItem))
- // const shopList = yield call(() => authService.editShopCart(newItem));
- } catch (error) {
- console.log(
- error,
- '-----error的完整信息' + '\n' + error.response.data.message,
- '-----相关错误信息'
- )
- }
- },
- // 获取购物车数量
- *getCartNum(action, { call, put }) {
- try {
- const cartNum = yield call(() =>
- authService.getCartCount(action.payload)
- )
- if (cartNum && cartNum.data && cartNum.data >= 0) {
- yield put(
- createAction('getShopTotalNum')({
- TotalNum: cartNum.data,
- })
- )
- }
- } catch (error) {
- console.log(
- error,
- '-----error的完整信息' + '\n' + error.response.data.message,
- '-----相关错误信息'
- )
- }
- },
- },
- // subscriptions: {
- // setup({ dispatch }) {
- // dispatch({
- // type: "getCartNum",
- // payload: {
- // params: {
- // customer: "d4b4677f-93ec-49b5-bcaa-c134df0f7295"
- // }
- // }
- // });
- // }
- // }
- }
|