honorList.jsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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, 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. 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 + "/api/user/cognizance/uploadHonor"}
  100. data={{ 'sign': 'honor' }}
  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={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>
  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 + "/api/user/cognizance/honorList",
  196. data: {
  197. pageNo: pageNo || 1,
  198. pageSize: this.state.pagination.pageSize
  199. }
  200. }).done((data) => {
  201. if (!data.data) {
  202. if (data.error && data.error.length) {
  203. message.warning(data.error[0].message);
  204. this.state.ButtonDisabled = true;
  205. }
  206. return;
  207. };
  208. for (let i = 0; i < data.data.list.length; i++) {
  209. let thisdata = data.data.list[i];
  210. this.state.data.push({
  211. key: i,
  212. id: thisdata.id,
  213. uid: thisdata.uid,
  214. name: thisdata.name,
  215. issuingTime: thisdata.issuingTime,
  216. enclosureUrl: thisdata.enclosureUrl,
  217. enclosureDownloadFileName: thisdata.enclosureDownloadFileName,
  218. enclosure: [thisdata.id, thisdata.enclosureDownloadFileName],
  219. issuingTimeFormattedDate: thisdata.issuingTimeFormattedDate,
  220. issuingMechanism: thisdata.issuingMechanism
  221. });
  222. };
  223. this.state.pagination.current = data.data.pageNo;
  224. this.state.pagination.total = data.data.totalCount;
  225. this.setState({
  226. dataSource: this.state.data,
  227. pagination: this.state.pagination
  228. });
  229. }).always(function () {
  230. this.setState({
  231. loading: false
  232. });
  233. }.bind(this));
  234. },
  235. getInitialState() {
  236. return {
  237. selectedRowKeys: [],
  238. selectedRows: [],
  239. loading: false,
  240. pagination: {
  241. defaultCurrent: 1,
  242. defaultPageSize: 10,
  243. showQuickJumper: true,
  244. pageSize: 10,
  245. onChange: function (page) {
  246. this.loadData(page);
  247. }.bind(this),
  248. showTotal: function (total) {
  249. return '共' + total + '条数据';
  250. }
  251. },
  252. columns: [
  253. {
  254. title: '名称',
  255. dataIndex: 'name',
  256. key: 'name'
  257. }, {
  258. title: '获取时间',
  259. dataIndex: 'issuingTimeFormattedDate',
  260. key: 'issuingTimeFormattedDate'
  261. }, {
  262. title: '发证机构',
  263. dataIndex: 'issuingMechanism',
  264. key: 'issuingMechanism'
  265. }, {
  266. title: '相关附件',
  267. dataIndex: 'enclosure',
  268. key: 'enclosure',
  269. render: (text) => {
  270. return <a onClick={newDownloadFile.bind(null, text[0], 'honor', '/api/user/cognizance/downloadHonor')}>{text[1]}</a>
  271. }
  272. }
  273. ],
  274. dataSource: []
  275. };
  276. },
  277. componentWillMount() {
  278. this.loadData();
  279. },
  280. tableRowClick(record, index) {
  281. this.state.RowData = record;
  282. this.setState({
  283. showDesc: true
  284. });
  285. },
  286. delectRow() {
  287. let deletedIds = [];
  288. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  289. let rowItem = this.state.selectedRows[idx];
  290. if (rowItem.id) {
  291. deletedIds.push(rowItem.id)
  292. }
  293. }
  294. this.setState({
  295. selectedRowKeys: [],
  296. loading: deletedIds.length > 0
  297. });
  298. $.ajax({
  299. method: "POST",
  300. dataType: "json",
  301. crossDomain: false,
  302. url: globalConfig.context + "/api/user/cognizance/deleteHonor",
  303. data: {
  304. ids: deletedIds
  305. }
  306. }).done(function (data) {
  307. if (!data.error.length) {
  308. message.success('保存成功!');
  309. this.setState({
  310. loading: false,
  311. });
  312. } else {
  313. message.warning(data.error[0].message);
  314. };
  315. this.loadData();
  316. }.bind(this));
  317. },
  318. closeDesc(e, s) {
  319. this.state.showDesc = e;
  320. if (s) {
  321. this.loadData();
  322. };
  323. },
  324. search() {
  325. this.loadData();
  326. },
  327. reset() {
  328. this.loadData();
  329. },
  330. render() {
  331. const rowSelection = {
  332. selectedRowKeys: this.state.selectedRowKeys,
  333. onChange: (selectedRowKeys, selectedRows) => {
  334. this.setState({
  335. selectedRows: selectedRows,
  336. selectedRowKeys: selectedRowKeys
  337. });
  338. }
  339. };
  340. const hasSelected = this.state.selectedRowKeys.length > 0;
  341. return (
  342. <div className="user-content" >
  343. <div className="content-title">
  344. <span>企业荣誉及其他证明材料</span>
  345. </div>
  346. <div className="user-search">
  347. <p>
  348. <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
  349. disabled={this.state.ButtonDisabled}
  350. onClick={this.tableRowClick}>添加<Icon type="plus" /></Button>
  351. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  352. disabled={!hasSelected}
  353. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  354. </p>
  355. </div>
  356. <div className="patent-table">
  357. <Spin spinning={this.state.loading}>
  358. <Table columns={this.state.columns}
  359. dataSource={this.state.dataSource}
  360. pagination={this.state.pagination}
  361. rowSelection={rowSelection}
  362. onRowClick={this.tableRowClick} />
  363. </Spin>
  364. </div>
  365. <HonorListDesc data={this.state.RowData}
  366. showDesc={this.state.showDesc} closeDesc={this.closeDesc} />
  367. </div >
  368. );
  369. }
  370. });
  371. export default HonorList;