websiteManage.jsx 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. // this.getContactsList();
  146. },
  147. tableRowClick(record, index) {
  148. this.state.RowData = record;
  149. this.setState({
  150. showDesc: true
  151. });
  152. },
  153. addClick() {
  154. this.setState({
  155. showAdd: true
  156. });
  157. },
  158. delectRow() {
  159. let deletedIds = [];
  160. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  161. let rowItem = this.state.selectedRows[idx];
  162. if (rowItem.id) {
  163. deletedIds.push(rowItem.id)
  164. }
  165. }
  166. this.setState({
  167. selectedRowKeys: [],
  168. loading: deletedIds.length > 0
  169. });
  170. $.ajax({
  171. method: "POST",
  172. dataType: "json",
  173. crossDomain: false,
  174. url: globalConfig.context + "/api/admintechproject/deleteTechWebsite",
  175. data: {
  176. ids: deletedIds
  177. }
  178. }).done(function (data) {
  179. if (!data.error.length) {
  180. message.success('保存成功!');
  181. this.setState({
  182. loading: false,
  183. });
  184. } else {
  185. message.warning(data.error[0].message);
  186. };
  187. this.loadData();
  188. }.bind(this));
  189. },
  190. closeDesc(e) {
  191. this.state.showDesc = e;
  192. this.loadData();
  193. },
  194. closeAdd(e) {
  195. this.state.showAdd = e;
  196. this.loadData();
  197. },
  198. search() {
  199. this.loadData();
  200. },
  201. reset() {
  202. this.state.province = undefined;
  203. this.state.unitName = undefined;
  204. this.loadData();
  205. },
  206. render() {
  207. const rowSelection = {
  208. selectedRowKeys: this.state.selectedRowKeys,
  209. onChange: (selectedRowKeys, selectedRows) => {
  210. this.setState({
  211. selectedRows: selectedRows,
  212. selectedRowKeys: selectedRowKeys
  213. });
  214. }
  215. };
  216. const hasSelected = this.state.selectedRowKeys.length > 0;
  217. return (
  218. <div className="foster-content" >
  219. <div className="content-title">
  220. <span>科技单位网址管理</span>
  221. <div className="foster-query" style={{ float: "right" }}>
  222. <div>
  223. <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
  224. onClick={this.addClick}>创建新单位网址<Icon type="plus" /></Button>
  225. </div>
  226. </div>
  227. </div>
  228. <div className="foster-query">
  229. <Select placeholder="选择省份"
  230. style={{ width: 200 }}
  231. value={this.state.province}
  232. showSearch
  233. filterOption={companySearch}
  234. onChange={(e) => { this.setState({ province: e }) }}>
  235. {this.state.provinceOption}
  236. </Select>
  237. <Select placeholder="选择公司"
  238. style={{ width: 200 }}
  239. value={this.state.unitName}
  240. showSearch
  241. filterOption={companySearch}
  242. onChange={(e) => { this.setState({ unitName: e }) }}>
  243. {this.state.companyOption}
  244. </Select>
  245. <Button type="primary" onClick={this.search}>搜索</Button>
  246. <Button onClick={this.reset}>重置</Button>
  247. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  248. disabled={!hasSelected}
  249. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  250. </div>
  251. <div className="patent-table">
  252. <Spin spinning={this.state.loading}>
  253. <Table columns={this.state.columns}
  254. rowSelection={rowSelection}
  255. dataSource={this.state.dataSource}
  256. pagination={this.state.pagination}
  257. onRowClick={this.tableRowClick} />
  258. </Spin>
  259. </div>
  260. <WebsiteChange
  261. data={this.state.RowData}
  262. companyAddOption={this.state.companyAddOption}
  263. showDesc={this.state.showDesc}
  264. closeDesc={this.closeDesc} />
  265. <WebsiteAdd
  266. companyAddOption={this.state.companyAddOption}
  267. showAdd={this.state.showAdd}
  268. closeAdd={this.closeAdd} />
  269. </div >
  270. );
  271. }
  272. });
  273. export default Cognizance;