@ledvance/ui-biz-bundle 1.1.168 → 1.1.169
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/navigation/Routers.ts +1 -0
- package/src/newModules/biorhythm/BiorhythmPage.tsx +1 -0
- package/src/newModules/energyConsumption/EditPriceSegmentContract.tsx +89 -0
- package/src/newModules/energyConsumption/EditPriceSegmentScreen.tsx +89 -0
- package/src/newModules/energyConsumption/EnergyConsumptionActions.ts +5 -1
- package/src/newModules/energyConsumption/EnergyConsumptionChart/EnergyChartSection.tsx +33 -5
- package/src/newModules/energyConsumption/EnergyConsumptionPage.tsx +228 -117
- package/src/newModules/energyConsumption/Router.ts +9 -0
- package/src/newModules/energyConsumption/SetSegmentPricesContract.tsx +423 -0
- package/src/newModules/energyConsumption/SetSegmentedPricesScreen.tsx +189 -0
- package/src/newModules/energyConsumption/component/EnergyModal.tsx +66 -5
- package/src/newModules/energyConsumption/component/NewBarChart.tsx +63 -5
- package/src/newModules/energyConsumption/component/VerticalDailyPricesIndicator.tsx +175 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import Segmented from '@ledvance/base/src/components/Segmented'
|
|
2
|
-
import {
|
|
2
|
+
import {resetElectricity, updateDynamicPrice} from './EnergyConsumptionActions'
|
|
3
3
|
import { ChartType } from './co2Data'
|
|
4
4
|
import { EnergyChartSection } from './EnergyConsumptionChart/EnergyChartSection'
|
|
5
5
|
import { PowerChartSection } from './EnergyConsumptionChart/PowerChartSection'
|
|
6
6
|
import { getStyles } from './EnergyConsumptionChart/styles'
|
|
7
7
|
import { useEnergyData } from './EnergyConsumptionChart/useEnergyData'
|
|
8
|
-
import React, { useEffect, useMemo } from "react";
|
|
8
|
+
import React, { useEffect, useMemo, useState } from "react";
|
|
9
9
|
import { ScrollView, StyleSheet, View, Text, Image, TouchableOpacity } from "react-native";
|
|
10
10
|
import { useNavigation, useIsFocused } from '@react-navigation/core'
|
|
11
11
|
import { useRoute } from '@react-navigation/core'
|
|
@@ -18,7 +18,7 @@ import Card from "@ledvance/base/src/components/Card";
|
|
|
18
18
|
import OverView from "./component/Overview";
|
|
19
19
|
import { useInterval, useReactive, useUpdateEffect } from "ahooks";
|
|
20
20
|
import { getDpResultByMonth } from "@ledvance/base/src/models/TuyaApi";
|
|
21
|
-
import {useDeviceId, useSolarPlug, useTimeZoneCity} from "@ledvance/base/src/models/modules/NativePropsSlice";
|
|
21
|
+
import { useDeviceId, useSolarPlug, useTimeZoneCity } from "@ledvance/base/src/models/modules/NativePropsSlice";
|
|
22
22
|
import { flattenDeep, isEmpty } from "lodash";
|
|
23
23
|
import { exchangeNumber, localeNumber, monthFormat, monthFormatShort, showDialog } from "@ledvance/base/src/utils/common";
|
|
24
24
|
import {
|
|
@@ -31,15 +31,16 @@ import {
|
|
|
31
31
|
usePower,
|
|
32
32
|
useVoltage
|
|
33
33
|
} from "./EnergyConsumptionActions";
|
|
34
|
-
import {ui_biz_routerKey} from "../../navigation/Routers";
|
|
34
|
+
import { ui_biz_routerKey } from "../../navigation/Routers";
|
|
35
35
|
import { EnergyConsumptionDetailProps } from "./EnergyConsumptionDetail";
|
|
36
36
|
import { EnergyConsumptionChartProps } from "./EnergyConsumptionChart";
|
|
37
|
-
import EnergyPopup, { EnergyData, UnitList } from "./component/EnergyModal";
|
|
37
|
+
import EnergyPopup, { calculateAveragePrice, EnergyType, EnergyData, UnitList, PriceSegment, DynamicEnergyData } from "./component/EnergyModal";
|
|
38
38
|
import { NativeApi, queryDpIds } from "@ledvance/base/src/api/native";
|
|
39
39
|
import { carbonDioxideEmission, countryAndRegion } from "./co2Data";
|
|
40
40
|
import ThemeType from '@ledvance/base/src/config/themeType'
|
|
41
41
|
import LdvSwitch from "@ledvance/base/src/components/ldvSwitch";
|
|
42
42
|
import dayjs from "dayjs";
|
|
43
|
+
import { SetSegmentedPricesParams } from './SetSegmentedPricesScreen'
|
|
43
44
|
|
|
44
45
|
const { convertX: cx } = Utils.RatioUtils
|
|
45
46
|
const { withTheme } = Utils.ThemeUtils
|
|
@@ -65,7 +66,7 @@ interface EnergyConsumptionState {
|
|
|
65
66
|
totalElectricity: string
|
|
66
67
|
overviewList: OverviewItem[]
|
|
67
68
|
listLoading: boolean
|
|
68
|
-
price: string
|
|
69
|
+
price: string //UI用值,包括动态价格算出的平均值
|
|
69
70
|
unit: string
|
|
70
71
|
showPopup: boolean
|
|
71
72
|
popupType: PopupType
|
|
@@ -73,8 +74,11 @@ interface EnergyConsumptionState {
|
|
|
73
74
|
loading: boolean
|
|
74
75
|
generationMode: boolean
|
|
75
76
|
energyGeneration: EnergyGeneration
|
|
77
|
+
energyType: 'fixed' | 'dynamic'
|
|
78
|
+
network_fixed_data ?: EnergyData,
|
|
76
79
|
}
|
|
77
|
-
|
|
80
|
+
|
|
81
|
+
const EnergyConsumptionPage = (props: { theme?: ThemeType }) => {
|
|
78
82
|
const params = useRoute().params as EnergyConsumptionPageProps
|
|
79
83
|
const devId = useDeviceId()
|
|
80
84
|
const navigation = useNavigation()
|
|
@@ -84,6 +88,7 @@ const EnergyConsumptionPage = (props: {theme?: ThemeType}) => {
|
|
|
84
88
|
const voltage = useVoltage(params.voltageDpCode)
|
|
85
89
|
const electric = useElectricCurrent(params.electricDpCode)
|
|
86
90
|
const isSolarPlug = useSolarPlug()
|
|
91
|
+
const [dynamicData, setDynamicData] = useState<DynamicEnergyData>()
|
|
87
92
|
const state = useReactive<EnergyConsumptionState>({
|
|
88
93
|
todayElectricity: '0',
|
|
89
94
|
totalElectricity: '0',
|
|
@@ -100,8 +105,18 @@ const EnergyConsumptionPage = (props: {theme?: ThemeType}) => {
|
|
|
100
105
|
generationMode: false,
|
|
101
106
|
totalElectricity: 0,
|
|
102
107
|
history: []
|
|
103
|
-
}
|
|
108
|
+
},
|
|
109
|
+
energyType: 'fixed'
|
|
104
110
|
})
|
|
111
|
+
const isGeneration = useMemo(() => {
|
|
112
|
+
// 当 isSolarPlug 和 state.generationMode 不相等时返回 true
|
|
113
|
+
return isSolarPlug !== state.generationMode
|
|
114
|
+
}, [isSolarPlug, state.generationMode])
|
|
115
|
+
|
|
116
|
+
const backTitle = useMemo(() => {
|
|
117
|
+
return I18n.getLang(isGeneration ? 'sockets_headline_power' : 'consumption_data_annual_bar_chart_system_back_text')
|
|
118
|
+
}, [isGeneration])
|
|
119
|
+
|
|
105
120
|
const chartHeadline = useMemo(() => {
|
|
106
121
|
const len = state.overviewList.length
|
|
107
122
|
return state.overviewList?.length ? `${state.overviewList[len - 1].key} - ${state.overviewList[0].key}` : ''
|
|
@@ -116,17 +131,20 @@ const EnergyConsumptionPage = (props: {theme?: ThemeType}) => {
|
|
|
116
131
|
addEleDpCode: params.addEleDpCode,
|
|
117
132
|
powerDpCode: params.powerDpCode,
|
|
118
133
|
date: (new Date()).getFullYear().toString(),
|
|
119
|
-
|
|
134
|
+
energyType: state.energyType,
|
|
135
|
+
dynamicData: dynamicData,
|
|
136
|
+
isGeneration: isGeneration,
|
|
137
|
+
}), [backTitle, chartHeadline, state.overviewList, state.price, state.unit, params.addEleDpCode, params.powerDpCode, state.energyType, dynamicData, isGeneration])
|
|
120
138
|
const { state: chartState, actions } = useEnergyData(chartParams, devId)
|
|
121
139
|
|
|
122
140
|
useInterval(() => {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
141
|
+
if (isFocused) {
|
|
142
|
+
const jsonData = JSON.stringify([params.electricDpCode, params.powerDpCode, params.voltageDpCode])
|
|
143
|
+
queryDpIds(jsonData, devId).then()
|
|
144
|
+
}
|
|
145
|
+
},
|
|
128
146
|
3000,
|
|
129
|
-
{immediate: true}
|
|
147
|
+
{ immediate: true }
|
|
130
148
|
)
|
|
131
149
|
|
|
132
150
|
useEffect(() => {
|
|
@@ -135,17 +153,13 @@ const EnergyConsumptionPage = (props: {theme?: ThemeType}) => {
|
|
|
135
153
|
getEnergyGeneration().then()
|
|
136
154
|
}, [])
|
|
137
155
|
|
|
138
|
-
const isGeneration = useMemo(() => {
|
|
139
|
-
// 当 isSolarPlug 和 state.generationMode 不相等时返回 true
|
|
140
|
-
return isSolarPlug !== state.generationMode
|
|
141
|
-
}, [isSolarPlug, state.generationMode])
|
|
142
156
|
|
|
143
157
|
const totalElectricity = useMemo(() => {
|
|
144
158
|
return Number(state.totalElectricity)
|
|
145
159
|
}, [state.totalElectricity])
|
|
146
160
|
|
|
147
|
-
useUpdateEffect(() =>{
|
|
148
|
-
if(totalElectricity >= 0 && timeZoneCity){
|
|
161
|
+
useUpdateEffect(() => {
|
|
162
|
+
if (totalElectricity >= 0 && timeZoneCity) {
|
|
149
163
|
const letOut = carbonDioxideEmission(timeZoneCity, countryAndRegion) || 0
|
|
150
164
|
state.co2Saved = localeNumber((letOut * totalElectricity) / 1000, 4)
|
|
151
165
|
}
|
|
@@ -236,22 +250,62 @@ const EnergyConsumptionPage = (props: {theme?: ThemeType}) => {
|
|
|
236
250
|
state.listLoading = false
|
|
237
251
|
}
|
|
238
252
|
|
|
239
|
-
const
|
|
240
|
-
const
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
253
|
+
const parsePrice = (dynamicCosts: PriceSegment[], dynamicGenerates: PriceSegment[], fixedModel?: any,): string => {
|
|
254
|
+
const type = fixedModel?.energyType ?? 'fixed'
|
|
255
|
+
const usingPrice = isGeneration ? (fixedModel?.generatePrice ?? fixedModel?.price): fixedModel?.price;
|
|
256
|
+
if (type === 'dynamic') {
|
|
257
|
+
const usingIntervals = isGeneration ? dynamicGenerates : dynamicCosts;
|
|
258
|
+
const dynamicPrice = usingIntervals
|
|
259
|
+
? String(calculateAveragePrice(usingIntervals))
|
|
260
|
+
: usingPrice;
|
|
261
|
+
return String(dynamicPrice ?? '0');
|
|
246
262
|
} else {
|
|
247
|
-
|
|
263
|
+
return String(usingPrice ?? '0');
|
|
248
264
|
}
|
|
249
265
|
}
|
|
266
|
+
const getInitPrice = async () => {
|
|
267
|
+
const fixedJob = NativeApi.getJson(devId, 'energiepreise')
|
|
268
|
+
const dynamicJob = NativeApi.getJson(devId, 'dynamicenergyprice')
|
|
269
|
+
Promise.all([fixedJob, dynamicJob]).then(([res, dynamicRes]) => {
|
|
270
|
+
if (res.success && res.data) {
|
|
271
|
+
const d = (dynamicRes.success && dynamicRes.data) ? JSON.parse(dynamicRes.data) : null
|
|
272
|
+
const { costs, generates } = d
|
|
273
|
+
? {
|
|
274
|
+
costs: (d.intervalPrices ?? []) as PriceSegment[],
|
|
275
|
+
generates: (d.generatePrices ?? []) as PriceSegment[]
|
|
276
|
+
}
|
|
277
|
+
: {
|
|
278
|
+
costs: [] as PriceSegment[],
|
|
279
|
+
generates: [] as PriceSegment[]
|
|
280
|
+
}
|
|
281
|
+
const v = JSON.parse(res.data)
|
|
282
|
+
state.network_fixed_data = {
|
|
283
|
+
price: v?.price ?? '0',
|
|
284
|
+
unit: v?.unit,
|
|
285
|
+
energyType: v?.energyType ?? 'fixed',
|
|
286
|
+
generatePrice: v?.generatePrice,
|
|
287
|
+
} //临时存储固定价格网络模型
|
|
288
|
+
state.energyType = v?.energyType ?? 'fixed'
|
|
289
|
+
state.price = parsePrice(costs, generates, v)
|
|
290
|
+
state.unit = v?.unit
|
|
291
|
+
setDynamicData({
|
|
292
|
+
intervalPrices: costs,
|
|
293
|
+
generatePrices: generates,
|
|
294
|
+
} as DynamicEnergyData)//临时存储动态价格网络模型
|
|
295
|
+
actions.setPriceAndUnit(v?.price, v?.unit || UnitList[0])
|
|
296
|
+
} else {
|
|
297
|
+
state.price = '0'
|
|
298
|
+
}
|
|
299
|
+
}).catch(() => {
|
|
300
|
+
state.price = '0'
|
|
301
|
+
})
|
|
302
|
+
}
|
|
250
303
|
|
|
251
304
|
const updateEnergyData = (data: EnergyData) => {
|
|
252
305
|
updatePrice(devId, data).then()
|
|
253
306
|
state.price = data.price || '0'
|
|
254
307
|
state.unit = data.unit
|
|
308
|
+
state.energyType = 'fixed'
|
|
255
309
|
actions.setPriceAndUnit(data.price, data.unit)
|
|
256
310
|
}
|
|
257
311
|
|
|
@@ -262,9 +316,6 @@ const EnergyConsumptionPage = (props: {theme?: ThemeType}) => {
|
|
|
262
316
|
return titleMapping[value ? 0 : 1]
|
|
263
317
|
}
|
|
264
318
|
|
|
265
|
-
const backTitle = useMemo(() => {
|
|
266
|
-
return I18n.getLang(isGeneration ? 'sockets_headline_power' : 'consumption_data_annual_bar_chart_system_back_text')
|
|
267
|
-
}, [isGeneration])
|
|
268
319
|
|
|
269
320
|
const styles = StyleSheet.create({
|
|
270
321
|
showTip: {
|
|
@@ -414,7 +465,7 @@ const EnergyConsumptionPage = (props: {theme?: ThemeType}) => {
|
|
|
414
465
|
}}>
|
|
415
466
|
<Text style={styles.cardTitle}>{I18n.getLang('consumption_data_field2_headline_text')}</Text>
|
|
416
467
|
<Image
|
|
417
|
-
source={{ uri: res.energy_consumption_chart}}
|
|
468
|
+
source={{ uri: res.energy_consumption_chart }}
|
|
418
469
|
style={{ width: cx(16), height: cx(16), marginLeft: cx(8) }}
|
|
419
470
|
/>
|
|
420
471
|
</View>
|
|
@@ -436,26 +487,29 @@ const EnergyConsumptionPage = (props: {theme?: ThemeType}) => {
|
|
|
436
487
|
<Card
|
|
437
488
|
style={styles.cardContainer}
|
|
438
489
|
>
|
|
439
|
-
<View style={{ flexDirection: 'row', alignItems: 'center'}}>
|
|
490
|
+
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
|
|
440
491
|
<View>
|
|
441
|
-
<View style={{height: cx(35), justifyContent: 'center'}}>
|
|
492
|
+
<View style={{ height: cx(35), justifyContent: 'center' }}>
|
|
442
493
|
<Text style={[styles.cardTitle]}>{I18n.getLang('consumption_data_field1_headline_text')}</Text>
|
|
443
494
|
</View>
|
|
444
495
|
<View style={{ flexDirection: 'row', alignItems: 'center', height: cx(35) }}>
|
|
445
496
|
<Text style={styles.cardTitle}>{I18n.getLang('consumption_data_field3_headline_text')}</Text>
|
|
446
|
-
{
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
497
|
+
{state.energyGeneration.history.length > 0 && <TouchableOpacity
|
|
498
|
+
onPress={() => {
|
|
499
|
+
state.showPopup = true
|
|
500
|
+
state.popupType = 'history'
|
|
501
|
+
}}
|
|
451
502
|
>
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
503
|
+
<Image
|
|
504
|
+
source={{ uri: res.co2_icon }}
|
|
505
|
+
resizeMode="contain"
|
|
506
|
+
style={{ height: cx(20), width: cx(20), tintColor: props.theme?.button.primary }}
|
|
507
|
+
/>
|
|
457
508
|
</TouchableOpacity>}
|
|
458
509
|
</View>
|
|
510
|
+
<View style={{ height: cx(35), justifyContent: 'center' }}>
|
|
511
|
+
<Text style={[styles.cardTitle]}>{I18n.getLang('consumption_energy_type_title')}</Text>
|
|
512
|
+
</View>
|
|
459
513
|
</View>
|
|
460
514
|
<View>
|
|
461
515
|
<View style={{ flexDirection: 'row', alignItems: 'flex-end', marginLeft: cx(10) }}>
|
|
@@ -466,45 +520,48 @@ const EnergyConsumptionPage = (props: {theme?: ThemeType}) => {
|
|
|
466
520
|
<Text style={[styles.consumptionNum, { fontSize: cx(30), marginRight: cx(8) }]}>{localeNumber(totalElectricity)}</Text>
|
|
467
521
|
<Text style={[styles.consumptionNum, { fontSize: cx(20), marginBottom: cx(4) }]}>kWh</Text>
|
|
468
522
|
</View>
|
|
523
|
+
<View style={{ flexDirection: 'row', alignItems: 'flex-end', marginLeft: cx(10) }}>
|
|
524
|
+
<Text style={[styles.consumptionNum, { fontSize: cx(16), marginRight: cx(8) }]}>{I18n.getLang(state.energyType === 'fixed' ? 'consumption_energy_type_fixed' : 'consumption_energy_type_dynamic')}</Text>
|
|
525
|
+
</View>
|
|
469
526
|
</View>
|
|
470
527
|
</View>
|
|
471
528
|
<Spacer />
|
|
472
529
|
{/* CO2 */}
|
|
473
530
|
{isGeneration && <>
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
</View>
|
|
531
|
+
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
|
|
532
|
+
<View style={styles.priceBg}>
|
|
533
|
+
<Image
|
|
534
|
+
source={{ uri: res.energy_consumption_cash }}
|
|
535
|
+
resizeMode="contain"
|
|
536
|
+
style={{ height: cx(20), width: cx(20), tintColor: props.theme?.button.primary }}
|
|
537
|
+
/>
|
|
538
|
+
</View>
|
|
539
|
+
<View style={styles.priceNum}>
|
|
540
|
+
<View style={{ flexDirection: 'row' }}>
|
|
541
|
+
<Text style={{ color: props.theme?.global.secondFontColor, marginRight: cx(5) }}>{I18n.getLang('consumption_data_field3_co2_topic_text')}</Text>
|
|
542
|
+
<TouchableOpacity
|
|
543
|
+
onPress={() => {
|
|
544
|
+
state.showPopup = true
|
|
545
|
+
state.popupType = 'co2'
|
|
546
|
+
}}
|
|
547
|
+
>
|
|
548
|
+
<Image
|
|
549
|
+
source={{ uri: res.co2_icon }}
|
|
550
|
+
resizeMode="contain"
|
|
551
|
+
style={{ height: cx(20), width: cx(20), tintColor: props.theme?.button.primary }}
|
|
552
|
+
/>
|
|
553
|
+
</TouchableOpacity>
|
|
554
|
+
</View>
|
|
555
|
+
<Text style={{ color: props.theme?.global.fontColor, fontWeight: 'bold' }}>{`${state.co2Saved} kg`}</Text>
|
|
500
556
|
</View>
|
|
501
|
-
|
|
557
|
+
</View>
|
|
558
|
+
<Spacer height={cx(10)} />
|
|
502
559
|
</>}
|
|
503
560
|
{/* money */}
|
|
504
561
|
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
|
|
505
562
|
<View style={styles.priceBg}>
|
|
506
563
|
<Image
|
|
507
|
-
source={{uri: res.energy_consumption_cash}}
|
|
564
|
+
source={{ uri: res.energy_consumption_cash }}
|
|
508
565
|
resizeMode="contain"
|
|
509
566
|
style={{ height: cx(20), width: cx(20), tintColor: props.theme?.button.primary }}
|
|
510
567
|
/>
|
|
@@ -512,21 +569,72 @@ const EnergyConsumptionPage = (props: {theme?: ThemeType}) => {
|
|
|
512
569
|
<View>
|
|
513
570
|
<View style={styles.priceNum}>
|
|
514
571
|
<Text style={{ color: props.theme?.global.secondFontColor }}>{I18n.getLang(isGeneration ? 'consumption_data_monthly_overview_field1_text2' : 'consumption_data_field3_value_text2')}</Text>
|
|
515
|
-
<Text style={{ color: props.theme?.global.fontColor, fontWeight: 'bold' }}>{state.price ? `${localeNumber(Number(state.price
|
|
572
|
+
<Text style={{ color: props.theme?.global.fontColor, fontWeight: 'bold' }}>{state.price ? `${localeNumber(Number(state.price) * totalElectricity, 2)} ${state.unit}` : '-'}</Text>
|
|
516
573
|
</View>
|
|
517
|
-
<
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
<
|
|
523
|
-
|
|
524
|
-
|
|
574
|
+
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
|
|
575
|
+
<TouchableOpacity onPress={() => {
|
|
576
|
+
state.showPopup = true
|
|
577
|
+
state.popupType = 'money'
|
|
578
|
+
}}>
|
|
579
|
+
<View style={styles.priceButton}>
|
|
580
|
+
<Text style={{ color: props.theme?.button.fontColor }}>{I18n.getLang('consumption_data_field3_button_text')}</Text>
|
|
581
|
+
</View>
|
|
582
|
+
</TouchableOpacity>
|
|
583
|
+
<TouchableOpacity onPress={() => {
|
|
584
|
+
navigation.navigate(ui_biz_routerKey.ui_biz_set_segmented_prices, {
|
|
585
|
+
backTitle: backTitle,
|
|
586
|
+
dynamicData: dynamicData ?? {
|
|
587
|
+
intervalPrices: [],
|
|
588
|
+
generatePrices: [],
|
|
589
|
+
},
|
|
590
|
+
priceUnit: state.unit,
|
|
591
|
+
isGenerate: isGeneration,
|
|
592
|
+
onSetPriceSements: async(segments: PriceSegment[], currency: string): Promise<boolean>=>{
|
|
593
|
+
console.log("onSetPriceSements ", JSON.stringify(segments), currency)
|
|
594
|
+
const fixedModel = state.network_fixed_data ?? {
|
|
595
|
+
price: '0',
|
|
596
|
+
unit: '$',
|
|
597
|
+
energyType: 'fixed',
|
|
598
|
+
generatePrice: '0',
|
|
599
|
+
}
|
|
600
|
+
const dynamicMdel = {
|
|
601
|
+
...dynamicData,
|
|
602
|
+
[isGeneration ? 'generatePrices' : 'intervalPrices']: segments
|
|
603
|
+
}
|
|
604
|
+
const[fixedRes, dynamicRes] = await Promise.all([
|
|
605
|
+
updatePrice(devId, {...fixedModel, energyType: 'dynamic', unit: currency}),
|
|
606
|
+
updateDynamicPrice(devId, dynamicMdel)
|
|
607
|
+
])
|
|
608
|
+
const isDynamicSuccess = dynamicRes && dynamicRes.success
|
|
609
|
+
const isRegularSuccess = fixedRes && fixedRes.success
|
|
610
|
+
const isAllSuccess = isDynamicSuccess && isRegularSuccess
|
|
611
|
+
if(isAllSuccess) {
|
|
612
|
+
setDynamicData(dynamicMdel)
|
|
613
|
+
state.price = String(calculateAveragePrice(segments))//价格
|
|
614
|
+
state.energyType = 'dynamic'
|
|
615
|
+
state.unit = currency
|
|
616
|
+
state.network_fixed_data = {
|
|
617
|
+
...fixedModel,
|
|
618
|
+
energyType: 'dynamic',
|
|
619
|
+
unit: currency
|
|
620
|
+
}
|
|
621
|
+
actions.setPriceAndUnit(state.price, currency)
|
|
622
|
+
}
|
|
623
|
+
return isAllSuccess
|
|
624
|
+
}
|
|
625
|
+
} as SetSegmentedPricesParams)
|
|
626
|
+
}}>
|
|
627
|
+
<View style={[styles.priceButton, { marginLeft: cx(8) }]}>
|
|
628
|
+
<Text style={{ color: props.theme?.button.fontColor }}>{I18n.getLang('consumption_data_field_dynamic_money')}</Text>
|
|
629
|
+
</View>
|
|
630
|
+
</TouchableOpacity>
|
|
631
|
+
</View>
|
|
632
|
+
|
|
525
633
|
</View>
|
|
526
634
|
</View>
|
|
527
635
|
</Card>
|
|
528
636
|
<Spacer />
|
|
529
|
-
<Card style={{marginHorizontal: cx(24)}}>
|
|
637
|
+
<Card style={{ marginHorizontal: cx(24) }}>
|
|
530
638
|
<LdvSwitch
|
|
531
639
|
title={isSolarPlug ? I18n.getLang('plug_energyconsumptionswitch', 'Switch to energy consumption mode') : I18n.getLang('plug_energygenerationswitch', 'Switch to energy generation mode')}
|
|
532
640
|
colorAlpha={0}
|
|
@@ -547,8 +655,8 @@ const EnergyConsumptionPage = (props: {theme?: ThemeType}) => {
|
|
|
547
655
|
}}
|
|
548
656
|
/>
|
|
549
657
|
</Card>
|
|
550
|
-
<Spacer/>
|
|
551
|
-
<ScrollView style={{marginHorizontal: cx(24)}}>
|
|
658
|
+
<Spacer />
|
|
659
|
+
<ScrollView style={{ marginHorizontal: cx(24) }}>
|
|
552
660
|
<Segmented
|
|
553
661
|
options={[
|
|
554
662
|
{ label: I18n.getLang('chartdisplay_energy'), value: ChartType.kWh },
|
|
@@ -559,40 +667,40 @@ const EnergyConsumptionPage = (props: {theme?: ThemeType}) => {
|
|
|
559
667
|
/>
|
|
560
668
|
{chartState.chartType === ChartType.kWh ? (
|
|
561
669
|
<EnergyChartSection state={chartState} actions={actions} params={chartParams} styles={chartStyles} theme={props.theme}
|
|
562
|
-
|
|
670
|
+
chartHeight={cx(400)} />
|
|
563
671
|
) : (
|
|
564
|
-
<PowerChartSection state={chartState} actions={actions} styles={chartStyles} theme={props.theme} chartHeight={cx(400)}/>
|
|
672
|
+
<PowerChartSection state={chartState} actions={actions} styles={chartStyles} theme={props.theme} chartHeight={cx(400)} />
|
|
565
673
|
)}
|
|
566
674
|
</ScrollView>
|
|
567
675
|
<Spacer />
|
|
568
676
|
{/* Annual overview */}
|
|
569
677
|
{!!state.price && <OverView
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
678
|
+
style={{ marginHorizontal: cx(24) }}
|
|
679
|
+
headlineText={I18n.getLang('consumption_data_field4_headline_text')}
|
|
680
|
+
headlineClick={() => {
|
|
681
|
+
navigation.navigate(ui_biz_routerKey.ui_biz_energy_consumption_chart, {
|
|
682
|
+
backTitle,
|
|
683
|
+
headlineText: chartHeadline,
|
|
684
|
+
chartData: state.overviewList,
|
|
685
|
+
price: state.price,
|
|
686
|
+
unit: state.unit,
|
|
687
|
+
addEleDpCode: params.addEleDpCode,
|
|
688
|
+
powerDpCode: params.powerDpCode,
|
|
689
|
+
date: (new Date()).getFullYear().toString(),
|
|
690
|
+
} as EnergyConsumptionChartProps)
|
|
691
|
+
}}
|
|
692
|
+
overviewItemClick={(item) => {
|
|
693
|
+
navigation.navigate(ui_biz_routerKey.ui_biz_energy_consumption_detail, {
|
|
694
|
+
backTitle,
|
|
695
|
+
addEleDpCode: params.addEleDpCode,
|
|
696
|
+
powerDpCode: params.powerDpCode,
|
|
697
|
+
curMonth: item,
|
|
698
|
+
price: state.price,
|
|
699
|
+
unit: state.unit,
|
|
700
|
+
updateEnergyData
|
|
701
|
+
} as EnergyConsumptionDetailProps)
|
|
702
|
+
}}
|
|
703
|
+
overViewList={state.overviewList}
|
|
596
704
|
/>}
|
|
597
705
|
{/* modal */}
|
|
598
706
|
<EnergyPopup
|
|
@@ -606,11 +714,14 @@ const EnergyConsumptionPage = (props: {theme?: ThemeType}) => {
|
|
|
606
714
|
onConfirm={(energyData) => {
|
|
607
715
|
state.popupType = ''
|
|
608
716
|
state.showPopup = false
|
|
609
|
-
if(energyData){
|
|
610
|
-
|
|
717
|
+
if (energyData) {
|
|
718
|
+
const internationalPrice = exchangeNumber(energyData.price)
|
|
719
|
+
const result = {
|
|
611
720
|
...energyData,
|
|
612
|
-
price:
|
|
613
|
-
|
|
721
|
+
[isGeneration ? 'generatePrice' : 'price']: internationalPrice,
|
|
722
|
+
energyType: 'fixed',
|
|
723
|
+
}
|
|
724
|
+
updateEnergyData(result)
|
|
614
725
|
}
|
|
615
726
|
}}
|
|
616
727
|
onCancel={() => {
|
|
@@ -3,6 +3,7 @@ import EnergyConsumptionPage from "./EnergyConsumptionPage";
|
|
|
3
3
|
import EnergyConsumptionDetail from "./EnergyConsumptionDetail";
|
|
4
4
|
import EnergyConsumptionChart from "./EnergyConsumptionChart/index";
|
|
5
5
|
import {ui_biz_routerKey} from "../../navigation/Routers";
|
|
6
|
+
import SetSegmentedPricesScreen from "./SetSegmentedPricesScreen";
|
|
6
7
|
|
|
7
8
|
const EnergyConsumptionPageRouters: NavigationRoute[] = [
|
|
8
9
|
{
|
|
@@ -29,6 +30,14 @@ const EnergyConsumptionPageRouters: NavigationRoute[] = [
|
|
|
29
30
|
showOfflineView: false,
|
|
30
31
|
}
|
|
31
32
|
},
|
|
33
|
+
{
|
|
34
|
+
name: ui_biz_routerKey.ui_biz_set_segmented_prices,
|
|
35
|
+
component: SetSegmentedPricesScreen,
|
|
36
|
+
options: {
|
|
37
|
+
hideTopbar: true,
|
|
38
|
+
showOfflineView: false,
|
|
39
|
+
}
|
|
40
|
+
}
|
|
32
41
|
]
|
|
33
42
|
|
|
34
43
|
export default EnergyConsumptionPageRouters
|