websiteManage.jsx 9.6 KB

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