page.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import React from 'react';
  2. import './index.less';
  3. import Page from '@src/containers/Page';
  4. import Money from '../../../components/Money';
  5. import Button from '../../../components/Button';
  6. import { SpecialRadioGroup } from '../../../components/Radio';
  7. import { Main } from '../../../stores/main';
  8. export default class extends Page {
  9. initState() {
  10. return {
  11. index: 0,
  12. };
  13. }
  14. initData() {
  15. const { service } = this.params;
  16. Main.getService(service)
  17. .then(result => {
  18. result.package = (result.package || []).map((row, index) => {
  19. row.label = `¥${row.price}/${row.title}`;
  20. row.value = index;
  21. return row;
  22. });
  23. this.setState({ data: result });
  24. });
  25. }
  26. buy() {
  27. const { data, index } = this.state;
  28. const item = data.package[index] || {};
  29. console.log(item);
  30. }
  31. // expire_info: '',
  32. renderView() {
  33. const { data = {}, index } = this.state;
  34. data.package = data.package || [];
  35. const item = data.package[index] || {};
  36. return (
  37. <div>
  38. <div className="b-g" style={{ backgroundImage: `url(${data.image})` }}>
  39. <div className="title">{item.title}</div>
  40. </div>
  41. <div className="detail">
  42. {data.package.length > 1 && <div className="title">可选套餐</div>}
  43. {data.package.length > 1 && (
  44. <SpecialRadioGroup
  45. theme="theme"
  46. list={data.package}
  47. value={index}
  48. onChange={value => this.setState({ index: value })}
  49. />
  50. )}
  51. {data.package.length > 1 && <div className="division" />}
  52. <div className="title">服务介绍</div>
  53. <h3>服务</h3>
  54. <p>
  55. {item.description} {item.expire_info}
  56. </p>
  57. <h3>退款政策</h3>
  58. <p>{item.refund_policy}</p>
  59. <h3>版权说明</h3>
  60. <p>{item.copyright_nnotes}</p>
  61. </div>
  62. <div className="fixed">
  63. <div className="fee">
  64. 总额: <Money value={item.price} size="lager" />
  65. </div>
  66. <Button
  67. width={110}
  68. className="f-r"
  69. radius
  70. onClick={() => {
  71. this.buy();
  72. }}
  73. >
  74. 立即购买
  75. </Button>
  76. </div>
  77. </div>
  78. );
  79. }
  80. }