honorList.jsx 16 KB

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