standard.jsx 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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. this.state.enclosureUrl = undefined;
  87. };
  88. this.state.visible = nextProps.showDesc;
  89. },
  90. render() {
  91. if (this.props.data) {
  92. return (
  93. <div className="admin-desc">
  94. <Modal maskClosable={false} title="企业参与国家标准或行业标准制定情况明细" visible={this.state.visible} onCancel={this.handleCancel}
  95. width='400px' footer={[
  96. <Button key="submit" type="primary" size="large" loading={this.state.loading} onClick={this.handleOk}>确认</Button>,
  97. <Button key="back" type="ghost" size="large" onClick={this.handleCancel}>取消</Button>
  98. ]}
  99. className="admin-desc-content">
  100. <div>
  101. <p>标准名称:</p>
  102. <Input defaultValue={this.props.data.standardName} value={this.state.standardName}
  103. onChange={(e) => { this.setState({ standardName: e.target.value }); }} />
  104. </div>
  105. <div>
  106. <p>标准编号:</p>
  107. <Input value={this.state.standardNumber}
  108. onChange={(e) => { this.setState({ standardNumber: e.target.value }); }} />
  109. </div>
  110. <div>
  111. <p>制定时间:</p>
  112. <Select
  113. placeholder="请选择年份"
  114. value={this.state.year}
  115. onChange={(e) => { this.setState({ year: e }); }}
  116. style={{ width: 80 }}>
  117. {this.state.yearOption}
  118. </Select>
  119. </div>
  120. <div>
  121. <p>标准级别:</p>
  122. <Radio.Group value={this.state.standardLevel} onChange={(e) => { this.setState({ standardLevel: e.target.value }) }}>
  123. <Radio value={0}>国家</Radio>
  124. <Radio value={1}>行业</Radio>
  125. </Radio.Group>
  126. </div>
  127. <div>
  128. <p>参与方式:</p>
  129. <Radio.Group value={this.state.participateWay} onChange={(e) => { this.setState({ participateWay: e.target.value }) }}>
  130. <Radio value={0}>主持</Radio>
  131. <Radio value={1}>参与</Radio>
  132. </Radio.Group>
  133. </div>
  134. <div className="hrSituation-roster">
  135. <Upload
  136. name="ratepay"
  137. action={globalConfig.context + "/api/admin/uploadStandard"}
  138. data={{ 'sign': 'standard', 'uid': this.props.uid }}
  139. beforeUpload={beforeUploadFile}
  140. fileList={this.state.fileList}
  141. onChange={(info) => {
  142. if (info.file.status !== 'uploading') {
  143. console.log(info.file, info.fileList);
  144. }
  145. if (info.file.status === 'done') {
  146. if (!info.file.response.error.length) {
  147. message.success(`${info.file.name} 文件上传成功!`);
  148. } else {
  149. message.warning(info.file.response.error[0].message);
  150. return;
  151. };
  152. this.state.enclosureUrl = info.file.response.data;
  153. } else if (info.file.status === 'error') {
  154. message.error(`${info.file.name} 文件上传失败。`);
  155. };
  156. this.setState({ fileList: info.fileList.slice(-1) });
  157. }}
  158. >
  159. <Button><Icon type="upload" /> 上传标准制定附件 </Button>
  160. </Upload>
  161. <p style={{ marginTop: '10px' }}>{this.state.enclosureUrl ?
  162. <span className="download-file">
  163. <a onClick={newDownloadFile.bind(null, this.props.data.id, 'standard', '/api/admin/downloadStandard')}>标准定制附件</a>
  164. <a onClick={() => {
  165. var newTab = window.open('about:blank'); getPreview(this.props.data.id, 'standard', 'standard', function (data) { newTab.location.href = data; });
  166. }}><Icon style={{ fontSize: '16px' }} type="eye-o" /></a>
  167. </span>
  168. : <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/admin/standard",
  189. data: {
  190. pageNo: pageNo || 1,
  191. pageSize: this.state.pagination.pageSize,
  192. uid: this.props.data.uid,
  193. standardName: this.state.standardName,
  194. standardNumber: this.state.standardNumber,
  195. standardLevel: this.state.standardLevel,
  196. participateWay: this.state.participateWay
  197. },
  198. success: function (data) {
  199. if (data.error.length || !data.data || !data.data.list) {
  200. message.warning(data.error[0].message);
  201. return;
  202. }
  203. for (let i = 0; i < data.data.list.length; i++) {
  204. let thisdata = data.data.list[i];
  205. this.state.data.push({
  206. key: i + 1,
  207. id: thisdata.id,
  208. uid: thisdata.uid,
  209. standardName: thisdata.standardName,
  210. standardNumber: thisdata.standardNumber,
  211. year: thisdata.year,
  212. enclosureUrl: thisdata.enclosureUrl,
  213. standardLevel: thisdata.standardLevel,
  214. participateWay: thisdata.participateWay,
  215. createTime: thisdata.createTime,
  216. createTimeFormattedDate: thisdata.createTimeFormattedDate
  217. });
  218. };
  219. this.state.pagination.current = data.data.pageNo;
  220. this.state.pagination.total = data.data.totalCount;
  221. this.setState({
  222. dataSource: this.state.data,
  223. pagination: this.state.pagination
  224. });
  225. }.bind(this),
  226. }).always(function () {
  227. this.setState({
  228. loading: false
  229. });
  230. }.bind(this));
  231. let _me = this;
  232. getProportion(this.props.data.uid, function (data) { _me.setState({ proportion: data }); });
  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/admin/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. <span className="proportion"> 是否已完成:</span>
  370. <Switch
  371. checked={this.state.proportion && this.state.proportion.standard == 1 ? true : false}
  372. checkedChildren={'已完成'}
  373. unCheckedChildren={'未完成'}
  374. onChange={(e) => {
  375. e ? this.state.proportion.standard = 1 : this.state.proportion.standard = 0;
  376. saveProportion(this.state.proportion.id, this.props.data.uid, 'standard', this.state.proportion.standard);
  377. this.setState({ proportion: this.state.proportion });
  378. }} />
  379. </div>
  380. <div className="user-search">
  381. <Input placeholder="标准名称" value={this.state.standardName}
  382. onChange={(e) => { this.setState({ standardName: e.target.value }); }} />
  383. <Input placeholder="标准编号" value={this.state.standardNumber}
  384. onChange={(e) => { this.setState({ standardNumber: e.target.value }); }} />
  385. <Select placeholder="标准级别" style={{ width: 200 }}
  386. value={this.state.standardLevel}
  387. onChange={(e) => { this.setState({ standardLevel: e }) }}>
  388. <Select.Option value="0" >国家</Select.Option>
  389. <Select.Option value="1" >行业</Select.Option>
  390. </Select>
  391. <Select placeholder="参与方式" style={{ width: 200 }}
  392. value={this.state.participateWay}
  393. onChange={(e) => { this.setState({ participateWay: e }) }}>
  394. <Select.Option value="0" >主持</Select.Option>
  395. <Select.Option value="1" >参与</Select.Option>
  396. </Select>
  397. <Button type="primary" onClick={this.search}>搜索</Button>
  398. <Button onClick={this.reset}>重置</Button>
  399. <p>
  400. <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
  401. onClick={this.tableRowClick}>添加<Icon type="plus" /></Button>
  402. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  403. disabled={!hasSelected}
  404. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  405. </p>
  406. </div>
  407. <div className="patent-table">
  408. <Spin spinning={this.state.loading}>
  409. <Table columns={this.state.columns}
  410. dataSource={this.state.dataSource}
  411. pagination={this.state.pagination}
  412. rowSelection={rowSelection}
  413. onRowClick={this.tableRowClick} />
  414. </Spin>
  415. </div>
  416. <StandardDesc uid={this.props.data.uid} data={this.state.RowData} showDesc={this.state.showDesc} closeDesc={this.closeDesc} />
  417. </div >
  418. );
  419. }
  420. });
  421. export default Standard;