standard.jsx 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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 } 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. let _me = this;
  220. getProportion(this.props.data.uid, function (data) { _me.setState({ proportion: data }); });
  221. },
  222. getInitialState() {
  223. return {
  224. selectedRowKeys: [],
  225. selectedRows: [],
  226. loading: false,
  227. pagination: {
  228. defaultCurrent: 1,
  229. defaultPageSize: 10,
  230. showQuickJumper: true,
  231. pageSize: 10,
  232. onChange: function (page) {
  233. this.loadData(page);
  234. }.bind(this),
  235. showTotal: function (total) {
  236. return '共' + total + '条数据';
  237. }
  238. },
  239. columns: [
  240. {
  241. title: '编号',
  242. dataIndex: 'key',
  243. key: 'key'
  244. }, {
  245. title: '标准名称',
  246. dataIndex: 'standardName',
  247. key: 'standardName'
  248. }, {
  249. title: '标准编号',
  250. dataIndex: 'standardNumber',
  251. key: 'standardNumber'
  252. }, {
  253. title: '制定时间',
  254. dataIndex: 'year',
  255. key: 'year'
  256. }, {
  257. title: '标准级别',
  258. dataIndex: 'standardLevel',
  259. key: 'standardLevel',
  260. render: text => {
  261. switch (text) {
  262. case 0:
  263. return "国家";
  264. case 1:
  265. return "行业";
  266. }
  267. }
  268. }, {
  269. title: '参与方式',
  270. dataIndex: 'participateWay',
  271. key: 'participateWay',
  272. render: text => {
  273. switch (text) {
  274. case 0:
  275. return "主持";
  276. case 1:
  277. return "参与";
  278. }
  279. }
  280. }
  281. ],
  282. dataSource: []
  283. };
  284. },
  285. componentWillMount() {
  286. this.loadData();
  287. },
  288. tableRowClick(record, index) {
  289. this.state.RowData = record;
  290. this.setState({
  291. showDesc: true
  292. });
  293. },
  294. delectRow() {
  295. let deletedIds = [];
  296. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  297. let rowItem = this.state.selectedRows[idx];
  298. if (rowItem.id) {
  299. deletedIds.push(rowItem.id)
  300. }
  301. }
  302. this.setState({
  303. selectedRowKeys: [],
  304. loading: deletedIds.length > 0
  305. });
  306. $.ajax({
  307. method: "POST",
  308. dataType: "json",
  309. crossDomain: false,
  310. url: globalConfig.context + "/api/admin/deleteStandard",
  311. data: {
  312. ids: deletedIds
  313. }
  314. }).done(function (data) {
  315. if (!data.error.length) {
  316. message.success('保存成功!');
  317. this.setState({
  318. loading: false,
  319. });
  320. } else {
  321. message.warning(data.error[0].message);
  322. };
  323. this.loadData();
  324. }.bind(this));
  325. },
  326. closeDesc(e, s) {
  327. this.state.showDesc = e;
  328. if (s) {
  329. this.loadData();
  330. };
  331. },
  332. search() {
  333. this.loadData();
  334. },
  335. reset() {
  336. this.state.standardName = undefined;
  337. this.state.standardNumber = undefined;
  338. this.state.standardLevel = undefined;
  339. this.state.participateWay = undefined;
  340. this.loadData();
  341. },
  342. render() {
  343. const rowSelection = {
  344. selectedRowKeys: this.state.selectedRowKeys,
  345. onChange: (selectedRowKeys, selectedRows) => {
  346. this.setState({
  347. selectedRows: selectedRows,
  348. selectedRowKeys: selectedRowKeys
  349. });
  350. }
  351. }
  352. const hasSelected = this.state.selectedRowKeys.length > 0;
  353. return (
  354. <div className="user-content" >
  355. <div className="content-title">
  356. <span>标准制定情况汇总</span>
  357. <span className="proportion"> 是否已完成:</span>
  358. <Switch
  359. checked={this.state.proportion && this.state.proportion.standard == 1 ? true : false}
  360. checkedChildren={'已完成'}
  361. unCheckedChildren={'未完成'}
  362. onChange={(e) => {
  363. e ? this.state.proportion.standard = 1 : this.state.proportion.standard = 0;
  364. saveProportion(this.state.proportion.id, this.props.data.uid, 'standard', this.state.proportion.standard);
  365. this.setState({ proportion: this.state.proportion });
  366. }} />
  367. </div>
  368. <div className="user-search">
  369. <Input placeholder="标准名称" value={this.state.standardName}
  370. onChange={(e) => { this.setState({ standardName: e.target.value }); }} />
  371. <Input placeholder="标准编号" value={this.state.standardNumber}
  372. onChange={(e) => { this.setState({ standardNumber: e.target.value }); }} />
  373. <Select placeholder="标准级别" style={{ width: 200 }}
  374. value={this.state.standardLevel}
  375. onChange={(e) => { this.setState({ standardLevel: e }) }}>
  376. <Select.Option value="0" >国家</Select.Option>
  377. <Select.Option value="1" >行业</Select.Option>
  378. </Select>
  379. <Select placeholder="参与方式" style={{ width: 200 }}
  380. value={this.state.participateWay}
  381. onChange={(e) => { this.setState({ participateWay: e }) }}>
  382. <Select.Option value="0" >主持</Select.Option>
  383. <Select.Option value="1" >参与</Select.Option>
  384. </Select>
  385. <Button type="primary" onClick={this.search}>搜索</Button>
  386. <Button onClick={this.reset}>重置</Button>
  387. <p>
  388. <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
  389. onClick={this.tableRowClick}>添加<Icon type="plus" /></Button>
  390. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  391. disabled={!hasSelected}
  392. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  393. </p>
  394. </div>
  395. <div className="patent-table">
  396. <Spin spinning={this.state.loading}>
  397. <Table columns={this.state.columns}
  398. dataSource={this.state.dataSource}
  399. pagination={this.state.pagination}
  400. rowSelection={rowSelection}
  401. onRowClick={this.tableRowClick} />
  402. </Spin>
  403. </div>
  404. <StandardDesc uid={this.props.data.uid} data={this.state.RowData} showDesc={this.state.showDesc} closeDesc={this.closeDesc} />
  405. </div >
  406. );
  407. }
  408. });
  409. export default Standard;