page.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import React from 'react';
  2. import './index.less';
  3. import Page from '@src/containers/Page';
  4. import Block from '@src/components/Block';
  5. import FilterLayout from '@src/layouts/FilterLayout';
  6. import ActionLayout from '@src/layouts/ActionLayout';
  7. import TableLayout from '@src/layouts/TableLayout';
  8. import { getMap } from '@src/services/Tools';
  9. import { asyncSMessage, asyncForm } from '@src/services/AsyncTools';
  10. import { ChannelModule, SwitchSelect, AskStatus } from '../../../../Constant';
  11. import { System } from '../../../stores/system';
  12. const SwitchSelectMap = getMap(SwitchSelect, 'value', 'label');
  13. const ChannelModuleMap = getMap(ChannelModule, 'value', 'label');
  14. export default class extends Page {
  15. init() {
  16. this.actionList = [{
  17. key: 'add',
  18. type: 'primary',
  19. name: '创建',
  20. }];
  21. this.formF = null;
  22. this.itemList = [{
  23. key: 'id',
  24. type: 'hidden',
  25. }, {
  26. key: 'channel',
  27. type: 'select',
  28. allowClear: true,
  29. name: '频道',
  30. select: ChannelModule,
  31. placeholder: '请选择',
  32. }, {
  33. key: 'position',
  34. type: 'select',
  35. allowClear: true,
  36. name: '位置',
  37. select: ChannelModule,
  38. placeholder: '请选择',
  39. }, {
  40. key: 'content',
  41. type: 'textarea',
  42. name: '用户留言',
  43. }, {
  44. key: 'answer',
  45. type: 'textarea',
  46. name: '编辑回复',
  47. }];
  48. this.filterForm = [{
  49. key: 'channel',
  50. type: 'select',
  51. allowClear: true,
  52. name: '频道',
  53. select: ChannelModule,
  54. placeholder: '请选择',
  55. }, {
  56. key: 'position',
  57. type: 'select',
  58. allowClear: true,
  59. name: '位置',
  60. select: ChannelModule,
  61. placeholder: '请选择',
  62. }, {
  63. key: 'answerStatus',
  64. type: 'select',
  65. allowClear: true,
  66. number: true,
  67. name: '状态',
  68. select: AskStatus,
  69. }, {
  70. key: 'isSpecial',
  71. type: 'select',
  72. allowClear: true,
  73. name: '精选',
  74. number: true,
  75. select: SwitchSelect,
  76. }];
  77. this.columns = [{
  78. title: '频道',
  79. dataIndex: 'channel',
  80. render: (text, record) => {
  81. return ChannelModuleMap[record.channel];
  82. },
  83. }, {
  84. title: '位置',
  85. dataIndex: 'position',
  86. }, {
  87. title: '问题摘要',
  88. dataIndex: 'content',
  89. }, {
  90. title: '精选',
  91. dataIndex: 'isSpecial',
  92. render: (text, record) => {
  93. return record.status > 0 ? SwitchSelectMap[text] || text : '-';
  94. },
  95. }, {
  96. title: '操作',
  97. dataIndex: 'handler',
  98. render: (text, record) => {
  99. return <div className="table-button">
  100. {(
  101. <a onClick={() => {
  102. this.editAction(record);
  103. }}>编辑</a>
  104. )}
  105. {!!record.isSpecial && (
  106. <a onClick={() => {
  107. this.special(record, 0);
  108. }}>取消精选</a>
  109. )}
  110. {!record.isSpecial && (
  111. <a onClick={() => {
  112. this.special(record, 1);
  113. }}>精选</a>
  114. )}
  115. </div>;
  116. },
  117. }];
  118. }
  119. initData() {
  120. System.listFAQ(Object.assign({ faqModule: 'system' }, this.state.search)).then(result => {
  121. this.setTableData(result.list, result.total);
  122. });
  123. }
  124. addAction() {
  125. asyncForm('创建', this.itemList, {}, data => {
  126. data.faqModule = 'system';
  127. return System.addFAQ(data).then(() => {
  128. asyncSMessage('添加成功!');
  129. this.refresh();
  130. });
  131. }).then(component => {
  132. this.formF = component;
  133. });
  134. }
  135. editAction(row) {
  136. asyncForm('编辑', this.itemList, row, data => {
  137. data.faqModule = 'system';
  138. return System.editFAQ(data).then(() => {
  139. asyncSMessage('编辑成功!');
  140. this.refresh();
  141. });
  142. }).then(component => {
  143. this.formF = component;
  144. });
  145. }
  146. special(row, isSpecial) {
  147. System.editFAQ({ id: row.id, isSpecial }).then(() => {
  148. asyncSMessage('编辑成功!');
  149. this.refresh();
  150. });
  151. }
  152. renderView() {
  153. return <Block flex>
  154. <FilterLayout
  155. show
  156. itemList={this.filterForm}
  157. data={this.state.search}
  158. onChange={data => {
  159. this.search(data);
  160. }} />
  161. <ActionLayout
  162. itemList={this.actionList}
  163. selectedKeys={this.state.selectedKeys}
  164. onAction={key => this.onAction(key)}
  165. />
  166. <TableLayout
  167. columns={this.columns}
  168. list={this.state.list}
  169. pagination={this.state.page}
  170. loading={this.props.core.loading}
  171. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  172. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  173. selectedKeys={this.state.selectedKeys}
  174. />
  175. </Block>;
  176. }
  177. }