import React, { Component } from 'react'; import './index.less'; import { Checkbox, Icon } from 'antd'; import Assets from '@src/components/Assets'; import { formatDate } from '@src/services/Tools'; import Tabs from '../Tabs'; import Modal from '../Modal'; import { Order } from '../../stores/order'; import { Main } from '../../stores/main'; import { My } from '../../stores/my'; import { User } from '../../stores/user'; export class PayModal extends Component { constructor(props) { super(props); this.state = { show: true }; } componentWillReceiveProps(nextProps) { if (nextProps.show && !this.init) { this.init = true; Main.getContract('course') .then((result) => { this.setState({ contract: result }); }); } } changePay(key) { const { order } = this.props.user; if (!order) return; this.setState({ info: {}, pay: key }); let handler = null; switch (key) { case 'wechatpay': handler = Order.wechatQr(order.id) .then((result) => { this.setState({ info: result }); }); break; case 'alipay': handler = Order.alipayQr(order.id) .then((result) => { this.setState({ info: result }); }); break; default: return; } handler.then(() => { this.queryPay(); }); } queryPay(force) { const { order, needPay } = this.props.user; if (this.time) { clearTimeout(this.time); } if (force) { this.times = 0; } else { this.times = (this.times || 0) + 1; } this.time = setTimeout(() => { Order.query(order.id) .then(result => { if (result) { // 支付成功 this.paySuccess(); } else if (needPay) { this.queryPay(); } else { this.setState({ select: null, pay: null, order: null, info: null }); } }); }, 1000); } paySuccess() { const { order } = this.props.user; const { info } = this.props.user; Order.getOrder(order.id).then(result => { User.formatOrder(result); // 确保开通用的是record记录id const [checkout] = result.checkouts; checkout.info.result = checkout.info.result.replace('{email}', info.email).replace('{useExpireDays}', checkout.useExpireDays).replace('{title}', checkout.title); if (checkout.service === 'vip') { // 查询最后有效期 My.getVipInfo().then(vip => { checkout.info.result = checkout.info.result.replace('{endTime}', formatDate(vip.expireTime, 'YYYY-MM-DD')); this.setState({ show: false, showVipEnd: true, order: result, checkout }); }); } else if (order.checkouts.length === 1 && checkout.productType === 'data') { this.setState({ show: false, showDataEnd: true, order: result, checkout }); } else if (order.checkouts.length === 1) { this.setState({ show: false, showEnd: true, order: result, checkout }); } else { User.closePay(); } }); } confirm() { const { pay } = this.state; if (pay === 'bank') { this.setState({ showBank: true, show: false }); } else { // } } open() { const { checkout } = this.state; Order.useRecord(checkout.id) .then(() => { User.closePay(); this.setState({ show: true, pay: null }); }); } read() { User.closePay(); linkTo('/my/data'); } close() { const { showEnd, showBank } = this.state; User.closePay(showEnd || showBank ? null : new Error('支付失败')); this.setState({ show: true, pay: null, showEnd: false, showBank: false }); } render() { const { needPay, order } = this.props.user; const { show, showBank, showEnd, showDataEnd, showVipEnd, contract } = this.state; if (!needPay) return []; return [ showBank && this.close()} />, showEnd && this.close()} onClose={() => this.close()} onConfirm={() => this.open()} />, showDataEnd && this.close()} onClose={() => this.close()} onConfirm={() => this.read()} />, showVipEnd && this.close()} />, show && (order.checkouts.length > 1 || order.productTypes.indexOf('course_package') < 0) && this.changePay(key)} onCancel={() => this.close()} onClose={() => this.close()} onConfirm={() => this.confirm()} />, show && order.checkouts.length === 1 && order.productTypes.indexOf('course_package') < 0 && this.changePay(key)} onCancel={() => this.close()} onClose={() => this.close()} onConfirm={() => this.confirm()} />, ]; } } export class PayMModal extends Component { constructor(props) { super(props); const payList = [{ key: 'alipay', title: '支付宝' }, { key: 'wechatpay', title: '微信' }]; if (props.productType === 'course') { payList.push({ key: 'bank', title: '银行转账' }); } this.state = { pay: 'alipay', payList, checked: true, showChecked: props.productType === 'course' }; setTimeout(() => { props.onChangePay('alipay'); }, 100); } render() { const { show, checkout, onClose, onConfirm, onChangePay, order, contract = {}, productType } = this.props; const { info } = checkout; const { pay, payList, checked, showChecked } = this.state; return (
商品: {productType === 'data' ? info.title : checkout.title}
服务: {productType === 'data' ? checkout.title : info.description}
开通有效期: {checkout.expireDays ? `${checkout.expireDays}天` : '付款后立即生效'}
使用有效期: {checkout.useExpireDays ? `${checkout.useExpireDays}天` : '永久'}
退款政策: {info.refund_policy}
版权说明: {info.copyright_notes}
应付金额:
¥ {order.money}
} onChange={key => { this.setState({ pay: key }); onChangePay(key); }} />
*若在购买过程中遇到问题
请联系千行小助手:0193191safad 协助解决。
); } } export class PayMutilModal extends Component { constructor(props) { super(props); this.state = { pay: 'alipay', checked: true, showChecked: true }; setTimeout(() => { props.onChangePay('alipay'); }, 100); } render() { const { show, onConfirm, onClose, onChangePay, order, contract = {} } = this.props; const { pay, checked, showChecked } = this.state; return (
商品: {order.checkouts.map(row => row.title).join(' ')}
服务: 见{contract.title}
开通有效期: 见订单详情
使用有效期: 见订单详情
退款政策: 本商品为虚拟产品,购买成功后不支持退款。
版权说明: 本商品为虚拟产品,购买成功后不支持退款。
应付金额:
¥ {order.money}
} onChange={key => { this.setState({ pay: key }); onChangePay(key); }} />
*若在购买过程中遇到问题
请联系千行小助手:0193191safad 协助解决。
); } } export class PayKBankModal extends Component { render() { const { show, onConfirm } = this.props; return (
汇款成功后,请添加微信号XXX或扫描二维码联系小助手,进行核实。
); } } export class PayMEndModal extends Component { render() { const { show, onConfirm, onCancel, checkout = {} } = this.props; const { info } = checkout; return (
{info.result}
{info.tips &&
*{info.tips}
}
); } } export class PayMDataEndModal extends Component { render() { const { show, onConfirm, onCancel, checkout = {} } = this.props; const { info } = checkout; return (
{info.result}
{info.tips &&
*{info.tips}
}
); } } export class PayMVipEndModal extends Component { render() { const { show, onConfirm, checkout = {} } = this.props; const { info } = checkout; return (
{info.result}
{info.tips &&
*{info.tips}
}
); } }