WareList.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. import React, { PureComponent } from 'react';
  2. import { connect } from 'dva';
  3. import { Link, routerRedux } from 'dva/router';
  4. import { Popconfirm, Progress, notification, Badge, message, Card, Icon, Button,
  5. Modal, Input, Select, Form, Row, Col, Tooltip } from 'antd';
  6. import moment from 'moment';
  7. import PageHeaderLayout from '../../layouts/PageHeaderLayout';
  8. import StandardTable from '../../components/StandardTable';
  9. import styles from './WareList.less';
  10. import config from '../../utils/config';
  11. import Logger from '../../utils/logger';
  12. const logger = Logger.getLogger('WareList');
  13. const { Option } = Select;
  14. const FormItem = Form.Item;
  15. const ButtonGroup = Button.Group;
  16. const getValue = obj => Object.keys(obj).map(key => obj[key]).join(',');
  17. @connect(state => ({
  18. ware: state.ware,
  19. cp: state.cp,
  20. }))
  21. @Form.create()
  22. export default class WareList extends PureComponent {
  23. state = {
  24. modalVisible: false,
  25. selectedRows: [],
  26. formValues: {},
  27. }
  28. componentDidMount() {
  29. const { dispatch, ware: { data } } = this.props
  30. dispatch({
  31. type: 'cp/getCPList',
  32. payload: {},
  33. });
  34. dispatch({
  35. type: 'ware/getWareList',
  36. payload: {},
  37. })
  38. }
  39. handleSearch = (e) => {
  40. e.preventDefault();
  41. const { dispatch, form } = this.props;
  42. form.validateFields((err, fieldsValue) => {
  43. if (err) return;
  44. const values = {
  45. ...fieldsValue,
  46. }
  47. logger.info('【Search Values】: %o', values);
  48. dispatch({
  49. type: 'ware/getWareList',
  50. payload: values,
  51. });
  52. });
  53. }
  54. handleReset = (e) => {
  55. e.preventDefault();
  56. const { dispatch, form } = this.props;
  57. form.resetFields();
  58. dispatch({
  59. type: 'ware/getWareList',
  60. payload: {},
  61. });
  62. }
  63. handleSelectRows = (rows) => {
  64. this.setState({
  65. selectedRows: rows,
  66. });
  67. }
  68. handleItemAdd = () => {
  69. const { dispatch } = this.props;
  70. dispatch(routerRedux.push('/product/ware/save'));
  71. }
  72. handleItemEdit = (record) => {
  73. const { dispatch } = this.props;
  74. dispatch({
  75. type: 'ware/saveItemData',
  76. payload: record,
  77. });
  78. dispatch(routerRedux.push('/product/ware/save'));
  79. }
  80. handleItemDel = (record) => {
  81. const { dispatch } = this.props;
  82. dispatch({
  83. type: 'ware/delWareItem',
  84. payload: { code: record.code },
  85. });
  86. dispatch({
  87. type: 'ware/getWareList',
  88. payload: {},
  89. });
  90. }
  91. handleModalVisible = (flag) => {
  92. this.setState({
  93. modalVisible: !!flag,
  94. });
  95. }
  96. //配置分页器
  97. handleStandardTableChange = (pagination, filterArgs, sorter) => {
  98. const { dispatch } = this.props;
  99. const { formValues } = this.state;
  100. logger.info('【TableChangePagination】: %o', pagination);
  101. const filters = Object.keys(filterArgs).reduce((obj, key) => {
  102. const newObj = {...obj};
  103. newObj[key] = getValue(filterArgs[key]);
  104. return newObj;
  105. }, {});
  106. const params = {
  107. pageNo: pagination.current,
  108. pageSize: pagination.pageSize,
  109. ...formValues,
  110. ...filters,
  111. };
  112. if (sorter.field) {
  113. params.sorter = `${sorter.field}_${sorter.order}`;
  114. }
  115. dispatch({
  116. type: 'ware/getWareList',
  117. payload: params,
  118. })
  119. }
  120. render() {
  121. const { selectedRows, modalVisible } = this.state;
  122. const { dispatch, ware, cp: { cpList } } = this.props;
  123. const { getFieldDecorator } = this.props.form;
  124. const columns = [{
  125. title: '课件编号',
  126. dataIndex: 'code',
  127. sorter: true,
  128. },{
  129. title: '课件名称',
  130. dataIndex: 'name',
  131. sorter: true,
  132. },{
  133. title: '课件类型',
  134. dataIndex: 'type',
  135. filters: config.WARE_TYPE.map((item) => ({
  136. text: item.name,
  137. value: item.value,
  138. })),
  139. render: (text, record) => (
  140. <p>
  141. {(config.WARE_TYPE.filter(item => item.value === record.type)[0] || { name: '未知' }).name}
  142. </p>
  143. ),
  144. },{
  145. title: '使用状态',
  146. dataIndex: 'state',
  147. filters: config.WARE_STATE.map((item) => ({
  148. text: item.name,
  149. value: item.value,
  150. })),
  151. render: (text, record) => (
  152. <p>
  153. {(config.WARE_STATE.filter(item => item.value === record.state)[0] || { name: '未知' }).name}
  154. </p>
  155. ),
  156. },{
  157. title: '内容提供商',
  158. dataIndex: 'cpName',
  159. filters: cpList.map((item) => ({
  160. text: item.cpName,
  161. value: item.cpId,
  162. }))
  163. },{
  164. title: '修改时间',
  165. dataIndex: 'gmtModified',
  166. sorter: true,
  167. },{
  168. title: '操作类型',
  169. render: (record) => (
  170. <p>
  171. <Button size="small" shape="circle" icon="edit" onClick={() => this.handleItemEdit(record)}></Button>
  172. <span className={styles.splitLine} />
  173. <Popconfirm
  174. placement="top"
  175. okText="删除"
  176. cancelText="取消"
  177. title={`确定删除${record.name}?`}
  178. onConfirm={() => this.handleItemDel(record)}
  179. >
  180. <Button size="small" shape="circle" icon="delete"></Button>
  181. </Popconfirm>
  182. </p>
  183. ),
  184. }];
  185. const standardTableProps = {
  186. dataSource: ware.data.list,
  187. pagination: ware.data.pagination,
  188. loading: ware.loading,
  189. columns: columns,
  190. rowKeyName: 'code',
  191. selectedRows: selectedRows,
  192. };
  193. const pageHeaderSearch = (
  194. <Form layout="inline" onSubmit={this.handleSearch}>
  195. <Row gutter={24}>
  196. <Col md={9} sm={24}>
  197. <FormItem label="课件编号">
  198. {getFieldDecorator('code')(
  199. <Input placeholder="请输入课件编号" />
  200. )}
  201. </FormItem>
  202. </Col>
  203. <Col md={10} sm={24}>
  204. <FormItem label="课件名称">
  205. {getFieldDecorator('name')(
  206. <Input placeholder="请输入课件名称" />
  207. )}
  208. </FormItem>
  209. </Col>
  210. <Col md={5} sm={24} push={1}>
  211. <FormItem>
  212. <ButtonGroup>
  213. <Button icon="search" type="primary" htmlType="submit">搜索</Button>
  214. <Button icon="reload" type="danger" onClick={this.handleReset}>重置</Button>
  215. </ButtonGroup>
  216. </FormItem>
  217. </Col>
  218. </Row>
  219. </Form>
  220. );
  221. return (
  222. <PageHeaderLayout
  223. content={pageHeaderSearch}
  224. >
  225. <div className={styles.content}>
  226. <div className={styles.newButton}>
  227. <Button type="primary" icon="plus" onClick={() => {this.handleItemAdd()}}>新建课件</Button>
  228. </div>
  229. <StandardTable
  230. {...standardTableProps}
  231. onChange={this.handleStandardTableChange}
  232. onSelectRow={this.handleSelectRows}
  233. />
  234. </div>
  235. </PageHeaderLayout>
  236. );
  237. }
  238. }