standard.jsx 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. import React from 'react';
  2. import { Switch, Icon, Button, Input, Spin, Table, message, Radio, Select, Modal, Upload } from 'antd';
  3. import { beforeUploadFile, newDownloadFile, getProportion, saveProportion, getPreview } 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. if (!this.state.standardName || !this.state.standardNumber || !this.state.year) {
  18. message.warning('请输入正确信息!');
  19. this.setState({
  20. loading: false
  21. });
  22. return;
  23. };
  24. $.ajax({
  25. method: "POST",
  26. dataType: "json",
  27. crossDomain: false,
  28. url: globalConfig.context + "/api/admin/developStandard",
  29. data: {
  30. id: this.props.data.id,
  31. uid: this.props.uid,
  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: this.state.enclosureUrl
  48. });
  49. } else if (data.error.length && data.error[0].message) {
  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: 80 }}>
  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/admin/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 ?
  169. <span className="download-file">
  170. <a onClick={newDownloadFile.bind(null, this.props.data.id, 'standard', '/api/admin/downloadStandard')}>标准定制附件</a>
  171. <a onClick={() => {
  172. var newTab = window.open('about:blank'); getPreview(this.props.data.id, 'standard', 'standard', function (data) { newTab.location.href = data; });
  173. }}><Icon style={{ fontSize: '16px' }} type="eye-o" /></a>
  174. </span>
  175. : <span><Icon type="exclamation-circle" style={{ color: '#ffbf00', marginRight: '6px' }} />未上传!</span>}</p>
  176. </div>
  177. </Modal>
  178. </div>
  179. );
  180. } else {
  181. return <div></div>
  182. }
  183. },
  184. });
  185. const Standard = React.createClass({
  186. loadData(pageNo) {
  187. this.state.data = [];
  188. this.setState({
  189. loading: true
  190. });
  191. $.ajax({
  192. method: "post",
  193. dataType: "json",
  194. crossDomain: false,
  195. url: globalConfig.context + "/api/admin/standard",
  196. data: {
  197. pageNo: pageNo || 1,
  198. pageSize: this.state.pagination.pageSize,
  199. uid: this.props.data.uid,
  200. standardName: this.state.standardName,
  201. standardNumber: this.state.standardNumber,
  202. standardLevel: this.state.standardLevel,
  203. participateWay: this.state.participateWay
  204. },
  205. success: function (data) {
  206. if (data.error.length || !data.data || !data.data.list) {
  207. message.warning(data.error[0].message);
  208. return;
  209. }
  210. for (let i = 0; i < data.data.list.length; i++) {
  211. let thisdata = data.data.list[i];
  212. this.state.data.push({
  213. key: i + 1,
  214. id: thisdata.id,
  215. uid: thisdata.uid,
  216. standardName: thisdata.standardName,
  217. standardNumber: thisdata.standardNumber,
  218. year: thisdata.year,
  219. enclosureUrl: thisdata.enclosureUrl,
  220. standardLevel: thisdata.standardLevel,
  221. participateWay: thisdata.participateWay,
  222. createTime: thisdata.createTime,
  223. createTimeFormattedDate: thisdata.createTimeFormattedDate
  224. });
  225. };
  226. this.state.pagination.current = data.data.pageNo;
  227. this.state.pagination.total = data.data.totalCount;
  228. this.setState({
  229. dataSource: this.state.data,
  230. pagination: this.state.pagination
  231. });
  232. }.bind(this),
  233. }).always(function () {
  234. this.setState({
  235. loading: false
  236. });
  237. }.bind(this));
  238. let _me = this;
  239. getProportion(this.props.data.uid, function (data) { _me.setState({ proportion: data }); });
  240. },
  241. getInitialState() {
  242. return {
  243. selectedRowKeys: [],
  244. selectedRows: [],
  245. loading: false,
  246. pagination: {
  247. defaultCurrent: 1,
  248. defaultPageSize: 10,
  249. showQuickJumper: true,
  250. pageSize: 10,
  251. onChange: function (page) {
  252. this.loadData(page);
  253. }.bind(this),
  254. showTotal: function (total) {
  255. return '共' + total + '条数据';
  256. }
  257. },
  258. columns: [
  259. {
  260. title: '编号',
  261. dataIndex: 'key',
  262. key: 'key'
  263. }, {
  264. title: '标准名称',
  265. dataIndex: 'standardName',
  266. key: 'standardName'
  267. }, {
  268. title: '标准编号',
  269. dataIndex: 'standardNumber',
  270. key: 'standardNumber'
  271. }, {
  272. title: '制定时间',
  273. dataIndex: 'year',
  274. key: 'year'
  275. }, {
  276. title: '标准级别',
  277. dataIndex: 'standardLevel',
  278. key: 'standardLevel',
  279. render: text => {
  280. switch (text) {
  281. case 0:
  282. return "国家";
  283. case 1:
  284. return "行业";
  285. }
  286. }
  287. }, {
  288. title: '参与方式',
  289. dataIndex: 'participateWay',
  290. key: 'participateWay',
  291. render: text => {
  292. switch (text) {
  293. case 0:
  294. return "主持";
  295. case 1:
  296. return "参与";
  297. }
  298. }
  299. }
  300. ],
  301. dataSource: []
  302. };
  303. },
  304. componentWillMount() {
  305. this.loadData();
  306. },
  307. tableRowClick(record, index) {
  308. this.state.RowData = record;
  309. this.setState({
  310. showDesc: true
  311. });
  312. },
  313. delectRow() {
  314. let deletedIds = [];
  315. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  316. let rowItem = this.state.selectedRows[idx];
  317. if (rowItem.id) {
  318. deletedIds.push(rowItem.id)
  319. }
  320. }
  321. this.setState({
  322. selectedRowKeys: [],
  323. loading: deletedIds.length > 0
  324. });
  325. $.ajax({
  326. method: "POST",
  327. dataType: "json",
  328. crossDomain: false,
  329. url: globalConfig.context + "/api/admin/deleteStandard",
  330. data: {
  331. ids: deletedIds
  332. }
  333. }).done(function (data) {
  334. if (!data.error.length) {
  335. message.success('删除成功!');
  336. this.setState({
  337. loading: false,
  338. });
  339. } else {
  340. message.warning(data.error[0].message);
  341. };
  342. this.loadData();
  343. }.bind(this));
  344. },
  345. closeDesc(e, s) {
  346. this.state.showDesc = e;
  347. if (s) {
  348. this.loadData();
  349. };
  350. },
  351. search() {
  352. this.loadData();
  353. },
  354. reset() {
  355. this.state.standardName = undefined;
  356. this.state.standardNumber = undefined;
  357. this.state.standardLevel = undefined;
  358. this.state.participateWay = undefined;
  359. this.loadData();
  360. },
  361. render() {
  362. const rowSelection = {
  363. selectedRowKeys: this.state.selectedRowKeys,
  364. onChange: (selectedRowKeys, selectedRows) => {
  365. this.setState({
  366. selectedRows: selectedRows,
  367. selectedRowKeys: selectedRowKeys
  368. });
  369. }
  370. }
  371. const hasSelected = this.state.selectedRowKeys.length > 0;
  372. return (
  373. <div className="user-content" >
  374. <div className="content-title">
  375. <span>标准制定情况汇总</span>
  376. <span className="proportion"> 是否已完成:</span>
  377. <Switch
  378. checked={this.state.proportion && this.state.proportion.standard == 1 ? true : false}
  379. checkedChildren={'已完成'}
  380. unCheckedChildren={'未完成'}
  381. onChange={(e) => {
  382. e ? this.state.proportion.standard = 1 : this.state.proportion.standard = 0;
  383. saveProportion(this.state.proportion.id, this.props.data.uid, 'standard', this.state.proportion.standard);
  384. this.setState({ proportion: this.state.proportion });
  385. }} />
  386. </div>
  387. <div className="user-search">
  388. <Input placeholder="标准名称" value={this.state.standardName}
  389. onChange={(e) => { this.setState({ standardName: e.target.value }); }} />
  390. <Input placeholder="标准编号" value={this.state.standardNumber}
  391. onChange={(e) => { this.setState({ standardNumber: e.target.value }); }} />
  392. <Select placeholder="标准级别" style={{ width: 200 }}
  393. value={this.state.standardLevel}
  394. onChange={(e) => { this.setState({ standardLevel: e }) }}>
  395. <Select.Option value="0" >国家</Select.Option>
  396. <Select.Option value="1" >行业</Select.Option>
  397. </Select>
  398. <Select placeholder="参与方式" style={{ width: 200 }}
  399. value={this.state.participateWay}
  400. onChange={(e) => { this.setState({ participateWay: e }) }}>
  401. <Select.Option value="0" >主持</Select.Option>
  402. <Select.Option value="1" >参与</Select.Option>
  403. </Select>
  404. <Button type="primary" onClick={this.search}>搜索</Button>
  405. <Button onClick={this.reset}>重置</Button>
  406. <p>
  407. <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
  408. onClick={this.tableRowClick}>添加<Icon type="plus" /></Button>
  409. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  410. disabled={!hasSelected}
  411. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  412. </p>
  413. </div>
  414. <div className="patent-table">
  415. <Spin spinning={this.state.loading}>
  416. <Table columns={this.state.columns}
  417. dataSource={this.state.dataSource}
  418. pagination={this.state.pagination}
  419. rowSelection={rowSelection}
  420. onRowClick={this.tableRowClick} />
  421. </Spin>
  422. </div>
  423. <StandardDesc uid={this.props.data.uid} data={this.state.RowData} showDesc={this.state.showDesc} closeDesc={this.closeDesc} />
  424. </div >
  425. );
  426. }
  427. });
  428. export default Standard;