index.jsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import React from 'react';
  2. import { Icon, message, Button, Spin, Table } from 'antd';
  3. import Moment from 'moment';
  4. import './index.less';
  5. import ajax from 'jquery/src/ajax/xhr.js'
  6. import $ from 'jquery/src/ajax';
  7. const Evaluate = React.createClass({
  8. getInitialState() {
  9. return {
  10. loading: false,
  11. dataSource: [],
  12. pagination: {
  13. defaultCurrent: 1,
  14. current: 1,
  15. defaultPageSize: 10,
  16. showQuickJumper: true,
  17. pageSize: 10,
  18. onChange: function (page) {
  19. this.loadData(page);
  20. }.bind(this),
  21. showTotal: function (total) {
  22. return '共' + (total || 0) + '条数据';
  23. }
  24. },
  25. selectedRowKeys: []
  26. };
  27. },
  28. componentWillMount() {
  29. this.loadData(1);
  30. },
  31. showCreate() {
  32. if (this.props.handlekey) {
  33. this.props.handlekey('createEvaluate');
  34. }
  35. },
  36. loadData(pageNo) {
  37. if (this.state.loading) {
  38. return;
  39. }
  40. this.setState({
  41. loading: true
  42. });
  43. let { pagination } = this.state;
  44. $.ajax({
  45. url: globalConfig.context + '/api/user/evaluate/list',
  46. data: {
  47. pageNo: pageNo || 1,
  48. pageSize: pagination.pageSize,
  49. },
  50. success: function (data) {
  51. if (!data.data || !data.data.list) {
  52. return;
  53. }
  54. pagination.current = data.data.pageNo;
  55. pagination.total = data.data.totalCount;
  56. this.setState({
  57. dataSource: data.data.list,
  58. pagination: pagination
  59. });
  60. }.bind(this),
  61. }).always(function () {
  62. this.setState({
  63. loading: false
  64. });
  65. }.bind(this));
  66. },
  67. tableRowClick(it) {
  68. if (this.props.handlekey) {
  69. this.props.handlekey('createEvaluate?id=' + it.id + '&name=' + (it.name || '') + '&step=' + it.step);
  70. }
  71. },
  72. remove() {
  73. if (this.state.loading || !this.state.selectedRowKeys.length) {
  74. return;
  75. }
  76. this.setState({
  77. loading: true
  78. });
  79. $.ajax({
  80. url: globalConfig.context + '/api/user/evaluate/remove',
  81. data: {
  82. ids: this.state.selectedRowKeys.join(',')
  83. },
  84. method: 'post',
  85. success: function (res) {
  86. if (res.error && res.error.length) {
  87. message.error(res.error[0].message);
  88. } else {
  89. message.info("删除" + (res.data || 0) + '条记录。', 2, () => {
  90. this.loadData(this.state.pagination.current);
  91. })
  92. }
  93. }.bind(this),
  94. }).always(function () {
  95. this.setState({
  96. loading: false
  97. });
  98. }.bind(this));
  99. },
  100. preview(e, it) {
  101. e.stopPropagation();
  102. e.preventDefault();
  103. alert(it.id);
  104. },
  105. render() {
  106. const rowSelection = {
  107. onChange: (selectedRowKeys, selectedRows) => {
  108. this.setState({
  109. selectedRowKeys
  110. });
  111. },
  112. getCheckboxProps: record => ({
  113. disabled: record.step === 7
  114. })
  115. }, columns = [
  116. {
  117. title: '编号',
  118. dataIndex: 'id',
  119. key: 'id',
  120. }, {
  121. title: '技术名称',
  122. dataIndex: 'name',
  123. key: 'name',
  124. }, {
  125. title: '价值',
  126. dataIndex: 'value',
  127. key: 'value',
  128. render: (text, it) => { return it.value || ''; }
  129. }, {
  130. title: '预览',
  131. dataIndex: 'preview',
  132. key: 'preview',
  133. render: (text, record) => {
  134. return record.step == 7 ?
  135. <Icon type="eye-o" style={{ fontSize: 18 }} onClick={(e) => {
  136. this.preview(e, record)
  137. }}></Icon> : <div />
  138. }
  139. }, {
  140. title: '日期',
  141. dataIndex: 'createTime',
  142. key: 'createTime',
  143. render: (text, it) => { return Moment(it.createTime).format('YYYY/MM/DD') }
  144. }
  145. ];
  146. return (
  147. <Spin spinning={this.state.loading}>
  148. <div className="content-container">
  149. <div className="content-title">
  150. 科技评估管理列表
  151. <div className="content-actions"><Button type="primary" onClick={this.showCreate}>开始新评估<Icon type="plus" /></Button></div>
  152. </div>
  153. <div className="content-search">
  154. <Button type="danger" onClick={this.remove} disabled={!this.state.selectedRowKeys.length}>删除</Button>
  155. </div>
  156. <div className="content-body">
  157. <Table rowKey="id" columns={columns}
  158. dataSource={this.state.dataSource}
  159. pagination={this.state.pagination}
  160. onRowClick={this.tableRowClick}
  161. rowSelection={rowSelection} />
  162. </div>
  163. </div>
  164. </Spin>
  165. )
  166. },
  167. });
  168. export default Evaluate;