honorList.jsx 14 KB

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