Commit 4a63869a by 姜雷

Merge branch 'develop' into test

parents 614cecdd 39a684d6
...@@ -137,7 +137,7 @@ export const getAppointmentDevice = ( ...@@ -137,7 +137,7 @@ export const getAppointmentDevice = (
type AppointingParams = { type AppointingParams = {
account: string; account: string;
// allowEmptyValue: false // allowEmptyValue: false
// 登录账号 // 设备登录账号
deviceCode: string; deviceCode: string;
// allowEmptyValue: false // allowEmptyValue: false
...@@ -155,7 +155,9 @@ type AppointingParams = { ...@@ -155,7 +155,9 @@ type AppointingParams = {
// allowEmptyValue: false // allowEmptyValue: false
// 用户名称 // 用户名称
}; };
export const appointingEquipment = (params: AppointingParams) => export const appointingEquipment = (
params: AppointingParams,
): Promise<ResponseDataEntity<number>> =>
showerFetch({ showerFetch({
url: '/dcxy/api/shower/appointment/appointing', url: '/dcxy/api/shower/appointment/appointing',
method: 'POST', method: 'POST',
...@@ -258,3 +260,20 @@ export const getUserAppointableData = ( ...@@ -258,3 +260,20 @@ export const getUserAppointableData = (
params.campusId params.campusId
}`, }`,
}); });
type AppointResultParams = {
recordId: number;
userId: number;
};
export enum AppointResultRes {
appointting = 0,
appointSuccess = 1,
appointFail = 4,
}
export const fetchAppointResult = (
params: AppointResultParams,
): Promise<ResponseDataEntity<AppointResultRes>> =>
showerFetch({
url: `/dcxy/api/shower/appointment/appointResult/${params.recordId}`,
data: params,
});
import './ShowerAppointment.scss'; import './ShowerAppointment.scss';
import { View, Input, Text, ScrollView } from '@tarojs/components'; import { View, Input, Text, ScrollView } from '@tarojs/components';
import Taro, { useState } from '@tarojs/taro'; import Taro, { useState, useEffect } from '@tarojs/taro';
import AppointermentCard from './components/AppointermentCard/AppointermentCard'; import AppointermentCard from './components/AppointermentCard/AppointermentCard';
import useInputValue from '@/hooks/useInputValue'; import useInputValue from '@/hooks/useInputValue';
import { import {
appointingEquipment, appointingEquipment,
ShowerUseType, ShowerUseType,
OperationMode, OperationMode,
fetchAppointResult,
AppointResultRes,
} from '@/api/shower'; } from '@/api/shower';
import { useSelector } from '@tarojs/redux'; import { useSelector } from '@tarojs/redux';
import { Customer } from '@/types/Customer/Customer'; import { Customer } from '@/types/Customer/Customer';
...@@ -25,6 +27,8 @@ function ShowerAppointment() { ...@@ -25,6 +27,8 @@ function ShowerAppointment() {
state.showerState.controllerConfigs, state.showerState.controllerConfigs,
); );
const [showState, setShowState] = useState(1); const [showState, setShowState] = useState(1);
const [recordId, setRecordId] = useState(0);
const [loopResultState, setLoopResultState] = useState(false);
const search = useInputValue(''); const search = useInputValue('');
const [searchString, setSearchString] = useState(''); const [searchString, setSearchString] = useState('');
...@@ -51,23 +55,87 @@ function ShowerAppointment() { ...@@ -51,23 +55,87 @@ function ShowerAppointment() {
mask: true, mask: true,
}); });
return appointingEquipment({ return appointingEquipment({
account: userInfo.customerId.toString(), account: userInfo.hardwareAccount,
phone: userInfo.customerPhone, phone: userInfo.customerPhone,
userId: userInfo.customerId, userId: userInfo.customerId,
userName: userInfo.customerName, userName: userInfo.customerName,
deviceCode: deviceCode, deviceCode: deviceCode,
}) })
.then(res => { .then(res => {
console.log(res); setRecordId(res.data);
Taro.showToast({
title: res.msg,
});
}) })
.catch(err => { .catch(err => {
Taro.hideLoading(); Taro.hideLoading();
Taro.showToast({
title: err.msg || '网络错误',
icon: 'none',
duration: 2000,
});
console.log(err); console.log(err);
}); });
}; };
const startLoopFetchResult = () => {
if (loopResultState) {
let intervalTime = 1000;
fetchAppointResult({
userId: userInfo.customerId,
recordId,
})
.then(res => {
if (res.data === AppointResultRes.appointting) {
setTimeout(() => {
startLoopFetchResult();
}, intervalTime);
} else {
setLoopResultState(false);
setRecordId(0);
if (res.data === AppointResultRes.appointFail) {
Taro.showToast({
title: res.msg || '预约失败',
icon: 'none',
duration: 2000,
});
} else if (res.data === AppointResultRes.appointSuccess) {
Taro.showToast({
title: res.msg || '预约成功',
duration: 2000,
});
}
}
})
.catch(err => {
console.log(err);
setTimeout(() => {
startLoopFetchResult();
}, intervalTime);
});
} else {
Taro.showToast({
title: '请求超时',
icon: 'none',
duration: 2000,
});
}
};
useEffect(() => {
let timer: NodeJS.Timeout | null = null;
if (recordId) {
setLoopResultState(true);
timer = setTimeout(() => {
setLoopResultState(false);
}, 30000);
}
return () => {
timer && clearTimeout(timer);
};
}, [recordId]);
useEffect(() => {
if (loopResultState) {
startLoopFetchResult();
}
}, [loopResultState]);
const appointingStart = ( const appointingStart = (
deviceCode: string, deviceCode: string,
operationMode: number, operationMode: number,
...@@ -143,7 +211,9 @@ function ShowerAppointment() { ...@@ -143,7 +211,9 @@ function ShowerAppointment() {
{showState == 1 && showerControlConfig.balances.length && ( {showState == 1 && showerControlConfig.balances.length && (
<View className='ShowerAppointment-Account'> <View className='ShowerAppointment-Account'>
{showerControlConfig.balances.map(item => ( {showerControlConfig.balances.map(item => (
<View className='ShowerAppointment-Account-item'> <View
key={item.serviceId}
className='ShowerAppointment-Account-item'>
<Text className='name'>{item.serviceName}</Text> <Text className='name'>{item.serviceName}</Text>
<Text>{item.amount.toFixed(2)}</Text> <Text>{item.amount.toFixed(2)}</Text>
</View> </View>
...@@ -160,6 +230,7 @@ function ShowerAppointment() { ...@@ -160,6 +230,7 @@ function ShowerAppointment() {
<AppointermentEquipment <AppointermentEquipment
key={item.code} key={item.code}
data={item} data={item}
disabled={appointableData.appointMode === 3}
appointingStart={appointingStart} appointingStart={appointingStart}
/> />
))} ))}
......
...@@ -13,13 +13,13 @@ ...@@ -13,13 +13,13 @@
.AppointermentCard-Time { .AppointermentCard-Time {
background-color: #e2e2e6; background-color: #e2e2e6;
} }
.AppointermentCard-Dis-Icon { }
position: absolute; .AppointermentCard-Dis-Icon {
width: 262px; position: absolute;
height: 246px; width: 262px;
right: 0; height: 246px;
bottom: 0; right: 0;
} bottom: 0;
} }
.AppointermentCard-Title { .AppointermentCard-Title {
line-height: 40px; line-height: 40px;
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
color: #6180f4; color: #6180f4;
background-color: #fafafe; background-color: #fafafe;
border-radius: 0 0 16px 16px; border-radius: 0 0 16px 16px;
text:last-child{ text:last-child {
display: inline-block; display: inline-block;
margin-left: 20px; margin-left: 20px;
width: 300px; width: 300px;
......
...@@ -11,7 +11,9 @@ const AppointermentCard = (props: PageOwnProps) => { ...@@ -11,7 +11,9 @@ const AppointermentCard = (props: PageOwnProps) => {
const { data } = props; const { data } = props;
return ( return (
<View <View
className={`AppointermentCard ${data.status === 5 ? 'disabled' : ''}`}> className={`AppointermentCard ${
data.status === 5 || data.status === 8 ? 'disabled' : ''
}`}>
<View className='AppointermentCard-Title'>我的预约</View> <View className='AppointermentCard-Title'>我的预约</View>
<View className='AppointermentCard-row'> <View className='AppointermentCard-row'>
<Text>设备编码:</Text> <Text>设备编码:</Text>
......
...@@ -4,6 +4,7 @@ import { AppointDeviceResponse } from '@/api/shower'; ...@@ -4,6 +4,7 @@ import { AppointDeviceResponse } from '@/api/shower';
import DisabledIcon from '@/images/shower/ic_jinyuyue@2x.png'; import DisabledIcon from '@/images/shower/ic_jinyuyue@2x.png';
type PageOwnProps = { type PageOwnProps = {
disabled: boolean;
data: AppointDeviceResponse; data: AppointDeviceResponse;
appointingStart: ( appointingStart: (
deviceCode: string, deviceCode: string,
...@@ -12,7 +13,7 @@ type PageOwnProps = { ...@@ -12,7 +13,7 @@ type PageOwnProps = {
) => void; ) => void;
}; };
const AppointermentEquipment = (props: PageOwnProps) => { const AppointermentEquipment = (props: PageOwnProps) => {
const { data, appointingStart } = props; const { data, appointingStart, disabled } = props;
const clickHandle = () => { const clickHandle = () => {
appointingStart && appointingStart &&
appointingStart(data.code, data.operationMode, data.location); appointingStart(data.code, data.operationMode, data.location);
...@@ -20,7 +21,7 @@ const AppointermentEquipment = (props: PageOwnProps) => { ...@@ -20,7 +21,7 @@ const AppointermentEquipment = (props: PageOwnProps) => {
return ( return (
<View <View
className={`ShowerAppointment-Equipment ${ className={`ShowerAppointment-Equipment ${
data.appointable && !data.inPunishment ? '' : 'disabled' data.appointable && !data.inPunishment && !disabled ? '' : 'disabled'
}`}> }`}>
<View className='ShowerAppointment-Equipment-row'> <View className='ShowerAppointment-Equipment-row'>
<Text className='ShowerAppointment-Equipment-name'>设备编码</Text> <Text className='ShowerAppointment-Equipment-name'>设备编码</Text>
...@@ -32,7 +33,7 @@ const AppointermentEquipment = (props: PageOwnProps) => { ...@@ -32,7 +33,7 @@ const AppointermentEquipment = (props: PageOwnProps) => {
{data.location} {data.location}
</Text> </Text>
</View> </View>
{data.appointable ? ( {data.appointable && !disabled ? (
<View <View
className='ShowerAppointment-Equipment-appoint' className='ShowerAppointment-Equipment-appoint'
onClick={clickHandle}> onClick={clickHandle}>
......
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