collection.jsx 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. import React, { Component } from 'react';
  2. import { Button,Radio ,message,Row,Col, Spin,Pagination} from 'antd';
  3. import axios from 'axios';
  4. import './collection.less';
  5. import SpinContainer from "../../SpinContainer";
  6. class Collection extends Component {
  7. constructor(props) {
  8. super(props);
  9. this.state = {
  10. loading:false,
  11. current:1,
  12. nub:'1'
  13. };
  14. }
  15. //服务
  16. loadDataService(page){
  17. this.setState({
  18. loading:true,
  19. })
  20. let url = globalConfig.context + '/api/user/portal/listProjectIInterestedIn'
  21. axios.get(url,{
  22. params:{
  23. pageNo:page||1,
  24. pageSize:(this.props.nub)?4:8
  25. }
  26. })
  27. .then(data=>{
  28. let theData=data.data.data,
  29. theArr = [],
  30. times = new Date().getTime(),
  31. days = parseInt(times / (1000 * 60 * 60 * 24));
  32. if (!data.data || !data.data.data.list) {
  33. if (data.data.error && data.data.error.length) {
  34. message.warning(data.data.error[0].message);
  35. };
  36. } else {
  37. for (let i = 0; i < theData.list.length; i++) {
  38. let thisdata = theData.list[i],
  39. create = parseInt(thisdata.createTime / (1000 * 60 * 60 * 24));
  40. let newState = (days-create)<7?true:false;
  41. var introd=thisdata.introduce?(thisdata.introduce).replace(/<\/?.+?>/g,""):thisdata.introduce;
  42. theArr.push({
  43. key: i,
  44. id: thisdata.id,
  45. newState:newState,
  46. name:thisdata.name,
  47. introduce:introd&&introd.length>40?introd.substr(0,40)+'...':introd,
  48. img: thisdata.maxImgUrl, //编号
  49. });
  50. };
  51. };
  52. this.setState({
  53. loading:false,
  54. dataList:theArr,
  55. total:data.data.data.totalCount
  56. })
  57. })
  58. }
  59. //成果
  60. loadDataAchievement(page){
  61. this.setState({
  62. loading:true,
  63. })
  64. let url = globalConfig.context + '/api/user/portal/listAchievementIInterestedIn'
  65. axios.get(url,{
  66. params:{
  67. pageNo:page||1,
  68. pageSize:(this.props.nub)?4:8
  69. }
  70. })
  71. .then(data=>{
  72. let theData=data.data.data,
  73. theArr = [],
  74. times = new Date().getTime(),
  75. days = parseInt(times / (1000 * 60 * 60 * 24));
  76. if (!data.data || !data.data.data.list) {
  77. if (data.data.error && data.data.error.length) {
  78. message.warning(data.data.error[0].message);
  79. };
  80. } else {
  81. for (let i = 0; i < theData.list.length; i++) {
  82. let thisdata = theData.list[i],
  83. create = parseInt(thisdata.releaseDate / (1000 * 60 * 60 * 24));
  84. let newState = (days-create)<7?true:false;
  85. theArr.push({
  86. key: i,
  87. id: thisdata.id,
  88. newState:newState,
  89. name:thisdata.name,
  90. introduce:thisdata.introduction&&thisdata.introduction.length>40?thisdata.introduction.substr(0,40)+'...':thisdata.introduction,
  91. img: thisdata.firstPicture, //编号
  92. });
  93. };
  94. };
  95. this.setState({
  96. loading:false,
  97. dataList:theArr,
  98. total:data.data.data.totalCount
  99. })
  100. })
  101. }
  102. //需求
  103. loadDataDemand(page){
  104. this.setState({
  105. loading:true,
  106. })
  107. let url = globalConfig.context + '/api/user/portal/listDemandIInterestedIn'
  108. axios.get(url,{
  109. params:{
  110. pageNo:page||1,
  111. pageSize:(this.props.nub)?4:8
  112. }
  113. })
  114. .then(data=>{
  115. let theData=data.data.data,
  116. theArr = [],
  117. times = new Date().getTime(),
  118. days = parseInt(times / (1000 * 60 * 60 * 24));
  119. if (!data.data || !data.data.data.list) {
  120. if (data.data.error && data.data.error.length) {
  121. message.warning(data.data.error[0].message);
  122. };
  123. } else {
  124. for (let i = 0; i < theData.list.length; i++) {
  125. let thisdata = theData.list[i],
  126. create = parseInt(thisdata.releaseDate / (1000 * 60 * 60 * 24));
  127. let newState = (days-create)<7?true:false;
  128. theArr.push({
  129. key: i,
  130. id: thisdata.id,
  131. newState:newState,
  132. name:thisdata.name,
  133. introduce:thisdata.problemDes&&thisdata.problemDes.length>40?thisdata.problemDes.substr(0,40)+'...':thisdata.problemDes,
  134. img: thisdata.firstPic, //编号
  135. });
  136. };
  137. };
  138. this.setState({
  139. loading:false,
  140. dataList:theArr,
  141. total:data.data.data.totalCount
  142. })
  143. })
  144. }
  145. componentWillMount(){
  146. this.loadDataService(1)
  147. }
  148. tabFun(e){
  149. this.setState({ nub: e.target.value,current:1})
  150. switch(e.target.value){
  151. case '1':
  152. this.loadDataService(1)
  153. break;
  154. case '2':
  155. this.loadDataDemand(1)
  156. break;
  157. case '3':
  158. this.loadDataAchievement(1)
  159. break;
  160. }
  161. }
  162. //分页
  163. onShowSizeChange(current, pageSize){
  164. this.setState({
  165. current:current,
  166. pageSize:pageSize
  167. })
  168. switch(this.state.nub){
  169. case '1':
  170. this.loadDataService(current)
  171. break;
  172. case '2':
  173. this.loadDataDemand(current)
  174. break;
  175. case '3':
  176. this.loadDataAchievement(current)
  177. break;
  178. }
  179. }
  180. jump(item){
  181. let url='';
  182. switch(this.state.nub){
  183. case '1':
  184. url = globalConfig.context+`/portal/service/serviceDetail?id=${item.id}`;
  185. break;
  186. case '2':
  187. url=globalConfig.context+`/portal/technologyTrading/demandDetail?id=${item.id}&type=0`;
  188. break;
  189. case '3':
  190. url=globalConfig.context+`/portal/technologyTrading/achievementDetail?id=${item.id}&type=1`;
  191. break;
  192. }
  193. window.open(url);
  194. }
  195. render() {
  196. const dataList =this.state.dataList || [];
  197. return <div className="user-content">
  198. <div className="title" >
  199. 我的收藏
  200. </div>
  201. <div>
  202. <Radio.Group className="btnGroup" value={this.state.nub} onChange={this.tabFun.bind(this)}>
  203. <Radio.Button value="1">运用</Radio.Button>
  204. <Radio.Button value="2">需求</Radio.Button>
  205. <Radio.Button value="3">成果</Radio.Button>
  206. </Radio.Group>
  207. </div>
  208. <div className="imgList">
  209. <SpinContainer spinning={this.state.loading}>
  210. {dataList.length?<Row>
  211. {dataList.map((item,index)=>{
  212. return<Col span={5} key={index} onClick={(e)=>{this.jump(item)}}>
  213. <div className="img">
  214. <div className="imgHeader">
  215. <div className="imgBj">
  216. {item.img?<img src={globalConfig.avatarHost+'/upload'+item.img} alt=""/>:''}
  217. </div>
  218. {item.newState&&<span className="new"></span>}
  219. <div className="divP"><p>{item.introduce?item.introduce:'暂无'}</p></div>
  220. </div>
  221. <p className="txt">{item.name}</p>
  222. </div>
  223. </Col>
  224. })
  225. }
  226. </Row>:
  227. <Row style={{color:'#333'}}>暂无数据</Row>}
  228. </SpinContainer>
  229. {this.state.total?<Pagination className="page" pageSize={this.props.nub?4:8} current={this.state.current} total={this.state.total} onChange={(e,pageSize)=>{this.onShowSizeChange(e,pageSize)}}/>:''}
  230. </div>
  231. </div>
  232. }
  233. }
  234. export default Collection;