honorList.jsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. import React from 'react';
  2. import { Icon, Form, Button, Input, Spin, Table, message, Modal, Upload, DatePicker } from 'antd';
  3. import './techProduct.less';
  4. import { beforeUploadFile, downloadFile } from '../../tools.js';
  5. import moment from 'moment';
  6. import ajax from 'jquery/src/ajax/xhr.js';
  7. import $ from 'jquery/src/ajax';
  8. const HonorListDescFrom = Form.create()(React.createClass({
  9. getInitialState() {
  10. return {
  11. loading: false
  12. };
  13. },
  14. handleSubmit(e) {
  15. e.preventDefault();
  16. this.props.form.validateFields((err, values) => {
  17. if (!err) {
  18. this.props.spinState(true);
  19. $.ajax({
  20. method: "POST",
  21. dataType: "json",
  22. crossDomain: false,
  23. url: globalConfig.context + "/techservice/cognizance/disposeHonor",
  24. data: {
  25. id: this.props.data.id,
  26. name: values.name,
  27. issuingMechanism: values.issuingMechanism,
  28. issuingTimeFormattedDate: values.issuingTimeFormattedDate.format("YYYY-MM-DD"),
  29. enclosureUrl: this.state.enclosureUrl
  30. }
  31. }).done(function (data) {
  32. if (!data.error.length) {
  33. message.success('保存成功!');
  34. this.props.clickOk();
  35. this.props.spinState(false);
  36. this.props.form.resetFields();
  37. } else {
  38. message.warning(data.error[0].message);
  39. this.props.spinState(false);
  40. }
  41. }.bind(this));
  42. }
  43. });
  44. },
  45. componentWillReceiveProps(nextProps) {
  46. if (!this.props.visible && nextProps.visible) {
  47. this.props.form.resetFields();
  48. };
  49. },
  50. render() {
  51. const FormItem = Form.Item;
  52. const { getFieldDecorator } = this.props.form;
  53. const theData = this.props.data;
  54. const formItemLayout = {
  55. labelCol: { span: 4 },
  56. wrapperCol: { span: 12 },
  57. };
  58. const _me = this;
  59. return (
  60. <Form onSubmit={this.handleSubmit} className="activityCost-form">
  61. <div className="clearfix">
  62. <FormItem
  63. {...formItemLayout}
  64. label="名称"
  65. >
  66. {getFieldDecorator('name', {
  67. rules: [{ required: true, message: '此项为必填项!' }],
  68. initialValue: theData.name
  69. })(
  70. <Input />
  71. )}
  72. </FormItem>
  73. <FormItem
  74. {...formItemLayout}
  75. label="获取时间"
  76. >
  77. {getFieldDecorator('issuingTimeFormattedDate', {
  78. rules: [{ type: 'object', required: true, message: '此项为必填项!' }],
  79. initialValue: theData.issuingTimeFormattedDate ? moment(theData.issuingTimeFormattedDate) : null
  80. })(
  81. <DatePicker />
  82. )}
  83. </FormItem>
  84. <FormItem
  85. {...formItemLayout}
  86. label="发证机构"
  87. >
  88. {getFieldDecorator('issuingMechanism', {
  89. rules: [{ required: true, message: '此项为必填项!' }],
  90. initialValue: theData.issuingMechanism
  91. })(
  92. <Input />
  93. )}
  94. </FormItem>
  95. </div>
  96. <div className="hrSituation-roster">
  97. <Upload
  98. name="ratepay"
  99. action={globalConfig.context + "/techservice/cognizance/upload"}
  100. data={{ 'sign': 'achievement' }}
  101. beforeUpload={beforeUploadFile}
  102. showUploadList={false}
  103. onChange={(info) => {
  104. if (info.file.status !== 'uploading') {
  105. console.log(info.file, info.fileList);
  106. }
  107. if (info.file.status === 'done') {
  108. if (!info.file.response.error.length) {
  109. message.success(`${info.file.name} 文件上传成功!`);
  110. } else {
  111. message.warning(info.file.response.error[0].message);
  112. return;
  113. };
  114. this.state.enclosureUrl = info.file.response.data;
  115. } else if (info.file.status === 'error') {
  116. message.error(`${info.file.name} 文件上传失败。`);
  117. }
  118. }}
  119. >
  120. <Button><Icon type="upload" /> 上传科技成果附件 </Button>
  121. </Upload>
  122. <p style={{ marginTop: '10px' }}>{theData.enclosureUrl ? <a onClick={downloadFile.bind(null, theData.enclosureUrl, theData.enclosureDownloadFileName)}>{theData.enclosureDownloadFileName}</a> : <span>未上传!</span>}</p>
  123. </div>
  124. <FormItem style={{ marginTop: '20px' }}>
  125. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  126. <Button type="ghost" style={{ marginLeft: '20px' }} onClick={this.props.closeModal}>取消</Button>
  127. </FormItem>
  128. </Form >
  129. );
  130. },
  131. }));
  132. const HonorListDesc = React.createClass({
  133. getInitialState() {
  134. return {
  135. visible: false,
  136. loading: false
  137. };
  138. },
  139. componentWillReceiveProps(nextProps) {
  140. this.state.visible = nextProps.showDesc
  141. },
  142. showModal() {
  143. this.setState({
  144. visible: true,
  145. });
  146. },
  147. handleOk() {
  148. this.setState({
  149. visible: false,
  150. });
  151. this.props.closeDesc(false, true);
  152. },
  153. handleCancel(e) {
  154. this.setState({
  155. visible: false,
  156. });
  157. this.props.closeDesc(false);
  158. },
  159. spinChange(e) {
  160. this.setState({
  161. loading: e
  162. });
  163. },
  164. render() {
  165. return (
  166. <div className="patent-addNew">
  167. <Spin spinning={this.state.loading} className='spin-box'>
  168. <Modal title="企业荣誉及其他证明材料" visible={this.state.visible}
  169. onOk={this.handleOk} onCancel={this.handleCancel}
  170. width='800px'
  171. footer=''
  172. >
  173. <HonorListDescFrom
  174. data={this.props.data}
  175. spinState={this.spinChange}
  176. visible={this.state.visible}
  177. closeModal={this.handleCancel}
  178. clickOk={this.handleOk} />
  179. </Modal>
  180. </Spin>
  181. </div>
  182. );
  183. },
  184. });
  185. const HonorList = React.createClass({
  186. loadData(pageNo) {
  187. this.state.data = [];
  188. this.setState({
  189. loading: true
  190. });
  191. $.ajax({
  192. method: "get",
  193. dataType: "json",
  194. crossDomain: false,
  195. url: globalConfig.context + "/techservice/cognizance/honorList",
  196. data: {
  197. pageNo: pageNo || 1,
  198. pageSize: this.state.pagination.pageSize
  199. }
  200. }).done((data) => {
  201. if (data.error.length || !data.data || !data.data.list) {
  202. message.warning(data.error[0].message);
  203. return;
  204. };
  205. for (let i = 0; i < data.data.list.length; i++) {
  206. let thisdata = data.data.list[i];
  207. this.state.data.push({
  208. key: i,
  209. id: thisdata.id,
  210. uid: thisdata.uid,
  211. name: thisdata.name,
  212. issuingTime: thisdata.issuingTime,
  213. enclosureUrl: thisdata.enclosureUrl,
  214. enclosureDownloadFileName: thisdata.enclosureDownloadFileName,
  215. enclosure: [thisdata.enclosureUrl, thisdata.enclosureDownloadFileName],
  216. issuingTimeFormattedDate: thisdata.issuingTimeFormattedDate,
  217. issuingMechanism: thisdata.issuingMechanism
  218. });
  219. };
  220. this.state.pagination.current = data.data.pageNo;
  221. this.state.pagination.total = data.data.totalCount;
  222. this.setState({
  223. dataSource: this.state.data,
  224. pagination: this.state.pagination
  225. });
  226. }).always(function () {
  227. this.setState({
  228. loading: false
  229. });
  230. }.bind(this));
  231. },
  232. getInitialState() {
  233. return {
  234. selectedRowKeys: [],
  235. selectedRows: [],
  236. loading: false,
  237. pagination: {
  238. defaultCurrent: 1,
  239. defaultPageSize: 10,
  240. showQuickJumper: true,
  241. pageSize: 10,
  242. onChange: function (page) {
  243. this.loadData(page);
  244. }.bind(this),
  245. showTotal: function (total) {
  246. return '共' + total + '条数据';
  247. }
  248. },
  249. columns: [
  250. {
  251. title: '名称',
  252. dataIndex: 'name',
  253. key: 'name'
  254. }, {
  255. title: '获取时间',
  256. dataIndex: 'issuingTimeFormattedDate',
  257. key: 'issuingTimeFormattedDate'
  258. }, {
  259. title: '发证机构',
  260. dataIndex: 'issuingMechanism',
  261. key: 'issuingMechanism'
  262. }, {
  263. title: '相关附件',
  264. dataIndex: 'enclosure',
  265. key: 'enclosure',
  266. render: (text) => {
  267. return <a onClick={downloadFile.bind(null, text[0], text[1])}>{text[1]}</a>
  268. }
  269. }
  270. ],
  271. dataSource: []
  272. };
  273. },
  274. componentWillMount() {
  275. this.loadData();
  276. },
  277. tableRowClick(record, index) {
  278. this.state.RowData = record;
  279. this.setState({
  280. showDesc: true
  281. });
  282. },
  283. delectRow() {
  284. let deletedIds = [];
  285. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  286. let rowItem = this.state.selectedRows[idx];
  287. if (rowItem.id) {
  288. deletedIds.push(rowItem.id)
  289. }
  290. }
  291. this.setState({
  292. selectedRowKeys: [],
  293. loading: deletedIds.length > 0
  294. });
  295. $.ajax({
  296. method: "POST",
  297. dataType: "json",
  298. crossDomain: false,
  299. url: globalConfig.context + "/techservice/cognizance/deleteHonor",
  300. data: {
  301. ids: deletedIds
  302. }
  303. }).done(function (data) {
  304. if (!data.error.length) {
  305. message.success('保存成功!');
  306. this.setState({
  307. loading: false,
  308. });
  309. } else {
  310. message.warning(data.error[0].message);
  311. };
  312. this.loadData();
  313. }.bind(this));
  314. },
  315. closeDesc(e, s) {
  316. this.state.showDesc = e;
  317. if (s) {
  318. this.loadData();
  319. };
  320. },
  321. search() {
  322. this.loadData();
  323. },
  324. reset() {
  325. this.loadData();
  326. },
  327. render() {
  328. const rowSelection = {
  329. selectedRowKeys: this.state.selectedRowKeys,
  330. onChange: (selectedRowKeys, selectedRows) => {
  331. this.setState({
  332. selectedRows: selectedRows,
  333. selectedRowKeys: selectedRowKeys
  334. });
  335. }
  336. };
  337. const hasSelected = this.state.selectedRowKeys.length > 0;
  338. return (
  339. <div className="user-content" >
  340. <div className="content-title">
  341. <span>企业荣誉及其他证明材料</span>
  342. </div>
  343. <div className="user-search">
  344. <p>
  345. <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
  346. onClick={this.tableRowClick}>添加<Icon type="plus" /></Button>
  347. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  348. disabled={!hasSelected}
  349. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  350. </p>
  351. </div>
  352. <div className="patent-table">
  353. <Spin spinning={this.state.loading}>
  354. <Table columns={this.state.columns}
  355. dataSource={this.state.dataSource}
  356. pagination={this.state.pagination}
  357. rowSelection={rowSelection}
  358. onRowClick={this.tableRowClick} />
  359. </Spin>
  360. </div>
  361. <HonorListDesc data={this.state.RowData}
  362. showDesc={this.state.showDesc} closeDesc={this.closeDesc} />
  363. </div >
  364. );
  365. }
  366. });
  367. export default HonorList;