<template>
<view>
<!--mine/collect/collect.wxml-->
<view class="list" v-if="pageList.length > 0">
	<view v-for="(item, index) in pageList" :key="index" class="li">
		<image :src="item.pic" @tap="redirectDetail" :data-id="item.id" mode="aspectFill" class="cimg"></image>
		<view class="zhinfo">
			<view class="zhtit" @tap="redirectDetail" :data-id="item.id">{{item.title}}</view>
			<!-- <view class="guige">规格：15g</view> -->
			<view class="jiage">
				<view class="zhjia" @tap="redirectDetail" :data-id="item.id"><text>{{item.endTime}}</text></view>
				<view class="btn" :data-index="index" @tap="clickCollect">取消收藏</view>
			</view>
		</view>
	</view>
</view>
<view class="nodata" v-else>
  <image :src="picUrlss+'empty_sc.png'"></image>
  <text>暂无收藏</text>
</view>
</view>
</template>

<script>
const req = require("../../utils/request.js");
const app = getApp();

export default {
  data() {
    return {
		picUrlss: req.public.picUrls,
      form: {
        page: 1,
        limit: 10
      },
      pageList: [],
      isLoad: true,
      ishow: false
    };
  },

  components: {},
  props: {},
  onLoad: function (options) {
    this.loadFootprint();
  },

  onReachBottom() {
    this.form.page++;
    this.loadCoupon();
  },

  methods: {
    loadFootprint() {
      let isShowLoading = false;

      if (this.form.page == 1 && !isShowLoading) {
        req.loadIng('加载中');
        isShowLoading = true;
      }

      if (!this.isLoad) return false;
      this.isLoad = false;
      let that = this;
      req.getRequest('/api/match/collectPage', this.form, data => {
		  data = data?data.list:[]
        if (data && data.length == 10) this.isLoad = true;
        if (that.form.page > 1) data = that.pageList.concat(data);
        that.setData({
          pageList: data
        });

        if (!this.pageList||this.pageList.length<1) {
          that.setData({
            ishow: true
          });
        } else {
          that.setData({
            ishow: false
          });
        }

        if (isShowLoading) {
          uni.hideLoading();
          isShowLoading = false;
        }
      });
    },

    clickCollect(event) {
		let _ts = this;
		
		const index = event.currentTarget.dataset.index;
		const page = this.pageList[index];
		var dataP = {};
		dataP.type =2 //、产品 2、活动 3、未知 4、内容 5、课程 6、老师 7、素材 8、题目 9、资料领取 10、招聘职位 12、用户须知 13、素材 15、医院科室 16、海报 20、医生 21 新闻 23名片
		dataP.behavior = 2; //1、关注 2、收藏 3、点赞 4、浏览 5、确认 6、分享
		dataP.bindId = page.id;
		req.postRequestLoding('/api/v3/behavior/save', dataP, data => {
			_ts.pageList.splice(index, 1);
			
			_ts.setData({
			  pageList: _ts.pageList
			});
		});
    },

    redirectDetail(event) {
      uni.navigateTo({
        url: '/match/activityDetail/activityDetail?id=' + event.currentTarget.dataset.id
      });
    }

  }
};
</script>
<style>
@import "./collect.css";
</style>