index.jsx 5.1 KB

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