standard.jsx 17 KB

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