honorList.jsx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. import React from 'react';
  2. import { Switch, Icon, Form, Button, Input, Spin, Table, message, Modal, Upload, DatePicker } from 'antd';
  3. import './techProduct.less';
  4. import { beforeUploadFile, newDownloadFile, getProportion, saveProportion } 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. let _me = this;
  252. getProportion(this.props.data.uid, function (data) { _me.setState({ proportion: data }); });
  253. },
  254. getInitialState() {
  255. return {
  256. selectedRowKeys: [],
  257. selectedRows: [],
  258. loading: false,
  259. pagination: {
  260. defaultCurrent: 1,
  261. defaultPageSize: 10,
  262. showQuickJumper: true,
  263. pageSize: 10,
  264. onChange: function (page) {
  265. this.loadData(page);
  266. }.bind(this),
  267. showTotal: function (total) {
  268. return '共' + total + '条数据';
  269. }
  270. },
  271. columns: [
  272. {
  273. title: '名称',
  274. dataIndex: 'name',
  275. key: 'name'
  276. }, {
  277. title: '获取时间',
  278. dataIndex: 'year',
  279. key: 'year'
  280. }, {
  281. title: '发证机构',
  282. dataIndex: 'issuingMechanism',
  283. key: 'issuingMechanism'
  284. }, {
  285. title: '相关附件',
  286. dataIndex: 'enclosure',
  287. key: 'enclosure',
  288. render: (text) => {
  289. return <a onClick={newDownloadFile.bind(null, text[0], 'honor', '/api/admin/downloadHonor')}>{text[1]}</a>
  290. }
  291. }
  292. ],
  293. dataSource: []
  294. };
  295. },
  296. componentWillMount() {
  297. this.loadData();
  298. },
  299. tableRowClick(record, index) {
  300. this.state.RowData = record;
  301. this.setState({
  302. showDesc: true
  303. });
  304. },
  305. delectRow() {
  306. let deletedIds = [];
  307. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  308. let rowItem = this.state.selectedRows[idx];
  309. if (rowItem.id) {
  310. deletedIds.push(rowItem.id)
  311. }
  312. }
  313. this.setState({
  314. selectedRowKeys: [],
  315. loading: deletedIds.length > 0
  316. });
  317. $.ajax({
  318. method: "POST",
  319. dataType: "json",
  320. crossDomain: false,
  321. url: globalConfig.context + "/api/admin/deleteHonor",
  322. data: {
  323. ids: deletedIds
  324. }
  325. }).done(function (data) {
  326. if (!data.error.length) {
  327. message.success('保存成功!');
  328. this.setState({
  329. loading: false,
  330. });
  331. } else {
  332. message.warning(data.error[0].message);
  333. };
  334. this.loadData();
  335. }.bind(this));
  336. },
  337. closeDesc(e, s) {
  338. this.state.showDesc = e;
  339. if (s) {
  340. this.loadData();
  341. };
  342. },
  343. search() {
  344. this.loadData();
  345. },
  346. reset() {
  347. this.loadData();
  348. },
  349. render() {
  350. const rowSelection = {
  351. selectedRowKeys: this.state.selectedRowKeys,
  352. onChange: (selectedRowKeys, selectedRows) => {
  353. this.setState({
  354. selectedRows: selectedRows,
  355. selectedRowKeys: selectedRowKeys
  356. });
  357. }
  358. };
  359. const hasSelected = this.state.selectedRowKeys.length > 0;
  360. return (
  361. <div className="user-content" >
  362. <div className="content-title">
  363. <span>企业荣誉及其他证明材料</span>
  364. <span className="proportion"> 是否已完成:</span>
  365. <Switch
  366. checked={this.state.proportion && this.state.proportion.honorDatum == 1 ? true : false}
  367. checkedChildren={'已完成'}
  368. unCheckedChildren={'未完成'}
  369. onChange={(e) => {
  370. e ? this.state.proportion.honorDatum = 1 : this.state.proportion.honorDatum = 0;
  371. saveProportion(this.state.proportion.id, this.props.data.uid, 'honorDatum', this.state.proportion.honorDatum);
  372. this.setState({ proportion: this.state.proportion });
  373. }} />
  374. </div>
  375. <div className="user-search">
  376. <p>
  377. <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
  378. onClick={this.tableRowClick}>添加<Icon type="plus" /></Button>
  379. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  380. disabled={!hasSelected}
  381. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  382. </p>
  383. </div>
  384. <div className="patent-table">
  385. <Spin spinning={this.state.loading}>
  386. <Table columns={this.state.columns}
  387. dataSource={this.state.dataSource}
  388. pagination={this.state.pagination}
  389. rowSelection={rowSelection}
  390. onRowClick={this.tableRowClick} />
  391. </Spin>
  392. </div>
  393. <HonorListDesc
  394. uid={this.props.data.uid}
  395. data={this.state.RowData}
  396. showDesc={this.state.showDesc} closeDesc={this.closeDesc} />
  397. </div >
  398. );
  399. }
  400. });
  401. export default HonorList;