honorList.jsx 16 KB

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