index.jsx 4.6 KB

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