ReedawFoodApp/pageTwo/devices/PCL22S.vue

172 lines
4.2 KiB
Vue
Raw Normal View History

2025-05-30 11:14:38 +08:00
<template>
<view class="weightPages">
<view class="content ">
<view class="title">连接成功开始测量</view>
<view class="text">{{text}}</view>
<view class="image">
<image src="/pageTwo/static/PCL.gif" class="image3"></image>
</view>
<view class="tips">
<view>提示</view>
<text>1.请确定设备已开机</text>
<text>2.请确定手机蓝牙及位置信息已打开</text>
</view>
</view>
<!-- 手动记录 -->
<view class="wrapper" v-if="isHeight">
<view class="bg"></view>
<view class="Blue">
<view class="h4">测量结果提示</view>
<view class="Blue-box">
本次测量体重为<text>{{weight}}{{unit}}</text>
</view>
<view class="Blue-box">
上次测量身高为<input v-model="height" type="digit" placeholder="请输入身高" />cm
</view>
<view class="Blue-btn Blue-close" @click="handleBack">取消</view>
<view class="Blue-btn" @click="handleGetMeasure">保存测量结果</view>
</view>
</view>
</view>
</template>
<script>
import {
mapState
} from "vuex";
let myTime;
export default {
data() {
return {
text: "",
imp: "",
weight: "",
height: "",
deviceId: "",
unit: "kg",
isHeight: false,
stopblue: false,
typeInfo: -1,
}
},
computed: {
2026-03-25 17:27:29 +08:00
...mapState(["user", "bleValue"]),
2025-05-30 11:14:38 +08:00
info() {
return this.user
},
},
onLoad(options) {
let that = this
that.text = ""
that.typeInfo = -1
that.stopblue = false
that.deviceId = options.deviceId
that.height = that.user.height
2026-03-25 17:27:29 +08:00
that.onBluetoothDeviceFound()
2025-05-30 11:14:38 +08:00
},
2026-03-27 10:04:26 +08:00
onUnload: function() {
let that = this
2026-03-30 10:02:10 +08:00
that.$store.commit("changeBluetoothValue", {
isFood: false,
isConnectStatus: 1,
bleTipsText: "点击重新连接",
})
2026-03-27 10:04:26 +08:00
that.$store.commit("changehomeCard", 0);
that.$ble.stopBluetoothDevicesDiscovery() //取消蓝牙搜索
},
2025-05-30 11:14:38 +08:00
watch: {
stopblue: function() {
let that = this
if (!that.stopblue) {
that.isHeight = false
return
}
if (that.stopblue && that.typeInfo == '1') {
that.isHeight = true
}
}
},
methods: {
/**
* 发现外围设备
*/
2026-03-25 17:27:29 +08:00
onBluetoothDeviceFound() {
var that = this
uni.onBluetoothDeviceFound(res => {
res.devices.forEach(device => {
device.advertisData = device.advertisData ? device.advertisData : ''
if (device.name.toLowerCase().indexOf("da") !== -1) {
clearTimeout(myTime);
let value = that.$tools.ab2hex(device.advertisData, "")
let type = value.substring(0, 1) //d测量e锁定
let type2 = value.substring(1, 2) //0~9体脂A~F体重
let weight = parseInt(value.substring(2, 6), 16) / 100
console.log("VALUE", value, type, isNaN(type2), weight)
if (type == "d") {
that.typeInfo = 0
that.stopblue = false
that.text = "您的实时体重是:" + weight + 'kg'
}
if (type == "e") {
that.typeInfo = 1
that.text = "您的稳定体重是:" + weight + 'kg'
that.imp = !isNaN(type2) ? parseInt(value.substring(6, 10), 16) : ''
that.weight = weight
that.stopblue = true
that.$ble.stopBluetoothDevicesDiscovery() //取消蓝牙搜索
return
}
return;
2026-03-23 09:50:49 +08:00
}
2026-03-25 17:27:29 +08:00
})
});
2025-05-30 11:14:38 +08:00
},
// 保存测量结果
handleGetMeasure() {
let that = this
if (!that.height) {
this.$tools.msg("请输入身高")
return
}
that.$model.getmeasurefunit({
adc: that.imp,
weight: that.weight + that.unit,
height: that.height,
2026-03-25 17:27:29 +08:00
aud_id: that.user.aud_id,
2025-05-30 11:14:38 +08:00
}).then(res => {
that.isHeight = false
console.log("res", res, that.imp)
if (res.code == 0) {
that.$store.dispatch('getUserInfo', {
2026-03-25 17:27:29 +08:00
aud_id: that.user.aud_id
2025-05-30 11:14:38 +08:00
})
that.$store.dispatch("getResult", {
2026-03-25 17:27:29 +08:00
aud_id: that.user.aud_id
2025-05-30 11:14:38 +08:00
})
that.$tools.msg("测量成功")
} else {
that.$tools.msg("测量失败")
}
setTimeout(function() {
2026-03-27 10:04:26 +08:00
that.handleBack()
2025-05-30 11:14:38 +08:00
}, 200)
})
},
//
handleBack() {
let that = this
that.text = ""
uni.switchTab({
2026-03-25 17:27:29 +08:00
url: "/pages/index/index"
2025-05-30 11:14:38 +08:00
})
},
},
}
</script>
<style scoped lang="scss">
.image3 {
width: 200px !important;
height: 340px !important;
}
</style>