<template>
  <view class="home-list flex-col">
    <view class="gc-1">
      <view class="list flex-col">
        <view v-for="(ele, idx) in datas.relations" :key="ele.id">
          <view class="r flex-row" @tap="jumpToDetail(ele)">
            <view class="r1"><img mode :src="ele.img" alt="" /></view>
            <view class="r2">
              <view class="n1"
                ><text>{{ ele.name }}</text></view
              >
              <text v-if="ele.tag" class="tag">{{ ele.tag }}</text>
              <view class="n2">
                <text class="price1"
                  >¥<text>{{ ele.show_price }}</text></text
                >
                <text v-if="ele.show_price != ele.source_price" class="price2"
                  >¥<text>{{ ele.source_price }}</text></text
                >
              </view>
              <view class="n3 justify-between">
                <img v-for="sub in ele.sub_imgs" :key="sub" :src="sub" alt="" />
              </view>
            </view>
          </view>
          <view v-if="idx < datas.relations.length - 1" class="line"></view>
        </view>
      </view>
    </view>
    <view class="footer">
      <view class="info">到底啦~ (￣▽￣)”</view>
      <view class="contact">联系我们：oushen2022@126.com</view>
    </view>
  </view>
</template>
<script>
import api from "@/lib/api/api";
export default {
  name: "PageList",
  data() {
    return {
      datas: [],
      id: "",
    };
  },
  onLoad(data) {
    this.id = data.id;
    this.loadModule(data.id);
  },
  // 分享
  onShareAppMessage() {
    return {
      title: "云果国潮，各种绝版大娃抽到飞起！",
    };
  },
  // 分享
  onShareTimeline() {
    return {
      title: "云果国潮，各种绝版大娃抽到飞起！",
    };
  },
  // 下拉刷新
  onPullDownRefresh() {
    this.loadModule(this.id, () => {
      uni.stopPullDownRefresh();
    });
  },
  methods: {
    // 获取数据
    loadModule(id, cb) {
      api
        .homeModule(id)
        .then((data) => {
          if (data.data) {
            this.datas = data.data;
            uni.setNavigationBarTitle({
              title: this.datas.title,
            });
          }
          if (cb) cb();
        })
        .catch(() => {
          uni.showToast({
            icon: "none",
            title: "出错啦，请稍后重试",
            duration: 2e3,
          });
          if (cb) cb();
        });
    },
    jumpToDetail(data) {
      if (data.play_type == 2) {
        uni.navigateTo({
          url: `../detail/pinche?id=${data.id}`,
        });
      } else {
        uni.navigateTo({
          url: `../detail/detail?id=${data.id}`,
        });
      }
    },
  },
};
</script>
<style lang="scss">
@import "./list.scss";
</style>
