/**
 * 拼团列表
 * 对齐后端 /api/marketing/group-buy/*
 * 点击拼团商品跳转对应商品详情下单
 */
const api = require('../../utils/api');

Page({
  data: {
    loading: true,
    list: []
  },

  onLoad() {
    this.loadList();
  },

  async loadList() {
    this.setData({ loading: true });
    const list = await api.getGroupBuyList().catch(() => []);
    this.setData({ list: Array.isArray(list) ? list : [], loading: false });
  },

  goProduct(e) {
    const id = e.currentTarget.dataset.pid;
    if (id) {
      wx.navigateTo({ url: '/pages/product/product?id=' + id });
    }
  }
});
