123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524 |
- import React, { Component } from 'react'
- import {
- StyleSheet,
- View,
- Image,
- Dimensions,
- Text,
- TouchableOpacity,
- FlatList,
- PixelRatio,
- ActivityIndicator,
- ImageBackground,
- } from 'react-native'
- import { connect } from 'react-redux'
- import ImgAliPay from '../../../static/images/order-AliPay.png'
- import ImgWechatPay from '../../../static/images/order-WechatPay.png'
- import ImgChanPay from '../../../static/images/order-ChanPay.png'
- import PayBacg from '../../../static/images/Pay-bacg.png'
- import PayLogo from '../../../static/images/Pay-Logo.png'
- import { HeaderView } from '../../common/HeaderView'
- import Checkbox from '../../../components/checkbox'
- import * as authService from '../../../services/auth'
- import { ScaleUtil, ReturnDate } from '../../../utils/utils'
- import { NavigationActions, createAction } from '../../../utils'
- import { _AliPay } from '../../../utils/payUtil'
- import Toast from 'react-native-root-toast'
- const { height, width } = Dimensions.get('window')
- @connect(({ rechargeModels, router }) => ({ ...rechargeModels, ...router }))
- class OrderPay extends Component {
- constructor(props) {
- super(props)
- /**
- * payChecked :0 支付宝支付
- * payChecked :1 微信支付
- * payChecked :2 畅捷支付
- */
- this.state = {
- payChecked: 0,
- submitLoading: false,
- // 支付等待状态
- payingState: false,
- alertState: false,
- totalAmount: props.navigation.state.params.totalAmount,
- submitData: props.navigation.state.params.submitData,
- comeFrom: props.navigation.state.params.comeFrom
- ? props.navigation.state.params.comeFrom
- : 'order',
- }
- }
- componentDidMount() {
- this.props.dispatch(createAction('rechargeModels/PaywaysSagas')())
- }
- paymentList(data, flag) {
- return (
- <TouchableOpacity
- onPress={() => this.setState({ payChecked: data.key })}
- style={{
- paddingTop: 10,
- paddingBottom: 10,
- flexDirection: 'row',
- justifyContent: 'space-between',
- alignItems: 'center',
- borderBottomColor: '#EEE',
- backgroundColor: '#FFF',
- paddingHorizontal: 10,
- borderBottomWidth: 1 / PixelRatio.get(),
- }}
- >
- <View style={{ flexDirection: 'row' }}>
- <Image
- resizeMode="contain"
- source={data.Img}
- style={{ width: 26, height: 26, marginRight: 10, borderRadius: 6 }}
- />
- <Text style={[styles.textFont14, { alignSelf: 'center' }]}>
- {data && data.name}
- </Text>
- </View>
- <Checkbox
- checkBoxColor={'#CCC'}
- checked={this.state.payChecked == data.key}
- size={28}
- onChange={bool => this.setState({ payChecked: data.key })}
- />
- </TouchableOpacity>
- )
- }
- //创建支付单
- async _createPayBill(payWay) {
- const searchInfo = { ...this.state.submitData, paymentModeId: payWay.code }
- this.props
- .dispatch(
- createAction('rechargeModels/submitPayBill')({
- searchInfo: searchInfo,
- })
- )
- .finally(() => {
- if (
- this.props.payBillData &&
- (this.props.payBillData.paymentAmount ||
- this.props.payBillData.paybillCode)
- ) {
- switch (payWay.name) {
- // 支付宝
- case '支付宝':
- _AliPay(
- this.props.payBillData,
- // 成功后操作
- () => {
- this.setState({ payingState: false })
- const routers = this.props.routes[0].routes
- routers.forEach(element => {
- if (element.routeName == 'RechargeAdd') {
- this.props.navigation.goBack(element.key)
- }
- })
- this.props.navigation.state.params.callBack()
- },
- // 验签失败操作
- () => this.setState({ payingState: false }),
- // 取消支付
- () => this.setState({ payingState: false })
- )
- break
- // 微信
- case '微信':
- this.toast = Toast.show('微信支付正在开发中', {
- position: toastHeight,
- })
- // _WechatPay();
- break
- // // 畅捷支付
- case '畅捷支付':
- this.toast = Toast.show('畅捷支付正在开发中', {
- position: toastHeight,
- })
- break
- }
- } else {
- this.toast = Toast.show('生成支付单报错', {
- position: toastHeight,
- })
- }
- })
- .catch(error => {
- this.setState({ payingState: false })
- this.toast = Toast.show('订单转支付单时异常', {
- position: toastHeight,
- })
- })
- }
- // 随单支付支付单
- _reqCreatePayBill(payWay) {
- const searchInfo = { ...this.state.submitData, paymentModeId: payWay.code }
- this.props
- .dispatch(
- createAction('rechargeModels/reqOrderpayBillPost')({
- searchInfo: searchInfo,
- })
- )
- .finally(() => {
- if (this.toast) {
- Toast.hide(this.toast)
- }
- if (
- this.props.reqPayBillData &&
- this.props.reqPayBillData.length == 1 &&
- (this.props.reqPayBillData[0].paymentAmount ||
- this.props.reqPayBillData[0].paybillCode)
- ) {
- switch (payWay.name) {
- // 支付宝
- case '支付宝':
- _AliPay(
- this.props.reqPayBillData[0],
- // 成功后操作
- () => {
- this.setState({ alertState: true })
- },
- // 验签失败操作
- () => this.setState({ payingState: false }),
- // 取消支付
- () => this.setState({ payingState: false })
- )
- // this._AliPay(this.props.reqPayBillData[0]);
- break
- // 微信
- case '微信':
- this.toast = Toast.show('微信支付正在开发中', {
- position: toastHeight,
- })
- // _WechatPay();
- break
- // // 畅捷支付
- case '畅捷支付':
- this.toast = Toast.show('畅捷支付正在开发中', {
- position: toastHeight,
- })
- break
- }
- } else if (
- this.props.reqPayBillData &&
- this.props.reqPayBillData.length > 1 &&
- this.props.reqPayBillData.every(reqdata => reqdata.paybillCode)
- ) {
- // 如果有多个支付单,则跳转到支付单列表
- this.props.dispatch(
- NavigationActions.navigate({
- routeName: 'RechargeHome',
- params: {
- searchPayListInfo: this.props.reqPayBillData[0].srcBillCode,
- },
- })
- )
- } else {
- this.setState({ payingState: false })
- this.toast = Toast.show('订单转支付单时异常', {
- position: toastHeight,
- })
- }
- })
- }
- render() {
- const { totalAmount, submitData } = this.state,
- { payWays } = this.props
- let reqPayBillData = ''
- if (this.props.reqPayBillData && this.props.reqPayBillData.length > 0) {
- reqPayBillData = this.props.reqPayBillData[0]
- }
- if (payWays && payWays.length > 0) {
- for (let val in payWays) {
- payWays[val].key = val
- if (payWays[val].name == '支付宝') {
- payWays[val].Img = ImgAliPay
- } else if (payWays[val].name == '微信') {
- payWays[val].Img = ImgWechatPay
- } else {
- payWays[val].Img = ImgChanPay
- }
- }
- }
- return (
- <View style={styles.container}>
- {HeaderView(this.props.dispatch, '收银台')}
- <View style={{ flex: 1 }}>
- {/* 需支付金额 */}
- <View
- style={{
- padding: 10,
- flexDirection: 'row',
- backgroundColor: '#FFF',
- }}
- >
- <Text
- style={[
- styles.text333,
- { alignSelf: 'flex-end', marginBottom: 4 },
- ]}
- >
- 待支付:
- </Text>
- <Text style={styles.textred}>
- {CURRENCY.currencySign + ' '}
- {ScaleUtil(
- totalAmount,
- submitData.currencyAmountScale || CURRENCY.currencyAmountScale
- )}
- </Text>
- </View>
- <FlatList
- keyExtractor={(item, index) => index}
- data={payWays}
- extraData={this.state}
- renderItem={({ item, index }) => this.paymentList(item)}
- style={{
- marginTop: 10,
- }}
- />
- </View>
- <TouchableOpacity
- onPress={() => {
- this.setState({ payingState: true })
- if (this.state.comeFrom == 'order') {
- this._reqCreatePayBill(payWays[this.state.payChecked])
- } else if (this.state.comeFrom == 'addPayBill') {
- this._createPayBill(payWays[this.state.payChecked])
- }
- }}
- style={{
- height: 50,
- backgroundColor: '#E70013',
- justifyContent: 'center',
- alignItems: 'center',
- }}
- >
- <Text style={styles.textWhite}>
- {payWays && payWays.length > 0
- ? payWays[this.state.payChecked].name
- : ''}
- {CURRENCY.currencySign}
- {ScaleUtil(
- totalAmount,
- submitData.currencyAmountScale || CURRENCY.currencyAmountScale
- )}
- </Text>
- </TouchableOpacity>
- {/* <TouchableOpacity
- onPress={() => {
- console.log(this.props);
- // this.props.navigation.replace("orderHome");
- this.props.dispatch(
- NavigationActions.replace({
- routeName: "RechargeHome"
- })
- );
- // this.props.dispatch(
- // NavigationActions.reset({
- // // 重置堆栈式导航的路由顺序
- // index: 0, // 到哪个索引的路由中去
- // actions: [
- // NavigationActions.navigate({ routeName: "RechargeHome" })
- // ]
- // })
- // );
- }}
- >
- <Text>aaa</Text>
- </TouchableOpacity> */}
- {this.state.payingState ? (
- <View
- style={{
- height: height + 200,
- width: width,
- backgroundColor: '#000',
- position: 'absolute',
- opacity: 0.5,
- alignSelf: 'center',
- justifyContent: 'center',
- }}
- >
- <ActivityIndicator />
- </View>
- ) : null}
- {this.state.alertState ? (
- <ImageBackground
- source={PayBacg}
- style={{
- position: 'absolute',
- height: 243,
- width: width * 0.95,
- top: height * 0.35,
- alignSelf: 'center',
- paddingTop: 15,
- }}
- >
- <Image
- source={PayLogo}
- style={{ width: 50, height: 50, alignSelf: 'center' }}
- />
- <View
- style={{
- flex: 1,
- backgroundColor: '#FFF',
- paddingTop: 3,
- paddingHorizontal: 10,
- }}
- >
- <Text
- style={{
- alignSelf: 'center',
- fontSize: 16,
- letterSpacing: 1.14,
- lineHeight: 22,
- color: '#333',
- }}
- >
- 支付成功
- </Text>
- <Text
- style={{
- alignSelf: 'center',
- fontSize: 24,
- lineHeight: 24,
- color: '#333',
- marginTop: 3,
- }}
- >
- {CURRENCY.currencySign}
- {' ' + ScaleUtil(totalAmount, CURRENCY.currencyAmountScale)}
- </Text>
- <View
- style={{
- flexDirection: 'row',
- justifyContent: 'space-between',
- marginTop: 10,
- }}
- >
- <Text
- style={{
- fontSize: 12,
- lineHeight: 20,
- color: '#999',
- }}
- >
- 支付时间
- </Text>
- <Text
- style={{
- fontSize: 12,
- lineHeight: 20,
- color: '#666',
- }}
- >
- {reqPayBillData && reqPayBillData.billDate
- ? ReturnDate(reqPayBillData.billDate)
- : ''}
- </Text>
- </View>
- <View
- style={{
- flexDirection: 'row',
- justifyContent: 'space-between',
- }}
- >
- <Text
- style={{
- fontSize: 12,
- lineHeight: 20,
- color: '#999',
- }}
- >
- 收款方
- </Text>
- <Text
- style={{
- fontSize: 12,
- lineHeight: 20,
- color: '#666',
- }}
- >
- {reqPayBillData && reqPayBillData.payeeName
- ? reqPayBillData.payeeName
- : ''}
- </Text>
- </View>
- </View>
- <View
- style={{
- height: 58,
- borderTopColor: '#EEE',
- borderTopWidth: 1 / PixelRatio.get(),
- justifyContent: 'center',
- }}
- >
- <TouchableOpacity
- onPress={() => {
- // 返回OrderHome
- this.props.dispatch(
- NavigationActions.navigate({
- routeName: 'OrderHome',
- action: NavigationActions.navigate({
- routeName: 'OrderHome',
- }),
- })
- )
- }}
- style={{
- alignSelf: 'center',
- backgroundColor: '#E70013',
- paddingHorizontal: 40,
- paddingVertical: 5,
- borderRadius: 30,
- }}
- >
- <Text style={{ fontSize: 14, color: '#FFF', lineHeight: 17 }}>
- 知道了
- </Text>
- </TouchableOpacity>
- </View>
- </ImageBackground>
- ) : null}
- </View>
- )
- }
- }
- const styles = StyleSheet.create({
- container: {
- flex: 1,
- },
- text333: {
- fontSize: 12,
- letterSpacing: 0.17,
- color: '#333',
- },
- textFont14: {
- fontSize: 14,
- letterSpacing: 0.17,
- color: '#333',
- },
- text666: {
- fontSize: 13,
- letterSpacing: 0.17,
- color: '#666',
- },
- textWhite: {
- fontSize: 14,
- letterSpacing: 0.17,
- color: '#FFF',
- },
- textred: {
- fontSize: 22,
- color: '#E70013',
- },
- })
- export default OrderPay
|