honorList.jsx 13 KB

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