index.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import React, { Component } from 'react';
  2. import './index.less';
  3. import Assets from '@src/components/Assets';
  4. import { formatMoney } from '@src/services/Tools';
  5. import Modal from '../Modal';
  6. import Tabs from '../Tabs';
  7. import { SpecialRadioGroup } from '../Radio';
  8. import Invite from '../Invite';
  9. import Button from '../Button';
  10. import { Main } from '../../stores/main';
  11. import { Order } from '../../stores/order';
  12. import { ServiceParamMap } from '../../../Constant';
  13. export default class extends Component {
  14. constructor(props) {
  15. super(props);
  16. this.state = { tab: '2', pay: '', select: null, auth: true };
  17. Main.getService('vip')
  18. .then(result => {
  19. result.package = result.package.map((row, index) => {
  20. row.label = `${row.title}: ¥${formatMoney(row.price)}`;
  21. row.value = ServiceParamMap.vip[index].value;
  22. return row;
  23. });
  24. this.setState({ service: result });
  25. });
  26. }
  27. select(key) {
  28. Order.speedPay({ productType: 'service', service: 'vip', param: key }).then(result => {
  29. this.setState({ order: result });
  30. this.changePay('alipay');
  31. });
  32. this.setState({ select: key });
  33. }
  34. changePay(key) {
  35. const { order } = this.state;
  36. if (!order) return;
  37. this.setState({ info: {}, pay: key });
  38. let handler = null;
  39. switch (key) {
  40. case 'wechatpay':
  41. handler = Order.wechatQr(order.id)
  42. .then((result) => {
  43. this.setState({ info: result });
  44. });
  45. break;
  46. case 'alipay':
  47. default:
  48. handler = Order.alipayQr(order.id)
  49. .then((result) => {
  50. this.setState({ info: result });
  51. });
  52. }
  53. handler.then(() => {
  54. this.queryPay();
  55. });
  56. }
  57. queryPay() {
  58. const { order, show } = this.state;
  59. if (this.time) {
  60. clearTimeout(this.time);
  61. }
  62. this.time = setTimeout(() => {
  63. Order.query(order.id)
  64. .then(result => {
  65. if (result) {
  66. // 支付成功
  67. this.setState();
  68. } else if (show) {
  69. this.queryPay();
  70. } else {
  71. this.setState({ select: null, pay: null, order: null, info: null });
  72. }
  73. });
  74. }, 1000);
  75. }
  76. render() {
  77. const { show, onClose } = this.props;
  78. const { tab } = this.state;
  79. return (
  80. <Modal className="vip-renew-modal" show={show} width={630} title="VIP续期" onClose={onClose}>
  81. <div className="vip-renew-wrapper">
  82. <Tabs
  83. border
  84. size="small"
  85. active={tab}
  86. width={80}
  87. tabs={[{ key: '1', title: '购买' }, { key: '2', title: '免费领取' }]}
  88. onChange={key => this.setState({ tab: key })}
  89. />
  90. {this[`renderTab${tab}`]()}
  91. </div>
  92. </Modal>
  93. );
  94. }
  95. renderTab1() {
  96. const { pay, select, service = {}, order } = this.state;
  97. return (
  98. <div className="tab-1-layout">
  99. <div className="select-layout">
  100. <SpecialRadioGroup
  101. list={service.package || []}
  102. value={select}
  103. width={150}
  104. space={10}
  105. onChange={key => this.select(key)}
  106. />
  107. </div>
  108. <div className="pay-layout">
  109. <Tabs
  110. border
  111. size="small"
  112. active={pay}
  113. width={80}
  114. tabs={[{ key: 'alipay', title: '支付宝' }, { key: 'wechatpay', title: '微信' }]}
  115. render={item => <Assets name={item.key} />}
  116. onChange={key => this.changePay(key)}
  117. />
  118. <div className="qrcode">
  119. <Assets name="qrcode" />
  120. </div>
  121. <div className="t">请使用手机微信或支付宝扫码付款</div>
  122. {order && <div className="t">支付金额: ¥ {order.money}</div>}
  123. </div>
  124. </div>
  125. );
  126. }
  127. renderTab2() {
  128. const { data, onReal, onPrepare } = this.props;
  129. const { showInvite } = this.state;
  130. return (
  131. <div className="tab-2-layout">
  132. <div className="list">
  133. <div className="item">
  134. {data.bindReal && <span className="over">已完成</span>}
  135. <Assets className="icon" name="realname2" />
  136. <div className="t">
  137. <Assets name="gift" />
  138. 6个月
  139. </div>
  140. <Button size="small" radius disabled={data.bindReal} onClick={() => {
  141. onReal();
  142. }}>
  143. 实名认证
  144. </Button>
  145. </div>
  146. <div className="item">
  147. <Assets className="icon" name="invite" />
  148. <div className="t">
  149. <Assets name="gift" />
  150. {data.inviteNumber > 0 ? `7天 X ${data.inviteNumber}位好友` : '7天/每位好友'}
  151. </div>
  152. <Button size="small" radius onClick={() => {
  153. this.setState({ showInvite: true });
  154. }}>
  155. 邀请好友
  156. </Button>
  157. </div>
  158. <div className="item">
  159. {data.bindPrepare && <span className="over">已完成</span>}
  160. <Assets className="icon" name="information2" />
  161. <div className="t">
  162. <Assets name="gift" />
  163. 1个月
  164. </div>
  165. <Button size="small" radius disabled={data.bindPrepare} onClick={() => {
  166. onPrepare();
  167. }}>
  168. 完善信息
  169. </Button>
  170. </div>
  171. </div>
  172. {showInvite && <Invite data={data} />}
  173. </div>
  174. );
  175. }
  176. }