Commit 61efbd65 authored by hewenhao's avatar hewenhao

feat: 兑换配置

parent cdb99eb2
...@@ -36,3 +36,11 @@ export function getAccountInfo () { ...@@ -36,3 +36,11 @@ export function getAccountInfo () {
} }
})) }))
} }
export function getSetting () {
return requestAfterSilentLogin<{pointToCard: number}, {}>(() => ({
method: 'GET',
url: '/service-idea/inlet/config/getConfig',
data: {}
}))
}
import { View } from '@tarojs/components' import { View } from '@tarojs/components'
import { useRouter, showToast, getMenuButtonBoundingClientRect, useDidShow, getCurrentInstance, getTabBar, pageScrollTo, getSystemInfoSync, showModal } from '@tarojs/taro' import {
useRouter, showToast, getMenuButtonBoundingClientRect, useDidShow,
getCurrentInstance, getTabBar, pageScrollTo, getSystemInfoSync, showModal,
nextTick
} from '@tarojs/taro'
import { useState, useMemo, useCallback } from 'react' import { useState, useMemo, useCallback } from 'react'
import { useStoreActions, useStoreState } from '@/store/hooks' import { useStoreActions, useStoreState } from '@/store/hooks'
import { joinTribe } from '@/api/group' import { joinTribe } from '@/api/group'
...@@ -49,7 +53,7 @@ const MainPage = () => { ...@@ -49,7 +53,7 @@ const MainPage = () => {
joinTribeByCode() joinTribeByCode()
fetchStage().then((list) => { fetchStage().then((list) => {
setTimeout(() => { nextTick(() => {
if (!list.find(c => c.status === StageStatus.CURRENT)) { if (!list.find(c => c.status === StageStatus.CURRENT)) {
setIsReady(true) setIsReady(true)
} else { } else {
...@@ -57,7 +61,7 @@ const MainPage = () => { ...@@ -57,7 +61,7 @@ const MainPage = () => {
setIsReady(true) setIsReady(true)
}) })
} }
}, 1000) })
}) })
}) })
......
...@@ -45,9 +45,12 @@ const StudyMarket = () => { ...@@ -45,9 +45,12 @@ const StudyMarket = () => {
const [isVisible, { setTrue, setFalse }] = useBoolean(false) const [isVisible, { setTrue, setFalse }] = useBoolean(false)
const [currentGoods, setCurrentGoods] = useState<ExchangeGoods | null>(null) const [currentGoods, setCurrentGoods] = useState<ExchangeGoods | null>(null)
const point = useStoreState(state => state.userModel.point) const point = useStoreState(state => state.userModel.point)
const setting = useStoreState(state => state.userModel.setting)
const fetchAccount = useStoreActions(actions => actions.userModel.fetchAccount) const fetchAccount = useStoreActions(actions => actions.userModel.fetchAccount)
const getSetting = useStoreActions(actions => actions.userModel.getSetting)
useDidShow(() => { useDidShow(() => {
getSetting()
fetchAccount() fetchAccount()
}) })
...@@ -70,7 +73,7 @@ const StudyMarket = () => { ...@@ -70,7 +73,7 @@ const StudyMarket = () => {
title={item.subTitle} title={item.subTitle}
cover={item.img} cover={item.img}
stock={item.stock} stock={item.stock}
price={item.price} price={setting.pointToCard}
disabled={item.stock !== null && item.stock < 1} disabled={item.stock !== null && item.stock < 1}
subtitle={item.description} subtitle={item.description}
onClick={() => { onClick={() => {
......
import { import {
action, Action, Thunk, thunk, State action, Action, Thunk, thunk, State
} from 'easy-peasy' } from 'easy-peasy'
import { getAccountInfo } from '@/api' import { getAccountInfo, getSetting } from '@/api'
import type { UserInfo } from '@/types' import type { UserInfo } from '@/types'
import { pointToCard } from '@/api/account' import { pointToCard } from '@/api/account'
import { showModal, showToast, showLoading, hideLoading } from '@tarojs/taro' import { showModal, showToast, showLoading, hideLoading } from '@tarojs/taro'
...@@ -15,6 +15,8 @@ export interface UserModel { ...@@ -15,6 +15,8 @@ export interface UserModel {
updateState: Action<UserModel, Partial<State<UserModel>>>; updateState: Action<UserModel, Partial<State<UserModel>>>;
fetchAccount: Thunk<UserModel, void, void, AppStoreModel>; fetchAccount: Thunk<UserModel, void, void, AppStoreModel>;
updateUserInfo: Action<UserModel, UserInfo>; updateUserInfo: Action<UserModel, UserInfo>;
setting: { pointToCard: number };
getSetting: Thunk<UserModel, void, void, AppStoreModel>;
exchangeItem: Thunk<UserModel, { name: string; num: number; }, void, AppStoreModel>; exchangeItem: Thunk<UserModel, { name: string; num: number; }, void, AppStoreModel>;
} }
...@@ -23,6 +25,15 @@ const userModel: UserModel = { ...@@ -23,6 +25,15 @@ const userModel: UserModel = {
userInfo: getStorage(StorageKeys.userInfo)!, userInfo: getStorage(StorageKeys.userInfo)!,
cardNum: 0, cardNum: 0,
point: 0, point: 0,
setting: { pointToCard: Infinity },
getSetting: thunk(async (actions) => {
try {
const { data } = await getSetting()
actions.updateState({ setting: data })
} catch (err) {
actions.updateState({ setting: { pointToCard: Infinity } })
}
}),
exchangeItem: thunk(async (actions, payload) => { exchangeItem: thunk(async (actions, payload) => {
try { try {
showLoading({ mask: true, title: '兑换中...' }) showLoading({ mask: true, title: '兑换中...' })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment