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 = {
deviceCode: string;
......@@ -8,12 +14,15 @@ type ShowerParams = {
export type DeviceInfoResponse = {
code: string;
isOnlyBluetooth: number;
operationMode: OperationMode;
position: string;
};
/**
* 通过设备码获取设备信息
*/
export const fetchShowerInfo = (params: ShowerParams) =>
export const fetchShowerInfo = (
params: ShowerParams,
): Promise<ResponseDataEntity<DeviceInfoResponse>> =>
showerFetch({
url: `/dcxy/api/shower/devices/${params.deviceCode}`,
data: params,
......@@ -46,3 +55,21 @@ export const startShowerEquipment = (params: StartParams) =>
method: 'POST',
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 {
DeviceInfoResponse,
startShowerEquipment,
fetchUsingShowerInfo,
getShowerController,
OperationMode,
} from '@/api/shower';
import { connect, useSelector } from '@tarojs/redux';
import { Customer } from '@/types/Customer/Customer';
import { ComponentClass } from 'react';
import { ResponseDataEntity } from '@/api';
import { connectSocket } from '@/api/socket';
import { SOCKET_URL } from '@/constants';
import { BluetoothDevice } from '@/types/Shower/Shower';
......@@ -331,12 +332,13 @@ class Shower extends Component {
customerId: userinfo.customerId.toString(),
campusId: userinfo.areaId,
})
.then((res: ResponseDataEntity<DeviceInfoResponse>) => {
.then(res => {
const data = res.data;
updateBluetoothDevice({
code: data.code,
isOnlyBluetooth: data.isOnlyBluetooth,
position: data.position,
operationMode: data.operationMode,
});
})
.catch(err => {
......@@ -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) {
if (!reConnect) {
Taro.showLoading({
......@@ -660,7 +719,8 @@ class Shower extends Component {
if (!sockedDone) {
this.connectDeviceSocket();
}
this.startDevicesDiscovery()
this.checkUserMonry()
.then(() => this.startDevicesDiscovery())
.then((deviceId: string) => this.createConnection(deviceId))
.then(this.getDeviceServices)
.then(res => {
......
import { OperationMode } from '@/api/shower';
export type BluetoothDevice = {
code: string;
isOnlyBluetooth: number;
operationMode: OperationMode;
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