OrderPay.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. import React, { Component } from 'react'
  2. import {
  3. StyleSheet,
  4. View,
  5. Image,
  6. Dimensions,
  7. Text,
  8. TouchableOpacity,
  9. FlatList,
  10. PixelRatio,
  11. ActivityIndicator,
  12. ImageBackground,
  13. } from 'react-native'
  14. import { connect } from 'react-redux'
  15. import ImgAliPay from '../../../static/images/order-AliPay.png'
  16. import ImgWechatPay from '../../../static/images/order-WechatPay.png'
  17. import ImgChanPay from '../../../static/images/order-ChanPay.png'
  18. import PayBacg from '../../../static/images/Pay-bacg.png'
  19. import PayLogo from '../../../static/images/Pay-Logo.png'
  20. import { HeaderView } from '../../common/HeaderView'
  21. import Checkbox from '../../../components/checkbox'
  22. import * as authService from '../../../services/auth'
  23. import { ScaleUtil, ReturnDate } from '../../../utils/utils'
  24. import { NavigationActions, createAction } from '../../../utils'
  25. import { _AliPay } from '../../../utils/payUtil'
  26. import Toast from 'react-native-root-toast'
  27. const { height, width } = Dimensions.get('window')
  28. @connect(({ rechargeModels, router }) => ({ ...rechargeModels, ...router }))
  29. class OrderPay extends Component {
  30. constructor(props) {
  31. super(props)
  32. /**
  33. * payChecked :0 支付宝支付
  34. * payChecked :1 微信支付
  35. * payChecked :2 畅捷支付
  36. */
  37. this.state = {
  38. payChecked: 0,
  39. submitLoading: false,
  40. // 支付等待状态
  41. payingState: false,
  42. alertState: false,
  43. totalAmount: props.navigation.state.params.totalAmount,
  44. submitData: props.navigation.state.params.submitData,
  45. comeFrom: props.navigation.state.params.comeFrom
  46. ? props.navigation.state.params.comeFrom
  47. : 'order',
  48. }
  49. }
  50. componentDidMount() {
  51. this.props.dispatch(createAction('rechargeModels/PaywaysSagas')())
  52. }
  53. paymentList(data, flag) {
  54. return (
  55. <TouchableOpacity
  56. onPress={() => this.setState({ payChecked: data.key })}
  57. style={{
  58. paddingTop: 10,
  59. paddingBottom: 10,
  60. flexDirection: 'row',
  61. justifyContent: 'space-between',
  62. alignItems: 'center',
  63. borderBottomColor: '#EEE',
  64. backgroundColor: '#FFF',
  65. paddingHorizontal: 10,
  66. borderBottomWidth: 1 / PixelRatio.get(),
  67. }}
  68. >
  69. <View style={{ flexDirection: 'row' }}>
  70. <Image
  71. resizeMode="contain"
  72. source={data.Img}
  73. style={{ width: 26, height: 26, marginRight: 10, borderRadius: 6 }}
  74. />
  75. <Text style={[styles.textFont14, { alignSelf: 'center' }]}>
  76. {data && data.name}
  77. </Text>
  78. </View>
  79. <Checkbox
  80. checkBoxColor={'#CCC'}
  81. checked={this.state.payChecked == data.key}
  82. size={28}
  83. onChange={bool => this.setState({ payChecked: data.key })}
  84. />
  85. </TouchableOpacity>
  86. )
  87. }
  88. //创建支付单
  89. async _createPayBill(payWay) {
  90. const searchInfo = { ...this.state.submitData, paymentModeId: payWay.code }
  91. this.props
  92. .dispatch(
  93. createAction('rechargeModels/submitPayBill')({
  94. searchInfo: searchInfo,
  95. })
  96. )
  97. .finally(() => {
  98. if (
  99. this.props.payBillData &&
  100. (this.props.payBillData.paymentAmount ||
  101. this.props.payBillData.paybillCode)
  102. ) {
  103. switch (payWay.name) {
  104. // 支付宝
  105. case '支付宝':
  106. _AliPay(
  107. this.props.payBillData,
  108. // 成功后操作
  109. () => {
  110. this.setState({ payingState: false })
  111. const routers = this.props.routes[0].routes
  112. routers.forEach(element => {
  113. if (element.routeName == 'RechargeAdd') {
  114. this.props.navigation.goBack(element.key)
  115. }
  116. })
  117. this.props.navigation.state.params.callBack()
  118. },
  119. // 验签失败操作
  120. () => this.setState({ payingState: false }),
  121. // 取消支付
  122. () => this.setState({ payingState: false })
  123. )
  124. break
  125. // 微信
  126. case '微信':
  127. this.toast = Toast.show('微信支付正在开发中', {
  128. position: toastHeight,
  129. })
  130. // _WechatPay();
  131. break
  132. // // 畅捷支付
  133. case '畅捷支付':
  134. this.toast = Toast.show('畅捷支付正在开发中', {
  135. position: toastHeight,
  136. })
  137. break
  138. }
  139. } else {
  140. this.toast = Toast.show('生成支付单报错', {
  141. position: toastHeight,
  142. })
  143. }
  144. })
  145. .catch(error => {
  146. this.setState({ payingState: false })
  147. this.toast = Toast.show('订单转支付单时异常', {
  148. position: toastHeight,
  149. })
  150. })
  151. }
  152. // 随单支付支付单
  153. _reqCreatePayBill(payWay) {
  154. const searchInfo = { ...this.state.submitData, paymentModeId: payWay.code }
  155. this.props
  156. .dispatch(
  157. createAction('rechargeModels/reqOrderpayBillPost')({
  158. searchInfo: searchInfo,
  159. })
  160. )
  161. .finally(() => {
  162. if (this.toast) {
  163. Toast.hide(this.toast)
  164. }
  165. if (
  166. this.props.reqPayBillData &&
  167. this.props.reqPayBillData.length == 1 &&
  168. (this.props.reqPayBillData[0].paymentAmount ||
  169. this.props.reqPayBillData[0].paybillCode)
  170. ) {
  171. switch (payWay.name) {
  172. // 支付宝
  173. case '支付宝':
  174. _AliPay(
  175. this.props.reqPayBillData[0],
  176. // 成功后操作
  177. () => {
  178. this.setState({ alertState: true })
  179. },
  180. // 验签失败操作
  181. () => this.setState({ payingState: false }),
  182. // 取消支付
  183. () => this.setState({ payingState: false })
  184. )
  185. // this._AliPay(this.props.reqPayBillData[0]);
  186. break
  187. // 微信
  188. case '微信':
  189. this.toast = Toast.show('微信支付正在开发中', {
  190. position: toastHeight,
  191. })
  192. // _WechatPay();
  193. break
  194. // // 畅捷支付
  195. case '畅捷支付':
  196. this.toast = Toast.show('畅捷支付正在开发中', {
  197. position: toastHeight,
  198. })
  199. break
  200. }
  201. } else if (
  202. this.props.reqPayBillData &&
  203. this.props.reqPayBillData.length > 1 &&
  204. this.props.reqPayBillData.every(reqdata => reqdata.paybillCode)
  205. ) {
  206. // 如果有多个支付单,则跳转到支付单列表
  207. this.props.dispatch(
  208. NavigationActions.navigate({
  209. routeName: 'RechargeHome',
  210. params: {
  211. searchPayListInfo: this.props.reqPayBillData[0].srcBillCode,
  212. },
  213. })
  214. )
  215. } else {
  216. this.setState({ payingState: false })
  217. this.toast = Toast.show('订单转支付单时异常', {
  218. position: toastHeight,
  219. })
  220. }
  221. })
  222. }
  223. render() {
  224. const { totalAmount, submitData } = this.state,
  225. { payWays } = this.props
  226. let reqPayBillData = ''
  227. if (this.props.reqPayBillData && this.props.reqPayBillData.length > 0) {
  228. reqPayBillData = this.props.reqPayBillData[0]
  229. }
  230. if (payWays && payWays.length > 0) {
  231. for (let val in payWays) {
  232. payWays[val].key = val
  233. if (payWays[val].name == '支付宝') {
  234. payWays[val].Img = ImgAliPay
  235. } else if (payWays[val].name == '微信') {
  236. payWays[val].Img = ImgWechatPay
  237. } else {
  238. payWays[val].Img = ImgChanPay
  239. }
  240. }
  241. }
  242. return (
  243. <View style={styles.container}>
  244. {HeaderView(this.props.dispatch, '收银台')}
  245. <View style={{ flex: 1 }}>
  246. {/* 需支付金额 */}
  247. <View
  248. style={{
  249. padding: 10,
  250. flexDirection: 'row',
  251. backgroundColor: '#FFF',
  252. }}
  253. >
  254. <Text
  255. style={[
  256. styles.text333,
  257. { alignSelf: 'flex-end', marginBottom: 4 },
  258. ]}
  259. >
  260. 待支付:
  261. </Text>
  262. <Text style={styles.textred}>
  263. {CURRENCY.currencySign + ' '}
  264. {ScaleUtil(
  265. totalAmount,
  266. submitData.currencyAmountScale || CURRENCY.currencyAmountScale
  267. )}
  268. </Text>
  269. </View>
  270. <FlatList
  271. keyExtractor={(item, index) => index}
  272. data={payWays}
  273. extraData={this.state}
  274. renderItem={({ item, index }) => this.paymentList(item)}
  275. style={{
  276. marginTop: 10,
  277. }}
  278. />
  279. </View>
  280. <TouchableOpacity
  281. onPress={() => {
  282. this.setState({ payingState: true })
  283. if (this.state.comeFrom == 'order') {
  284. this._reqCreatePayBill(payWays[this.state.payChecked])
  285. } else if (this.state.comeFrom == 'addPayBill') {
  286. this._createPayBill(payWays[this.state.payChecked])
  287. }
  288. }}
  289. style={{
  290. height: 50,
  291. backgroundColor: '#E70013',
  292. justifyContent: 'center',
  293. alignItems: 'center',
  294. }}
  295. >
  296. <Text style={styles.textWhite}>
  297. {payWays && payWays.length > 0
  298. ? payWays[this.state.payChecked].name
  299. : ''}
  300. {CURRENCY.currencySign}
  301. {ScaleUtil(
  302. totalAmount,
  303. submitData.currencyAmountScale || CURRENCY.currencyAmountScale
  304. )}
  305. </Text>
  306. </TouchableOpacity>
  307. {/* <TouchableOpacity
  308. onPress={() => {
  309. console.log(this.props);
  310. // this.props.navigation.replace("orderHome");
  311. this.props.dispatch(
  312. NavigationActions.replace({
  313. routeName: "RechargeHome"
  314. })
  315. );
  316. // this.props.dispatch(
  317. // NavigationActions.reset({
  318. // // 重置堆栈式导航的路由顺序
  319. // index: 0, // 到哪个索引的路由中去
  320. // actions: [
  321. // NavigationActions.navigate({ routeName: "RechargeHome" })
  322. // ]
  323. // })
  324. // );
  325. }}
  326. >
  327. <Text>aaa</Text>
  328. </TouchableOpacity> */}
  329. {this.state.payingState ? (
  330. <View
  331. style={{
  332. height: height + 200,
  333. width: width,
  334. backgroundColor: '#000',
  335. position: 'absolute',
  336. opacity: 0.5,
  337. alignSelf: 'center',
  338. justifyContent: 'center',
  339. }}
  340. >
  341. <ActivityIndicator />
  342. </View>
  343. ) : null}
  344. {this.state.alertState ? (
  345. <ImageBackground
  346. source={PayBacg}
  347. style={{
  348. position: 'absolute',
  349. height: 243,
  350. width: width * 0.95,
  351. top: height * 0.35,
  352. alignSelf: 'center',
  353. paddingTop: 15,
  354. }}
  355. >
  356. <Image
  357. source={PayLogo}
  358. style={{ width: 50, height: 50, alignSelf: 'center' }}
  359. />
  360. <View
  361. style={{
  362. flex: 1,
  363. backgroundColor: '#FFF',
  364. paddingTop: 3,
  365. paddingHorizontal: 10,
  366. }}
  367. >
  368. <Text
  369. style={{
  370. alignSelf: 'center',
  371. fontSize: 16,
  372. letterSpacing: 1.14,
  373. lineHeight: 22,
  374. color: '#333',
  375. }}
  376. >
  377. 支付成功
  378. </Text>
  379. <Text
  380. style={{
  381. alignSelf: 'center',
  382. fontSize: 24,
  383. lineHeight: 24,
  384. color: '#333',
  385. marginTop: 3,
  386. }}
  387. >
  388. {CURRENCY.currencySign}
  389. {' ' + ScaleUtil(totalAmount, CURRENCY.currencyAmountScale)}
  390. </Text>
  391. <View
  392. style={{
  393. flexDirection: 'row',
  394. justifyContent: 'space-between',
  395. marginTop: 10,
  396. }}
  397. >
  398. <Text
  399. style={{
  400. fontSize: 12,
  401. lineHeight: 20,
  402. color: '#999',
  403. }}
  404. >
  405. 支付时间
  406. </Text>
  407. <Text
  408. style={{
  409. fontSize: 12,
  410. lineHeight: 20,
  411. color: '#666',
  412. }}
  413. >
  414. {reqPayBillData && reqPayBillData.billDate
  415. ? ReturnDate(reqPayBillData.billDate)
  416. : ''}
  417. </Text>
  418. </View>
  419. <View
  420. style={{
  421. flexDirection: 'row',
  422. justifyContent: 'space-between',
  423. }}
  424. >
  425. <Text
  426. style={{
  427. fontSize: 12,
  428. lineHeight: 20,
  429. color: '#999',
  430. }}
  431. >
  432. 收款方
  433. </Text>
  434. <Text
  435. style={{
  436. fontSize: 12,
  437. lineHeight: 20,
  438. color: '#666',
  439. }}
  440. >
  441. {reqPayBillData && reqPayBillData.payeeName
  442. ? reqPayBillData.payeeName
  443. : ''}
  444. </Text>
  445. </View>
  446. </View>
  447. <View
  448. style={{
  449. height: 58,
  450. borderTopColor: '#EEE',
  451. borderTopWidth: 1 / PixelRatio.get(),
  452. justifyContent: 'center',
  453. }}
  454. >
  455. <TouchableOpacity
  456. onPress={() => {
  457. // 返回OrderHome
  458. this.props.dispatch(
  459. NavigationActions.navigate({
  460. routeName: 'OrderHome',
  461. action: NavigationActions.navigate({
  462. routeName: 'OrderHome',
  463. }),
  464. })
  465. )
  466. }}
  467. style={{
  468. alignSelf: 'center',
  469. backgroundColor: '#E70013',
  470. paddingHorizontal: 40,
  471. paddingVertical: 5,
  472. borderRadius: 30,
  473. }}
  474. >
  475. <Text style={{ fontSize: 14, color: '#FFF', lineHeight: 17 }}>
  476. 知道了
  477. </Text>
  478. </TouchableOpacity>
  479. </View>
  480. </ImageBackground>
  481. ) : null}
  482. </View>
  483. )
  484. }
  485. }
  486. const styles = StyleSheet.create({
  487. container: {
  488. flex: 1,
  489. },
  490. text333: {
  491. fontSize: 12,
  492. letterSpacing: 0.17,
  493. color: '#333',
  494. },
  495. textFont14: {
  496. fontSize: 14,
  497. letterSpacing: 0.17,
  498. color: '#333',
  499. },
  500. text666: {
  501. fontSize: 13,
  502. letterSpacing: 0.17,
  503. color: '#666',
  504. },
  505. textWhite: {
  506. fontSize: 14,
  507. letterSpacing: 0.17,
  508. color: '#FFF',
  509. },
  510. textred: {
  511. fontSize: 22,
  512. color: '#E70013',
  513. },
  514. })
  515. export default OrderPay