Commit 4aaf14a6 by 姜雷

添加洗浴设备提示

parent dcaeb0a8
import { showerFetch } from './index'; import { showerFetch, ResponseDataEntity } from './index';
export enum OperationMode {
beanFirst = 1,
aimiFirst = 2,
onlyAimi = 3,
}
type ShowerParams = { type ShowerParams = {
deviceCode: string; deviceCode: string;
...@@ -8,12 +14,15 @@ type ShowerParams = { ...@@ -8,12 +14,15 @@ type ShowerParams = {
export type DeviceInfoResponse = { export type DeviceInfoResponse = {
code: string; code: string;
isOnlyBluetooth: number; isOnlyBluetooth: number;
operationMode: OperationMode;
position: string; position: string;
}; };
/** /**
* 通过设备码获取设备信息 * 通过设备码获取设备信息
*/ */
export const fetchShowerInfo = (params: ShowerParams) => export const fetchShowerInfo = (
params: ShowerParams,
): Promise<ResponseDataEntity<DeviceInfoResponse>> =>
showerFetch({ showerFetch({
url: `/dcxy/api/shower/devices/${params.deviceCode}`, url: `/dcxy/api/shower/devices/${params.deviceCode}`,
data: params, data: params,
...@@ -46,3 +55,21 @@ export const startShowerEquipment = (params: StartParams) => ...@@ -46,3 +55,21 @@ export const startShowerEquipment = (params: StartParams) =>
method: 'POST', method: 'POST',
data: params, data: params,
}); });
type ControllerParams = {
customerId: number;
campusId: number;
};
type ControllerResponse = {
beanAmount: number;
money: number;
thresholdPrompt: string;
thresholdValue: number;
};
export const getShowerController = (
params: ControllerParams,
): Promise<ResponseDataEntity<ControllerResponse>> =>
showerFetch({
url: '/dcxy/api/shower/controllerConfigs',
data: params,
});
...@@ -12,11 +12,12 @@ import { ...@@ -12,11 +12,12 @@ import {
DeviceInfoResponse, DeviceInfoResponse,
startShowerEquipment, startShowerEquipment,
fetchUsingShowerInfo, fetchUsingShowerInfo,
getShowerController,
OperationMode,
} from '@/api/shower'; } from '@/api/shower';
import { connect, useSelector } from '@tarojs/redux'; import { connect, useSelector } from '@tarojs/redux';
import { Customer } from '@/types/Customer/Customer'; import { Customer } from '@/types/Customer/Customer';
import { ComponentClass } from 'react'; import { ComponentClass } from 'react';
import { ResponseDataEntity } from '@/api';
import { connectSocket } from '@/api/socket'; import { connectSocket } from '@/api/socket';
import { SOCKET_URL } from '@/constants'; import { SOCKET_URL } from '@/constants';
import { BluetoothDevice } from '@/types/Shower/Shower'; import { BluetoothDevice } from '@/types/Shower/Shower';
...@@ -331,12 +332,13 @@ class Shower extends Component { ...@@ -331,12 +332,13 @@ class Shower extends Component {
customerId: userinfo.customerId.toString(), customerId: userinfo.customerId.toString(),
campusId: userinfo.areaId, campusId: userinfo.areaId,
}) })
.then((res: ResponseDataEntity<DeviceInfoResponse>) => { .then(res => {
const data = res.data; const data = res.data;
updateBluetoothDevice({ updateBluetoothDevice({
code: data.code, code: data.code,
isOnlyBluetooth: data.isOnlyBluetooth, isOnlyBluetooth: data.isOnlyBluetooth,
position: data.position, position: data.position,
operationMode: data.operationMode,
}); });
}) })
.catch(err => { .catch(err => {
...@@ -649,6 +651,63 @@ class Shower extends Component { ...@@ -649,6 +651,63 @@ class Shower extends Component {
}); });
} }
checkUserMonry() {
const { userinfo } = this.props;
return getShowerController({
customerId: userinfo.customerId,
campusId: userinfo.areaId,
})
.then(res => {
console.log(res);
const {
bluetoothDevice: { operationMode },
} = this.props;
const { thresholdValue, thresholdPrompt, money, beanAmount } = res.data;
if (thresholdValue) {
if (
operationMode === OperationMode.onlyAimi &&
money < thresholdValue
) {
return this.userWarnningHandle(thresholdPrompt, money, beanAmount);
}
if (
(operationMode === OperationMode.aimiFirst ||
operationMode === OperationMode.beanFirst) &&
money + beanAmount < thresholdValue
) {
return this.userWarnningHandle(thresholdPrompt, money, beanAmount);
}
return Promise.resolve();
}
return Promise.resolve();
})
.catch(console.error);
}
userWarnningHandle(thresholdPrompt, money, beanAmount) {
Taro.hideLoading();
console.log('in userWarnningHandle');
let arr = [money, beanAmount];
let i = -1;
return Taro.showModal({
title: '提示',
content: thresholdPrompt.replace(/(\{.*?\})/g, () => {
i++;
return arr[i];
}),
}).then(res => {
if (res.confirm) {
Taro.showLoading({
title: '开启中',
mask: true,
});
return Promise.resolve();
} else {
return Promise.reject();
}
});
}
startUseShower(reConnect: boolean) { startUseShower(reConnect: boolean) {
if (!reConnect) { if (!reConnect) {
Taro.showLoading({ Taro.showLoading({
...@@ -660,7 +719,8 @@ class Shower extends Component { ...@@ -660,7 +719,8 @@ class Shower extends Component {
if (!sockedDone) { if (!sockedDone) {
this.connectDeviceSocket(); this.connectDeviceSocket();
} }
this.startDevicesDiscovery() this.checkUserMonry()
.then(() => this.startDevicesDiscovery())
.then((deviceId: string) => this.createConnection(deviceId)) .then((deviceId: string) => this.createConnection(deviceId))
.then(this.getDeviceServices) .then(this.getDeviceServices)
.then(res => { .then(res => {
......
import { OperationMode } from '@/api/shower';
export type BluetoothDevice = { export type BluetoothDevice = {
code: string; code: string;
isOnlyBluetooth: number; isOnlyBluetooth: number;
operationMode: OperationMode;
position: string; position: string;
}; };
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