websiteManage.jsx 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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/techproject/websiteUnit",
  68. success: function (data) {
  69. if (!data.data) {
  70. if (data.error && data.error.length) {
  71. message.warning(data.error[0].message);
  72. };
  73. return;
  74. };
  75. let _me = this;
  76. for (var item in data.data) {
  77. _me.state.companyOption.push(
  78. <Select.Option value={data.data[item]} key={data.data[item]}>{data.data[item]}</Select.Option>
  79. )
  80. _me.state.companyAddOption.push(
  81. <Select.Option value={item} key={item}>{data.data[item]}</Select.Option>
  82. )
  83. };
  84. }.bind(this),
  85. }).always(function () {
  86. this.setState({
  87. loading: false
  88. });
  89. }.bind(this));
  90. },
  91. getInitialState() {
  92. return {
  93. provinceOption: [],
  94. companyOption: [],
  95. companyAddOption: [],
  96. authorOption: [],
  97. selectedRows: [],
  98. selectedRowKeys: [],
  99. loading: false,
  100. showAdd: false,
  101. showDesc: false,
  102. pagination: {
  103. defaultCurrent: 1,
  104. defaultPageSize: 10,
  105. showQuickJumper: true,
  106. pageSize: 10,
  107. onChange: function (page) {
  108. this.loadData(page);
  109. }.bind(this),
  110. showTotal: function (total) {
  111. return '共' + total + '条数据';
  112. }
  113. },
  114. columns: [
  115. {
  116. title: '公司',
  117. dataIndex: 'unitName',
  118. key: 'unitName'
  119. }, {
  120. title: '科技单位',
  121. dataIndex: 'department',
  122. key: 'department'
  123. }, {
  124. title: '网址',
  125. dataIndex: 'webSite',
  126. key: 'webSite'
  127. }, {
  128. title: '用户名',
  129. dataIndex: 'userName',
  130. key: 'userName'
  131. }, {
  132. title: '密码',
  133. dataIndex: 'password',
  134. key: 'password'
  135. }
  136. ],
  137. dataSource: []
  138. };
  139. },
  140. componentWillMount() {
  141. this.loadData();
  142. this.getCompanyList();
  143. },
  144. tableRowClick(record, index) {
  145. this.state.RowData = record;
  146. this.setState({
  147. showDesc: true
  148. });
  149. },
  150. addClick() {
  151. this.setState({
  152. showAdd: true
  153. });
  154. },
  155. delectRow() {
  156. let deletedIds = [];
  157. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  158. let rowItem = this.state.selectedRows[idx];
  159. if (rowItem.id) {
  160. deletedIds.push(rowItem.id)
  161. }
  162. };
  163. this.setState({
  164. selectedRowKeys: [],
  165. loading: deletedIds.length > 0
  166. });
  167. $.ajax({
  168. method: "POST",
  169. dataType: "json",
  170. crossDomain: false,
  171. url: globalConfig.context + "/api/admin/techproject/deleteTechWebsite",
  172. data: {
  173. ids: deletedIds
  174. }
  175. }).done(function (data) {
  176. if (!data.error.length) {
  177. message.success('保存成功!');
  178. this.setState({
  179. loading: false,
  180. });
  181. } else {
  182. message.warning(data.error[0].message);
  183. };
  184. this.loadData();
  185. }.bind(this));
  186. },
  187. closeDesc(e) {
  188. this.state.showDesc = e;
  189. this.loadData();
  190. },
  191. closeAdd(e) {
  192. this.state.showAdd = e;
  193. this.loadData();
  194. },
  195. search() {
  196. this.loadData();
  197. },
  198. reset() {
  199. this.state.unitName = undefined;
  200. this.loadData();
  201. },
  202. render() {
  203. const rowSelection = {
  204. selectedRowKeys: this.state.selectedRowKeys,
  205. onChange: (selectedRowKeys, selectedRows) => {
  206. this.setState({
  207. selectedRows: selectedRows,
  208. selectedRowKeys: selectedRowKeys
  209. });
  210. }
  211. };
  212. const hasSelected = this.state.selectedRowKeys.length > 0;
  213. return (
  214. <div className="foster-content" >
  215. <div className="content-title">
  216. <span>科技单位网址管理</span>
  217. <div className="foster-query" style={{ float: "right" }}>
  218. <div>
  219. <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
  220. onClick={this.addClick}>创建新单位网址<Icon type="plus" /></Button>
  221. </div>
  222. </div>
  223. </div>
  224. <div className="foster-query">
  225. <Select placeholder="选择公司"
  226. style={{ width: 200 }}
  227. value={this.state.unitName}
  228. showSearch
  229. filterOption={companySearch}
  230. onChange={(e) => { this.setState({ unitName: e }) }}>
  231. {this.state.companyOption}
  232. </Select>
  233. <Button type="primary" onClick={this.search}>搜索</Button>
  234. <Button onClick={this.reset}>重置</Button>
  235. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  236. disabled={!hasSelected}
  237. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  238. </div>
  239. <div className="patent-table">
  240. <Spin spinning={this.state.loading}>
  241. <Table columns={this.state.columns}
  242. rowSelection={rowSelection}
  243. dataSource={this.state.dataSource}
  244. pagination={this.state.pagination}
  245. onRowClick={this.tableRowClick} />
  246. </Spin>
  247. </div>
  248. <WebsiteChange
  249. data={this.state.RowData}
  250. companyAddOption={this.state.companyAddOption}
  251. showDesc={this.state.showDesc}
  252. closeDesc={this.closeDesc} />
  253. <WebsiteAdd
  254. companyAddOption={this.state.companyAddOption}
  255. showAdd={this.state.showAdd}
  256. closeAdd={this.closeAdd} />
  257. </div >
  258. );
  259. }
  260. });
  261. export default Cognizance;