honorList.jsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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 + "/api/admin/disposeHonor",
  24. data: {
  25. id: this.props.data.id,
  26. uid: this.props.uid,
  27. name: values.name,
  28. issuingMechanism: values.issuingMechanism,
  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. render() {
  52. const FormItem = Form.Item;
  53. const { getFieldDecorator } = this.props.form;
  54. const theData = this.props.data;
  55. const formItemLayout = {
  56. labelCol: { span: 4 },
  57. wrapperCol: { span: 12 },
  58. };
  59. const _me = this;
  60. return (
  61. <Form onSubmit={this.handleSubmit} className="activityCost-form">
  62. <div className="clearfix">
  63. <FormItem
  64. {...formItemLayout}
  65. label="名称"
  66. >
  67. {getFieldDecorator('name', {
  68. rules: [{ required: true, message: '此项为必填项!' }],
  69. initialValue: theData.name
  70. })(
  71. <Input />
  72. )}
  73. </FormItem>
  74. <FormItem
  75. {...formItemLayout}
  76. label="获取时间"
  77. >
  78. {getFieldDecorator('issuingTimeFormattedDate', {
  79. rules: [{ type: 'object', required: true, message: '此项为必填项!' }],
  80. initialValue: theData.issuingTimeFormattedDate ? moment(theData.issuingTimeFormattedDate) : null
  81. })(
  82. <DatePicker />
  83. )}
  84. </FormItem>
  85. <FormItem
  86. {...formItemLayout}
  87. label="发证机构"
  88. >
  89. {getFieldDecorator('issuingMechanism', {
  90. rules: [{ required: true, message: '此项为必填项!' }],
  91. initialValue: theData.issuingMechanism
  92. })(
  93. <Input />
  94. )}
  95. </FormItem>
  96. </div>
  97. <div className="hrSituation-roster">
  98. <Upload
  99. name="ratepay"
  100. action={globalConfig.context + "/api/admin/uploadHonor"}
  101. data={{ 'sign': 'honor','uid': this.props.uid }}
  102. beforeUpload={beforeUploadFile}
  103. showUploadList={false}
  104. onChange={(info) => {
  105. if (info.file.status !== 'uploading') {
  106. console.log(info.file, info.fileList);
  107. }
  108. if (info.file.status === 'done') {
  109. if (!info.file.response.error.length) {
  110. message.success(`${info.file.name} 文件上传成功!`);
  111. } else {
  112. message.warning(info.file.response.error[0].message);
  113. return;
  114. };
  115. this.state.enclosureUrl = info.file.response.data;
  116. } else if (info.file.status === 'error') {
  117. message.error(`${info.file.name} 文件上传失败。`);
  118. }
  119. }}
  120. >
  121. <Button><Icon type="upload" /> 上传企业荣誉附件 </Button>
  122. </Upload>
  123. <p style={{ marginTop: '10px' }}>{theData.enclosureUrl ? <a onClick={downloadFile.bind(null, theData.enclosureUrl, theData.enclosureDownloadFileName)}>{theData.enclosureDownloadFileName}</a> : <span><Icon type="exclamation-circle" style={{ color: '#ffbf00', marginRight: '6px' }} />未上传!</span>}</p>
  124. </div>
  125. <FormItem style={{ marginTop: '20px' }}>
  126. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  127. <Button type="ghost" style={{ marginLeft: '20px' }} onClick={this.props.closeModal}>取消</Button>
  128. </FormItem>
  129. </Form >
  130. );
  131. },
  132. }));
  133. const HonorListDesc = React.createClass({
  134. getInitialState() {
  135. return {
  136. visible: false,
  137. loading: false
  138. };
  139. },
  140. componentWillReceiveProps(nextProps) {
  141. this.state.visible = nextProps.showDesc
  142. },
  143. showModal() {
  144. this.setState({
  145. visible: true,
  146. });
  147. },
  148. handleOk() {
  149. this.setState({
  150. visible: false,
  151. });
  152. this.props.closeDesc(false, true);
  153. },
  154. handleCancel(e) {
  155. this.setState({
  156. visible: false,
  157. });
  158. this.props.closeDesc(false);
  159. },
  160. spinChange(e) {
  161. this.setState({
  162. loading: e
  163. });
  164. },
  165. render() {
  166. return (
  167. <div className="patent-addNew">
  168. <Spin spinning={this.state.loading} className='spin-box'>
  169. <Modal title="企业荣誉及其他证明材料" visible={this.state.visible}
  170. onOk={this.handleOk} onCancel={this.handleCancel}
  171. width='800px'
  172. footer=''
  173. >
  174. <HonorListDescFrom
  175. uid={this.props.uid}
  176. data={this.props.data}
  177. spinState={this.spinChange}
  178. visible={this.state.visible}
  179. closeModal={this.handleCancel}
  180. clickOk={this.handleOk} />
  181. </Modal>
  182. </Spin>
  183. </div>
  184. );
  185. },
  186. });
  187. const HonorList = React.createClass({
  188. loadData(pageNo) {
  189. this.state.data = [];
  190. this.setState({
  191. loading: true
  192. });
  193. $.ajax({
  194. method: "post",
  195. dataType: "json",
  196. crossDomain: false,
  197. url: globalConfig.context + "/api/admin/honorList",
  198. data: {
  199. pageNo: pageNo || 1,
  200. pageSize: this.state.pagination.pageSize,
  201. uid: this.props.data.uid
  202. }
  203. }).done((data) => {
  204. if (data.error.length || !data.data || !data.data.list) {
  205. message.warning(data.error[0].message);
  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.enclosureUrl, 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={downloadFile.bind(null, text[0], text[1])}>{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/admin/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. onClick={this.tableRowClick}>添加<Icon type="plus" /></Button>
  350. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  351. disabled={!hasSelected}
  352. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  353. </p>
  354. </div>
  355. <div className="patent-table">
  356. <Spin spinning={this.state.loading}>
  357. <Table columns={this.state.columns}
  358. dataSource={this.state.dataSource}
  359. pagination={this.state.pagination}
  360. rowSelection={rowSelection}
  361. onRowClick={this.tableRowClick} />
  362. </Spin>
  363. </div>
  364. <HonorListDesc
  365. uid={this.props.data.uid}
  366. data={this.state.RowData}
  367. showDesc={this.state.showDesc} closeDesc={this.closeDesc} />
  368. </div >
  369. );
  370. }
  371. });
  372. export default HonorList;