page.js 2.6 KB

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