TabCharge.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. /**
  2. * 新版充电页面
  3. * @邠心vbe on 2023/02/06
  4. */
  5. import React, { Component } from 'react';
  6. import { View, Text, StyleSheet, ImageBackground, Image, ScrollView } from 'react-native';
  7. import apiCharge from '../../api/apiCharge';
  8. import Button from '../../components/Button';
  9. import Dialog from '../../components/Dialog';
  10. import { PageList } from '../Router';
  11. import { BatteryView, ChargeStyle, circleSize, DashboardView, EnterStationDialog, TypeImage } from './Charging';
  12. import Payment, { PaymentDefault, PAYTYPE } from '../wallet/Payment';
  13. import { QRResult } from '../charge/QRScan';
  14. import { ErrorDialog } from './InfoDialog';
  15. import utils from '../../utils/utils';
  16. import PagerUtil from './PagerUtil';
  17. import { PaymentList } from './Payment';
  18. import BadgeSelectItem from '../../components/BadgeSelectItem';
  19. export default class TabCharge extends Component {
  20. constructor(props) {
  21. super(props);
  22. this.state = {
  23. available: false,
  24. isPrivate: false,
  25. refreshId: 0,
  26. isStart: false,
  27. isPending: false,
  28. isCharging: false,
  29. isAuthentic: false,
  30. selectRate: '',
  31. connectorInfo: {},
  32. stationInfo: {},
  33. lastUpdated: '',
  34. errorCode: 'A9',
  35. errorMessage: '',
  36. showErrorDialog: false,
  37. showStationDialog: false,
  38. curerntPerUser: undefined,
  39. //currentPayment: PAYTYPE.CREDIT_WALLET,
  40. //currentPaytype: "Credit Wallet",
  41. currentPayment: PaymentDefault.DEFAULT.payType,
  42. currentPaytype: PaymentDefault.DEFAULT.payName
  43. };
  44. this.changeMethod = false;
  45. this.canAutoRefresh = false;
  46. this.inputStationId = '';
  47. }
  48. componentDidMount() {
  49. this.canAutoRefresh = true;
  50. PagerUtil.addOnRefresh(this);
  51. this.onRefresh();
  52. }
  53. onRefresh() {
  54. console.log("Charge刷新", this.props.route.name);
  55. const info = PagerUtil.getStationInfo();
  56. this.setState({
  57. stationInfo: info
  58. }, () => {
  59. this.init();
  60. //console.log("站点信息", this.state.stationInfo);
  61. //this.checkIsCharge();
  62. });
  63. }
  64. init() {
  65. console.log("Charge刷新", "init");
  66. this.onMethodChanged();
  67. this.refreshAvailable();
  68. if (QRResult.haveResult()) {
  69. console.log("Charge刷新", "haveResult");
  70. const info = QRResult.getResult()
  71. console.log('QRResult', info);
  72. this.setState({
  73. isAuthentic: true,
  74. connectorInfo: info
  75. //soc: info.chargeType == 'AC' ? 0 : 'In Charging'
  76. });
  77. this.checkChargeStatus();
  78. } else if (this.state.isStart) {
  79. console.log("Charge刷新", "isStart");
  80. this.checkIsCharge();
  81. } else {
  82. console.log("Charge刷新", "noStart");
  83. this.getConnectorInfo();
  84. //this.checkChargeStatus();
  85. }
  86. }
  87. componentWillUnmount() {
  88. this.canAutoRefresh = false;
  89. }
  90. //刷新可用充电接口
  91. refreshAvailable() {
  92. const info = this.state.stationInfo
  93. const all = info?.allConnector;
  94. if (info.siteType == 'Private') {
  95. this.setState({
  96. isPrivate: true
  97. })
  98. }
  99. if (all) {
  100. this.setState({
  101. available: !all.available > 0
  102. });
  103. }
  104. }
  105. enterStatioinId() {
  106. if (QRResult.haveResult()) {
  107. const info = QRResult.getResult()
  108. console.log('EnterResult', info);
  109. this.setState({
  110. isAuthentic: true,
  111. connectorInfo: info
  112. //soc: info.chargeType == 'AC' ? 0 : 'In Charging'
  113. });
  114. this.checkChargeStatus();
  115. }
  116. }
  117. onPaymentMethodChanged(payment) {
  118. this.setState({
  119. currentPayment: payment
  120. })
  121. }
  122. onMethodChange() {
  123. this.changeMethod = true;
  124. startPage(PageList.paymentMethod, {info: this.state.connectorInfo, type: this.state.currentPayment});
  125. }
  126. onMethodChanged() {
  127. if (this.changeMethod) {
  128. this.changeMethod = false;
  129. if (global.paymentOption?.title) {
  130. this.setState({
  131. curerntPerUser: global.paymentOption.amount,
  132. currentPayment: global.paymentOption.value,
  133. currentPaytype: global.paymentOption.title
  134. }, () => {
  135. global.paymentOption= {}
  136. })
  137. }
  138. }
  139. }
  140. //扫码之前和扫码之后的站点信息Section
  141. StationInfo() {
  142. return (
  143. <BadgeSelectItem
  144. style={ChargeStyle.stationInfoView}
  145. checked={true}>
  146. {/* <ImageBackground
  147. style={{
  148. width: 42,
  149. height: 42
  150. }}
  151. source={require('../../images/charge/icon-station-no.png')}>
  152. <Text style={{
  153. left: 0,
  154. right: 0,
  155. bottom: 1,
  156. fontSize: 8,
  157. color: 'white',
  158. textAlign: 'center',
  159. position: 'absolute'
  160. }}>{this.state.connectorInfo.connectorId}</Text>
  161. </ImageBackground> */}
  162. <Image
  163. style={ChargeStyle.infoIcon}
  164. source={this.state.connectorInfo.chargeType.indexOf('AC') >= 0 ? TypeImage.AC : TypeImage.DC}/>
  165. <View style={ChargeStyle.infoGroup}>
  166. <Text
  167. numberOfLines={1}
  168. ellipsizeMode="tail"
  169. style={ChargeStyle.infoText}>{this.state.connectorInfo.chargeType}{this.state.connectorInfo.wattage}</Text>
  170. <Text style={ChargeStyle.infoTitle}>Type</Text>
  171. </View>
  172. <View style={ChargeStyle.infoGroup}>
  173. <Text
  174. numberOfLines={1}
  175. ellipsizeMode="tail"
  176. style={ChargeStyle.infoText}>{currency}{this.state.connectorInfo.rate}/{this.state.connectorInfo.rateType}</Text>
  177. <Text style={ChargeStyle.infoTitle}>Rate</Text>
  178. </View>
  179. <View style={ChargeStyle.infoGroup}>
  180. <Text
  181. numberOfLines={1}
  182. ellipsizeMode="tail"
  183. style={ChargeStyle.infoText}>{this.state.connectorInfo.wattage}kW{/*this.state.connectorInfo.rateType*/}</Text>
  184. <Text style={ChargeStyle.infoTitle}>Power</Text>
  185. </View>
  186. <View style={ChargeStyle.infoGroup}>
  187. { this.state.isCharging
  188. ? (this.state.isPending
  189. ? (
  190. <Text
  191. numberOfLines={1}
  192. ellipsizeMode="tail"
  193. style={[ChargeStyle.infoStatus, ChargeStyle.statusAuthenticated]}>
  194. Preparing
  195. </Text>
  196. )
  197. : (
  198. <Text
  199. numberOfLines={1}
  200. ellipsizeMode="tail"
  201. style={[ChargeStyle.infoStatus, ChargeStyle.statusAuthenticated]}>
  202. Charging
  203. </Text>
  204. )
  205. )
  206. : (this.state.connectorInfo.isCheckThrough
  207. ? (
  208. <Text
  209. numberOfLines={1}
  210. ellipsizeMode="tail"
  211. style={[ChargeStyle.infoStatus, ChargeStyle.statusAuthenticated]}>
  212. Authenticated
  213. </Text>
  214. )
  215. : (
  216. <Text
  217. numberOfLines={1}
  218. ellipsizeMode="tail"
  219. style={[ChargeStyle.infoStatus, ChargeStyle.statusError]}>
  220. Not Connected
  221. </Text>
  222. )
  223. )
  224. }
  225. <Text style={ChargeStyle.infoTitle}>Status</Text>
  226. </View>
  227. </BadgeSelectItem>
  228. );
  229. }
  230. //扫码之前-站点信息Section-end
  231. //初始页面-扫码认证之前
  232. StepRateView() {
  233. return (
  234. <View>
  235. <View style={{minHeight: $vht(80)}}>
  236. <Text style={styles.gstText}>All rates Include 8% GST</Text>
  237. <Text style={styles.title}>AC Chargers ({this.state.stationInfo?.acConnector?.available ?? "0"} available)</Text>
  238. { this.state.stationInfo.acRates?.length > 0
  239. ? this.state.stationInfo.acRates.map((item, index) => {
  240. return (
  241. <View key={index} style={ChargeStyle.stationInfoView}>
  242. <Image
  243. style={ChargeStyle.infoIcon}
  244. source={TypeImage.AC}/>
  245. <View style={ChargeStyle.infoGroup}>
  246. <Text style={ChargeStyle.infoText}>{item.type}</Text>
  247. <Text style={ChargeStyle.infoTitle}>Type</Text>
  248. </View>
  249. <View style={ChargeStyle.infoGroup}>
  250. <Text style={ChargeStyle.infoText}>{item.rates}</Text>
  251. <Text style={ChargeStyle.infoTitle}>Rate</Text>
  252. </View>
  253. <View style={ChargeStyle.infoGroup}>
  254. <Text style={ChargeStyle.infoText}>{item.power}</Text>
  255. <Text style={ChargeStyle.infoTitle}>Power</Text>
  256. </View>
  257. <View style={ChargeStyle.infoGroup}>
  258. { item?.connectorCount?.available > 0
  259. ? <Text style={[ChargeStyle.infoStatus, ChargeStyle.statusAvailable]}>Available</Text>
  260. : <Text style={[ChargeStyle.infoStatus, ChargeStyle.statusUnavailable]}>Unavailable</Text>
  261. }
  262. <Text style={ChargeStyle.infoTitle}>Status</Text>
  263. </View>
  264. </View>
  265. );
  266. })
  267. : <Text style={ui.noData}>No Rates</Text>
  268. }
  269. <Text style={styles.title}>DC Chargers ({this.state.stationInfo?.dcConnector?.available ?? "0"} available)</Text>
  270. { this.state.stationInfo.dcRates?.length > 0
  271. ? this.state.stationInfo.dcRates.map((item, index) => {
  272. return (
  273. <View key={index} style={ChargeStyle.stationInfoView}>
  274. <Image
  275. style={ChargeStyle.infoIcon}
  276. source={TypeImage.DC}/>
  277. <View style={ChargeStyle.infoGroup}>
  278. <Text style={ChargeStyle.infoText}>{item.type}</Text>
  279. <Text style={ChargeStyle.infoTitle}>Type</Text>
  280. </View>
  281. <View style={ChargeStyle.infoGroup}>
  282. <Text style={ChargeStyle.infoText}>{item.rates}</Text>
  283. <Text style={ChargeStyle.infoTitle}>Rate</Text>
  284. </View>
  285. <View style={ChargeStyle.infoGroup}>
  286. <Text style={ChargeStyle.infoText}>{item.power}</Text>
  287. <Text style={ChargeStyle.infoTitle}>Power</Text>
  288. </View>
  289. <View style={ChargeStyle.infoGroup}>
  290. { item?.connectorCount?.available > 0
  291. ? <Text style={[ChargeStyle.infoStatus, ChargeStyle.statusAvailable]}>Available</Text>
  292. : <Text style={[ChargeStyle.infoStatus, ChargeStyle.statusUnavailable]}>Unavailable</Text>
  293. }
  294. <Text style={ChargeStyle.infoTitle}>Status</Text>
  295. </View>
  296. </View>
  297. );
  298. })
  299. : <Text style={ui.noData}>No Rates</Text>
  300. }
  301. { this.state.isPrivate &&
  302. <View style={styles.privateView}>
  303. <Text style={styles.privateText}>NOTE: The charging stations are for private usage.</Text>
  304. </View>
  305. }
  306. </View>
  307. {/* <Payment refreshId={this.state.refreshId}/> */}
  308. <View style={styles.buttonGroup}>
  309. <Button
  310. style={styles.buttonLeft}
  311. text='Scan QR'
  312. //disabled={this.state.available}
  313. onClick={() => {
  314. startPage(PageList.scanqr, {actionDetail: false, id: this.state.stationInfo.id});
  315. }}/>
  316. <Button
  317. style={styles.buttonRight}
  318. text='Enter Station ID'
  319. //disabled={this.state.available}
  320. onClick={() => {
  321. this.setState({
  322. showStationDialog: true
  323. })
  324. }}/>
  325. </View>
  326. </View>
  327. );
  328. }
  329. //初始页面-扫码认证之前-end
  330. //扫码认证之后-充电开始之前
  331. StepStartView() {
  332. return (
  333. <>
  334. <View style={{minHeight: $vht(80)}}>
  335. <DashboardView isCharging={this.state.isCharging}/>
  336. <Text style={styles.title}>Selected Charger</Text>
  337. {this.StationInfo()}
  338. {/* <View style={ui.center}>
  339. <ImageBackground
  340. style={styles.batteryBorder}
  341. source={require('../../images/charge/ic-charge-circle.png')}>
  342. <Text style={{
  343. color: textPrimary,
  344. fontSize: 16,
  345. lineHeight: 22,
  346. textAlign: 'center'
  347. }}>
  348. Press<Text style={{padding: 10, fontWeight: 'bold'}}> Start </Text>to begin Charging
  349. </Text>
  350. </ImageBackground>
  351. </View> */}
  352. <Text style={styles.title}>Select Payment Method</Text>
  353. <PaymentList
  354. payType={this.state.currentPayment}
  355. payPerUse={this.state.curerntPerUser}
  356. onMethodChange={(type) => this.onPaymentMethodChanged(type)}
  357. />
  358. {/* <Payment
  359. refreshId={this.state.refreshId}
  360. payType={this.state.currentPaytype}
  361. balance={this.state.curerntPerUser}
  362. isPayPerUse={this.state.currentPayment == PAYTYPE.PAY_PER_USE}
  363. onMethodChange={() => this.onMethodChange()}
  364. /> */}
  365. </View>
  366. <Button
  367. style={styles.buttonView}
  368. text='START CHARGING'
  369. elevation={1.5}
  370. onClick={() => this.startCharge()}/>
  371. </>
  372. );
  373. }
  374. //扫码认证之后-充电开始之前-end
  375. //正在充电页面
  376. StepChargeView() {
  377. return (
  378. <>
  379. <View style={{minHeight: $vht(80)}}>
  380. <DashboardView isCharging={this.state.isCharging} connectorInfo={this.state.connectorInfo}/>
  381. <Text style={styles.title}>Selected Charger</Text>
  382. {this.StationInfo()}
  383. {/* <BatteryView
  384. soc={this.state.connectorInfo.batteryPercent}
  385. isCharging={this.state.isCharging}
  386. isPending={this.state.isPending}
  387. /> */}
  388. <Text style={styles.title}>Select Payment Method</Text>
  389. <PaymentList
  390. isSelect={false}
  391. payType={this.state.currentPayment}
  392. payPerUse={this.state.curerntPerUser}
  393. onMethodChange={(type) => this.onPaymentMethodChanged(type)}
  394. />
  395. {/* <Payment
  396. refreshId={this.state.refreshId}
  397. payType={this.state.currentPaytype}
  398. balance={this.state.curerntPerUser}
  399. /> */}
  400. { this.state.lastUpdated
  401. ? <Text style={styles.updateTip}>{'Last updated at ' + this.state.lastUpdated + '\nPull down to refresh'}</Text>
  402. : null
  403. }
  404. </View>
  405. <Button
  406. style={styles.buttonView}
  407. disabled={this.state.isPending}
  408. text={this.state.isCharging ? 'STOP CHARGING' : 'Complete'}
  409. elevation={1.5}
  410. onClick={() => {
  411. if (this.state.isCharging) {
  412. Dialog.showDialog({
  413. title: 'Stop Charging',
  414. message: 'Are you sure stop charging?',
  415. callback: ok => {
  416. if (ok == Dialog.BUTTON_OK) {
  417. this.stopCharge();
  418. }
  419. }
  420. });
  421. } else {
  422. this.stopCharge();
  423. }
  424. }}/>
  425. </>
  426. );
  427. }
  428. //正在充电页面-end
  429. //自动刷新
  430. autoCheckIsCharge() {
  431. if (this.canAutoRefresh) {
  432. this.checkIsCharge();
  433. }
  434. }
  435. //自动刷新状态
  436. autoCheckChargeStatus() {
  437. setTimeout(() => {
  438. if (this.canAutoRefresh) {
  439. this.checkChargeStatus();
  440. }
  441. }, 10000);
  442. }
  443. getConnectorInfo() {
  444. console.log("getConnectorInfo", this.state.stationInfo.id);
  445. apiCharge.checkIsCharging({sitePk: this.state.stationInfo.id}).then(res => {
  446. this.setState({
  447. connectorInfo: res.data
  448. }, () => {
  449. this.checkChargeStatus();
  450. });
  451. }).catch(err => {
  452. });
  453. }
  454. //获取充电数据(百分比)
  455. checkIsCharge(showError) {
  456. const params = {
  457. sitePk: this.state.stationInfo.id
  458. }
  459. apiCharge.checkIsCharging(params).then(res => {
  460. this.setState({
  461. isStart: true,
  462. isCharging: true,
  463. isAuthentic: true,
  464. connectorInfo: res.data,
  465. lastUpdated: utils.getNowHHmm()
  466. });
  467. if (this.canAutoRefresh) {
  468. setTimeout(() => {
  469. this.autoCheckIsCharge();
  470. }, 30000);
  471. }
  472. PagerUtil.onCharge();
  473. }).catch(err => {
  474. //TODO 模拟测试
  475. this.setState({
  476. isStart: false,
  477. isCharging: false
  478. });
  479. setTimeout(() => {
  480. this.autoCheckIsCharge();
  481. }, 30000);
  482. if (showError) {
  483. this.setState({
  484. errorCode: 'A4',
  485. showErrorDialog: true,
  486. errorMessage: 'Your vehicle doesn’t seem to be charging. Please check your vehicle.'
  487. });
  488. }
  489. });
  490. }
  491. //获取充电桩对应接口的状态
  492. checkChargeStatus() {
  493. //TODO 模拟测试
  494. /*this.setState({
  495. isStart: true,
  496. isCharging: true,
  497. isAuthentic: true
  498. });
  499. return;*/
  500. const params = {
  501. connectorId: this.state.connectorInfo.connectorId,
  502. chargeBoxId: this.state.connectorInfo.chargeBoxId,
  503. }
  504. if (!params.chargeBoxId || !params.connectorId) {
  505. this.checkIsCharge();
  506. return;
  507. }
  508. apiCharge.getCurrentStatus(params).then(res => {
  509. if (res.data.status) {
  510. switch (res.data.status) {
  511. case 'Available': //可用的
  512. this.state.connectorInfo.isCheckThrough = false;
  513. this.setState({
  514. isStart: false,
  515. isPending: false,
  516. isCharging: false,
  517. connectorInfo: this.state.connectorInfo
  518. });
  519. break;
  520. case 'Preparing': //已插入
  521. this.state.connectorInfo.isCheckThrough = true;
  522. this.setState({
  523. isStart: false,
  524. isPending: false,
  525. isCharging: false,
  526. available: true,
  527. connectorInfo: this.state.connectorInfo
  528. });
  529. //this.checkIsCharge();
  530. break;
  531. case 'Charging': //正在充电
  532. this.canAutoRefresh = true;
  533. this.state.connectorInfo.isCheckThrough = true;
  534. this.setState({
  535. isPending: false,
  536. connectorInfo: this.state.connectorInfo
  537. });
  538. this.checkIsCharge();
  539. break;
  540. case 'Initiating': //充电确认中
  541. this.canAutoRefresh = true;
  542. this.state.connectorInfo.isCheckThrough = true;
  543. this.setState({
  544. isStart: true,
  545. isPending: true,
  546. isCharging: true,
  547. isAuthentic: true,
  548. connectorInfo: this.state.connectorInfo
  549. });
  550. this.autoCheckChargeStatus();
  551. break;
  552. case 'SuspendedEVSE':
  553. this.setState({
  554. errorCode: 'A5',
  555. showErrorDialog: true,
  556. errorMessage: 'The charging station is unable to charge your vehicle.Please reauthenticate.'
  557. });
  558. break;
  559. case 'SuspendedEV': //已连接上但未充电
  560. this.checkIsCharge(true);
  561. break;
  562. case 'Reserved': //预定中
  563. this.setState({
  564. errorCode: 'A5',
  565. showErrorDialog: true,
  566. errorMessage: 'The charging station is reserved and unable to charge your vehicle.'
  567. });
  568. break;
  569. case 'Finishing': //已完成
  570. this.setState({
  571. isStart: true,
  572. isPending: false,
  573. isCharging: false
  574. });
  575. break;
  576. default:
  577. this.setState({
  578. isStart: false,
  579. isPending: false,
  580. isCharging: false
  581. });
  582. this.setState({
  583. errorCode: 'A4',
  584. showErrorDialog: true,
  585. errorMessage: 'Your vehicle doesn’t seem to be charging. Please check your vehicle. (E0)'
  586. });
  587. break;
  588. }
  589. }
  590. }).catch(err => {
  591. toastShort(err)
  592. this.setState({
  593. errorCode: 'A9',
  594. showErrorDialog: true,
  595. errorMessage: 'There seems to be an authentication error! Please try again'
  596. });
  597. })
  598. }
  599. //开始充电api
  600. startCharge() {
  601. if (this.state.connectorInfo.isCheckThrough) {
  602. Dialog.showProgressDialog();
  603. const params = {
  604. chargeBoxId: this.state.connectorInfo.chargeBoxId,
  605. connectorId: this.state.connectorInfo.connectorId
  606. }
  607. apiCharge.startCharge(params).then(res => {
  608. this.setState({
  609. isStart: true,
  610. isPending: true,
  611. isCharging: true
  612. });
  613. this.canAutoRefresh = true;
  614. this.autoCheckChargeStatus();
  615. /*setTimeout(() => {
  616. this.autoCheckIsCharge();
  617. }, 30000);*/
  618. Dialog.dismissLoading();
  619. }).catch(err => {
  620. //toastShort(err);
  621. Dialog.dismissLoading();
  622. this.setState({
  623. errorCode: 'A4',
  624. showErrorDialog: true,
  625. errorMessage: ''+err
  626. });
  627. });
  628. } else {
  629. this.setState({
  630. errorCode: 'A1',
  631. showErrorDialog: true,
  632. errorMessage: 'Your vehicle is not connected to the charging station. Please check the connector.'
  633. });
  634. }
  635. }
  636. //停止充电api
  637. stopCharge() {
  638. this.canAutoRefresh = false;
  639. Dialog.showProgressDialog();
  640. apiCharge.stopCharge().then(res => {
  641. if (res.data.chargingPk) {
  642. setTimeout(() => {
  643. Dialog.dismissLoading();
  644. this.setState({
  645. isStart: false,
  646. isPending: false,
  647. isCharging: false
  648. });
  649. startPage(PageList.summary, {
  650. chargingPk: res.data.chargingPk,
  651. id: this.state.stationInfo.id,
  652. name: this.state.stationInfo.name,
  653. address: this.state.stationInfo.address
  654. });
  655. }, 3000);
  656. } else {
  657. Dialog.dismissLoading();
  658. toastShort('An error detected, please retry.')
  659. }
  660. }).catch(err => {
  661. Dialog.dismissLoading();
  662. toastShort(err);
  663. this.setState({
  664. isStart: false,
  665. isPending: false,
  666. isCharging: false
  667. });
  668. //模拟进入结算页
  669. /*startPage(PageList.summary, {
  670. chargingPk: 1,
  671. id: this.state.stationInfo.id,
  672. name: this.state.stationInfo.name,
  673. address: this.state.stationInfo.address
  674. });*/
  675. });
  676. }
  677. closeError() {
  678. this.setState({
  679. showErrorDialog: false,
  680. showStationDialog: false
  681. });
  682. }
  683. render() {
  684. return (
  685. <View style={styles.container}>
  686. { this.state.isAuthentic //是否扫码认证
  687. ? this.state.isStart //是否开始充电
  688. ? this.StepChargeView()
  689. : this.StepStartView()
  690. : this.StepRateView()
  691. }
  692. <ErrorDialog
  693. visible={this.state.showErrorDialog}
  694. code={this.state.errorCode}
  695. message={this.state.errorMessage}
  696. onClose={() => {
  697. this.closeError();
  698. }}
  699. />
  700. <EnterStationDialog
  701. visible={this.state.showStationDialog}
  702. stationId={this.state.stationInfo.id}
  703. onConfirm={() => this.enterStatioinId()}
  704. onClose={() => this.closeError()}
  705. />
  706. </View>
  707. );
  708. }
  709. }
  710. const styles = StyleSheet.create({
  711. container: {
  712. flex: 1,
  713. paddingLeft: 16,
  714. paddingRight: 16
  715. },
  716. title: {
  717. color: '#000',
  718. fontSize: 14,
  719. fontWeight: 'bold',
  720. paddingTop: 16,
  721. paddingBottom: 16
  722. },
  723. gstText: {
  724. color: '#EF3340',
  725. fontSize: 16,
  726. paddingTop: 16,
  727. fontWeight: 'bold',
  728. textAlign: 'center'
  729. },
  730. listView: {
  731. padding: 8,
  732. },
  733. batteryBorder: {
  734. margin: 30,
  735. padding: 32,
  736. width: circleSize,
  737. height: circleSize,
  738. alignItems: 'center',
  739. justifyContent: 'center'
  740. },
  741. buttonView: {
  742. marginTop: 16,
  743. marginBottom: 32
  744. },
  745. buttonGroup: {
  746. marginTop: 16,
  747. marginBottom: 16,
  748. alignItems: 'center',
  749. flexDirection: 'row'
  750. },
  751. buttonLeft: {
  752. flex: 1,
  753. elevation: 1.5,
  754. },
  755. buttonRight: {
  756. flex: 1,
  757. marginLeft: 16,
  758. elevation: 1.5
  759. },
  760. inUse: {
  761. color: '#fff',
  762. fontSize: 12,
  763. paddingTop: 4,
  764. paddingLeft: 8,
  765. paddingRight: 8,
  766. paddingBottom: 4,
  767. borderRadius: 4,
  768. backgroundColor: '#FF7A00'
  769. },
  770. updateTip: {
  771. color: '#aaa',
  772. fontSize: 10,
  773. textAlign: 'center',
  774. paddingTop: 32,
  775. paddingBottom: 16
  776. },
  777. privateView: {
  778. height: $vht(25),
  779. alignItems: 'center',
  780. justifyContent: 'center'
  781. },
  782. privateText: {
  783. color: '#FA5759'
  784. }
  785. })