websiteManage.jsx 8.9 KB

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