collection.jsx 8.6 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. 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: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. theArr.push({
  41. key: i,
  42. id: thisdata.id,
  43. newState:newState,
  44. name:thisdata.name,
  45. introduce:thisdata.introduce&&thisdata.introduce.length>40?thisdata.introduce.substr(0,40)+'...':'',
  46. img: thisdata.maxImgUrl, //编号
  47. });
  48. };
  49. };
  50. this.setState({
  51. loading:false,
  52. dataList:theArr,
  53. total:data.data.data.totalCount
  54. })
  55. })
  56. }
  57. //成果
  58. loadDataAchievement(page){
  59. this.setState({
  60. loading:true,
  61. })
  62. let url = globalConfig.context + '/api/user/portal/listAchievementIInterestedIn'
  63. axios.get(url,{
  64. params:{
  65. pageNo:page||1,
  66. pageSize:8
  67. }
  68. })
  69. .then(data=>{
  70. let theData=data.data.data,
  71. theArr = [],
  72. times = new Date().getTime(),
  73. days = parseInt(times / (1000 * 60 * 60 * 24));
  74. if (!data.data || !data.data.data.list) {
  75. if (data.data.error && data.data.error.length) {
  76. message.warning(data.data.error[0].message);
  77. };
  78. } else {
  79. for (let i = 0; i < theData.list.length; i++) {
  80. let thisdata = theData.list[i],
  81. create = parseInt(thisdata.releaseDate / (1000 * 60 * 60 * 24));
  82. let newState = (days-create)<7?true:false;
  83. theArr.push({
  84. key: i,
  85. id: thisdata.id,
  86. newState:newState,
  87. name:thisdata.name,
  88. introduce:thisdata.introduction&&thisdata.introduction.length>40?thisdata.introduction.substr(0,40)+'...':'',
  89. img: thisdata.firstPicture, //编号
  90. });
  91. };
  92. };
  93. this.setState({
  94. loading:false,
  95. dataList:theArr,
  96. total:data.data.data.totalCount
  97. })
  98. })
  99. }
  100. //需求
  101. loadDataDemand(page){
  102. this.setState({
  103. loading:true,
  104. })
  105. let url = globalConfig.context + '/api/user/portal/listDemandIInterestedIn'
  106. axios.get(url,{
  107. params:{
  108. pageNo:page||1,
  109. pageSize:8
  110. }
  111. })
  112. .then(data=>{
  113. let theData=data.data.data,
  114. theArr = [],
  115. times = new Date().getTime(),
  116. days = parseInt(times / (1000 * 60 * 60 * 24));
  117. if (!data.data || !data.data.data.list) {
  118. if (data.data.error && data.data.error.length) {
  119. message.warning(data.data.error[0].message);
  120. };
  121. } else {
  122. for (let i = 0; i < theData.list.length; i++) {
  123. let thisdata = theData.list[i],
  124. create = parseInt(thisdata.releaseDate / (1000 * 60 * 60 * 24));
  125. let newState = (days-create)<7?true:false;
  126. console.log(thisdata.firstPic)
  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)+'...':'',
  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 })
  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={6} 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={8} current={this.state.current} total={this.state.total} onChange={this.onShowSizeChange.bind(this)}/>:''}
  229. </div>
  230. </div>
  231. }
  232. }
  233. export default Collection;