ReedawFoodApp/pageTwo/devices/PCL22.vue

199 lines
5.0 KiB
Vue
Raw Normal View History

2025-05-30 11:14:38 +08:00
<template>
<view class="weightPages">
<view class="content ">
2026-04-11 11:37:58 +08:00
<view class="title">{{$t("linkBluetoothSuccess")}}</view>
2025-05-30 11:14:38 +08:00
<view class="text">{{text}}</view>
<view class="image">
<image src="/pageTwo/static/PCL.gif" class="image3"></image>
</view>
<view class="tips">
2026-04-11 11:37:58 +08:00
<text>{{$t("msgTitle")}}:</text>
<text>1.{{$t("onDeviceBluetoothTips")}}</text>
<text>2.{{$t("openDeviceeMeasureTips")}}</text>
2025-05-30 11:14:38 +08:00
</view>
</view>
<!-- 手动记录 -->
<view class="wrapper" v-if="isHeight">
<view class="bg"></view>
<view class="Blue">
2026-04-11 11:37:58 +08:00
<view class="h4">{{$t("measureResultTips")}}</view>
2025-05-30 11:14:38 +08:00
<view class="Blue-box">
2026-04-11 11:37:58 +08:00
{{$t("nowWeight")}}<text>{{weight}}{{unit}}</text>
2025-05-30 11:14:38 +08:00
</view>
<view class="Blue-box">
2026-04-11 11:37:58 +08:00
{{$t("lastHeight")}}<input v-model="height" type="digit" :placeholder="$t('verifyHeight')" />cm
2025-05-30 11:14:38 +08:00
</view>
2026-04-11 11:37:58 +08:00
<view class="Blue-btn Blue-close" @click="handleBack">{{$t("remeasure")}}</view>
<view class="Blue-btn" @click="handleGetMeasure">{{$t("SaveResult")}}</view>
2025-05-30 11:14:38 +08:00
</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-04-11 11:37:58 +08:00
...mapState(["user", "bleValue", "isBluetoothTyle"]),
2025-05-30 11:14:38 +08:00
info() {
return this.user
},
},
onLoad(options) {
let that = this
that.text = ""
that.typeInfo = -1
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,
2026-04-11 11:37:58 +08:00
bleTipsText: that.$t("ConnectionTimeout"),
2026-03-30 10:02:10 +08:00
})
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: {
2026-04-11 11:37:58 +08:00
isBluetoothTyle: function() {
let that = this
if (!that.isBluetoothTyle) {
that.$tools.showModal(that.$t("linkBluetoothFail2"))
}
},
2025-05-30 11:14:38 +08:00
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 : ''
let value = that.$tools.ab2hex(device.advertisData, "")
let type = value.substring(0, 2)
if (type.toLowerCase() == 'c0') {
let msg = parseInt(value.substring(16, 18), 16).toString(2)
let type = msg.substring(0, 1) //类型 0体重1体脂
let unit = msg.substring(1, 3) //单位
let num = msg.substring(3, 5) //小数点
let weight = parseInt(value.substring(4, 8), 16)
let status = msg.substring(5, 6) //0实时,1稳定
console.log("value", value, "状态:", status, "类型:", type, )
console.log('体重:', weight, "小数点:", num, "单位:", unit)
2025-05-30 11:14:38 +08:00
if (unit == "10") {
that.unit = "lb"
2026-03-25 17:27:29 +08:00
}
if (num == "00") {
2025-05-30 11:14:38 +08:00
weight = weight / 10
}
2026-04-07 15:16:46 +08:00
if (num == "01") {
that.unit = "斤"
}
2026-03-25 17:27:29 +08:00
if (num == "10") {
if (unit == "10") {
that.unit = "lb"
weight = weight / 10
} else {
weight = weight / 100
}
}
if (status == "0") {
that.typeInfo = 0
that.stopblue = false
2026-04-11 11:37:58 +08:00
that.text = that.$t("realTimeWeight") + weight + that.unit
2026-03-25 17:27:29 +08:00
}
if (status == "1") {
if (type == '1') {
that.imp = parseInt(value.substring(8, 12), 16) / 10
}
that.typeInfo = 1
2026-04-11 11:37:58 +08:00
that.text = that.$t("StableWeight")+ weight + that.unit
2026-03-25 17:27:29 +08:00
that.weight = weight
that.stopblue = true
that.$ble.stopBluetoothDevicesDiscovery() //取消蓝牙搜索
console.log("测量完成", that.weight, that.imp)
2025-05-30 11:14:38 +08:00
}
2026-03-25 17:27:29 +08:00
return;
2025-05-30 11:14:38 +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) {
2026-04-11 11:37:58 +08:00
this.$tools.msg(that.$t("verifyHeight"))
2025-05-30 11:14:38 +08:00
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
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
})
2026-04-11 11:37:58 +08:00
that.$tools.msg(that.$t("msgSuccess"))
2025-05-30 11:14:38 +08:00
} else {
2026-04-11 11:37:58 +08:00
that.$tools.msg(that.$t("msgFail"))
2025-05-30 11:14:38 +08:00
}
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>