You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1231 lines
40 KiB
TypeScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import { go, getStorageSync, setStorageSync, msg } from "@/utils/traoAPI";
import { getBindInstrumentListApi } from "@/utils/carePlanApi";
import { InstrumentInfo } from "@/utils/Interface";
import dayjs from "dayjs";
import Taro from "@tarojs/taro";
import { minSecToS, s_to_ms, s_to_hms, sleep, s_to_s } from "@/utils/util";
// 设备运行时间校准频率,每多少秒校准一次
const TIME_CALIBRATION_FREQUENCY = 5;
const MODE_WORKING_ENUM = {
STANDBY: "standby", // 待命
WORKING: "working", // 工作
PAUSE: "pause",
END: "end",
};
let WL200Function = {
pop: { //弹窗
onModeLockClose: function () { //该模式即将上线,敬请期待弹窗
this.setState({ isModeLock: false });
},
openStepTips: function () { //每次进入设备运行页,打开首个模式的介绍弹窗
let isFirstEntryModeNot = getStorageSync(
"isFirstEntryMode_" + this.state.currentDevice.id
);
// 1.如果没有持久化不再提示,每次进入都会弹窗提示
if (!isFirstEntryModeNot) {
// 2.必须要有数据才弹窗
if (this.tempModeCurrent.openSourceData.length > 0) {
this.setState({ isShowStepTips: true });
this.handleVideoPause()
return;
}
}
this.handleVideoPlay()
},
onTipShowClose: function () { // 首次使用介绍弹窗
setStorageSync("first_instrument_" + this.state.currentDevice.id, true);
this.setState({ isFirstTipShow: false });
this.openStepTips(); // 弹出首个模式弹窗
},
cancelEndBtn: function () { //结束护理关闭弹窗
this.setState({
isEndCarePlan: false,
});
},
confirmEndBtn: function () { //结束护理确认弹窗
console.log("confirmEndBtn", this.isCheckNurseTime());
if (this.isCheckNurseTime()) {
this.endNurseFun();
this.cancelEndBtn();
} else {
setTimeout(() => {
this.bluetoothContainer.handleWorkStatus(false, "end");
}, 500);
this.setState({
isEndCarePlan: false,
isNotEnoughTime: true,
});
}
},
switchModeCurrentFun: function (data) { /** 切换护理模式 */
this.tempModeCurrent = data;
this.setState({
SwitchActiveModeItem: data,
SwitchActiveModeID: data.id,
SwitchModeID: "mode_" + data.id,
});
if (!this.state.isShowNurse) {
console.log("切换护理模式");
this.onEmitErrorTips();
}
},
openModeSwitch: function () { // 打开模式切换弹窗
console.log("openModeSwitch");
let { ActiveModeItem } = this.state;
this.tempModeCurrent = ActiveModeItem;
this.setState({
isSwitchActiveMode: true,
SwitchActiveModeItem: ActiveModeItem,
SwitchActiveModeID: ActiveModeItem.id,
SwitchModeID: "mode_" + ActiveModeItem.id,
});
},
onModeLockOpen: function () {
this.setState({ isModeLock: true });
},
cancelModeSwitchBtn: function () { //护理模式切换- 取消并关闭切换护理模式弹窗
let { ActiveModeItem } = this.state;
this.tempModeCurrent = ActiveModeItem;
this.setState({
isSwitchActiveMode: false,
});
},
confirmModeSwitchBtn: function () { // 弹窗确定切换护理模式
let { SwitchActiveModeItem, isStandStatus } = this.state;
this.cancelModeSwitchBtn();
// 2.检测是否满足最低护理时间
if (this.isCheckNurseTime()) {
// 3.满足时间条件,提示是否保存部分护理记录
this.setState({
isShowTipsSave: true,
});
}
// 判断是否连接支架
if (SwitchActiveModeItem.isCabinMode && !isStandStatus) {
this.showTips(
`检测到舱体未连接成功,请确认面罩开机后与舱体连接,并接通舱体电源`
);
return;
} else if (!SwitchActiveModeItem.isCabinMode && isStandStatus) {
this.showTips(`检测到面罩仍和舱体连接中,请分离后切换`);
return;
}
this.modeCurrentFun(SwitchActiveModeItem);
this.setState({
ModeType: this.ModeArray[SwitchActiveModeItem.modeClass],
});
},
closeStepTips: function (data) { //使用教程弹窗
if (data.isLocal) {
setStorageSync("isFirstEntryMode_" + this.state.currentDevice.id, true); // 关闭首次进入弹窗
}
this.setState({ isShowStepTips: false });
setTimeout(() => this.handleVideoPlay(), 0)
},
closeNotEnoughTime: function () { //本次护理时间不足弹窗
Taro.removeStorageSync("WL200NursingHistory");
this.setState({
isNotEnoughTime: false,
});
Taro.reLaunch({
url: "/pages/index/index",
});
},
closeErrorTipsText: function () { // 关闭通用错误弹窗
this.setState({
isShowErrorTipsText: false,
});
},
closeTipsSave: function () {// 手动护理模式切换:提示是否保存护理/**仅关闭*/
let { SwitchActiveModeItem, isStandStatus } = this.state;
// 重连中状态赋值false
this.isBluetoothReconnectionIng = false;
this.setState({
isShowTipsSave: false,
});
// 判断是否连接支架
if (SwitchActiveModeItem.isCabinMode && !isStandStatus) {
this.showTips(
`检测到舱体未连接成功,请确认面罩开机后与舱体连接,并接通舱体电源`
);
return;
} else if (!SwitchActiveModeItem.isCabinMode && isStandStatus) {
this.showTips(`检测到面罩仍和舱体连接中,请分离后切换`);
return;
}
// 不处于暂停状态时,继续倒计时
if (!this.state.isStopNurse) {
this.resetTimer()
}
},
cancelTipsSave: function () {/**关闭+切换*/
let { isStandStatus } = this.state;
this.setState({
isShowTipsSave: false,
});
// 判断是否连接支架
if (this.tempModeCurrent.isCabinMode && !isStandStatus) {
this.showTips(
`检测到舱体未连接成功,请确认面罩开机后与舱体连接,并接通舱体电源`
);
this.isBluetoothReconnectionIng = false;
return;
} else if (!this.tempModeCurrent.isCabinMode && isStandStatus) {
this.showTips(`检测到面罩仍和舱体连接中,请分离后切换`);
this.isBluetoothReconnectionIng = false;
return;
}
if (this.isBluetoothReconnectionIng) {
// 重连中状态赋值false
this.isBluetoothReconnectionIng = false;
return;
}
this.modeCurrentFun(this.tempModeCurrent, true); // 不提交护理记录,也不进行校验
},
confirmTipsSave: function () {/**关闭+提交+切换*/
let { isStandStatus } = this.state;
this.setState({
isShowTipsSave: false,
});
// 判断是否连接支架
if (this.tempModeCurrent.isCabinMode && !isStandStatus) {
this.showTips(
`检测到舱体未连接成功,请确认面罩开机后与舱体连接,并接通舱体电源`
);
this.isBluetoothReconnectionIng = false;
return;
} else if (!this.tempModeCurrent.isCabinMode && isStandStatus) {
this.showTips(`检测到面罩仍和舱体连接中,请分离后切换`);
this.isBluetoothReconnectionIng = false;
return;
}
if (this.isBluetoothReconnectionIng) {
// 重连中状态赋值false
this.isBluetoothReconnectionIng = false;
return;
}
this.PostNursingLogClock(null, false); // 先提交护理记录
setTimeout(() => {
this.modeCurrentFun(this.tempModeCurrent, true); // 不进行校验
}, 100)
},
firstNurseInfo: async function () { /** 初次护理信息弹窗 */
let { currentDevice } = this.state;
let res = await InstrumentInfo.firstNurseInfo({
instrumentId: currentDevice.id,
});
console.log(res, "接口");
if (res.data.code === 200) {
let isFirstTipShow = getStorageSync(
"first_instrument_" + currentDevice.id
);
console.log(isFirstTipShow, "查看返回值");
if (!isFirstTipShow) {
if (res.data.data.length !== 0) {
// 首次进入页面:自动打开打卡介绍弹窗
this.setState({ nurseInfo: res.data.data, isFirstTipShow: true });
}
setStorageSync("first_instrument_" + currentDevice.id, true);
} else {
this.setState({ nurseInfo: res.data.data });
}
}
},
showTips: function (ctx) {// 护理的错误提示
if (!ctx) return;
if (this.showTipsTimer) clearTimeout(this.showTipsTimer);
this.setState({
errorTips: ctx,
});
this.showTipsTimer = setTimeout(() => {
this.setState({
errorTips: "",
});
}, 2000);
},
openErrorTipsText: function (str) { // 打开通用错误弹窗
this.setState({
isShowErrorTipsText: true,
errorTipsText: str,
});
}
},
PreparationPage: { //准备页
GetBindInstrumentListApi: async function () { //获取护理计划的模式
let PlanNowProgress = Taro.getStorageSync("PlanNowProgress");
if (PlanNowProgress) {
let res: any = await getBindInstrumentListApi({
planId: PlanNowProgress.planId,
});
if (res.data.code !== 200) return;
console.log("WL200 GetBindInstrumentListApi", res);
if (res.data.data) {
let planFilterModeArray = res.data.data.filter((item: any) => {
return item.instrumentId === this.state.currentDevice.id;
});
this.setState({
planFilterModeArray,
});
}
}
},
GetModeList: async function (id) { //获取模式列表
let params = {
instrumentId: id,
};
let res = await InstrumentInfo.modeInfoList(params);
if (res.data.code === 200) {
if (res.data.data.length > 0) {
// planFilterModeArray
let { planFilterModeArray } = this.state;
// 过滤出不是医美的分类
let ModeList = res.data.data.filter((item) => item.modeClass !== 3);
// 过滤出医美分类的模式
let YimeiModeList = res.data.data.filter(
(item) => item.modeClass === 3
);
if (YimeiModeList.length) {
let planModeIds = planFilterModeArray
.map((item) => {
if (item.model === "WL200") {
return item.modeId;
}
return "";
})
.filter((item) => item);
// 护理计划存在的医美分类模式增加到ModeList尾部
YimeiModeList.forEach((item) => {
if (planModeIds.includes(item.id)) {
ModeList.push(item);
}
});
}
this.setState({
ModeList: ModeList,
});
setTimeout(() => {
// 判断是否同步记录进入设备页
let isSyncHistory = Taro.getStorageSync("isSyncHistory");
if (!isSyncHistory) {
console.log(this.state.activeModeID, 'this.state.activeModeID');
if (this.state.activeModeID == "") {
// 只有不是读取记录,才选中默认第一个
this.tempModeCurrent = res.data.data[0];
this.modeCurrentFun(res.data.data[0]);
} else {
let item = res.data.data.find(e => e.id == this.state.activeModeID)
// 只有不是读取记录,才选中默认第一个
this.tempModeCurrent = item;
this.modeCurrentFun(item);
}
}
}, 100);
} else {
this.setState({ ModeList: [] });
}
}
},
modeCurrentFun: function (data, isNotCheck) { /** 选中护理模式 */
if (data.lock) {
this.onModeLockOpen();
return;
}
console.log("modeCurrentFun", data, isNotCheck);
// 护理检查改变模式,是否提示切换护理模式
// isNotCheck为真时不进行校验直接切换
this.tempModeCurrent = data;
// 仅在未开始护理前,切换模式的时候提示模式弹窗
if (!this.state.isShowNurse) {
this.openStepTips();
}
// 如果按钮不可点击则报错,内部自带检查底部按钮函数
this.onEmitErrorTips();
if (!isNotCheck) {
let isReturn = this.modeRuningChange();
if (isReturn) return;
}
let { isShowNurse } = this.state;
let currentServiceData = {
startSource: "",
stopSource: "",
};
if (data.serviceData.length) {
currentServiceData = data.serviceData[0];
}
console.log("currentServiceData", currentServiceData);
let currentTime = data.modeTimeStr;
this.setState({
ActiveModeItem: data,
activeModeID: data.id,
SwitchActiveModeID: data.id,
ModeID: "mode_" + data.id,
SwitchModeID: "mode_" + data.id,
currentServiceData,
ModeStepIndex: 0,
currentTime,
// ModeType: modeArray[data.modeClass],
});
setTimeout(() => {
this.handleVideoPlay()
}, 100);
// 只有点击过开始,才隐藏其他模式类型
if (isShowNurse) {
this.setState({
ModeType: this.ModeArray[data.modeClass],
});
}
setTimeout(() => {
// 设置时间组合
if (data.serviceData.length > 0) {
this.setServiceTimeData();
}
// 存在组合模式时,设置组合模式
if (data.combineData.length > 0) {
this.setCustomMaskData();
}
});
console.log("isShowNurse", isShowNurse);
let isDisabled = this.footerIsDisabled();
console.log("isDisabled", isDisabled);
// 如果是正在运行中切换,则直接准备运行
if (isShowNurse) {
// 如果切换模式,则不执行开始逻辑
if (!isDisabled) {
this.stepNext();
setTimeout(() => {
this.onNursingTap("switch");
}, 800);
}
}
},
modeCurrentFunForce: function (data) { /** 选中护理模式 */
// 护理检查改变模式,是否提示切换护理模式
// isNotCheck为真时不进行校验直接切换
this.tempModeCurrent = data;
if (this.currentTimeTimer) {
clearInterval(this.currentTimeTimer);
this.currentTimeTimer = null;
}
let currentServiceData = {
startSource: "",
stopSource: "",
};
if (data.serviceData.length) {
currentServiceData = data.serviceData[0];
}
let currentTime = data.modeTimeStr;
this.setState({
ActiveModeItem: data,
activeModeID: data.id,
SwitchActiveModeID: data.id,
ModeID: "mode_" + data.id,
SwitchModeID: "mode_" + data.id,
currentServiceData,
ModeStepIndex: 0,
currentTime,
});
setTimeout(() => {
this.handleVideoPlay()
}, 100);
setTimeout(() => {
// 设置时间组合
if (data.serviceData.length > 0) {
this.setServiceTimeData();
}
// 存在组合模式时,设置组合模式
if (data.combineData.length > 0) {
this.setCustomMaskData();
}
});
// 强制切换运行
this.workStatus = "working";
this.setState({
ModeType: this.ModeArray[data.modeClass],
isShowNurse: true,
isStopNurse: false,
step: 2,
});
setTimeout(() => {
this.onNursingTap("switch");
}, 200);
},
modeRuningChange: function () { /** 设备运行中切换模式 */
// 运行中切换模式逻辑
if (
this.workStatus === MODE_WORKING_ENUM.PAUSE ||
this.workStatus === MODE_WORKING_ENUM.WORKING
) {
const { totalWorkingMinutes, totalWorkingSeconds } = this.DeviceSyncData;
const totalTime = totalWorkingMinutes * 60 + totalWorkingSeconds; // 设备时间
if (!this.tempModeCurrent || totalTime === 0) {
return false;
}
if (this.state.step == 2 && this.state.facialMaskConnectStatus == 1) {
// 提示切换护理模式
if (this.isCheckNurseTime()) {
// 满足时间条件,提示是否保存部分护理记录
this.judgementWorkStatus(
MODE_WORKING_ENUM.PAUSE,
this.tempModeCurrent?.modeType
);
this.setState({
isShowTipsSave: true,
});
return true;
}
}
}
return false;
},
},
Bluetooth: { //蓝牙弹窗
listener: function (res) { // 断开链接触发
console.log("listener res", res);
if (res?.connected) return;
// 蓝牙未连接才执行下面逻辑
Taro.offBLECharacteristicValueChange((res) => {
console.log("offBLECharacteristicValueChange", res);
});
// console.log(commandMap.WL200Command, "监听到蓝牙断开, 打开断开提示");
this.workStatus = "";
if (this.currentTimeTimer) {
clearInterval(this.currentTimeTimer);
this.currentTimeTimer = null;
}
if (this.loadingTipsTimer) clearTimeout(this.loadingTipsTimer);
// 显示蓝牙断开弹窗
this.setState({
isConnectShow: true, // 打开蓝牙链接弹窗
isConnectionBlutoot: false, // 是否已连接蓝牙:未连接,已断开蓝牙
isShowCountdown: false, // 关闭倒计时,防止倒计时还在运行
countdown: 0,
});
this.footerIsDisabled();
},
bluetoothDisconnectProcessing: function () { //蓝牙断开连接处理
Taro.offBLEConnectionStateChange(this.listener); // 需传入与监听时同一个的函数对象
Taro.offBLECharacteristicValueChange((res) => {
console.log("offBLECharacteristicValueChange", res);
});
if (!this.state.isToOTA) {
Taro.closeBluetoothAdapter();
}
},
pairingChange: function () { // 完成配对
console.log("pairingChange");
// 重连蓝牙初始化监听
this.init();
this.setState({
isConnectionBlutoot: true, // 是否已连接蓝牙:已连接蓝牙
facialMaskConnectStatus: 1
})
setTimeout(() => {
this.setState({
isConnectShow: false,
});
}, 2000)
},
connectionClose: function () {
this.setState({
isConnectShow: false,
});
// 断线时,如果已运行时间满足最低运行时间,则直接提交结束任务
if (this.isCheckNurseTime()) {
this.endNurseFun();
} else {
// Taro.switchTab({ url: "/pages/index/index" });
this.WL200NursingHistory.id = "";
this.setState({ isNotEnoughTime: true });
}
}
},
NursinControlFunction: { //护理中控制功能
// 时间倒计时
updateDeviceSyncData: function (newData, jsonStatus) { //仪器返回实时数据
this.DeviceSyncData = {
...this.DeviceSyncData,
...newData,
};
if (newData.hasOwnProperty("totalWorkingSeconds")) {
this.renderDeviceStatus.renderWorkTime(jsonStatus);
}
},
renderWorkTime: function (jsonStatus) { //处理仪器返回的时间处理
const { totalWorkingMinutes, totalWorkingSeconds } = this.DeviceSyncData;
let { ActiveModeItem, currentTime } = this.state;
const totalTime = totalWorkingMinutes * 60 + totalWorkingSeconds;
console.log("仪器上报的已经运行的总秒数", totalTime);
console.log("时间校准频率默认5秒一次", TIME_CALIBRATION_FREQUENCY);
//对比仪器上报运行的总秒数 和小程序页面运行的已经运行的总秒数,如果不一致就进行校准
const currentScene = ActiveModeItem; // 获取当前的场景
let sceneTime = minSecToS(currentScene.modeTimeStr);
console.log("场景时间 sceneTime", sceneTime);
console.log("当前显示时间 currentTime", currentTime);
console.log("设备运行时间 totalTime", totalTime);
// 界面倒计时同步设备时间:每5秒强制同步更新一次
const showtime = sceneTime - totalTime; // 场景时间 - 已运行时间 = 剩余时间
if (showtime > 0 && showtime % 5 === 0) {
this.setState({
currentTime: s_to_ms(showtime),
});
}
// 更新界面倒计时
if (!this.currentTimeTimer && this.workStatus !== "end") {
console.log("更新界面倒计时resetTimer");
this.resetTimer();
}
// 每次同步后,更新历史缓存
setTimeout(() => {
this.updateWL200NursingHistory();
}, 100);
},
resetTimer: function () { // 重置并同步计时器
// 切换模式后, 需要重新设置计时器, 以防进行中的计时器
if (this.currentTimeTimer) {
clearInterval(this.currentTimeTimer);
this.currentTimeTimer = null;
}
this.currentTimeTimer = setInterval(() => {
let {
step,
facialMaskConnectStatus,
currentTime,
ModeStepTimeArray,
ModeStepIndex,
ActiveModeItem,
} = this.state;
if (
this.workStatus == MODE_WORKING_ENUM.WORKING &&
step == 2 &&
facialMaskConnectStatus == 1
) {
let totalSeconds = ActiveModeItem?.breakTimeStr
? minSecToS(ActiveModeItem.breakTimeStr)
: minSecToS(ActiveModeItem.modeTimeStr);
// 现在的倒计时剩余时间:同步时检查是否断开重连,如果是,则使用断开的剩余时长,进行倒计时计算
let currentSeconds = minSecToS(currentTime);
let checkTime = totalSeconds - currentSeconds;
// 缓存经过的时间:用于接口提交
this.elapsedTime = checkTime;
// // 每隔15秒发一次心跳
// if (this.elapsedTime > 10 && this.elapsedTime % 15 === 0) {
// this.hearting = true; // 心跳中,禁止切换和暂停操作
// let minuteNum = Math.floor((this.elapsedTime + 1) / 60);
// let secondsNum = Math.floor((this.elapsedTime + 1) % 60);
// setTimeout(() => {
// this.bluetoothContainer.sendsideRemind(
// ActiveModeItem?.modeType,
// minuteNum,
// secondsNum
// );
// }, 200);
// }
// 如果存在中断时间,则要加上间隔的时间
if (ActiveModeItem?.breakTimeStr) {
let intervalTime =
minSecToS(ActiveModeItem.modeTimeStr) -
minSecToS(ActiveModeItem.breakTimeStr);
this.elapsedTime += intervalTime;
}
// 判断剩余时间是否大于1
console.log("currentSeconds", currentSeconds);
if (currentSeconds > 0) {
// 小程序显示倒计时
this.setState({
currentTime: s_to_ms(--currentSeconds),
});
let length = ModeStepTimeArray.length;
if (length) {
// 模式多个步骤节点切换
// 已运行时间达到下一节点时,切换
if (checkTime > ModeStepTimeArray[ModeStepIndex]) {
// 已运行时间达到下一节点,且存在下一节点,步骤切换时更新
if (ModeStepIndex < length - 1) {
let index = ModeStepIndex + 1; // 提前步骤+1
let currentServiceData = {
startSource: "",
stopSource: "",
};
let serviceLength = ActiveModeItem.serviceData.length;
if (serviceLength > index) {
currentServiceData = ActiveModeItem.serviceData[index];
}
this.setState({
ModeStepIndex: index,
currentServiceData,
});
}
}
}
} else {
if (this.currentTimeTimer) {
clearInterval(this.currentTimeTimer)
this.currentTimeTimer = null;
}
console.log("倒计时结束了00:00");
this.setState({
currentTime: "00:00",
ModeStepIndex: 0,
facialMaskConnectStatus: 0, // 倒计时结束会关机,逻辑预先关机
});
let modeTimeSec = minSecToS(ActiveModeItem.modeTimeStr);
this.elapsedTime =
this.elapsedTime > modeTimeSec ? modeTimeSec : this.elapsedTime;
setTimeout(() => {
this.endNurseFun(); // 自动结束护理,并自动跳转报告页
});
}
}
}, 1000);
},
setLoadingTips: function (time) { // 仪器开始倒计时
this.setState({
countdown: time,
});
if (time >= 0) {
this.loadingTipsTimer = setTimeout(() => {
this.setLoadingTips(--time);
}, 1000);
} else {
// 停止倒计时
// that.data.startSettingCountDown = false;
this.setState({
isShowCountdown: false,
});
}
},
showCountdownFun: function (count, callback) { //倒计时弹窗
this.setState({
countdown: count,
});
setTimeout(() => {
if (this.CountdownTimer) clearInterval(this.CountdownTimer);
this.setState({
isShowCountdown: true,
});
this.CountdownTimer = setInterval(() => {
if (this.state.countdown === 0) {
if (this.CountdownTimer) clearInterval(this.CountdownTimer);
this.setState({
isShowCountdown: false,
});
if (callback) callback();
} else {
this.setState({
countdown: this.state.countdown - 1,
});
}
}, 1000);
}, 0);
},
// 护理中控制功能
onEndDevice: function () {
this.rmWL200NursingHistory();
// 判断护理时间,如果不足,则提示不足
if (!this.isCheckNurseTime()) {
this.setState({ isNotEnoughTime: true });
} else {
this.endNurseFun();
}
},
judgementWorkStatus: function (nWorkStatus, nWorkMode) { //设备上报不同状态
const { step, workMode, ActiveModeItem, ModeList } = this.state;
const opts: any = {};
// ActiveModeItem
let nowModeItem;
if (nWorkMode) {
nowModeItem = ModeList.find((item) => {
return item.modeType === nWorkMode;
});
}
opts.workStatus = nWorkStatus;
let nowCurrentTime = ActiveModeItem.modeTimeStr;
// 完成重连同步则删除重连时间字段
if (ActiveModeItem?.breakTimeStr) {
nowCurrentTime = ActiveModeItem?.breakTimeStr;
}
const statusF = {
sleep: () => {
this.setState({
isShowCountdown: false,
});
},
standby: () => {
this.setState({
isShowCountdown: false,
});
if (nowModeItem?.isCabinMode && step == 2) {
opts.currentTime = nowCurrentTime;
} else if (!nowModeItem?.isCabinMode && step == 2) {
// fix: 启动非支架模式倒计时时连上支架仪器的状态变为standby
opts.step = 1;
}
},
setting: () => {
// that.data.hadShowBreakTips = false;
this.setState({
hadShowBreakTips: false,
});
if (step != 2 && !ActiveModeItem.isCabinMode) {
opts.step = 2;
this.setState({
title: "正在护理",
isStopNurse: false,
});
} else if (step != 2 && ActiveModeItem.isCabinMode) {
opts.step = 2;
// this.setState({
// title: "正在护理",
// });
this.setState({
title: "正在护理",
isStopNurse: false,
});
}
if (nowModeItem) {
opts.currentTime = nowCurrentTime;
}
// startSettingCountDown 用于标记打开了倒计时loading
if (!this.state.isShowCountdown) {
this.setState({
isShowCountdown: true,
});
this.setLoadingTips(this.CountDownTime[workMode] || 6);
}
},
working: () => {
if (this.state.facialMaskConnectStatus != 1) {
opts.workStatus = MODE_WORKING_ENUM.STANDBY;
opts.step = 1;
} else if (step != 2) {
opts.step = 2;
this.setState({
title: "正在护理",
isStopNurse: false,
});
}
this.setState({
isShowCountdown: false,
hadShowBreakTips: false,
});
},
pause: () => {
if (this.currentTimeTimer) {
clearInterval(this.currentTimeTimer)
this.currentTimeTimer = null;
}
this.setState({
isShowCountdown: false,
});
if (ActiveModeItem.isCabinMode) {
this.setState({
title: "暂停护理",
isStopNurse: true,
});
}
},
end: () => {
// 已进入了报告阶段, 防止重复进入, 主要防止在手动点击结束护理接收到仪器消息
console.log("END 护理结束");
if (this.currentTimeTimer) {
clearInterval(this.currentTimeTimer)
this.currentTimeTimer = null;
}
this.endNurseFun();
},
};
statusF[nWorkStatus] && statusF[nWorkStatus]();
if (Object.keys(opts).length) {
this.setState(opts);
}
},
stepNext: function () {
// //0未定义全部 1面罩模式 2舱体模式 3医美术后
let modeClass = this.state.ActiveModeItem.modeClass;
this.workStatus = "pause";
this.setState({
ModeType: this.ModeArray[modeClass],
isShowNurse: true,
isStopNurse: true,
step: 2,
});
},
onNursingTap: function (type) { //点击开始护理
// 如果已禁止运行,则停止执行后续逻辑
if (this.state.isFooterBtnDisabled) return;
// 防止多次点击
if (this.state.hadClickStart) return;
this.setState({
hadClickStart: true,
});
setTimeout(() => {
this.setState({
hadClickStart: false,
});
}, 500);
const { isStandStatus, facialMaskConnectStatus } = this.state;
if (facialMaskConnectStatus != 1) {
this.showTips("检测到面罩未连接成功,请确认面罩开机并佩戴");
return;
}
if (this.tempModeCurrent.isCabinMode && !isStandStatus) {
this.showTips(
`检测到舱体未连接成功,请确认面罩开机后与舱体连接,并接通舱体电源`
);
return;
}
if (!this.tempModeCurrent.isCabinMode && isStandStatus) {
this.showTips(`检测到面罩仍和舱体连接中,请分离后切换`);
return;
}
if (
this.tempModeCurrent.modeType === "MaskCustom" &&
!this.state.isCombineSuccess
) {
this.showTips(
`${this.tempModeCurrent.modeName}模式设置失败,请联系小助手`
);
return;
}
// 仅在切换模式的时候,弹窗倒计时.
if (type === "switch" || this.isStandChangeFlag === true) {
this.isStandChangeFlag = false;
let downNum = this.CountDownTime[this.tempModeCurrent.modeType] || 3;
this.showCountdownFun(downNum, () => { }); // 倒计时弹窗
}
// 开始执行护理
this.workStatus = MODE_WORKING_ENUM.WORKING; // 不管当前什么状态,直接设为工作状态
this.bluetoothContainer.handleWorkStatus(true, MODE_WORKING_ENUM.WORKING);
this.setState({
isStopNurse: false,
});
},
endNurseFun: async function () { //结束护理并关机
if (this.isCheckNurseTime()) {
await this.PostNursingLogClock();
} else {
// 时间不满足,回到主页
this.setState({
isEndCarePlan: false,
isNotEnoughTime: true,
});
}
},
// 提交报告模块
PostNursingLogClock: async function (data, isJump) {// 提交报告模块
let { currentDevice, ActiveModeItem } = this.state;
let params = {};
if (data) {
params = data;
} else {
params = {
instrumentId: currentDevice.id,
instrumentName: currentDevice.name,
modeId: ActiveModeItem.id,
modeName: ActiveModeItem.modeName,
nursingTime: s_to_hms(this.elapsedTime),
};
}
let res: any = await InstrumentInfo.apiNursingLog.addLog(params);
if (res.data.code === 200) {
let params = {
instrumentId: currentDevice.id,
};
// 上传护理完成的仪器ID
let res2 = await InstrumentInfo.apiClock.addClockInstrument(params);
console.log(res2, "护理完成");
this.rmWL200NursingHistory(); // 护理完成,删除记录
if (isJump) {
this.setState({
isShowNursingSuccess: true,
});
setTimeout(() => {
this.setState({
isShowNursingSuccess: false,
});
this.goFaceReport(res.data.data);
}, 2000);
}
}
},
goFaceReport: function (id) {/** 完成护理提交:跳转护理报告页 */
// 跳转前置空定时器,防止重复提交
if (this.currentTimeTimer) {
clearInterval(this.currentTimeTimer)
this.currentTimeTimer = null;
}
// 完成提交跳转护理页前: 清空WL200缓存防止断开蓝牙导致的反复提交bug
Taro.removeStorageSync("isSyncHistory");
Taro.removeStorageSync("WL200NursingHistory");
this.WL200NursingHistory = null;
this.bluetoothContainer.handleWorkStatus(false, "end");
console.log("goFaceReport id", id);
setTimeout(() => {
Taro.redirectTo({
url: `/recoding/pages/face_report/face_report?id=${id}&recordId=${this.state.currentDevice?.id}`,
});
}, 100);
}
},
LocalStorageOfData: { //本地存储
getWL200NursingHistory: function () {/** 获取小程序本地缓存的历史记录 */
this.WL200NursingHistory = Taro.getStorageSync("WL200NursingHistory");
let isSyncHistory = Taro.getStorageSync("isSyncHistory");
if (isSyncHistory) {
this.setState({
isShowHistoryMsg: true,
});
this.WL200NursingHistory = Taro.getStorageSync("WL200NursingHistory");
}
// // 是否同步历史记录
// let isSyncHistory = Taro.getStorageSync("isSyncHistory");
// if (isSyncHistory) {
// let ActiveModeItem = this.WL200NursingHistory.ActiveModeItem;
// // 直接进入开始护理状态
// this.setState({
// isShowNurse: true,
// isShowHistoryMsg: true,
// currentServiceData: this.WL200NursingHistory.currentServiceData,
// ModeStepIndex: this.WL200NursingHistory.ModeStepIndex,
// tempModeCurrent: ActiveModeItem,
// ActiveModeItem: ActiveModeItem,
// activeModeID: ActiveModeItem.id,
// ModeID: "mode_" + ActiveModeItem.id,
// currentTime: this.WL200NursingHistory.currentTime,
// });
// setTimeout(() => {
// // 设置时间组合
// if (ActiveModeItem.serviceData.length > 0) {
// this.setServiceTimeData();
// }
// // 存在组合模式时,设置组合模式
// if (ActiveModeItem.combineData.length > 0) {
// this.setCustomMaskData();
// }
// });
// }
},
setWL200NursingHistory: function (jsonStatus) {/** 设置WL200护理历史 */
let { currentDevice, ActiveModeItem, ModeList } = this.state;
const params = {
createDate: dayjs().format("YYYY-MM-DD"),
workMode: jsonStatus.workMode,
instrumentId: currentDevice.id,
instrumentName: currentDevice.name,
modeId: ActiveModeItem.id,
modeName: ActiveModeItem.modeName,
id: jsonStatus.id,
neededTotalSeconds: jsonStatus.neededTotalSeconds,
jsonStatus,
ActiveModeItem: this.state.ActiveModeItem,
ModeStepIndex: this.state.ModeStepIndex,
currentServiceData: this.state.currentServiceData,
};
this.WL200NursingHistory = JSON.parse(JSON.stringify(params));
Taro.setStorageSync("WL200NursingHistory", params);
console.log("保存setWL200NursingHistory");
},
updateWL200NursingHistory: function (data) {
this.WL200NursingHistory = Taro.getStorageSync("WL200NursingHistory");
if (this.WL200NursingHistory) {
let params: any = this.WL200NursingHistory;
// 设置当前时间
params.currentTime = this.state.currentTime;
params.ModeStepIndex = this.state.ModeStepIndex;
// 设置正确封面
if (data) {
params.currentServiceData = data;
} else {
let currentServiceData = {
startSource: "",
stopSource: "",
};
let serviceLength = this.state.ActiveModeItem.serviceData.length;
if (serviceLength > 0) {
currentServiceData = this.state.ActiveModeItem.serviceData[0];
}
params.currentServiceData = currentServiceData;
}
Taro.setStorageSync("WL200NursingHistory", params);
console.log("更新updateWL200NursingHistory");
}
},
rmWL200NursingHistory: function () { //删除WL200护理历史
Taro.removeStorageSync("WL200NursingHistory");
this.WL200NursingHistory = null;
},
},
Footer: { //底部按钮事件
onStartNurse: function () { /** 开始护理按钮:点击开始,页面进行到下一步 */
// 如果检查通过,可运行,则执行下一步
if (!this.footerIsDisabled()) {
this.stepNext();
setTimeout(() => {
this.onNursingTap();
let downNum = this.CountDownTime[this.tempModeCurrent.modeType] || 3;
this.showCountdownFun(downNum, () => { }); // 倒计时弹窗
}, 500);
return;
}
// 如果检查失败,则报错
this.onEmitErrorTips();
},
onSwitchChange: function () {/** 切换光照 */
// todo
let { isStopNurse } = this.state;
if (isStopNurse) {
// 开始光照逻辑
this.onNursingTap();
this.setState({
isStopNurse: false,
});
} else {
// 暂停光照逻辑
// 带校验的切换开关状态
this.bluetoothContainer.handleWorkStatus(false, MODE_WORKING_ENUM.PAUSE);
this.setState({
isStopNurse: true,
});
}
},
onEndPlan: function () { /** 结束护理弹窗 */
this.setState({
isEndCarePlan: true,
});
},
onEmitErrorTips: function () { // 不可切换光照提示
setTimeout(() => {
let { ActiveModeItem, isShowNurse, isStandStatus } = this.state;
let obj: any = null;
if (isShowNurse) {
obj = ActiveModeItem;
} else {
obj = this.tempModeCurrent;
}
// 按钮不可点击时,提示报错
let isDisabled = this.footerIsDisabled();
console.log(isDisabled, 'isDisabled');
if (isDisabled) {
if (obj.isCabinMode === 0 && isStandStatus) {
this.showTips("检测到面罩与舱体仍在连接中,该模式需要分离面罩和舱体");
return;
}
if (obj.isCabinMode === 1 && !isStandStatus) {
this.showTips(
`检测到舱体未连接成功,请确认面罩开机后与舱体连接,并接通舱体电源`
);
return;
}
}
});
}
}
}
export default WL200Function