<template>
<view id="mealList">
	  <view class="no-list" v-if="!list.length && init">
		  暂无数据
	  </view>
    <view v-for="(items,idx) in list" :key="idx" class="gergwr">
        <view class="item" :data-id="item.id" v-for="(item, index) in list[idx]" :key="index" @tap="jump">
            <view class="left">
                <image mode="widthFix" :src="item.items[0].goods.img" alt></image>
                <view class="img-box">
                    <image mode="widthFix" :src="item.goods.img" v-for="(item, index) in item.items" :key="index" v-if="index > 0 && index < 3" alt></image>
                </view>
            </view>
            <view class="right">
                <view class="name">
                    {{item.items[0].goods.name}}等{{item.items.length}}件商品
                </view>
                <view class="price-box">
                    <view class="old-price">
                        {{item.items.length}}件单买价 ￥{{item.origin_total}}
                    </view>
                    <view class="meal-price">
                        <view class="price">
                            <span>套餐价</span>
                            ￥{{item.total}}
                        </view>
                        <view class="btn">
                            去购买
							<!-- <i class="iconfont icon-Chevron"></i> -->
                        </view>
                    </view>
                </view>
            </view>
        </view>
    </view>
</view>
</template>
<script>
import {pageLogin, getUrl,config,is} from '@/common/js/utils.js';
import Animation from '@/common/js/animation.js';

export default {
  data() {
    return {
      hasMore: true,
      init: false,
      list: [],
      page: ''
    };
  },

  onReachBottom() {
    if (this.hasMore) {
      var page = this.page + 1;
      this.querySuitList(page);
    } else {
      wx.showToast({
        image: '../../../static/error.png',
        title: '再拉也没有啦'
      });
    }
  },

  onLoad(e) {
    wx.showLoading({
      title: "加载中",
      mask: true
    });
     this.querySuitList();
  },
  
  props: {},
  methods: {
    jump(e) {
      wx.navigateTo({
        url: '/pages/store/meal/meal?id=' + e.currentTarget.dataset.id
      });
    },

    querySuitList(page = 1) {
      this.$http.get({
        api: 'api/suit/list',
        data: {
          page: page
        }
      }).then(res => {
        if (res.statusCode == 200) {
          res = res.data;
		
          if (res.status) {
            var pages = res.meta.pagination;
            var current_page = pages.current_page;
            var total_pages = pages.total_pages;
            this.setData({
              //[`list[${page - 1}]`]: res.data,
              init: true,
              page: current_page,
              hasMore: current_page < total_pages
            });
			
			this.$set(this.list, page -1, res.data);

          } else {
            wx.showModal({
              title: '',
              content: '请求失败',
              showCancel: false
            });
          }
        } else {
          wx.showModal({
            title: '',
            content: '请求失败',
            showCancel: false
          });
        }

        wx.hideLoading();
        // this.setData({
        //   show: false
        // });
		this.show=false;
		
      }, err => {
        wx.hideLoading();
       this.show=false;
      });
    },

    setData: function (obj) {
      let that = this;
      let keys = [];
      let val, data;
      Object.keys(obj).forEach(function (key) {
        keys = key.split('.');
        val = obj[key];
        data = that.$data;
        keys.forEach(function (key2, index) {
          if (index + 1 == keys.length) {
            that.$set(data, key2, val);
          } else {
            if (!data[key2]) {
              that.$set(data, key2, {});
            }
          }

          data = data[key2];
        });
      });
    }
  },
  computed: {},
  watch: {}
};
</script>
<style rel="stylesheet/less" lang="less">
    @import "mealList";
</style>