ReedawFoodApp/pageTwo/devices/PCL.vue

185 lines
4.6 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view class="weightPages">
<view class="content ">
<view class="title">{{$t("linkBluetoothSuccess")}}</view>
<view class="text">{{text}}</view>
<view class="image">
<image src="/pageTwo/static/PCL.gif" class="image3"></image>
</view>
<view class="tips">
<text>{{$t("msgTitle")}}:</text>
<text>1.{{$t("onDeviceBluetoothTips")}}</text>
<text>2.{{$t("openDeviceeMeasureTips")}}</text>
</view>
</view>
<!-- 手动记录 -->
<view class="wrapper" v-if="isHeight">
<view class="bg"></view>
<view class="Blue">
<view class="h4">{{$t("measureResultTips")}}</view>
<view class="Blue-box">
{{$t("nowWeight")}}<text>{{weight}}{{unit}}</text>
</view>
<view class="Blue-box">
{{$t("lastHeight")}}<input v-model="height" type="digit" :placeholder="$t('verifyHeight')" />cm
</view>
<view class="Blue-btn Blue-close" @click="handleBack">{{$t("remeasure")}}</view>
<view class="Blue-btn" @click="handleGetMeasure">{{$t("SaveResult")}}</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: true,
}
},
computed: {
...mapState(["user", "bleValue", "isBluetoothTyle"]),
info() {
return this.user
},
},
onLoad(options) {
let that = this
that.text = ""
that.stopblue = true
that.deviceId = options.deviceId
that.height = that.user.height
that.onBluetoothDeviceFound()
},
onUnload: function() {
let that = this
that.$store.commit("changeBluetoothValue", {
isFood: false,
isConnectStatus: 1,
bleTipsText: that.$t("ConnectionTimeout"),
})
that.$store.commit("changehomeCard", 0);
that.$ble.stopBluetoothDevicesDiscovery() //取消蓝牙搜索
},
watch: {
isBluetoothTyle: function() {
let that = this
if (!that.isBluetoothTyle) {
that.$tools.showModal(that.$t("linkBluetoothFail2"))
}
},
stopblue: function() {
let that = this
if (!that.stopblue) {
that.isHeight = true
}
}
},
methods: {
/**
* 发现外围设备
*/
onBluetoothDeviceFound() {
var that = this
uni.onBluetoothDeviceFound(res => {
res.devices.forEach(device => {
device.advertisData = device.advertisData ? device.advertisData : ''
if (device.name.toLowerCase().indexOf("pcl") !== -1 && device.deviceId.indexOf(that
.deviceId) != -1) {
let value = that.$tools.ab2hex(device.advertisData, "")
let data = parseInt(value.substring(4, 8), 16)
let msg = parseInt(value.substring(16, 18), 16).toString(2)
let type = msg.substring(5, 6) //0实时,1稳定
let num = msg.substring(3, 5) //小数点
let dw = msg.substring(1, 3) //单位
if (dw == "01") {
that.unit = "斤"
}
if (dw == "10") {
that.unit = "lb"
}
if (num == "00") {
data = data / 10
}
if (num == "10") {
if (dw == "10") {
that.unit = "lb"
data = data / 10
} else {
data = data / 100
}
}
that.text = that.$t("realTimeWeight") + data + that.unit
if (type == "1") {
that.text = that.$t("StableWeight") + data + that.unit
that.imp = parseInt(value.substring(8, 12), 16) / 10
that.deviceId = device.deviceId
that.weight = data
that.stopblue = false
that.$ble.stopBluetoothDevicesDiscovery() //取消蓝牙搜索
return
}
return;
}
})
});
},
// 保存测量结果
handleGetMeasure() {
let that = this
if (!that.height) {
this.$tools.msg(that.$t("verifyHeight"))
return
}
that.$model.getmeasurefunit({
adc: that.imp,
weight: that.weight + that.unit,
height: that.height,
aud_id: that.user.aud_id,
}).then(res => {
that.isHeight = false
if (res.code == 0) {
that.$store.dispatch('getUserInfo', {
aud_id: that.user.aud_id
})
that.$store.dispatch("getResult", {
aud_id: that.user.aud_id
})
that.$tools.msg(that.$t("msgSuccess"))
} else {
that.$tools.msg(that.$t("msgFail"))
}
setTimeout(function() {
that.handleBack()
}, 200)
})
},
//
handleBack() {
let that = this
that.text = ""
uni.switchTab({
url: "/pages/index/index"
})
},
},
}
</script>
<style scoped lang="scss">
.image3 {
width: 200px !important;
height: 340px !important;
}
</style>