standard.jsx 17 KB

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