standard.jsx 18 KB

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