standard.jsx 18 KB

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