123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- import { createAction, NavigationActions } from '../../utils'
- import * as authService from '../../services/auth'
- export default {
- namespace: 'detail',
- state: {
- detailDatas: [],
- detailPicts: [],
- detailSpec: {},
- questSuccess: false,
- },
- reducers: {
- pictureReducer(state, { payload }) {
- return { ...state, ...payload }
- },
- specReducer(state, { payload }) {
- return { ...state, ...payload }
- },
- },
- effects: {
- // 进入详情
- *gotoDetail(action, { call, put }) {
- try {
- const hotdata = yield call(() =>
- authService.getPicture({ id: action.payload.item.id })
- )
- const hotdetaildata = yield call(() =>
- authService.getDetailAuth({
- id: action.payload.item.id,
- customer: CUSTOMERINFO.id,
- supplier: action.payload.item.saleOrgId,
- })
- )
- if (hotdata && hotdata.data) {
- let pictures = []
- hotdata.data.map(items => pictures.push(items.fileUrl))
- yield put(
- createAction('pictureReducer')({
- detailPicts: pictures,
- detailDatas: hotdetaildata.data,
- })
- )
- yield put(
- NavigationActions.navigate({
- routeName: 'CommodityTab',
- params: action.payload.userFor,
- })
- )
- }
- } catch (error) {
- console.log(
- error,
- '-----获取商品列表及图片并进入详情的完整信息' +
- '\n' +
- '相关错误信息---->:' +
- error.response.data.message
- )
- }
- },
- //获取商品详情
- *getDetail(action, { call, put }) {
- try {
- let pictures = [],
- questSuccess = false
- const hotdata = yield call(() =>
- authService.getDetailAuth(action.payload.inFo)
- )
- if (action.payload.useFor == 'specification') {
- const pictureData = yield call(() =>
- authService.getPicture({ id: action.payload.inFo.id })
- )
- pictureData.data.map(item => pictures.push(item.fileUrl))
- }
- if (hotdata && hotdata.data && Object.keys(hotdata.data).length > 0) {
- if (action.payload.useFor == 'specification') {
- questSuccess = true
- yield put(
- createAction('pictureReducer')({
- detailDatas: hotdata.data,
- detailPicts: pictures,
- questSuccess: questSuccess,
- })
- )
- } else {
- yield put(
- createAction('pictureReducer')({
- detailDatas: hotdata.data,
- })
- )
- }
- if (action.payload.useFor == 'specification') {
- action.payload.refresh._refreshdata(
- hotdata.data.salePrice || hotdata.data.basePrice,
- pictures[0]
- )
- }
- }
- } catch (error) {
- console.log(
- error,
- '-----获取商品详情的完整信息' +
- '\n' +
- '相关错误信息---->:' +
- error.response.data.message
- )
- }
- },
- //商品规格
- *getSpec(action, { call, put }) {
- try {
- const hotdata = yield call(() =>
- authService.getSpecification(action.payload)
- )
- if (hotdata && Object.keys(hotdata).length > 0) {
- yield put(
- createAction('specReducer')({
- detailSpec: hotdata.data,
- })
- )
- }
- } catch (error) {
- yield put(
- createAction('specReducer')({
- detailSpec: {},
- })
- )
- console.log(
- error,
- '-----商品规格的完整信息' +
- '\n' +
- '相关错误信息---->:' +
- error.response.data.message
- )
- }
- },
- },
- }
|