Skip to content

Commit

Permalink
fix(electricityQuickview): Synchronize remaining electricity bills
Browse files Browse the repository at this point in the history
  • Loading branch information
xixiIBN5100 committed Dec 15, 2024
1 parent 8696089 commit cb541d6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/components/ElectricityQuickView/index.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<template>
<quick-view title="电费查询" icon-name="electricity" @tap="nav2electricity">
<quick-view title="电量查询" icon-name="electricity" @tap="nav2electricity">
<view class="text-view">
<text class="sub-text-left">
当前电费({{ updateTimeString }})
当前电量({{ updateTimeString }})
</text>
<text v-if="isUrgent" class="sub-text-right">
温馨提示: 电量较低
</text>
</view>
<card class="electricity-card">
<view v-if="!loading" class="text-wrapper">
<text>寝室剩余电费</text>
<text>寝室剩余电量</text>
<text :class="isUrgent ? 'dangerous' : 'normal'">
{{ balanceData?.data.soc || 0 }}
</text>
Expand All @@ -27,7 +27,7 @@
import { QuickView } from "@/components";
import Taro from "@tarojs/taro";
import "./index.scss";
import { computed } from "vue";
import { computed, watch } from "vue";
import { YxyService } from "@/services";
import store, { serviceStore } from "@/store";
import Card from "../Card/index.vue";
Expand All @@ -37,17 +37,31 @@ import { useRequest } from "@/hooks";
function nav2electricity() {
Taro.navigateTo({ url: "/pages/electricity/index" });
}
const campus = computed(() => serviceStore.electricity.electricityCampus);
const { data: balanceData, loading, error } = useRequest(
YxyService.queryBalance, {
const { data: balanceData, loading, error, run } = useRequest(
YxyService.queryBalance,
{
manual: true,
onSuccess: (res) => {
if (res.data.data?.soc) {
serviceStore.electricity.lastCampus = campus.value;
store.commit("setBalance", res.data.data.soc);
} else throw new Error();
} else {
throw new Error("No SOC data found");
}
}
}
);
watch(
campus,
(newCampus) => {
run({ campus: newCampus });
},
{ immediate: true }
);
const isUrgent = computed(() => {
if (balanceData.value)
return balanceData.value.data.soc < 20;
Expand Down
1 change: 1 addition & 0 deletions src/store/service/electricity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const ElectricityServiceStore = {
balance: undefined,
electricityCampus: "zhpf",
selectIndex: 0,
lastCampus: "zhpf",
todayConsumption: undefined,
updateTime: {
balance: undefined
Expand Down

0 comments on commit cb541d6

Please sign in to comment.