123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- import { createAction, NavigationActions } from '../../utils'
- import * as authService from '../../services/auth'
- import deviceStorage from '../../utils/storage'
- import utils from '../../utils/utils'
- export default {
- namespace: 'home',
- state: {
- hotSaleDatas: [],
- allProDatas: [],
- recentDatas: [],
- ReqNumData: [],
- fetching: false,
- },
- reducers: {
- hotSale(state, { payload }) {
- return { ...state, ...payload }
- },
- allProduct(state, { payload }) {
- return { ...state, ...payload }
- },
- recentView(state, { payload }) {
- return { ...state, ...payload }
- },
- homeReqRenducer(state, { payload }) {
- return { ...state, ...payload }
- },
- },
- effects: {
- //热卖促销
- *getHotSale(action, { call, put }) {
- try {
- yield put(createAction('hotSale')({ fetching: true }))
- const hotdata = yield call(() =>
- authService.hotsale({ customerId: CUSTOMERINFO.id })
- )
- if (hotdata.data) {
- yield put(
- createAction('hotSale')({
- hotSaleDatas: hotdata.data,
- fetching: false,
- })
- )
- }
- } catch (error) {
- yield put(createAction('hotSale')({ fetching: false }))
- console.log(
- error,
- '-----error的完整信息' + '\n' + error.response.data.message,
- '-----相关错误信息'
- )
- }
- // yield put(createAction("getAllPro")());
- // yield put(createAction("getRecentView")());
- yield put(createAction('category/getCategory')())
- yield put(createAction('homeOrderNum')())
- },
- //所有商品
- *getAllPro(action, { call, put }) {
- try {
- yield put(createAction('allProduct')({ fetching: true }))
- const alldata = yield call(() =>
- authService.searchCommodityList({
- search_customerId: CUSTOMERINFO.id,
- search_customerRankCode: CUSTOMERINFO.customerRankCode,
- search_EQ_isEnable: 1,
- // search_EQ_isOptional: 0,
- // search_EQ_enableStrucManage: 0
- })
- )
- if (alldata.data) {
- yield put(
- createAction('allProduct')({
- allProDatas: alldata.data,
- fetching: false,
- })
- )
- }
- } catch (error) {
- console.log(
- error,
- '-----error的完整信息' + '\n' + error.response.data.message,
- '-----相关错误信息'
- )
- yield put(createAction('allProduct')({ fetching: false }))
- }
- },
- //最近浏览(注释的为根据浏览次数排序)
- *getRecentView(action, { call, put }) {
- yield put(createAction('recentView')({ fetching: true }))
- let recentView = []
- if (action && action.payload && action.payload.clear) {
- deviceStorage.remove('recentView')
- }
- const storageView = yield call(deviceStorage.get, 'recentView')
- if (!storageView && !action.payload) return
- if (!storageView) {
- recentView.push(action.payload.recentView)
- // recentView[0].clickNum = 1;
- deviceStorage.set('recentView', recentView)
- } else {
- recentView = storageView
- // if (recentView && action.payload) {
- if (
- storageView &&
- action.payload &&
- action.payload.recentView &&
- action.payload.recentView.code &&
- !utils.comparison(storageView, action.payload.recentView.code)
- ) {
- // action.payload.recentView.clickNum = 1;
- recentView.unshift(action.payload.recentView)
- deviceStorage.set('recentView', recentView)
- }
- // else {
- // for (let i = 0; i < recentView.length; i++) {
- // if (action.payload.recentView.code == recentView[i].code) {
- // recentView[i].clickNum = recentView[i].clickNum + 1;
- // deviceStorage.set("recentView", recentView);
- // }
- // }
- // }
- // }
- }
- yield put(
- createAction('recentView')({ recentDatas: recentView, fetching: false })
- )
- },
- //最近浏览清除
- *recentViewClear(action, { call, put }) {
- deviceStorage.remove('recentView')
- yield put(createAction('recentView')({ recentDatas: [] }))
- },
- //首页订单数量
- *homeOrderNum(action, { call, put }) {
- try {
- yield put(createAction('homeReqRenducer')({ fetching: true }))
- const orderNum = yield call(() =>
- authService.getHomeOrderNum({ customerId: CUSTOMERINFO.id })
- )
- if (orderNum.data) {
- yield put(
- createAction('homeReqRenducer')({
- ReqNumData: orderNum.data,
- fetching: false,
- })
- )
- }
- } catch (error) {
- console.log(
- error,
- '-----error的完整信息' + '\n' + error.response.data.message,
- '-----相关错误信息'
- )
- yield put(createAction('homeReqRenducer')({ fetching: false }))
- }
- },
- },
- // // 加入登录后删除
- // subscriptions: {
- // setup({ dispatch }) {
- // dispatch({ type: "getHotSale" });
- // }
- // }
- }
|