standard.jsx 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. import React from 'react';
  2. import { Icon, Button, Input, Spin, Table, message, Radio, Select, Modal, Upload } from 'antd';
  3. import { beforeUploadFile, newDownloadFile } from '../../tools.js';
  4. import './standard.less';
  5. import ajax from 'jquery/src/ajax/xhr.js';
  6. import $ from 'jquery/src/ajax';
  7. const StandardDesc = React.createClass({
  8. getInitialState() {
  9. return {
  10. visible: false,
  11. loading: false
  12. };
  13. },
  14. handleOk() {
  15. this.setState({
  16. loading: true,
  17. });
  18. $.ajax({
  19. method: "POST",
  20. dataType: "json",
  21. crossDomain: false,
  22. url: globalConfig.context + "/api/user/cognizance/developStandard",
  23. data: {
  24. id: this.props.data.id,
  25. standardName: this.state.standardName,
  26. standardNumber: this.state.standardNumber,
  27. year: this.state.year,
  28. standardLevel: this.state.standardLevel,
  29. participateWay: this.state.participateWay,
  30. enclosureUrl: this.state.enclosureUrl
  31. },
  32. success: function (data) {
  33. if (data.data) {
  34. this.setState({
  35. id: data.data.id,
  36. standardName: data.data.standardName,
  37. standardNumber: data.data.standardNumber,
  38. standardLevel: data.data.standardLevel,
  39. participateWay: data.data.participateWay,
  40. enclosureUrl: this.state.enclosureUrl
  41. });
  42. } else if (data.error && data.error.length) {
  43. message.warning(data.error[0].message);
  44. };
  45. }.bind(this),
  46. }).done(function (data) {
  47. if (!data.error.length) {
  48. message.success('保存成功!');
  49. this.setState({
  50. loading: false,
  51. visible: false
  52. });
  53. } else {
  54. message.warning(data.error[0].message);
  55. };
  56. this.props.closeDesc(false, true);
  57. }.bind(this));
  58. },
  59. handleCancel(e) {
  60. this.setState({
  61. visible: false,
  62. });
  63. this.props.closeDesc(false);
  64. },
  65. componentWillMount() {
  66. const Option = Select.Option;
  67. const d = new Date();
  68. const thisYear = d.getFullYear();
  69. let theOption = [];
  70. for (let i = thisYear; i >= 1950; i--) {
  71. theOption.push(<Option key={i.toString()}>{i}</Option>)
  72. };
  73. this.state.yearOption = theOption;
  74. },
  75. componentWillReceiveProps(nextProps) {
  76. if (!this.state.visible && nextProps.showDesc) {
  77. if (nextProps.data) {
  78. this.state.standardName = nextProps.data.standardName;
  79. this.state.standardNumber = nextProps.data.standardNumber;
  80. this.state.year = nextProps.data.year;
  81. this.state.standardLevel = nextProps.data.standardLevel;
  82. this.state.participateWay = nextProps.data.participateWay;
  83. this.state.enclosureUrl = nextProps.data.enclosureUrl;
  84. };
  85. this.state.fileList = [];
  86. this.state.enclosureUrl = undefined;
  87. };
  88. this.state.visible = nextProps.showDesc;
  89. },
  90. render() {
  91. if (this.props.data) {
  92. return (
  93. <div className="admin-desc">
  94. <Modal maskClosable={false} title="企业参与国家标准或行业标准制定情况明细" visible={this.state.visible} onCancel={this.handleCancel}
  95. width='400px' footer={[
  96. <Button key="submit" type="primary" size="large" loading={this.state.loading} onClick={this.handleOk}>确认</Button>,
  97. <Button key="back" type="ghost" size="large" onClick={this.handleCancel}>取消</Button>
  98. ]}
  99. className="admin-desc-content">
  100. <div>
  101. <p>标准名称:</p>
  102. <Input defaultValue={this.props.data.standardName} value={this.state.standardName}
  103. onChange={(e) => { this.setState({ standardName: e.target.value }); }} />
  104. </div>
  105. <div>
  106. <p>标准编号:</p>
  107. <Input value={this.state.standardNumber}
  108. onChange={(e) => { this.setState({ standardNumber: e.target.value }); }} />
  109. </div>
  110. <div>
  111. <p>制定时间:</p>
  112. <Select
  113. placeholder="请选择年份"
  114. value={this.state.year}
  115. onChange={(e) => { this.setState({ year: e }); }}
  116. style={{ width: 120 }}>
  117. {this.state.yearOption}
  118. </Select>
  119. </div>
  120. <div>
  121. <p>标准级别:</p>
  122. <Radio.Group value={this.state.standardLevel} onChange={(e) => { this.setState({ standardLevel: e.target.value }) }}>
  123. <Radio value={0}>国家</Radio>
  124. <Radio value={1}>行业</Radio>
  125. </Radio.Group>
  126. </div>
  127. <div>
  128. <p>参与方式:</p>
  129. <Radio.Group value={this.state.participateWay} onChange={(e) => { this.setState({ participateWay: e.target.value }) }}>
  130. <Radio value={0}>主持</Radio>
  131. <Radio value={1}>参与</Radio>
  132. </Radio.Group>
  133. </div>
  134. <div className="hrSituation-roster">
  135. <Upload
  136. name="ratepay"
  137. action={globalConfig.context + "/api/user/cognizance/uploadStandard"}
  138. data={{ 'sign': 'standard', 'uid': this.props.uid }}
  139. beforeUpload={beforeUploadFile}
  140. fileList={this.state.fileList}
  141. onChange={(info) => {
  142. if (info.file.status !== 'uploading') {
  143. console.log(info.file, info.fileList);
  144. }
  145. if (info.file.status === 'done') {
  146. if (!info.file.response.error.length) {
  147. message.success(`${info.file.name} 文件上传成功!`);
  148. } else {
  149. message.warning(info.file.response.error[0].message);
  150. return;
  151. };
  152. this.state.enclosureUrl = info.file.response.data;
  153. } else if (info.file.status === 'error') {
  154. message.error(`${info.file.name} 文件上传失败。`);
  155. };
  156. this.setState({ fileList: info.fileList.slice(-1) });
  157. }}
  158. >
  159. <Button><Icon type="upload" /> 上传标准制定附件 </Button>
  160. </Upload>
  161. <p style={{ marginTop: '10px' }}>{this.state.enclosureUrl ? <a onClick={newDownloadFile.bind(null, this.props.data.id, 'standard', '/api/user/cognizance/downloadStandard')}>标准定制附件</a> : <span><Icon type="exclamation-circle" style={{ color: '#ffbf00', marginRight: '6px' }} />未上传!</span>}</p>
  162. </div>
  163. </Modal>
  164. </div>
  165. );
  166. } else {
  167. return <div></div>
  168. }
  169. },
  170. });
  171. const Standard = React.createClass({
  172. loadData(pageNo) {
  173. this.state.data = [];
  174. this.setState({
  175. loading: true
  176. });
  177. $.ajax({
  178. method: "post",
  179. dataType: "json",
  180. crossDomain: false,
  181. url: globalConfig.context + "/api/user/cognizance/standard",
  182. data: {
  183. pageNo: pageNo || 1,
  184. pageSize: this.state.pagination.pageSize,
  185. standardName: this.state.standardName,
  186. standardNumber: this.state.standardNumber,
  187. standardLevel: this.state.standardLevel,
  188. participateWay: this.state.participateWay
  189. },
  190. success: function (data) {
  191. if (!data.data) {
  192. if (data.error && data.error.length) {
  193. message.warning(data.error[0].message);
  194. this.state.ButtonDisabled = true;
  195. }
  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 + 1,
  202. id: thisdata.id,
  203. uid: thisdata.uid,
  204. standardName: thisdata.standardName,
  205. standardNumber: thisdata.standardNumber,
  206. year: thisdata.year,
  207. enclosureUrl: thisdata.enclosureUrl,
  208. standardLevel: thisdata.standardLevel,
  209. participateWay: thisdata.participateWay,
  210. createTime: thisdata.createTime,
  211. createTimeFormattedDate: thisdata.createTimeFormattedDate
  212. });
  213. };
  214. this.state.pagination.current = data.data.pageNo;
  215. this.state.pagination.total = data.data.totalCount;
  216. this.setState({
  217. dataSource: this.state.data,
  218. pagination: this.state.pagination
  219. });
  220. }.bind(this),
  221. }).always(function () {
  222. this.setState({
  223. loading: false
  224. });
  225. }.bind(this));
  226. },
  227. getInitialState() {
  228. return {
  229. selectedRowKeys: [],
  230. selectedRows: [],
  231. loading: false,
  232. pagination: {
  233. defaultCurrent: 1,
  234. defaultPageSize: 10,
  235. showQuickJumper: true,
  236. pageSize: 10,
  237. onChange: function (page) {
  238. this.loadData(page);
  239. }.bind(this),
  240. showTotal: function (total) {
  241. return '共' + total + '条数据';
  242. }
  243. },
  244. columns: [
  245. {
  246. title: '编号',
  247. dataIndex: 'key',
  248. key: 'key'
  249. }, {
  250. title: '标准名称',
  251. dataIndex: 'standardName',
  252. key: 'standardName'
  253. }, {
  254. title: '标准编号',
  255. dataIndex: 'standardNumber',
  256. key: 'standardNumber'
  257. }, {
  258. title: '制定时间',
  259. dataIndex: 'year',
  260. key: 'year'
  261. }, {
  262. title: '标准级别',
  263. dataIndex: 'standardLevel',
  264. key: 'standardLevel',
  265. render: text => {
  266. switch (text) {
  267. case 0:
  268. return "国家";
  269. case 1:
  270. return "行业";
  271. }
  272. }
  273. }, {
  274. title: '参与方式',
  275. dataIndex: 'participateWay',
  276. key: 'participateWay',
  277. render: text => {
  278. switch (text) {
  279. case 0:
  280. return "主持";
  281. case 1:
  282. return "参与";
  283. }
  284. }
  285. }
  286. ],
  287. dataSource: []
  288. };
  289. },
  290. componentWillMount() {
  291. this.loadData();
  292. },
  293. tableRowClick(record, index) {
  294. this.state.RowData = record;
  295. this.setState({
  296. showDesc: true
  297. });
  298. },
  299. delectRow() {
  300. let deletedIds = [];
  301. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  302. let rowItem = this.state.selectedRows[idx];
  303. if (rowItem.id) {
  304. deletedIds.push(rowItem.id)
  305. }
  306. }
  307. this.setState({
  308. selectedRowKeys: [],
  309. loading: deletedIds.length > 0
  310. });
  311. $.ajax({
  312. method: "POST",
  313. dataType: "json",
  314. crossDomain: false,
  315. url: globalConfig.context + "/api/user/cognizance/deleteStandard",
  316. data: {
  317. ids: deletedIds
  318. }
  319. }).done(function (data) {
  320. if (!data.error.length) {
  321. message.success('删除成功!');
  322. this.setState({
  323. loading: false,
  324. });
  325. } else {
  326. message.warning(data.error[0].message);
  327. };
  328. this.loadData();
  329. }.bind(this));
  330. },
  331. closeDesc(e, s) {
  332. this.state.showDesc = e;
  333. if (s) {
  334. this.loadData();
  335. };
  336. },
  337. search() {
  338. this.loadData();
  339. },
  340. reset() {
  341. this.state.standardName = undefined;
  342. this.state.standardNumber = undefined;
  343. this.state.standardLevel = undefined;
  344. this.state.participateWay = undefined;
  345. this.loadData();
  346. },
  347. render() {
  348. const rowSelection = {
  349. selectedRowKeys: this.state.selectedRowKeys,
  350. onChange: (selectedRowKeys, selectedRows) => {
  351. this.setState({
  352. selectedRows: selectedRows,
  353. selectedRowKeys: selectedRowKeys
  354. });
  355. }
  356. }
  357. const hasSelected = this.state.selectedRowKeys.length > 0;
  358. return (
  359. <div className="user-content" >
  360. <div className="content-title">
  361. <span>标准制定情况汇总</span>
  362. </div>
  363. <div className="user-search">
  364. <Input placeholder="标准名称" value={this.state.standardName}
  365. onChange={(e) => { this.setState({ standardName: e.target.value }); }} />
  366. <Input placeholder="标准编号" value={this.state.standardNumber}
  367. onChange={(e) => { this.setState({ standardNumber: e.target.value }); }} />
  368. <Select placeholder="标准级别" style={{ width: 200 }}
  369. value={this.state.standardLevel}
  370. onChange={(e) => { this.setState({ standardLevel: e }) }}>
  371. <Select.Option value="0" >国家</Select.Option>
  372. <Select.Option value="1" >行业</Select.Option>
  373. </Select>
  374. <Select placeholder="参与方式" style={{ width: 200 }}
  375. value={this.state.participateWay}
  376. onChange={(e) => { this.setState({ participateWay: e }) }}>
  377. <Select.Option value="0" >主持</Select.Option>
  378. <Select.Option value="1" >参与</Select.Option>
  379. </Select>
  380. <Button type="primary" onClick={this.search}>搜索</Button>
  381. <Button onClick={this.reset}>重置</Button>
  382. <p>
  383. <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
  384. disabled={this.state.ButtonDisabled}
  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. <StandardDesc data={this.state.RowData} showDesc={this.state.showDesc} closeDesc={this.closeDesc} />
  401. </div >
  402. );
  403. }
  404. });
  405. export default Standard;