slide-item.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <view class="slide-box">
  3. <tantan ref="jmList" @onChange="onChange" @onClickImage="clickImage"></tantan>
  4. </view>
  5. </template>
  6. <script>
  7. import tantan from '@/components/dgex-tantan/dgex-tantan.vue'
  8. import {getDiscoverList, setDislike, setLike} from "@/api/discovery";
  9. import tools from "@/service/tools";
  10. export default {
  11. name: "slide-item",
  12. components: {
  13. tantan
  14. },
  15. props: {},
  16. data() {
  17. return {
  18. page:1,
  19. total:undefined,
  20. isAjax:false,
  21. list:[],
  22. }
  23. },
  24. watch: {},
  25. mounted() {
  26. this.getDiscoverList()
  27. },
  28. methods: {
  29. onChange(data){
  30. if(this.type ==='love'){
  31. //选择了喜欢
  32. this.setLike(data.currentItem.userId)
  33. }else {
  34. //选择了不喜欢
  35. this.setDislike(data.currentItem.userId)
  36. }
  37. if(this.list.length<data.currentIndex+5){
  38. this.getDiscoverList()
  39. }
  40. },
  41. setLike(userId){
  42. setLike(userId).then((res)=>{
  43. console.log(res)
  44. })
  45. },
  46. setDislike(userId){
  47. setDislike(userId).then((res)=>{
  48. console.log(res)
  49. })
  50. },
  51. getDiscoverList(){
  52. if(this.isAjax){
  53. return
  54. }
  55. this.isAjax=true
  56. getDiscoverList(10).then((res)=>{
  57. this.isAjax=false
  58. if(res.code===0){
  59. let arr=[]
  60. res.data.forEach( (item)=>{
  61. let galleryUrls=item.galleryUrls
  62. let age=tools.getAge(item.dateOfBirth)
  63. if(galleryUrls.length>0){
  64. if(galleryUrls.length>8){
  65. galleryUrls=galleryUrls.slice(0,7)
  66. }
  67. this.list.push(item.userId)
  68. let newdata = {
  69. image: galleryUrls[0],
  70. images: galleryUrls,
  71. imgIndex:0,
  72. title: item.nickname,
  73. userId: item.userId,
  74. age: age,
  75. online: item.online,
  76. longitude: item.longitude,
  77. latitude: item.latitude,
  78. distance: 0,
  79. city: item.province+' '+item.city,
  80. weChat: item.wechatId,
  81. likeCount: item.likeCount,
  82. tagList: item.tagList,
  83. slogan: item.slogan,
  84. realAvatar: item.realAvatar,
  85. animation:{}
  86. }
  87. arr.push(newdata)
  88. }
  89. })
  90. this.$refs.jmList.setData(arr)
  91. }
  92. })
  93. },
  94. clickImage(data) {
  95. console.log(data);
  96. }
  97. }
  98. }
  99. </script>
  100. <style scoped lang="scss">
  101. .slide-box{
  102. margin-top: 10rpx;
  103. box-sizing: border-box;
  104. }
  105. </style>