websiteManage.jsx 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. import React from 'react';
  2. import { Icon, Button, Select, Spin, Table, message } from 'antd';
  3. import { companySearch } from '../../../tools.js';
  4. import ajax from 'jquery/src/ajax/xhr.js';
  5. import $ from 'jquery/src/ajax';
  6. import './technology.less';
  7. import WebsiteAdd from './websiteAdd.jsx';
  8. import WebsiteChange from './websiteChange.jsx';
  9. const Cognizance = React.createClass({
  10. loadData(pageNo) {
  11. this.state.data = [];
  12. this.setState({
  13. loading: true
  14. });
  15. $.ajax({
  16. method: "post",
  17. dataType: "json",
  18. crossDomain: false,
  19. url: globalConfig.context + "/api/admin/techproject/listTechWebsite",
  20. data: {
  21. pageNo: pageNo || 1,
  22. pageSize: this.state.pagination.pageSize,
  23. unitName: this.state.unitName,
  24. },
  25. success: function (data) {
  26. if (!data.data || !data.data.list) {
  27. if (data.error && data.error.length) {
  28. message.warning(data.error[0].message);
  29. };
  30. return;
  31. };
  32. for (let i = 0; i < data.data.list.length; i++) {
  33. let thisdata = data.data.list[i];
  34. this.state.data.push({
  35. key: i,
  36. id: thisdata.id,
  37. uid: thisdata.uid,
  38. unitName: thisdata.unitName,
  39. department: thisdata.department,
  40. webSite: thisdata.website,
  41. userName: thisdata.accountNumber,
  42. password: thisdata.password
  43. });
  44. };
  45. this.state.pagination.current = data.data.pageNo;
  46. this.state.pagination.total = data.data.totalCount;
  47. this.setState({
  48. dataSource: this.state.data,
  49. pagination: this.state.pagination
  50. });
  51. }.bind(this),
  52. }).always(function () {
  53. this.setState({
  54. loading: false
  55. });
  56. }.bind(this));
  57. },
  58. getCompanyList() {
  59. this.setState({
  60. loading: true
  61. });
  62. $.ajax({
  63. method: "get",
  64. dataType: "json",
  65. crossDomain: false,
  66. url: globalConfig.context + "/api/admin/techproject/websiteUnit",
  67. success: function (data) {
  68. if (!data.data) {
  69. if (data.error && data.error.length) {
  70. message.warning(data.error[0].message);
  71. };
  72. return;
  73. };
  74. let _me = this;
  75. for (var item in data.data) {
  76. _me.state.companyOption.push(
  77. <Select.Option value={data.data[item]} key={data.data[item]}>{data.data[item]}</Select.Option>
  78. )
  79. _me.state.companyAddOption.push(
  80. <Select.Option value={item} key={item}>{data.data[item]}</Select.Option>
  81. )
  82. };
  83. }.bind(this),
  84. }).always(function () {
  85. this.setState({
  86. loading: false
  87. });
  88. }.bind(this));
  89. },
  90. getInitialState() {
  91. return {
  92. companyOption: [],
  93. companyAddOption: [],
  94. authorOption: [],
  95. selectedRows: [],
  96. selectedRowKeys: [],
  97. loading: false,
  98. showAdd: false,
  99. showDesc: false,
  100. pagination: {
  101. defaultCurrent: 1,
  102. defaultPageSize: 10,
  103. showQuickJumper: true,
  104. pageSize: 10,
  105. onChange: function (page) {
  106. this.loadData(page);
  107. }.bind(this),
  108. showTotal: function (total) {
  109. return '共' + total + '条数据';
  110. }
  111. },
  112. columns: [
  113. {
  114. title: '公司',
  115. dataIndex: 'unitName',
  116. key: 'unitName'
  117. }, {
  118. title: '科技单位',
  119. dataIndex: 'department',
  120. key: 'department'
  121. }, {
  122. title: '网址',
  123. dataIndex: 'webSite',
  124. key: 'webSite'
  125. }, {
  126. title: '用户名',
  127. dataIndex: 'userName',
  128. key: 'userName'
  129. }, {
  130. title: '密码',
  131. dataIndex: 'password',
  132. key: 'password'
  133. }
  134. ],
  135. dataSource: []
  136. };
  137. },
  138. componentWillMount() {
  139. this.loadData();
  140. this.getCompanyList();
  141. },
  142. tableRowClick(record, index) {
  143. this.state.RowData = record;
  144. this.setState({
  145. showDesc: true
  146. });
  147. },
  148. addClick() {
  149. this.setState({
  150. showAdd: true
  151. });
  152. },
  153. delectRow() {
  154. let deletedIds = [];
  155. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  156. let rowItem = this.state.selectedRows[idx];
  157. if (rowItem.id) {
  158. deletedIds.push(rowItem.id)
  159. }
  160. };
  161. this.setState({
  162. selectedRowKeys: [],
  163. loading: deletedIds.length > 0
  164. });
  165. $.ajax({
  166. method: "POST",
  167. dataType: "json",
  168. crossDomain: false,
  169. url: globalConfig.context + "/api/admin/techproject/deleteTechWebsite",
  170. data: {
  171. ids: deletedIds
  172. }
  173. }).done(function (data) {
  174. if (!data.error.length) {
  175. message.success('删除成功!');
  176. this.setState({
  177. loading: false,
  178. });
  179. } else {
  180. message.warning(data.error[0].message);
  181. };
  182. this.loadData();
  183. }.bind(this));
  184. },
  185. closeDesc(e) {
  186. this.state.showDesc = e;
  187. this.loadData();
  188. },
  189. closeAdd(e) {
  190. this.state.showAdd = e;
  191. this.loadData();
  192. },
  193. search() {
  194. this.loadData();
  195. },
  196. reset() {
  197. this.state.unitName = undefined;
  198. this.loadData();
  199. },
  200. render() {
  201. const rowSelection = {
  202. selectedRowKeys: this.state.selectedRowKeys,
  203. onChange: (selectedRowKeys, selectedRows) => {
  204. this.setState({
  205. selectedRows: selectedRows,
  206. selectedRowKeys: selectedRowKeys
  207. });
  208. }
  209. };
  210. const hasSelected = this.state.selectedRowKeys.length > 0;
  211. return (
  212. <div className="foster-content" >
  213. <div className="content-title">
  214. <span>科技单位网址管理</span>
  215. <div className="foster-query" style={{ float: "right" }}>
  216. <div>
  217. <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
  218. onClick={this.addClick}>创建新单位网址<Icon type="plus" /></Button>
  219. </div>
  220. </div>
  221. </div>
  222. <div className="foster-query">
  223. <Select placeholder="选择公司"
  224. style={{ width: 200 }}
  225. value={this.state.unitName}
  226. showSearch
  227. filterOption={companySearch}
  228. onChange={(e) => { this.setState({ unitName: e }) }}>
  229. {this.state.companyOption}
  230. </Select>
  231. <Button type="primary" onClick={this.search}>搜索</Button>
  232. <Button onClick={this.reset}>重置</Button>
  233. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  234. disabled={!hasSelected}
  235. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  236. </div>
  237. <div className="patent-table">
  238. <Spin spinning={this.state.loading}>
  239. <Table size="middle" columns={this.state.columns}
  240. rowSelection={rowSelection}
  241. dataSource={this.state.dataSource}
  242. pagination={this.state.pagination}
  243. style={{
  244. cursor: 'pointer',
  245. }}
  246. onRowClick={this.tableRowClick} />
  247. </Spin>
  248. </div>
  249. <WebsiteChange
  250. data={this.state.RowData}
  251. companyAddOption={this.state.companyAddOption}
  252. showDesc={this.state.showDesc}
  253. closeDesc={this.closeDesc} />
  254. <WebsiteAdd
  255. companyAddOption={this.state.companyAddOption}
  256. showAdd={this.state.showAdd}
  257. closeAdd={this.closeAdd} />
  258. </div >
  259. );
  260. }
  261. });
  262. export default Cognizance;