123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <template>
- <view class="slide-box">
- <tantan ref="jmList" @onChange="onChange" @onClickImage="clickImage"></tantan>
- </view>
- </template>
- <script>
- import tantan from '@/components/dgex-tantan/dgex-tantan.vue'
- import {getDiscoverList, getMoments, setDislike, setLike} from "@/api/discovery";
- import tools from "@/service/tools";
- export default {
- name: "slide-item",
- components: {
- tantan
- },
- props: {},
- data() {
- return {
- page:1,
- total:undefined,
- isAjax:false,
- list:[],
- }
- },
- watch: {},
- mounted() {
- this.getDiscoverList()
- },
- methods: {
- onChange(data){
- if(this.type ==='love'){
- //选择了喜欢
- this.setLike(data.currentItem.userId)
- }else {
- //选择了不喜欢
- this.setDislike(data.currentItem.userId)
- }
- if(this.list.length<data.currentIndex+5){
- this.getDiscoverList()
- }
- },
- setLike(userId){
- setLike(userId).then((res)=>{
- console.log(res)
- })
- },
- setDislike(userId){
- setDislike(userId).then((res)=>{
- console.log(res)
- })
- },
- getDiscoverList(){
- if(this.isAjax){
- return
- }
- this.isAjax=true
- getDiscoverList({'count':10}).then((res)=>{
- this.isAjax=false
- if(res.code===0){
- this.list=res
- let arr=[]
- res.data.forEach( (item)=>{
- let galleryUrls=item.galleryUrls
- let age=tools.getAge(item.dateOfBirth)
- if(galleryUrls.length>0){
- if(galleryUrls.length>8){
- galleryUrls=galleryUrls.slice(0,7)
- }
- let newdata = {
- image: galleryUrls[0],
- images: galleryUrls,
- imgIndex:0,
- title: item.nickname,
- userId: item.userId,
- age: age,
- online: item.online,
- longitude: item.longitude,
- latitude: item.latitude,
- distance: 0,
- city: item.province+' '+item.city,
- weChat: item.wechatId,
- likeCount: item.likeCount,
- tagList: item.tagList,
- slogan: item.slogan,
- verified: item.verified,
- animation:{}
- }
- arr.push(newdata)
- }
- })
- this.$refs.jmList.setData(arr)
- }
- })
- },
- clickImage(data) {
- console.log(data);
- }
- }
- }
- </script>
- <style scoped lang="scss">
- .slide-box{
- margin-top: 10rpx;
- box-sizing: border-box;
- }
- </style>
|