collection.jsx 8.7 KB

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