honorList.jsx 15 KB

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