honorList.jsx 16 KB

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