honorList.jsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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 } 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 + "/techservice/cognizance/disposeHonor",
  24. data: {
  25. id: this.props.data.id,
  26. name: values.name,
  27. issuingMechanism: values.issuingMechanism,
  28. issuingTimeFormattedDate: values.issuingTimeFormattedDate.format("YYYY-MM-DD"),
  29. enclosureUrl: this.state.enclosureUrl
  30. }
  31. }).done(function (data) {
  32. if (!data.error.length) {
  33. message.success('保存成功!');
  34. this.props.closeModal();
  35. this.props.spinState(false);
  36. this.props.form.resetFields();
  37. } else {
  38. message.warning(data.error[0].message);
  39. this.props.spinState(false);
  40. }
  41. }.bind(this));
  42. }
  43. });
  44. },
  45. render() {
  46. const FormItem = Form.Item;
  47. const { getFieldDecorator } = this.props.form;
  48. const theData = this.props.data;
  49. const formItemLayout = {
  50. labelCol: { span: 4 },
  51. wrapperCol: { span: 12 },
  52. };
  53. const _me = this;
  54. return (
  55. <Form onSubmit={this.handleSubmit} className="activityCost-form">
  56. <div className="clearfix">
  57. <FormItem
  58. {...formItemLayout}
  59. label="名称"
  60. >
  61. {getFieldDecorator('name', {
  62. rules: [{ required: true, message: '此项为必填项!' }],
  63. initialValue: theData.name
  64. })(
  65. <Input />
  66. )}
  67. </FormItem>
  68. <FormItem
  69. {...formItemLayout}
  70. label="获取时间"
  71. >
  72. {getFieldDecorator('issuingTimeFormattedDate', {
  73. rules: [{ type: 'object', required: true, message: '此项为必填项!' }],
  74. initialValue: theData.issuingTimeFormattedDate ? moment(theData.issuingTimeFormattedDate) : null
  75. })(
  76. <DatePicker />
  77. )}
  78. </FormItem>
  79. <FormItem
  80. {...formItemLayout}
  81. label="发证机构"
  82. >
  83. {getFieldDecorator('issuingMechanism', {
  84. rules: [{ required: true, message: '此项为必填项!' }],
  85. initialValue: theData.issuingMechanism
  86. })(
  87. <Input />
  88. )}
  89. </FormItem>
  90. </div>
  91. <div className="hrSituation-roster">
  92. <Upload
  93. name="ratepay"
  94. action={globalConfig.context + "/techservice/cognizance/upload"}
  95. data={{ 'sign': this.props.year + 'enclosure' }}
  96. beforeUpload={beforeUploadFile}
  97. onChange={(info) => {
  98. if (info.file.status !== 'uploading') {
  99. console.log(info.file, info.fileList);
  100. }
  101. if (info.file.status === 'done') {
  102. message.success(`${info.file.name} 文件上传成功!`);
  103. this.state.enclosureUrl = info.file.response.data;
  104. } else if (info.file.status === 'error') {
  105. message.error(`${info.file.name} 文件上传失败。`);
  106. }
  107. }}
  108. >
  109. <Button><Icon type="upload" /> 上传文件 </Button>
  110. </Upload>
  111. </div>
  112. <FormItem style={{ marginTop: '20px' }}>
  113. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  114. <Button type="ghost" style={{ marginLeft: '20px' }} onClick={this.props.closeModal}>取消</Button>
  115. </FormItem>
  116. </Form >
  117. );
  118. },
  119. }));
  120. const HonorListDesc = React.createClass({
  121. getInitialState() {
  122. return {
  123. visible: false,
  124. loading: false
  125. };
  126. },
  127. componentWillReceiveProps(nextProps) {
  128. this.state.visible = nextProps.showDesc
  129. },
  130. showModal() {
  131. this.setState({
  132. visible: true,
  133. });
  134. },
  135. handleOk() {
  136. this.setState({
  137. visible: false,
  138. });
  139. this.props.closeDesc(false);
  140. },
  141. handleCancel(e) {
  142. this.setState({
  143. visible: false,
  144. });
  145. this.props.closeDesc(false);
  146. },
  147. spinChange(e) {
  148. this.setState({
  149. loading: e
  150. });
  151. },
  152. render() {
  153. return (
  154. <div className="patent-addNew">
  155. <Spin spinning={this.state.loading} className='spin-box'>
  156. <Modal title="企业荣誉及其他证明材料" visible={this.state.visible}
  157. onOk={this.handleOk} onCancel={this.handleCancel}
  158. width='800px'
  159. footer=''
  160. >
  161. <HonorListDescFrom data={this.props.data}
  162. spinState={this.spinChange} closeModal={this.handleCancel} />
  163. </Modal>
  164. </Spin>
  165. </div>
  166. );
  167. },
  168. });
  169. const HonorList = React.createClass({
  170. loadData(pageNo) {
  171. this.state.data = [];
  172. this.setState({
  173. loading: true
  174. });
  175. $.ajax({
  176. method: "get",
  177. dataType: "json",
  178. crossDomain: false,
  179. url: globalConfig.context + "/techservice/cognizance/honorList",
  180. data: {
  181. pageNo: pageNo || 1,
  182. pageSize: this.state.pagination.pageSize
  183. }
  184. }).done((data) => {
  185. if (data.error.length || !data.data || !data.data.list) {
  186. message.warning(data.error[0].message);
  187. return;
  188. };
  189. for (let i = 0; i < data.data.list.length; i++) {
  190. let thisdata = data.data.list[i];
  191. this.state.data.push({
  192. key: i,
  193. id: thisdata.id,
  194. uid: thisdata.uid,
  195. name: thisdata.name,
  196. issuingTime: thisdata.issuingTime,
  197. enclosureUrl: thisdata.enclosureUrl,
  198. issuingTimeFormattedDate: thisdata.issuingTimeFormattedDate,
  199. issuingMechanism: thisdata.issuingMechanism
  200. });
  201. };
  202. this.state.pagination.current = data.data.pageNo;
  203. this.state.pagination.total = data.data.totalCount;
  204. this.setState({
  205. dataSource: this.state.data,
  206. pagination: this.state.pagination
  207. });
  208. }).always(function () {
  209. this.setState({
  210. loading: false
  211. });
  212. }.bind(this));
  213. },
  214. getInitialState() {
  215. return {
  216. selectedRowKeys: [],
  217. selectedRows: [],
  218. loading: false,
  219. pagination: {
  220. defaultCurrent: 1,
  221. defaultPageSize: 10,
  222. showQuickJumper: true,
  223. pageSize: 10,
  224. onChange: function (page) {
  225. this.loadData(page);
  226. }.bind(this),
  227. showTotal: function (total) {
  228. return '共' + total + '条数据';
  229. }
  230. },
  231. columns: [
  232. {
  233. title: '名称',
  234. dataIndex: 'name',
  235. key: 'name'
  236. }, {
  237. title: '获取时间',
  238. dataIndex: 'issuingTimeFormattedDate',
  239. key: 'issuingTimeFormattedDate'
  240. }, {
  241. title: '发证机构',
  242. dataIndex: 'issuingMechanism',
  243. key: 'issuingMechanism'
  244. }, {
  245. title: '相关附件',
  246. dataIndex: 'enclosureUrl',
  247. key: 'enclosureUrl',
  248. render: (text) => {
  249. <a href="" onClick={() => {
  250. window.open(globalConfig.context + "/techservice/patent/downloadFile?path=" + text + "&sign=" + "type")
  251. }}></a>
  252. }
  253. }
  254. ],
  255. dataSource: []
  256. };
  257. },
  258. componentWillMount() {
  259. this.loadData();
  260. },
  261. tableRowClick(record, index) {
  262. this.state.RowData = record;
  263. this.setState({
  264. showDesc: true
  265. });
  266. },
  267. delectRow() {
  268. let deletedIds = [];
  269. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  270. let rowItem = this.state.selectedRows[idx];
  271. if (rowItem.id) {
  272. deletedIds.push(rowItem.id)
  273. }
  274. }
  275. this.setState({
  276. selectedRowKeys: [],
  277. loading: deletedIds.length > 0
  278. });
  279. $.ajax({
  280. method: "POST",
  281. dataType: "json",
  282. crossDomain: false,
  283. url: globalConfig.context + "/techservice/cognizance/deleteHonor",
  284. data: {
  285. ids: deletedIds
  286. }
  287. }).done(function (data) {
  288. if (!data.error.length) {
  289. message.success('保存成功!');
  290. this.setState({
  291. loading: false,
  292. });
  293. } else {
  294. message.warning(data.error[0].message);
  295. };
  296. this.loadData();
  297. }.bind(this));
  298. },
  299. closeDesc(e) {
  300. this.state.showDesc = e;
  301. this.loadData();
  302. },
  303. search() {
  304. this.loadData();
  305. },
  306. reset() {
  307. this.loadData();
  308. },
  309. render() {
  310. const rowSelection = {
  311. selectedRowKeys: this.state.selectedRowKeys,
  312. onChange: (selectedRowKeys, selectedRows) => {
  313. this.setState({
  314. selectedRows: selectedRows,
  315. selectedRowKeys: selectedRowKeys
  316. });
  317. }
  318. };
  319. const hasSelected = this.state.selectedRowKeys.length > 0;
  320. return (
  321. <div className="user-content" >
  322. <div className="content-title">
  323. <span>企业荣誉及其他证明材料</span>
  324. </div>
  325. <div className="user-search">
  326. <p>
  327. <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
  328. onClick={this.tableRowClick}>添加<Icon type="plus" /></Button>
  329. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  330. disabled={!hasSelected}
  331. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  332. </p>
  333. </div>
  334. <div className="patent-table">
  335. <Spin spinning={this.state.loading}>
  336. <Table columns={this.state.columns}
  337. dataSource={this.state.dataSource}
  338. pagination={this.state.pagination}
  339. rowSelection={rowSelection}
  340. onRowClick={this.tableRowClick} />
  341. </Spin>
  342. </div>
  343. <HonorListDesc data={this.state.RowData}
  344. showDesc={this.state.showDesc} closeDesc={this.closeDesc} />
  345. </div >
  346. );
  347. }
  348. });
  349. export default HonorList;