page.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import React from 'react';
  2. import './index.less';
  3. import { Drawer } from 'antd-mobile';
  4. import Page from '@src/containers/Page';
  5. import Assets from '@src/components/Assets';
  6. import { formatTreeData } from '@src/services/Tools';
  7. import { DataBlock } from '../../../components/Block';
  8. import { SpecialRadioGroup } from '../../../components/Radio';
  9. import Switch from '../../../components/Switch';
  10. import Button from '../../../components/Button';
  11. import Checkbox from '../../../components/CheckBox';
  12. import { Course } from '../../../stores/course';
  13. import { Main } from '../../../stores/main';
  14. import { DataType } from '../../../../Constant';
  15. export default class extends Page {
  16. init() {
  17. Main.dataStruct().then((list) => {
  18. const structTree = formatTreeData(list.map(row => {
  19. row.title = `${row.titleZh} ${row.titleEn}`;
  20. row.label = row.title;
  21. row.key = row.id;
  22. return row;
  23. }), 'id', 'title', 'parentId');
  24. this.setState({ structTree });
  25. });
  26. const { search } = this.state;
  27. if (!search.order) search.order = 'saleNumber';
  28. this.setState({ search });
  29. }
  30. initData() {
  31. Course.listData(this.state.search).then(result => {
  32. this.setTableData(result.list, result.total);
  33. });
  34. }
  35. changeOrder(order, direction) {
  36. const { search = {} } = this.state;
  37. search.order = order;
  38. search.direction = direction;
  39. this.setState({ search });
  40. this.refresh();
  41. }
  42. changeNovice() {
  43. const { search = {} } = this.state;
  44. search.isNovice = !search.isNovice;
  45. this.setState({ search });
  46. }
  47. changeOriginal() {
  48. const { search = {} } = this.state;
  49. search.isOriginal = !search.isOriginal;
  50. this.setState({ search });
  51. }
  52. changeDataType(value) {
  53. const { search = {} } = this.state;
  54. search.dataType = value;
  55. this.setState({ search });
  56. }
  57. changeStruct(value) {
  58. const { search = {} } = this.state;
  59. search.structId = value;
  60. this.setState({ search });
  61. }
  62. renderView() {
  63. const { filter, list = [], search = {} } = this.state;
  64. return (<Drawer
  65. style={{ minHeight: document.documentElement.clientHeight }}
  66. position="right"
  67. open={filter}
  68. sidebar={this.renderFilter()}
  69. onOpenChange={isOpen => this.setState({ filter: isOpen })}
  70. >
  71. <div className="top">
  72. <div className={search.order === 'saleNumber' ? 'tab active' : 'tab'} onClick={() => {
  73. if (search.order !== 'saleNumber') this.changeOrder('saleNumber', 'desc');
  74. }}>销量</div>
  75. <div className={search.order === 'updateTime' ? 'tab active' : 'tab'} onClick={() => {
  76. if (search.order !== 'updateTime') this.changeOrder('updateTime', 'desc');
  77. }}>更新时间</div>
  78. <div className="right" onClick={() => this.setState({ filter: true })}>
  79. 筛选
  80. <Assets name="screen" />
  81. </div>
  82. </div>
  83. <div className="list">
  84. {list.map(row => <DataBlock data={row} />)}
  85. </div>
  86. </Drawer>
  87. );
  88. }
  89. renderFilter() {
  90. const { search, structTree = [] } = this.state;
  91. return (
  92. <div className="filter">
  93. <div className="body">
  94. <div className="item">
  95. <div className="label left">适合新手</div>
  96. <div className="value right">
  97. <Switch checked={search.isNovice} onClick={() => {
  98. this.changeNovice();
  99. }} />
  100. </div>
  101. </div>
  102. <div className="item">
  103. <div className="label left">原创资料</div>
  104. <div className="value right">
  105. <Switch checked={search.isOriginal} onClick={() => {
  106. this.changeOriginal();
  107. }} />
  108. </div>
  109. </div>
  110. <div className="item">
  111. <div className="label left">资料形式</div>
  112. <div className="value right">
  113. <SpecialRadioGroup
  114. list={DataType}
  115. value={search.dataType}
  116. onChange={(value) => {
  117. this.changeDataType(value);
  118. }}
  119. />
  120. </div>
  121. </div>
  122. <div className="sub">
  123. <div className="title">筛选学科</div>
  124. {structTree.map((row) => {
  125. return <div className="item">
  126. <div className={row.children.length > 0 ? 'label' : 'label left'}>{row.title}</div>
  127. {row.children.length > 0 && <div className="value">
  128. <SpecialRadioGroup
  129. list={row.children}
  130. value={search.structId}
  131. onChange={(value) => {
  132. this.changeStruct(value);
  133. }}
  134. />
  135. </div>}
  136. {row.children.length === 0 && <div className="value right">
  137. <Checkbox checked={search.structId === row.id} onClick={() => {
  138. this.changeStruct(row.id);
  139. }} />
  140. </div>}
  141. </div>;
  142. })}
  143. </div>
  144. </div>
  145. <div className="footer">
  146. <Button radius width={90} onClick={() => {
  147. this.refresh();
  148. }}>
  149. 确定
  150. </Button>
  151. </div>
  152. </div>
  153. );
  154. }
  155. }