honorList.jsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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/admin/disposeHonor",
  24. data: {
  25. id: this.props.data.id,
  26. uid: this.props.uid,
  27. name: values.name,
  28. issuingMechanism: values.issuingMechanism,
  29. year: values.year,
  30. //issuingTimeFormattedDate: values.issuingTimeFormattedDate.format("YYYY-MM-DD"),
  31. enclosureUrl: this.state.enclosureUrl
  32. }
  33. }).done(function (data) {
  34. if (!data.error.length) {
  35. message.success('保存成功!');
  36. this.props.clickOk();
  37. this.props.spinState(false);
  38. this.props.form.resetFields();
  39. } else {
  40. message.warning(data.error[0].message);
  41. this.props.spinState(false);
  42. }
  43. }.bind(this));
  44. }
  45. });
  46. },
  47. componentWillReceiveProps(nextProps) {
  48. if (!this.props.visible && nextProps.visible) {
  49. this.props.form.resetFields();
  50. };
  51. },
  52. componentWillMount() {
  53. const Option = Select.Option;
  54. const d = new Date();
  55. const thisYear = d.getFullYear();
  56. let theOption = [];
  57. for (let i = thisYear; i >= 1950; i--) {
  58. theOption.push(<Option key={i.toString()}>{i}</Option>)
  59. };
  60. this.state.yearOption = theOption;
  61. },
  62. render() {
  63. const FormItem = Form.Item;
  64. const { getFieldDecorator } = this.props.form;
  65. const theData = this.props.data;
  66. const formItemLayout = {
  67. labelCol: { span: 4 },
  68. wrapperCol: { span: 12 },
  69. };
  70. const _me = this;
  71. return (
  72. <Form onSubmit={this.handleSubmit} className="activityCost-form">
  73. <div className="clearfix">
  74. <FormItem
  75. {...formItemLayout}
  76. label="名称"
  77. >
  78. {getFieldDecorator('name', {
  79. rules: [{ required: true, message: '此项为必填项!' }],
  80. initialValue: theData.name
  81. })(
  82. <Input />
  83. )}
  84. </FormItem>
  85. <FormItem
  86. {...formItemLayout}
  87. label="获取时间"
  88. >
  89. {getFieldDecorator('year', {
  90. rules: [{ required: true, message: '此项为必填项!' }],
  91. initialValue: theData.year
  92. })(
  93. <Select
  94. placeholder="请选择年份"
  95. style={{ width: 80 }}>
  96. {this.state.yearOption}
  97. </Select>
  98. )}
  99. <span> 年</span>
  100. </FormItem>
  101. <FormItem
  102. {...formItemLayout}
  103. label="发证机构"
  104. >
  105. {getFieldDecorator('issuingMechanism', {
  106. rules: [{ required: true, message: '此项为必填项!' }],
  107. initialValue: theData.issuingMechanism
  108. })(
  109. <Input />
  110. )}
  111. </FormItem>
  112. </div>
  113. <div className="hrSituation-roster">
  114. <Upload
  115. name="ratepay"
  116. action={globalConfig.context + "/api/admin/uploadHonor"}
  117. data={{ 'sign': 'honor','uid': this.props.uid }}
  118. beforeUpload={beforeUploadFile}
  119. showUploadList={false}
  120. onChange={(info) => {
  121. if (info.file.status !== 'uploading') {
  122. console.log(info.file, info.fileList);
  123. }
  124. if (info.file.status === 'done') {
  125. if (!info.file.response.error.length) {
  126. message.success(`${info.file.name} 文件上传成功!`);
  127. } else {
  128. message.warning(info.file.response.error[0].message);
  129. return;
  130. };
  131. this.state.enclosureUrl = info.file.response.data;
  132. } else if (info.file.status === 'error') {
  133. message.error(`${info.file.name} 文件上传失败。`);
  134. }
  135. }}
  136. >
  137. <Button><Icon type="upload" /> 上传企业相关资质证书 </Button>
  138. </Upload>
  139. <p style={{ marginTop: '10px' }}>{theData.enclosureUrl ? <a onClick={newDownloadFile.bind(null, this.props.data.id, 'honor', '/api/admin/downloadHonor')}>{theData.enclosureDownloadFileName}</a> : <span><Icon type="exclamation-circle" style={{ color: '#ffbf00', marginRight: '6px' }} />未上传!</span>}</p>
  140. </div>
  141. <FormItem style={{ marginTop: '20px' }}>
  142. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  143. <Button type="ghost" style={{ marginLeft: '20px' }} onClick={this.props.closeModal}>取消</Button>
  144. </FormItem>
  145. </Form >
  146. );
  147. },
  148. }));
  149. const HonorListDesc = React.createClass({
  150. getInitialState() {
  151. return {
  152. visible: false,
  153. loading: false
  154. };
  155. },
  156. componentWillReceiveProps(nextProps) {
  157. this.state.visible = nextProps.showDesc
  158. },
  159. showModal() {
  160. this.setState({
  161. visible: true,
  162. });
  163. },
  164. handleOk() {
  165. this.setState({
  166. visible: false,
  167. });
  168. this.props.closeDesc(false, true);
  169. },
  170. handleCancel(e) {
  171. this.setState({
  172. visible: false,
  173. });
  174. this.props.closeDesc(false);
  175. },
  176. spinChange(e) {
  177. this.setState({
  178. loading: e
  179. });
  180. },
  181. render() {
  182. return (
  183. <div className="patent-addNew">
  184. <Spin spinning={this.state.loading} className='spin-box'>
  185. <Modal title="企业荣誉及其他证明材料" visible={this.state.visible}
  186. onOk={this.handleOk} onCancel={this.handleCancel}
  187. width='800px'
  188. footer=''
  189. >
  190. <HonorListDescFrom
  191. uid={this.props.uid}
  192. data={this.props.data}
  193. spinState={this.spinChange}
  194. visible={this.state.visible}
  195. closeModal={this.handleCancel}
  196. clickOk={this.handleOk} />
  197. </Modal>
  198. </Spin>
  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: "post",
  211. dataType: "json",
  212. crossDomain: false,
  213. url: globalConfig.context + "/api/admin/honorList",
  214. data: {
  215. pageNo: pageNo || 1,
  216. pageSize: this.state.pagination.pageSize,
  217. uid: this.props.data.uid
  218. }
  219. }).done((data) => {
  220. if (data.error.length || !data.data || !data.data.list) {
  221. message.warning(data.error[0].message);
  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. issuingTime: thisdata.issuingTime,
  232. enclosureUrl: thisdata.enclosureUrl,
  233. enclosureDownloadFileName: thisdata.enclosureDownloadFileName,
  234. enclosure: [thisdata.id, thisdata.enclosureDownloadFileName],
  235. //issuingTimeFormattedDate: thisdata.issuingTimeFormattedDate,
  236. year:thisdata.year,
  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/admin/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/admin/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. onClick={this.tableRowClick}>添加<Icon type="plus" /></Button>
  367. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  368. disabled={!hasSelected}
  369. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  370. </p>
  371. </div>
  372. <div className="patent-table">
  373. <Spin spinning={this.state.loading}>
  374. <Table columns={this.state.columns}
  375. dataSource={this.state.dataSource}
  376. pagination={this.state.pagination}
  377. rowSelection={rowSelection}
  378. onRowClick={this.tableRowClick} />
  379. </Spin>
  380. </div>
  381. <HonorListDesc
  382. uid={this.props.data.uid}
  383. data={this.state.RowData}
  384. showDesc={this.state.showDesc} closeDesc={this.closeDesc} />
  385. </div >
  386. );
  387. }
  388. });
  389. export default HonorList;