honorList.jsx 13 KB

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