standard.jsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. import React from 'react';
  2. import { Icon, Button, Input, Spin, Table, message, Radio, Select, Modal } from 'antd';
  3. import './standard.less';
  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 + "/techservice/cognizance/developStandard",
  22. data: {
  23. id: this.props.data.id,
  24. standardName: this.state.standardName,
  25. standardNumber: this.state.standardNumber,
  26. standardLevel: this.state.standardLevel,
  27. participateWay: this.state.participateWay
  28. },
  29. success: function (data) {
  30. if (data.data) {
  31. this.setState({
  32. id: data.data.id,
  33. standardName: data.data.standardName,
  34. standardNumber: data.data.standardNumber,
  35. standardLevel: data.data.standardLevel,
  36. participateWay: data.data.participateWay
  37. });
  38. } else if (data.error.length && data.error[0].message) {
  39. message.warning(data.error[0].message);
  40. }
  41. }.bind(this),
  42. }).done(function (data) {
  43. if (!data.error.length) {
  44. message.success('保存成功!');
  45. this.setState({
  46. loading: false,
  47. visible: false
  48. });
  49. } else {
  50. message.warning(data.error[0].message);
  51. };
  52. this.props.closeDesc(false);
  53. }.bind(this));
  54. },
  55. handleCancel(e) {
  56. this.setState({
  57. visible: false,
  58. });
  59. this.props.closeDesc(false);
  60. },
  61. componentWillReceiveProps(nextProps) {
  62. this.state.visible = nextProps.showDesc;
  63. if (nextProps.data) {
  64. this.state.standardName = nextProps.data.standardName;
  65. this.state.standardNumber = nextProps.data.standardNumber;
  66. this.state.standardLevel = nextProps.data.standardLevel;
  67. this.state.participateWay = nextProps.data.participateWay;
  68. };
  69. },
  70. render() {
  71. if (this.props.data) {
  72. return (
  73. <div className="admin-desc">
  74. <Modal title="企业参与国家标准或行业标准制定情况明细" visible={this.state.visible} onCancel={this.handleCancel}
  75. width='400px' footer={[
  76. <Button key="submit" type="primary" size="large" loading={this.state.loading} onClick={this.handleOk}>确认</Button>,
  77. <Button key="back" type="ghost" size="large" onClick={this.handleCancel}>取消</Button>
  78. ]}
  79. className="admin-desc-content">
  80. <div>
  81. <p>标准名称:</p>
  82. <Input defaultValue={this.props.data.standardName} value={this.state.standardName}
  83. onChange={(e) => { this.setState({ standardName: e.target.value }); }} />
  84. </div>
  85. <div>
  86. <p>标准编号:</p>
  87. <Input value={this.state.standardNumber}
  88. onChange={(e) => { this.setState({ standardNumber: e.target.value }); }} />
  89. </div>
  90. <div>
  91. <p>标准级别:</p>
  92. <Radio.Group value={this.state.standardLevel} onChange={(e) => { this.setState({ standardLevel: e.target.value }) }}>
  93. <Radio value="0">国家</Radio>
  94. <Radio value="1">行业</Radio>
  95. </Radio.Group>
  96. </div>
  97. <div>
  98. <p>参与方式:</p>
  99. <Radio.Group value={this.state.participateWay} onChange={(e) => { this.setState({ participateWay: e.target.value }) }}>
  100. <Radio value="0">主持</Radio>
  101. <Radio value="1">参与</Radio>
  102. </Radio.Group>
  103. </div>
  104. </Modal>
  105. </div>
  106. );
  107. } else {
  108. return <div></div>
  109. }
  110. },
  111. });
  112. const Standard = React.createClass({
  113. loadData(pageNo) {
  114. this.state.data = [];
  115. this.setState({
  116. loading: true
  117. });
  118. $.ajax({
  119. method: "post",
  120. dataType: "json",
  121. crossDomain: false,
  122. url: globalConfig.context + "/techservice/cognizance/standard",
  123. data: {
  124. pageNo: pageNo || 1,
  125. pageSize: this.state.pagination.pageSize,
  126. standardName: this.state.standardName,
  127. standardNumber: this.state.standardNumber,
  128. standardLevel: this.state.standardLevel,
  129. participateWay: this.state.participateWay
  130. },
  131. success: function (data) {
  132. if (data.error.length || !data.data || !data.data.list) {
  133. message.warning(data.error[0].message);
  134. return;
  135. }
  136. for (let i = 0; i < data.data.list.length; i++) {
  137. let thisdata = data.data.list[i];
  138. this.state.data.push({
  139. key: i + 1,
  140. id: thisdata.id,
  141. uid: thisdata.uid,
  142. standardName: thisdata.standardName,
  143. standardNumber: thisdata.standardNumber,
  144. standardLevel: String(thisdata.standardLevel),
  145. participateWay: String(thisdata.participateWay),
  146. createTime: thisdata.createTime,
  147. createTimeFormattedDate: thisdata.createTimeFormattedDate
  148. });
  149. };
  150. this.state.pagination.current = data.data.pageNo;
  151. this.state.pagination.total = data.data.totalCount;
  152. this.setState({
  153. dataSource: this.state.data,
  154. pagination: this.state.pagination
  155. });
  156. }.bind(this),
  157. }).always(function () {
  158. this.setState({
  159. loading: false
  160. });
  161. }.bind(this));
  162. },
  163. getInitialState() {
  164. return {
  165. selectedRowKeys: [],
  166. selectedRows: [],
  167. loading: false,
  168. pagination: {
  169. defaultCurrent: 1,
  170. defaultPageSize: 10,
  171. showQuickJumper: true,
  172. pageSize: 10,
  173. onChange: function (page) {
  174. this.loadData(page);
  175. }.bind(this),
  176. showTotal: function (total) {
  177. return '共' + total + '条数据';
  178. }
  179. },
  180. columns: [
  181. {
  182. title: '编号',
  183. dataIndex: 'key',
  184. key: 'key'
  185. }, {
  186. title: '标准名称',
  187. dataIndex: 'standardName',
  188. key: 'standardName'
  189. }, {
  190. title: '标准编号',
  191. dataIndex: 'standardNumber',
  192. key: 'standardNumber'
  193. }, {
  194. title: '标准级别',
  195. dataIndex: 'standardLevel',
  196. key: 'standardLevel',
  197. render: text => {
  198. switch (String(text)) {
  199. case "0":
  200. return "国家";
  201. case "1":
  202. return "行业";
  203. }
  204. }
  205. }, {
  206. title: '参与方式',
  207. dataIndex: 'participateWay',
  208. key: 'participateWay',
  209. render: text => {
  210. switch (String(text)) {
  211. case "0":
  212. return "主持";
  213. case "1":
  214. return "参与";
  215. }
  216. }
  217. }
  218. ],
  219. dataSource: []
  220. };
  221. },
  222. componentWillMount() {
  223. this.loadData();
  224. },
  225. tableRowClick(record, index) {
  226. this.state.RowData = record;
  227. this.setState({
  228. showDesc: true
  229. });
  230. },
  231. delectRow() {
  232. let deletedIds = [];
  233. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  234. let rowItem = this.state.selectedRows[idx];
  235. if (rowItem.id) {
  236. deletedIds.push(rowItem.id)
  237. }
  238. }
  239. this.setState({
  240. selectedRowKeys: [],
  241. loading: deletedIds.length > 0
  242. });
  243. $.ajax({
  244. method: "POST",
  245. dataType: "json",
  246. crossDomain: false,
  247. url: globalConfig.context + "/techservice/cognizance/deleteStandard",
  248. data: {
  249. ids: deletedIds
  250. }
  251. }).done(function (data) {
  252. if (!data.error.length) {
  253. message.success('保存成功!');
  254. this.setState({
  255. loading: false,
  256. });
  257. } else {
  258. message.warning(data.error[0].message);
  259. };
  260. this.loadData();
  261. }.bind(this));
  262. },
  263. closeDesc(e) {
  264. this.state.showDesc = e;
  265. this.loadData();
  266. },
  267. search() {
  268. this.loadData();
  269. },
  270. reset() {
  271. this.state.standardName = undefined;
  272. this.state.standardNumber = undefined;
  273. this.state.standardLevel = undefined;
  274. this.state.participateWay = undefined;
  275. this.loadData();
  276. },
  277. render() {
  278. const rowSelection = {
  279. selectedRowKeys: this.state.selectedRowKeys,
  280. onChange: (selectedRowKeys, selectedRows) => {
  281. this.setState({
  282. selectedRows: selectedRows,
  283. selectedRowKeys: selectedRowKeys
  284. });
  285. }
  286. }
  287. const hasSelected = this.state.selectedRowKeys.length > 0;
  288. return (
  289. <div className="user-content" >
  290. <div className="content-title">
  291. <span>标准制定情况汇总</span>
  292. </div>
  293. <div className="user-search">
  294. <Input placeholder="标准名称" value={this.state.standardName}
  295. onChange={(e) => { this.setState({ standardName: e.target.value }); }} />
  296. <Input placeholder="标准编号" value={this.state.standardNumber}
  297. onChange={(e) => { this.setState({ standardNumber: e.target.value }); }} />
  298. <Select placeholder="标准级别" style={{ width: 200 }}
  299. value={this.state.standardLevel}
  300. onChange={(e) => { this.setState({ standardLevel: e }) }}>
  301. <Select.Option value="0" >国家</Select.Option>
  302. <Select.Option value="1" >行业</Select.Option>
  303. </Select>
  304. <Select placeholder="参与方式" style={{ width: 200 }}
  305. value={this.state.participateWay}
  306. onChange={(e) => { this.setState({ participateWay: e }) }}>
  307. <Select.Option value="0" >主持</Select.Option>
  308. <Select.Option value="1" >参与</Select.Option>
  309. </Select>
  310. <Button type="primary" onClick={this.search}>搜索</Button>
  311. <Button onClick={this.reset}>重置</Button>
  312. <p>
  313. <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
  314. onClick={this.tableRowClick}>添加<Icon type="plus" /></Button>
  315. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  316. disabled={!hasSelected}
  317. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  318. </p>
  319. </div>
  320. <div className="patent-table">
  321. <Spin spinning={this.state.loading}>
  322. <Table columns={this.state.columns}
  323. dataSource={this.state.dataSource}
  324. pagination={this.state.pagination}
  325. rowSelection={rowSelection}
  326. onRowClick={this.tableRowClick} />
  327. </Spin>
  328. </div>
  329. <StandardDesc data={this.state.RowData} showDesc={this.state.showDesc} closeDesc={this.closeDesc} />
  330. </div >
  331. );
  332. }
  333. });
  334. export default Standard;