standard.jsx 17 KB

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