364 lines
8.9 KiB
Vue
Raw Normal View History

2025-04-14 10:57:27 +08:00
<!-- 换电 -->
<template>
2025-07-21 14:47:22 +08:00
<div class="b-body-gray">
<scroll-view scroll-y="true" :style="{ height: scrollHeight + 'px' }">
<div style="padding-top: 5px">
<uni-forms :border="true" :label-width="90">
<uni-card>
<uni-forms-item label="车辆编号:">
<bikeCodeScan
ref="refbikeScan"
v-model="bikeCode"
@scan-change="getBikeInfo"
/>
</uni-forms-item>
<uni-forms-item label="车辆状态:">
<div class="divContent divCenter">{{ formdata.online }}</div>
<div class="divContent">{{ formdata.timestamp }}</div>
</uni-forms-item>
<uni-forms-item label="老电池编号:">
<div class="divContent divCenter">
{{ formdata.oldBatteryCode }}
</div>
</uni-forms-item>
<uni-forms-item label="电池电量:">
<div class="divContent divCenter">
{{ formdata.soc ? formdata.soc : 0 }}%
</div>
</uni-forms-item>
<uni-forms-item label="车辆位置:">
<uni-list :border="false">
<uni-list-item
showArrow
title="查看地图"
:note="
formdata.latitude
? formdata.latitude + ',' + formdata.longitude
: ''
"
link="navigateTo"
clickable
@click="mapClick"
/>
<!-- :to=" '/pages/map/map-findbike?longitude=' + formdata.longitude
+ '&latitude=' + formdata.latitude " -->
</uni-list>
</uni-forms-item>
2025-04-14 10:57:27 +08:00
2025-07-21 14:47:22 +08:00
<div class="divBtn">
<text
:class="formdata.ecuId ? 'b-btn-babyblue' : 'b-btn-gray'"
v-for="item in arrEcuBtn"
@click="checkecu(item.url)"
>{{ item.title }}</text
>
</div>
<uni-forms-item label="新电池编号:">
<scanCode v-model="newBatteryCode" placeholder="请输入" />
</uni-forms-item>
<div
class="b-btn-blue"
style="text-align: center"
@click="checkecu('openBatteryLock')"
>
打开电池仓
</div>
<div style="text-align: right">
<text style="margin-right: 5px; margin-top: 5px">
<uni-icons
custom-prefix="iconfont"
type="icon-ebikeguzhangshangbao1"
size="20"
color="#999"
/>
</text>
<text class="b-font-gray-sm">电池仓打不开</text>
<text
class="b-font-blue-sm"
style="font-weight: bold"
@click="openfaultreport"
>上报故障</text
>
</div>
</uni-card>
2025-04-14 10:57:27 +08:00
2025-07-21 14:47:22 +08:00
<div style="padding: 15px">
<div
class="b-font-gray-base"
style="margin-bottom: 10px; font-weight: bold"
>
温馨提示
</div>
<div class="b-font-gray-sm">
1读取到新电池的电量即视为更换成功新的电池;
</div>
<div class="b-font-gray-sm">
2电池更换完成自动读取设备状态和电池电量过程可能需要个 几分钟
</div>
<div class="b-font-gray-sm">
3更换完成请点击下面完成换电按钮
</div>
<div class="b-font-gray-sm">
4如果直接点击更换完成电量会暂时变成41%系统检测到电
量上报后会自动变成上报的电量
</div>
</div>
</uni-forms>
</div>
</scroll-view>
</div>
2025-04-14 10:57:27 +08:00
2025-07-21 14:47:22 +08:00
<!-- <div class="divBottom">
2025-04-14 10:57:27 +08:00
<text class="b-btn-white" style="margin-right: 15px;" @click="refresh">刷新</text>
<text class="b-btn-blue" @click="completebatter">完成换电</text>
2025-04-28 11:40:00 +08:00
</div> -->
2025-07-21 14:47:22 +08:00
<view class="nav-panel">
<c-uni-goods-nav
:fill="true"
:options="[]"
:buttonGroup="navButtonGroup"
@buttonClick="navButtonClick"
/>
</view>
2025-04-14 10:57:27 +08:00
</template>
<script setup>
2025-07-21 14:47:22 +08:00
import * as api from "@/utils/api.js";
import dayjs from "dayjs";
import { showModelMessage } from "@/utils/tools.js";
import { ref, watch, reactive, onMounted } from "vue";
import { onLoad } from "@dcloudio/uni-app";
import navigator from "@/utils/navigator.js";
//车辆信息
let bikeCode = ref(null); //车辆编号
const refbikeScan = ref(null);
let formdata = ref({
bikeId: "",
ecuId: "",
latitude: null,
longitude: null,
oldBatteryCode: "",
online: null,
soc: "", //电量
timestamp: "",
});
let newBatteryCode = ref(""); //新电池编号
2025-04-14 10:57:27 +08:00
2025-07-21 14:47:22 +08:00
// 获取设备信息
const systemInfo = uni.getSystemInfoSync();
// 获取屏幕高度和状态栏高度
const screenHeight = systemInfo.screenHeight;
let scrollHeight = screenHeight - 150;
2025-04-14 10:57:27 +08:00
2025-07-21 14:47:22 +08:00
//按钮
let arrEcuBtn = [
{
title: "寻车铃声",
url: "findEbike",
},
{
title: "开锁",
url: "unlock",
},
{
title: "关锁",
url: "lock",
},
];
2025-04-14 10:57:27 +08:00
2025-07-21 14:47:22 +08:00
//加载
onLoad((option) => {
const { bikeCode } = option;
getBikeInfo(bikeCode);
});
onMounted(() => {
if (bikeCode.value != "") {
if (refbikeScan.value) {
refbikeScan.value.onSetValue(bikeCode.value); // 调用子组件暴露的方法来更新子组件值
}
}
});
2025-04-14 10:57:27 +08:00
2025-07-21 14:47:22 +08:00
//获取车辆信息
const getBikeInfo = (bikecode) => {
if (bikecode == bikeCode.value) return;
const params = {
bikeCode: bikecode,
};
bikeCode.value = bikecode;
api.callEbikeBatteryApply("getBikeMsg", params, "get").then((res) => {
const { code, data, message } = res;
if (code === 500) {
showModelMessage(message);
formdata.value = {};
return;
}
if (arrEcuBtn.length < 4) {
arrEcuBtn.push({
title: "关电池仓",
url: "closeBatteryLock",
});
}
const timestamp = data.timestamp;
let newtime = timestamp
? dayjs(timestamp * 1000).format("YYYY-MM-DD HH:mm:ss")
: "";
const newdata = {
...data,
timestamp: newtime,
};
formdata.value = {
...newdata,
};
});
};
2025-04-14 10:57:27 +08:00
2025-07-21 14:47:22 +08:00
// 地图点击事件
const mapClick = (e) => {
console.log(navigator);
const { longitude, latitude } = formdata.value;
if (longitude & latitude) {
navigator.to("/pages/map/map-findbike", {
longitude,
latitude,
});
} else {
showModelMessage("请先扫码车辆编号!");
}
};
2025-04-14 10:57:27 +08:00
2025-07-21 14:47:22 +08:00
//中控操作
const checkecu = (url) => {
const { ecuId, bikeId } = formdata.value;
if (!ecuId) {
showModelMessage("请先扫码车辆编号!");
return;
}
api
.callCoreApi(
url,
{
ecuId,
bikeId,
},
"get"
)
.then((res) => {
const { code, message } = res;
showModelMessage(message);
});
};
//上报故障
const openfaultreport = () => {
const bikecode = bikeCode.value;
if (!bikecode) {
showModelMessage("请先扫码车辆编号!");
return;
}
uni.navigateTo({
url: "/pages/devops/faultreport/faultreport?bikeCode=" + bikecode,
});
};
2025-04-14 10:57:27 +08:00
2025-07-21 14:47:22 +08:00
//刷新
const refresh = () => {
const bikecode = bikeCode.value;
if (!bikecode) {
showModelMessage("请先扫码车辆编号!");
return;
}
getBikeInfo(bikecode);
};
2025-04-14 10:57:27 +08:00
2025-07-21 14:47:22 +08:00
//完成换电
const completebatter = () => {
const bikeId = formdata.value.bikeId;
const bikecode = bikeCode.value;
const newbattercode = newBatteryCode.value;
if (!bikecode) {
showModelMessage("请先扫码车辆编号!");
return;
}
if (!newbattercode) {
showModelMessage("请先扫码新电池编号!");
return;
}
//校验新电池
const params = {
bikeId,
newBatteryCode: newbattercode,
bikeCode: bikecode,
};
api.callEbikeBatteryApply("change", params).then((res) => {
const { code, message } = res;
showModelMessage(message);
if (code == 200) {
uni.navigateBack();
}
});
};
2025-04-14 10:57:27 +08:00
2025-07-21 14:47:22 +08:00
const navButtonGroup = reactive([
{
text: "刷新",
backgroundColor: "#0078D4",
color: "#fff",
disable: false,
},
{
text: "完成换电",
backgroundColor: "#0078D4",
color: "#fff",
disable: false,
},
]);
2025-04-14 10:57:27 +08:00
2025-07-21 14:47:22 +08:00
const navButtonClick = (e) => {
const index = e.index;
if (index == 0) {
refresh();
} else if (index == 1) {
completebatter();
}
};
2025-04-14 10:57:27 +08:00
</script>
<style scoped>
2025-07-21 14:47:22 +08:00
.divContent {
}
2025-04-14 10:57:27 +08:00
2025-07-21 14:47:22 +08:00
.divBtn {
height: 35px;
}
2025-04-14 10:57:27 +08:00
2025-07-21 14:47:22 +08:00
.divBtn text {
margin-right: 5px;
font-size: 12px;
}
2025-04-14 10:57:27 +08:00
2025-07-21 14:47:22 +08:00
.divCenter {
display: flex;
align-items: center;
height: 35px;
}
2025-04-14 10:57:27 +08:00
2025-07-21 14:47:22 +08:00
.divBottom {
position: absolute;
bottom: 0px;
padding: 0px 15px;
text-align: center;
background: white;
width: 100%;
line-height: 55px;
}
.nav-panel {
position: fixed;
bottom: 0rpx;
width: 100%;
padding-bottom: 10px;
z-index: 999;
background-color: #fff;
}
</style>