@ledvance/ui-biz-bundle 1.1.168 → 1.1.170
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 +234 -118
- package/src/newModules/energyConsumption/Router.ts +9 -0
- package/src/newModules/energyConsumption/SetSegmentPricesContract.tsx +424 -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/PowerLineChart.tsx +18 -9
- 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,67 @@ 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()
|
|
306
|
+
state.network_fixed_data = {
|
|
307
|
+
unit: data.unit,
|
|
308
|
+
energyType: 'fixed',
|
|
309
|
+
[isGeneration ? 'generatePrice' : 'price']: data.price,
|
|
310
|
+
}
|
|
253
311
|
state.price = data.price || '0'
|
|
254
312
|
state.unit = data.unit
|
|
313
|
+
state.energyType = 'fixed'
|
|
255
314
|
actions.setPriceAndUnit(data.price, data.unit)
|
|
256
315
|
}
|
|
257
316
|
|
|
@@ -262,9 +321,6 @@ const EnergyConsumptionPage = (props: {theme?: ThemeType}) => {
|
|
|
262
321
|
return titleMapping[value ? 0 : 1]
|
|
263
322
|
}
|
|
264
323
|
|
|
265
|
-
const backTitle = useMemo(() => {
|
|
266
|
-
return I18n.getLang(isGeneration ? 'sockets_headline_power' : 'consumption_data_annual_bar_chart_system_back_text')
|
|
267
|
-
}, [isGeneration])
|
|
268
324
|
|
|
269
325
|
const styles = StyleSheet.create({
|
|
270
326
|
showTip: {
|
|
@@ -414,7 +470,7 @@ const EnergyConsumptionPage = (props: {theme?: ThemeType}) => {
|
|
|
414
470
|
}}>
|
|
415
471
|
<Text style={styles.cardTitle}>{I18n.getLang('consumption_data_field2_headline_text')}</Text>
|
|
416
472
|
<Image
|
|
417
|
-
source={{ uri: res.energy_consumption_chart}}
|
|
473
|
+
source={{ uri: res.energy_consumption_chart }}
|
|
418
474
|
style={{ width: cx(16), height: cx(16), marginLeft: cx(8) }}
|
|
419
475
|
/>
|
|
420
476
|
</View>
|
|
@@ -436,26 +492,29 @@ const EnergyConsumptionPage = (props: {theme?: ThemeType}) => {
|
|
|
436
492
|
<Card
|
|
437
493
|
style={styles.cardContainer}
|
|
438
494
|
>
|
|
439
|
-
<View style={{ flexDirection: 'row', alignItems: 'center'}}>
|
|
495
|
+
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
|
|
440
496
|
<View>
|
|
441
|
-
<View style={{height: cx(35), justifyContent: 'center'}}>
|
|
497
|
+
<View style={{ height: cx(35), justifyContent: 'center' }}>
|
|
442
498
|
<Text style={[styles.cardTitle]}>{I18n.getLang('consumption_data_field1_headline_text')}</Text>
|
|
443
499
|
</View>
|
|
444
500
|
<View style={{ flexDirection: 'row', alignItems: 'center', height: cx(35) }}>
|
|
445
501
|
<Text style={styles.cardTitle}>{I18n.getLang('consumption_data_field3_headline_text')}</Text>
|
|
446
|
-
{
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
502
|
+
{state.energyGeneration.history.length > 0 && <TouchableOpacity
|
|
503
|
+
onPress={() => {
|
|
504
|
+
state.showPopup = true
|
|
505
|
+
state.popupType = 'history'
|
|
506
|
+
}}
|
|
451
507
|
>
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
508
|
+
<Image
|
|
509
|
+
source={{ uri: res.co2_icon }}
|
|
510
|
+
resizeMode="contain"
|
|
511
|
+
style={{ height: cx(20), width: cx(20), tintColor: props.theme?.button.primary }}
|
|
512
|
+
/>
|
|
457
513
|
</TouchableOpacity>}
|
|
458
514
|
</View>
|
|
515
|
+
<View style={{ height: cx(35), justifyContent: 'center' }}>
|
|
516
|
+
<Text style={[styles.cardTitle]}>{I18n.getLang('consumption_energy_type_title')}</Text>
|
|
517
|
+
</View>
|
|
459
518
|
</View>
|
|
460
519
|
<View>
|
|
461
520
|
<View style={{ flexDirection: 'row', alignItems: 'flex-end', marginLeft: cx(10) }}>
|
|
@@ -466,45 +525,48 @@ const EnergyConsumptionPage = (props: {theme?: ThemeType}) => {
|
|
|
466
525
|
<Text style={[styles.consumptionNum, { fontSize: cx(30), marginRight: cx(8) }]}>{localeNumber(totalElectricity)}</Text>
|
|
467
526
|
<Text style={[styles.consumptionNum, { fontSize: cx(20), marginBottom: cx(4) }]}>kWh</Text>
|
|
468
527
|
</View>
|
|
528
|
+
<View style={{ flexDirection: 'row', alignItems: 'flex-end', marginLeft: cx(10) }}>
|
|
529
|
+
<Text style={[styles.consumptionNum, { fontSize: cx(16), marginRight: cx(8) }]}>{I18n.getLang(state.energyType === 'fixed' ? 'consumption_energy_type_fixed' : 'consumption_energy_type_dynamic')}</Text>
|
|
530
|
+
</View>
|
|
469
531
|
</View>
|
|
470
532
|
</View>
|
|
471
533
|
<Spacer />
|
|
472
534
|
{/* CO2 */}
|
|
473
535
|
{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>
|
|
536
|
+
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
|
|
537
|
+
<View style={styles.priceBg}>
|
|
538
|
+
<Image
|
|
539
|
+
source={{ uri: res.energy_consumption_cash }}
|
|
540
|
+
resizeMode="contain"
|
|
541
|
+
style={{ height: cx(20), width: cx(20), tintColor: props.theme?.button.primary }}
|
|
542
|
+
/>
|
|
543
|
+
</View>
|
|
544
|
+
<View style={styles.priceNum}>
|
|
545
|
+
<View style={{ flexDirection: 'row' }}>
|
|
546
|
+
<Text style={{ color: props.theme?.global.secondFontColor, marginRight: cx(5) }}>{I18n.getLang('consumption_data_field3_co2_topic_text')}</Text>
|
|
547
|
+
<TouchableOpacity
|
|
548
|
+
onPress={() => {
|
|
549
|
+
state.showPopup = true
|
|
550
|
+
state.popupType = 'co2'
|
|
551
|
+
}}
|
|
552
|
+
>
|
|
553
|
+
<Image
|
|
554
|
+
source={{ uri: res.co2_icon }}
|
|
555
|
+
resizeMode="contain"
|
|
556
|
+
style={{ height: cx(20), width: cx(20), tintColor: props.theme?.button.primary }}
|
|
557
|
+
/>
|
|
558
|
+
</TouchableOpacity>
|
|
559
|
+
</View>
|
|
560
|
+
<Text style={{ color: props.theme?.global.fontColor, fontWeight: 'bold' }}>{`${state.co2Saved} kg`}</Text>
|
|
500
561
|
</View>
|
|
501
|
-
|
|
562
|
+
</View>
|
|
563
|
+
<Spacer height={cx(10)} />
|
|
502
564
|
</>}
|
|
503
565
|
{/* money */}
|
|
504
566
|
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
|
|
505
567
|
<View style={styles.priceBg}>
|
|
506
568
|
<Image
|
|
507
|
-
source={{uri: res.energy_consumption_cash}}
|
|
569
|
+
source={{ uri: res.energy_consumption_cash }}
|
|
508
570
|
resizeMode="contain"
|
|
509
571
|
style={{ height: cx(20), width: cx(20), tintColor: props.theme?.button.primary }}
|
|
510
572
|
/>
|
|
@@ -512,21 +574,72 @@ const EnergyConsumptionPage = (props: {theme?: ThemeType}) => {
|
|
|
512
574
|
<View>
|
|
513
575
|
<View style={styles.priceNum}>
|
|
514
576
|
<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
|
|
577
|
+
<Text style={{ color: props.theme?.global.fontColor, fontWeight: 'bold' }}>{state.price ? `${localeNumber(Number(state.price) * totalElectricity, 2)} ${state.unit}` : '-'}</Text>
|
|
516
578
|
</View>
|
|
517
|
-
<
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
<
|
|
523
|
-
|
|
524
|
-
|
|
579
|
+
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
|
|
580
|
+
<TouchableOpacity onPress={() => {
|
|
581
|
+
state.showPopup = true
|
|
582
|
+
state.popupType = 'money'
|
|
583
|
+
}}>
|
|
584
|
+
<View style={styles.priceButton}>
|
|
585
|
+
<Text style={{ color: props.theme?.button.fontColor }}>{I18n.getLang('consumption_data_field3_button_text')}</Text>
|
|
586
|
+
</View>
|
|
587
|
+
</TouchableOpacity>
|
|
588
|
+
<TouchableOpacity onPress={() => {
|
|
589
|
+
navigation.navigate(ui_biz_routerKey.ui_biz_set_segmented_prices, {
|
|
590
|
+
backTitle: backTitle,
|
|
591
|
+
dynamicData: dynamicData ?? {
|
|
592
|
+
intervalPrices: [],
|
|
593
|
+
generatePrices: [],
|
|
594
|
+
},
|
|
595
|
+
priceUnit: state.unit,
|
|
596
|
+
isGenerate: isGeneration,
|
|
597
|
+
onSetPriceSements: async(segments: PriceSegment[], currency: string): Promise<boolean>=>{
|
|
598
|
+
console.log("onSetPriceSements ", JSON.stringify(segments), currency)
|
|
599
|
+
const fixedModel = state.network_fixed_data ?? {
|
|
600
|
+
price: '0',
|
|
601
|
+
unit: '$',
|
|
602
|
+
energyType: 'fixed',
|
|
603
|
+
generatePrice: '0',
|
|
604
|
+
}
|
|
605
|
+
const dynamicMdel = {
|
|
606
|
+
...dynamicData,
|
|
607
|
+
[isGeneration ? 'generatePrices' : 'intervalPrices']: segments
|
|
608
|
+
}
|
|
609
|
+
const[fixedRes, dynamicRes] = await Promise.all([
|
|
610
|
+
updatePrice(devId, {...fixedModel, energyType: 'dynamic', unit: currency}),
|
|
611
|
+
updateDynamicPrice(devId, dynamicMdel)
|
|
612
|
+
])
|
|
613
|
+
const isDynamicSuccess = dynamicRes && dynamicRes.success
|
|
614
|
+
const isRegularSuccess = fixedRes && fixedRes.success
|
|
615
|
+
const isAllSuccess = isDynamicSuccess && isRegularSuccess
|
|
616
|
+
if(isAllSuccess) {
|
|
617
|
+
setDynamicData(dynamicMdel)
|
|
618
|
+
state.price = String(calculateAveragePrice(segments))//价格
|
|
619
|
+
state.energyType = 'dynamic'
|
|
620
|
+
state.unit = currency
|
|
621
|
+
state.network_fixed_data = {
|
|
622
|
+
...fixedModel,
|
|
623
|
+
energyType: 'dynamic',
|
|
624
|
+
unit: currency
|
|
625
|
+
}
|
|
626
|
+
actions.setPriceAndUnit(state.price, currency)
|
|
627
|
+
}
|
|
628
|
+
return isAllSuccess
|
|
629
|
+
}
|
|
630
|
+
} as SetSegmentedPricesParams)
|
|
631
|
+
}}>
|
|
632
|
+
<View style={[styles.priceButton, { marginLeft: cx(8) }]}>
|
|
633
|
+
<Text style={{ color: props.theme?.button.fontColor }}>{I18n.getLang('consumption_data_field_dynamic_money')}</Text>
|
|
634
|
+
</View>
|
|
635
|
+
</TouchableOpacity>
|
|
636
|
+
</View>
|
|
637
|
+
|
|
525
638
|
</View>
|
|
526
639
|
</View>
|
|
527
640
|
</Card>
|
|
528
641
|
<Spacer />
|
|
529
|
-
<Card style={{marginHorizontal: cx(24)}}>
|
|
642
|
+
<Card style={{ marginHorizontal: cx(24) }}>
|
|
530
643
|
<LdvSwitch
|
|
531
644
|
title={isSolarPlug ? I18n.getLang('plug_energyconsumptionswitch', 'Switch to energy consumption mode') : I18n.getLang('plug_energygenerationswitch', 'Switch to energy generation mode')}
|
|
532
645
|
colorAlpha={0}
|
|
@@ -547,8 +660,8 @@ const EnergyConsumptionPage = (props: {theme?: ThemeType}) => {
|
|
|
547
660
|
}}
|
|
548
661
|
/>
|
|
549
662
|
</Card>
|
|
550
|
-
<Spacer/>
|
|
551
|
-
<ScrollView style={{marginHorizontal: cx(24)}}>
|
|
663
|
+
<Spacer />
|
|
664
|
+
<ScrollView style={{ marginHorizontal: cx(24) }}>
|
|
552
665
|
<Segmented
|
|
553
666
|
options={[
|
|
554
667
|
{ label: I18n.getLang('chartdisplay_energy'), value: ChartType.kWh },
|
|
@@ -559,40 +672,40 @@ const EnergyConsumptionPage = (props: {theme?: ThemeType}) => {
|
|
|
559
672
|
/>
|
|
560
673
|
{chartState.chartType === ChartType.kWh ? (
|
|
561
674
|
<EnergyChartSection state={chartState} actions={actions} params={chartParams} styles={chartStyles} theme={props.theme}
|
|
562
|
-
|
|
675
|
+
chartHeight={cx(400)} />
|
|
563
676
|
) : (
|
|
564
|
-
<PowerChartSection state={chartState} actions={actions} styles={chartStyles} theme={props.theme} chartHeight={cx(400)}/>
|
|
677
|
+
<PowerChartSection state={chartState} actions={actions} styles={chartStyles} theme={props.theme} chartHeight={cx(400)} />
|
|
565
678
|
)}
|
|
566
679
|
</ScrollView>
|
|
567
680
|
<Spacer />
|
|
568
681
|
{/* Annual overview */}
|
|
569
682
|
{!!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
|
-
|
|
683
|
+
style={{ marginHorizontal: cx(24) }}
|
|
684
|
+
headlineText={I18n.getLang('consumption_data_field4_headline_text')}
|
|
685
|
+
headlineClick={() => {
|
|
686
|
+
navigation.navigate(ui_biz_routerKey.ui_biz_energy_consumption_chart, {
|
|
687
|
+
backTitle,
|
|
688
|
+
headlineText: chartHeadline,
|
|
689
|
+
chartData: state.overviewList,
|
|
690
|
+
price: state.price,
|
|
691
|
+
unit: state.unit,
|
|
692
|
+
addEleDpCode: params.addEleDpCode,
|
|
693
|
+
powerDpCode: params.powerDpCode,
|
|
694
|
+
date: (new Date()).getFullYear().toString(),
|
|
695
|
+
} as EnergyConsumptionChartProps)
|
|
696
|
+
}}
|
|
697
|
+
overviewItemClick={(item) => {
|
|
698
|
+
navigation.navigate(ui_biz_routerKey.ui_biz_energy_consumption_detail, {
|
|
699
|
+
backTitle,
|
|
700
|
+
addEleDpCode: params.addEleDpCode,
|
|
701
|
+
powerDpCode: params.powerDpCode,
|
|
702
|
+
curMonth: item,
|
|
703
|
+
price: state.price,
|
|
704
|
+
unit: state.unit,
|
|
705
|
+
updateEnergyData
|
|
706
|
+
} as EnergyConsumptionDetailProps)
|
|
707
|
+
}}
|
|
708
|
+
overViewList={state.overviewList}
|
|
596
709
|
/>}
|
|
597
710
|
{/* modal */}
|
|
598
711
|
<EnergyPopup
|
|
@@ -601,16 +714,19 @@ const EnergyConsumptionPage = (props: {theme?: ThemeType}) => {
|
|
|
601
714
|
title={state.popupType === 'co2' ? I18n.getLang('consumption_data_field3_co2_topic_text') : state.popupType === 'history' ? I18n.getLang('group_energytotal') : ''}
|
|
602
715
|
cancelText={['co2', 'history'].includes(state.popupType) ? '' : I18n.getLang("auto_scan_system_cancel")}
|
|
603
716
|
confirmText={I18n.getLang(['co2', 'history'].includes(state.popupType) ? 'home_screen_home_dialog_yes_con' : 'auto_scan_system_wifi_confirm')}
|
|
604
|
-
energyData={{ price: state.price, unit: state.unit }}
|
|
717
|
+
energyData={{ price: state.popupType === 'money' ? (state.network_fixed_data?.price ?? '0'): state.price , unit: state.unit }}
|
|
605
718
|
energyHistory={state.energyGeneration.history}
|
|
606
719
|
onConfirm={(energyData) => {
|
|
607
720
|
state.popupType = ''
|
|
608
721
|
state.showPopup = false
|
|
609
|
-
if(energyData){
|
|
610
|
-
|
|
722
|
+
if (energyData) {
|
|
723
|
+
const internationalPrice = exchangeNumber(energyData.price)
|
|
724
|
+
const result = {
|
|
611
725
|
...energyData,
|
|
612
|
-
price:
|
|
613
|
-
|
|
726
|
+
[isGeneration ? 'generatePrice' : 'price']: internationalPrice,
|
|
727
|
+
energyType: 'fixed',
|
|
728
|
+
}
|
|
729
|
+
updateEnergyData(result)
|
|
614
730
|
}
|
|
615
731
|
}}
|
|
616
732
|
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
|