Browse Source

根据用户获取台球桌价格

master
DU 2 months ago
parent
commit
650e2cc720
  1. 13
      src/api/startDevice.ts
  2. 22
      src/pageScan/couponStart/index.tsx
  3. 24
      src/pageScan/renewFee/index.tsx
  4. 29
      src/pageScan/selfStart/index.tsx
  5. 31
      src/pageScan/timedStart/index.tsx
  6. 10
      src/types/startDevice.ts

13
src/api/startDevice.ts

@ -7,6 +7,7 @@ import { @@ -7,6 +7,7 @@ import {
StartGroupDevRequestDto,
StartDeviceResponse,
WechatPayParameters,
PriceRequestDto,
CtrlType,
PayType,
} from '../types/startDevice'
@ -178,6 +179,17 @@ export const turnOffRestart = (grpSn: string, openId: string) => { @@ -178,6 +179,17 @@ export const turnOffRestart = (grpSn: string, openId: string) => {
})
}
/**
* VIP/
* @param openId OpenId
* @param groupDevSn grpSn
* @returns /
*/
export const getTablePrice = (openId: string, groupDevSn: string) => {
const data: PriceRequestDto = { openId, groupDevSn }
return post<number>('/TablesDev/get-price', data)
}
// 导出枚举类型
export { CtrlType, PayType }
@ -192,6 +204,7 @@ export default { @@ -192,6 +204,7 @@ export default {
immediateClose,
renewFee,
turnOffRestart,
getTablePrice,
CtrlType,
PayType,
}

22
src/pageScan/couponStart/index.tsx

@ -5,7 +5,7 @@ import { View, Text, Image, Input } from '@tarojs/components' @@ -5,7 +5,7 @@ import { View, Text, Image, Input } from '@tarojs/components'
import Taro, { useLoad, useRouter } from '@tarojs/taro'
import { useState } from 'react'
import { observer } from 'mobx-react'
import { couponStart, invokeWechatPay } from '../../api/startDevice'
import { couponStart, invokeWechatPay, getTablePrice } from '../../api/startDevice'
import { userStore, tableStore } from '../../store'
import './index.scss'
@ -38,6 +38,7 @@ const CouponStart = observer(() => { @@ -38,6 +38,7 @@ const CouponStart = observer(() => {
const [selectedCouponType, setSelectedCouponType] = useState<CouponType>(CouponType.THIRD_PARTY)
const [selectedCouponId, setSelectedCouponId] = useState<number>(1) // 选中的券ID
const [loading, setLoading] = useState(false) // 加载状态
const [pricePerHour, setPricePerHour] = useState(0) // 每小时价格(从接口获取)
// 从路由参数获取设备信息,如果没有则从 store 获取
const grpSn = tableStore.getGrpSn(router.params.grpSn)
@ -75,6 +76,20 @@ const CouponStart = observer(() => { @@ -75,6 +76,20 @@ const CouponStart = observer(() => {
if (grpSn) {
tableStore.setCurrentGrpSn(grpSn)
}
// 获取该用户对应的台球桌价格
const openId = userStore.userInfo?.wxOpenId || Taro.getStorageSync('openId')
if (openId && grpSn) {
getTablePrice(openId, grpSn)
.then((res) => {
if (res.data) {
setPricePerHour(res.data)
}
})
.catch((err) => {
console.error('获取价格失败:', err)
})
}
})
// 拨打电话
@ -253,16 +268,13 @@ const CouponStart = observer(() => { @@ -253,16 +268,13 @@ const CouponStart = observer(() => {
{/* 价格信息 */}
<View className="price-info">
<View className="price-item">
<Text className="price-value">¥28.80</Text>
<Text className="price-value">¥{pricePerHour > 0 ? pricePerHour.toFixed(2) : '--'}</Text>
<Text className="price-label">/</Text>
</View>
<View className="price-item">
<Text className="price-label"></Text>
<Text className="price-value">¥100.00</Text>
</View>
<View className="vip-price">
<Text className="vip-text">VIP ¥20.00</Text>
</View>
</View>
{/* 价格时段 */}

24
src/pageScan/renewFee/index.tsx

@ -6,7 +6,7 @@ import Taro, { useLoad, useRouter } from '@tarojs/taro' @@ -6,7 +6,7 @@ import Taro, { useLoad, useRouter } from '@tarojs/taro'
import { useState } from 'react'
import { observer } from 'mobx-react'
import { Stepper } from '@taroify/core'
import { renewFee, invokeWechatPay, PayType } from '../../api/startDevice'
import { renewFee, invokeWechatPay, getTablePrice, PayType } from '../../api/startDevice'
import { userStore, tableStore } from '../../store'
import './index.scss'
@ -19,6 +19,7 @@ const RenewFee = observer(() => { @@ -19,6 +19,7 @@ const RenewFee = observer(() => {
const [renewAmount, setRenewAmount] = useState(100) // 续费金额(修改初始值为100)
const [paymentMethod] = useState('微信支付') // 支付方式
const [loading, setLoading] = useState(false) // 加载状态
const [pricePerHour, setPricePerHour] = useState(0) // 每小时价格(从接口获取)
// 从路由参数获取设备信息和操作记录ID,如果没有则从 store 获取
const grpSn = tableStore.getGrpSn(router.params.grpSn)
@ -34,6 +35,20 @@ const RenewFee = observer(() => { @@ -34,6 +35,20 @@ const RenewFee = observer(() => {
if (operationId) {
tableStore.setCurrentOperationId(operationId)
}
// 获取该用户对应的台球桌价格
const openId = userStore.userInfo?.wxOpenId || Taro.getStorageSync('openId')
if (openId && grpSn) {
getTablePrice(openId, grpSn)
.then((res) => {
if (res.data) {
setPricePerHour(res.data)
}
})
.catch((err) => {
console.error('获取价格失败:', err)
})
}
})
// 拨打电话
@ -50,10 +65,11 @@ const RenewFee = observer(() => { @@ -50,10 +65,11 @@ const RenewFee = observer(() => {
setRenewAmount(value)
}
// 计算续费时长(以小时为单位,假设 28.8元/小时)
// 根据实际价格计算续费时长
const calculateDuration = () => {
const hours = Math.floor(renewAmount / 28.8)
const minutes = Math.round((renewAmount / 28.8 - hours) * 60)
if (!pricePerHour) return '-'
const hours = Math.floor(renewAmount / pricePerHour)
const minutes = Math.round((renewAmount / pricePerHour - hours) * 60)
return `${hours}小时${minutes}分钟`
}

29
src/pageScan/selfStart/index.tsx

@ -6,7 +6,7 @@ import Taro, { useLoad, useRouter } from '@tarojs/taro' @@ -6,7 +6,7 @@ import Taro, { useLoad, useRouter } from '@tarojs/taro'
import { useState } from 'react'
import { observer } from 'mobx-react'
import { Stepper } from '@taroify/core'
import { depositStart, balanceStart, invokeWechatPay, PayType } from '../../api/startDevice'
import { depositStart, balanceStart, invokeWechatPay, getTablePrice, PayType } from '../../api/startDevice'
import { userStore, tableStore } from '../../store'
import './index.scss'
@ -18,6 +18,7 @@ const SelfStart = observer(() => { @@ -18,6 +18,7 @@ const SelfStart = observer(() => {
const [deposit, setDeposit] = useState(100) // 押金金额
const [paymentMethod, setPaymentMethod] = useState<'微信支付' | '余额支付'>('微信支付') // 支付方式
const [loading, setLoading] = useState(false) // 加载状态
const [pricePerHour, setPricePerHour] = useState(0) // 每小时价格(从接口获取)
// 从路由参数获取设备信息,如果没有则从 store 获取
const grpSn = tableStore.getGrpSn(router.params.grpSn)
@ -33,6 +34,20 @@ const SelfStart = observer(() => { @@ -33,6 +34,20 @@ const SelfStart = observer(() => {
tableStore.setCurrentGrpSn(grpSn)
}
// 获取该用户对应的台球桌价格
const openId = userStore.userInfo?.wxOpenId || Taro.getStorageSync('openId')
if (openId && grpSn) {
getTablePrice(openId, grpSn)
.then((res) => {
if (res.data) {
setPricePerHour(res.data)
}
})
.catch((err) => {
console.error('获取价格失败:', err)
})
}
// 显示提示 Toast
setTimeout(() => {
Taro.showToast({
@ -57,10 +72,11 @@ const SelfStart = observer(() => { @@ -57,10 +72,11 @@ const SelfStart = observer(() => {
setDeposit(value)
}
// 计算续费时长(以小时为单位,假设 28.8元/小时)
// 根据押金和实际价格计算预计时长
const calculateDuration = () => {
const hours = Math.floor(deposit / 28.8)
const minutes = Math.round((deposit / 28.8 - hours) * 60)
if (!pricePerHour) return '-'
const hours = Math.floor(deposit / pricePerHour)
const minutes = Math.round((deposit / pricePerHour - hours) * 60)
return `${hours}小时${minutes}分钟`
}
@ -224,16 +240,13 @@ const SelfStart = observer(() => { @@ -224,16 +240,13 @@ const SelfStart = observer(() => {
{/* 价格信息 */}
<View className="price-info">
<View className="price-item">
<Text className="price-value">¥28.80</Text>
<Text className="price-value">¥{pricePerHour > 0 ? pricePerHour.toFixed(2) : '--'}</Text>
<Text className="price-label">/</Text>
</View>
<View className="price-item">
<Text className="price-label"></Text>
<Text className="price-value">¥100.00</Text>
</View>
<View className="vip-price">
<Text className="vip-text">VIP ¥20.00</Text>
</View>
</View>
{/* 价格时段 */}

31
src/pageScan/timedStart/index.tsx

@ -5,7 +5,7 @@ import { View, Text, Image } from '@tarojs/components' @@ -5,7 +5,7 @@ import { View, Text, Image } from '@tarojs/components'
import Taro, { useLoad, useRouter } from '@tarojs/taro'
import { useState } from 'react'
import { observer } from 'mobx-react'
import { timedStart, invokeWechatPay, PayType } from '../../api/startDevice'
import { timedStart, invokeWechatPay, getTablePrice, PayType } from '../../api/startDevice'
import { userStore, tableStore } from '../../store'
import './index.scss'
@ -29,6 +29,7 @@ const TimedStart = observer(() => { @@ -29,6 +29,7 @@ const TimedStart = observer(() => {
const [selectedDuration, setSelectedDuration] = useState(1) // 选中的时长
const [paymentMethod] = useState('微信支付') // 支付方式
const [loading, setLoading] = useState(false) // 加载状态
const [pricePerHour, setPricePerHour] = useState(0) // 每小时价格(从接口获取)
// 从路由参数获取设备信息,如果没有则从 store 获取
const grpSn = tableStore.getGrpSn(router.params.grpSn)
@ -40,6 +41,20 @@ const TimedStart = observer(() => { @@ -40,6 +41,20 @@ const TimedStart = observer(() => {
if (grpSn) {
tableStore.setCurrentGrpSn(grpSn)
}
// 获取该用户对应的台球桌价格
const openId = userStore.userInfo?.wxOpenId || Taro.getStorageSync('openId')
if (openId && grpSn) {
getTablePrice(openId, grpSn)
.then((res) => {
if (res.data) {
setPricePerHour(res.data)
}
})
.catch((err) => {
console.error('获取价格失败:', err)
})
}
})
// 拨打电话
@ -65,9 +80,10 @@ const TimedStart = observer(() => { @@ -65,9 +80,10 @@ const TimedStart = observer(() => {
})
}
// 计算支付金额(28.8元/小时)
// 根据实际价格计算支付金额
const calculateAmount = () => {
return (selectedDuration * 28.8).toFixed(2)
if (!pricePerHour) return '0.00'
return (selectedDuration * pricePerHour).toFixed(2)
}
// 立即开台
@ -191,16 +207,9 @@ const TimedStart = observer(() => { @@ -191,16 +207,9 @@ const TimedStart = observer(() => {
{/* 价格信息 */}
<View className="price-info">
<View className="price-item">
<Text className="price-value">¥28.80</Text>
<Text className="price-value">¥{pricePerHour > 0 ? pricePerHour.toFixed(2) : '--'}</Text>
<Text className="price-label">/</Text>
</View>
<View className="price-item">
<Text className="price-label"></Text>
<Text className="price-value">¥100.00</Text>
</View>
<View className="vip-price">
<Text className="vip-text">VIP ¥20.00</Text>
</View>
</View>
{/* 价格时段 */}

10
src/types/startDevice.ts

@ -157,3 +157,13 @@ export interface OrderInfo { @@ -157,3 +157,13 @@ export interface OrderInfo {
/** 收费标准 */
pricingRule: string
}
/**
*
*/
export interface PriceRequestDto {
/** 用户微信 OpenId */
openId: string
/** 设备序列号 */
groupDevSn: string
}

Loading…
Cancel
Save