<template>
  <view class="act-list">
    <template v-if="activetys.length">
      <view class="title">推荐活动</view>
      <activity
        v-for="item in activetys"
        :key="item.id"
        :activity="item"
        @click="handleToDetail"
        @end="handleTimeEnd"
      ></activity>
    </template>
    <template v-if="moreList.length">
      <view class="title">更多活动</view>
      <activity
        v-for="item in moreList"
        :key="item.id"
        :activity="item"
        @click="handleToDetail"
      ></activity>
    </template>
  </view>
</template>

<script>
import api from "@/lib/api/api";
import activity from "@/components/activity/activity.vue";
export default {
  name: "PageActivity",
  components: { activity },
  data() {
    return {
      activetys: [],
      moreList: [],
    };
  },
  onShow() {
    this.loadList();
  },
  onPullDownRefresh() {
    this.loadList()
      .then(() => {
        uni.stopPullDownRefresh();
      })
      .catch(() => {
        uni.stopPullDownRefresh();
      });
  },
  onShareAppMessage() {
    return {
      title: "@你，欢迎进入<初见福利社>，各种0元免费活动享不停！",
      imageUrl:
        "https://chujianchaowan.oss-cn-beijing.aliyuncs.com/images/7c221479f67a19a85ec1b8f5916436c1.jpg",
      path: "/pages/activity/index",
    };
  },
  onShareTimeline() {
    return {
      title: "@你，欢迎进入<初见福利社>，各种0元免费活动享不停！",
      imageUrl:
        "https://chujianchaowan.oss-cn-beijing.aliyuncs.com/images/7c221479f67a19a85ec1b8f5916436c1.jpg",
      path: "/pages/activity/index",
    };
  },
  methods: {
    async loadList() {
      const { data = {} } = await api.activityList();
      this.activetys = data.activetys || [];
      this.moreList = data.other_activetys || [];
    },
    handleToDetail(item) {
      uni.navigateTo({
        url: `./detail?id=${item.id}`,
      });
      // if (!url) return;

      // if (/^https?:\/\//i.test(url)) {
      // 	uni.navigateTo({
      // 		url: `../webview/webview?url=${encodeURIComponent(url)}`,
      // 	});
      // 	return;
      // }
      // uni.navigateTo({
      // 	url: url,
      // });
    },
    handleTimeEnd(item) {
      item.status = 2;
    },
  },
};
</script>
<style lang="scss">
.act-list {
  box-sizing: border-box;
  padding: 36rpx 24rpx;
  min-height: 100vh;
  background: #f5f5f5;

  .title {
    display: block;
    margin: 26rpx 0;
    font-weight: 400;
    font-family: ysbth;
    font-size: 46rpx;
    color: #000;

    &:first-child {
      margin-top: 0;
    }
  }
}
</style>
