page.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import React from 'react';
  2. import './index.less';
  3. import Page from '@src/containers/Page';
  4. import Assets from '@src/components/Assets';
  5. import { asyncSMessage } from '@src/services/AsyncTools';
  6. import { H5Url } from '../../../../Constant';
  7. import Button from '../../../components/Button';
  8. import Input from '../../../components/Input';
  9. import Tag from '../../../components/Tag';
  10. import { My } from '../../../stores/my';
  11. import { Common } from '../../../stores/common';
  12. export default class extends Page {
  13. initState() {
  14. return {
  15. emails: [],
  16. select: -1,
  17. };
  18. }
  19. init() {
  20. Common.readyWechat(window.location.href, ['onMenuShareAppMessage'])
  21. .then((wx) => {
  22. const { info } = this.props.user;
  23. wx.onMenuShareAppMessage({
  24. title: '千行GMAT 好友邀请连接', // Share title
  25. desc: '点击邀请连接', // Share description
  26. link: `${H5Url}/id/${info.inviteCode}`, // Share Link,this link domain name and path must be the same as the current page which corresponding to JS secured domain name as Official account
  27. imgUrl: '', // Share Icon
  28. type: 'link', // Share type, music, video link, not filled default link
  29. dataUrl: '', // If type is music or video, provide data links, the default is empty
  30. success() {
  31. // The user confirms the callback function that was executed after sharing
  32. },
  33. cancel() {
  34. // The user cancels the callback function that was executed after sharing
  35. },
  36. });
  37. });
  38. }
  39. addEmail(value) {
  40. const { emails } = this.state;
  41. emails.push(value.replace(';', '').replace(';', ''));
  42. this.setState({
  43. email: '',
  44. emails,
  45. });
  46. }
  47. removeEmail(index) {
  48. const { emails } = this.state;
  49. emails.splice(index, 1);
  50. this.setState({
  51. emails,
  52. });
  53. }
  54. submit() {
  55. const { emails } = this.state;
  56. if (emails.length === 0) return;
  57. My.inviteEmail(emails).then(() => {
  58. asyncSMessage('发送成功');
  59. this.setState({ email: '', emails: [] });
  60. }).catch(() => {
  61. asyncSMessage('发送失败', 'warn');
  62. });
  63. }
  64. renderView() {
  65. return (
  66. <div>
  67. <div className="text">
  68. 每邀请一位好友注册“千行GMAT”,
  69. <br />
  70. 你的VIP权限会延长7天,可累加无上限。
  71. </div>
  72. <div className="line" />
  73. <div className="title">微信邀请</div>
  74. <div className="t-c">
  75. <div className="item t-c">
  76. <Assets name="img1" />
  77. <div>1.点击右上角「 ···」</div>
  78. </div>
  79. <div className="item t-c">
  80. <Assets name="img2" />
  81. <div>2.发送给朋友</div>
  82. </div>
  83. </div>
  84. {/* <Button className="go" block width={110} radius>
  85. 去邀请
  86. </Button> */}
  87. <div className="title">邮件邀请</div>
  88. <Input placeholder="添加多个邮箱,请用「;」间隔" value={this.state.email || ''} onChange={(e) => {
  89. const { value } = e.target;
  90. if (value.length > 0) {
  91. const last = value[value.length - 1];
  92. if (last === ';' || last === ';') {
  93. // 添加邮箱
  94. this.addEmail(value);
  95. } else {
  96. this.setState({ email: value });
  97. }
  98. } else {
  99. this.setState({ email: value });
  100. }
  101. }} />
  102. <div className="tag-list">
  103. {this.state.emails.map((email, index) => <Tag theme={this.state.select !== index ? 'white' : 'disabled'} radius onClick={() => {
  104. if (this.state.select === index) this.setState({ select: -1 });
  105. else this.setState({ select: index });
  106. }} onClose={this.state.select === index ? () => this.removeEmail(index) : null}>
  107. {email}
  108. </Tag>)}
  109. </div>
  110. <Button block width={110} radius onClick={() => {
  111. this.submit();
  112. }}>
  113. 发送邀请
  114. </Button>
  115. </div>
  116. );
  117. }
  118. }