honorList.jsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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.clickOk();
  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. if (!info.file.response.error.length) {
  103. message.success(`${info.file.name} 文件上传成功!`);
  104. } else {
  105. message.warning(info.file.response.error[0].message);
  106. return;
  107. };
  108. this.state.enclosureUrl = info.file.response.data;
  109. } else if (info.file.status === 'error') {
  110. message.error(`${info.file.name} 文件上传失败。`);
  111. }
  112. }}
  113. >
  114. <Button><Icon type="upload" /> 上传文件 </Button>
  115. </Upload>
  116. </div>
  117. <FormItem style={{ marginTop: '20px' }}>
  118. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  119. <Button type="ghost" style={{ marginLeft: '20px' }} onClick={this.props.closeModal}>取消</Button>
  120. </FormItem>
  121. </Form >
  122. );
  123. },
  124. }));
  125. const HonorListDesc = React.createClass({
  126. getInitialState() {
  127. return {
  128. visible: false,
  129. loading: false
  130. };
  131. },
  132. componentWillReceiveProps(nextProps) {
  133. this.state.visible = nextProps.showDesc
  134. },
  135. showModal() {
  136. this.setState({
  137. visible: true,
  138. });
  139. },
  140. handleOk() {
  141. this.setState({
  142. visible: false,
  143. });
  144. this.props.closeDesc(false,true);
  145. },
  146. handleCancel(e) {
  147. this.setState({
  148. visible: false,
  149. });
  150. this.props.closeDesc(false);
  151. },
  152. spinChange(e) {
  153. this.setState({
  154. loading: e
  155. });
  156. },
  157. render() {
  158. return (
  159. <div className="patent-addNew">
  160. <Spin spinning={this.state.loading} className='spin-box'>
  161. <Modal title="企业荣誉及其他证明材料" visible={this.state.visible}
  162. onOk={this.handleOk} onCancel={this.handleCancel}
  163. width='800px'
  164. footer=''
  165. >
  166. <HonorListDescFrom data={this.props.data}
  167. spinState={this.spinChange} closeModal={this.handleCancel} clickOk={this.handleOk} />
  168. </Modal>
  169. </Spin>
  170. </div>
  171. );
  172. },
  173. });
  174. const HonorList = React.createClass({
  175. loadData(pageNo) {
  176. this.state.data = [];
  177. this.setState({
  178. loading: true
  179. });
  180. $.ajax({
  181. method: "get",
  182. dataType: "json",
  183. crossDomain: false,
  184. url: globalConfig.context + "/techservice/cognizance/honorList",
  185. data: {
  186. pageNo: pageNo || 1,
  187. pageSize: this.state.pagination.pageSize
  188. }
  189. }).done((data) => {
  190. if (data.error.length || !data.data || !data.data.list) {
  191. message.warning(data.error[0].message);
  192. return;
  193. };
  194. for (let i = 0; i < data.data.list.length; i++) {
  195. let thisdata = data.data.list[i];
  196. this.state.data.push({
  197. key: i,
  198. id: thisdata.id,
  199. uid: thisdata.uid,
  200. name: thisdata.name,
  201. issuingTime: thisdata.issuingTime,
  202. enclosureUrl: thisdata.enclosureUrl,
  203. issuingTimeFormattedDate: thisdata.issuingTimeFormattedDate,
  204. issuingMechanism: thisdata.issuingMechanism
  205. });
  206. };
  207. this.state.pagination.current = data.data.pageNo;
  208. this.state.pagination.total = data.data.totalCount;
  209. this.setState({
  210. dataSource: this.state.data,
  211. pagination: this.state.pagination
  212. });
  213. }).always(function () {
  214. this.setState({
  215. loading: false
  216. });
  217. }.bind(this));
  218. },
  219. getInitialState() {
  220. return {
  221. selectedRowKeys: [],
  222. selectedRows: [],
  223. loading: false,
  224. pagination: {
  225. defaultCurrent: 1,
  226. defaultPageSize: 10,
  227. showQuickJumper: true,
  228. pageSize: 10,
  229. onChange: function (page) {
  230. this.loadData(page);
  231. }.bind(this),
  232. showTotal: function (total) {
  233. return '共' + total + '条数据';
  234. }
  235. },
  236. columns: [
  237. {
  238. title: '名称',
  239. dataIndex: 'name',
  240. key: 'name'
  241. }, {
  242. title: '获取时间',
  243. dataIndex: 'issuingTimeFormattedDate',
  244. key: 'issuingTimeFormattedDate'
  245. }, {
  246. title: '发证机构',
  247. dataIndex: 'issuingMechanism',
  248. key: 'issuingMechanism'
  249. }, {
  250. title: '相关附件',
  251. dataIndex: 'enclosureUrl',
  252. key: 'enclosureUrl',
  253. render: (text) => {
  254. <a href="" onClick={() => {
  255. window.open(globalConfig.context + "/techservice/patent/downloadFile?path=" + text + "&sign=" + "type")
  256. }}></a>
  257. }
  258. }
  259. ],
  260. dataSource: []
  261. };
  262. },
  263. componentWillMount() {
  264. this.loadData();
  265. },
  266. tableRowClick(record, index) {
  267. this.state.RowData = record;
  268. this.setState({
  269. showDesc: true
  270. });
  271. },
  272. delectRow() {
  273. let deletedIds = [];
  274. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  275. let rowItem = this.state.selectedRows[idx];
  276. if (rowItem.id) {
  277. deletedIds.push(rowItem.id)
  278. }
  279. }
  280. this.setState({
  281. selectedRowKeys: [],
  282. loading: deletedIds.length > 0
  283. });
  284. $.ajax({
  285. method: "POST",
  286. dataType: "json",
  287. crossDomain: false,
  288. url: globalConfig.context + "/techservice/cognizance/deleteHonor",
  289. data: {
  290. ids: deletedIds
  291. }
  292. }).done(function (data) {
  293. if (!data.error.length) {
  294. message.success('保存成功!');
  295. this.setState({
  296. loading: false,
  297. });
  298. } else {
  299. message.warning(data.error[0].message);
  300. };
  301. this.loadData();
  302. }.bind(this));
  303. },
  304. closeDesc(e, s) {
  305. this.state.showDesc = e;
  306. if (s) {
  307. this.loadData();
  308. };
  309. },
  310. search() {
  311. this.loadData();
  312. },
  313. reset() {
  314. this.loadData();
  315. },
  316. render() {
  317. const rowSelection = {
  318. selectedRowKeys: this.state.selectedRowKeys,
  319. onChange: (selectedRowKeys, selectedRows) => {
  320. this.setState({
  321. selectedRows: selectedRows,
  322. selectedRowKeys: selectedRowKeys
  323. });
  324. }
  325. };
  326. const hasSelected = this.state.selectedRowKeys.length > 0;
  327. return (
  328. <div className="user-content" >
  329. <div className="content-title">
  330. <span>企业荣誉及其他证明材料</span>
  331. </div>
  332. <div className="user-search">
  333. <p>
  334. <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
  335. onClick={this.tableRowClick}>添加<Icon type="plus" /></Button>
  336. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  337. disabled={!hasSelected}
  338. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  339. </p>
  340. </div>
  341. <div className="patent-table">
  342. <Spin spinning={this.state.loading}>
  343. <Table columns={this.state.columns}
  344. dataSource={this.state.dataSource}
  345. pagination={this.state.pagination}
  346. rowSelection={rowSelection}
  347. onRowClick={this.tableRowClick} />
  348. </Spin>
  349. </div>
  350. <HonorListDesc data={this.state.RowData}
  351. showDesc={this.state.showDesc} closeDesc={this.closeDesc} />
  352. </div >
  353. );
  354. }
  355. });
  356. export default HonorList;