<template>
  <view class="waper">
    <u-navbar auto-back bgColor="#fff">
      <view slot='center' class="navbar_title">全部菜品</view>
    </u-navbar>
    <view class="tabs-box" :style="'top: ' + navHeight + 'px;'">
      <!-- <scroll-view scroll-x="true">
        <view class="tab" :class="{active: activeType === 0}" @click="getData(0)">全部</view>
        <view class="tab" :class="{active: activeType === item.id}" v-for="(item, index) in typeList" :key="index"
              @click="getData(item.id)">{{ item.name }}
        </view>
      </scroll-view> -->
        <u-tabs lineWidth="42rpx" lineHeight="6rpx" lineColor="#4C90FF" :activeStyle="{ color: 'rgba(0, 0, 0, 0.85)', fontWeight: '600', fontSize:'32rpx' }" :inactiveStyle="{ color: 'rgba(0, 0, 0, 0.45)', fontSize:'28rpx' }" :itemStyle="{ height: '80rpx', lineHeight: '80rpx' }" :list="typeList" @click="getData"></u-tabs>
    </view>
    <mescroll-body @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption" :top="paddingTop + 'px'">
      <view class="list-box">
        <view class="item" v-for="(item,index) in list" :key="item.id">
          <view class="img">
            <image :src="$utils.setImgUrl(item.img)" mode=""></image>
          </view>
          <view class="info">
            <view class="title">{{ item.name }}</view>
            <view class="msg">
              ￥
              <view class="num">{{ item.salePrise }}</view>
            </view>
          </view>
        </view>
      </view>
    </mescroll-body>

  </view>
</template>

<script>

import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";

export default {
  mixins: [MescrollMixin],
  data() {
    return {
      downOption: {auto: false},
	  navHeight: 0,
      paddingTop: 0,
      activeType: 0,
      list: [],
      typeList: []
    };
  },
  onLoad(option) {
    this.merchantId = option.merchantId
    let menu = [{ name: '全部', id: 0 }];
    this.$eatery.getTypeList({
      merchantId: option.merchantId ?? 267
    }).then(res => {
      this.typeList = menu.concat(res.data);
    })
    this.navHeight = this.$paddingTop;
    this.paddingTop = this.$paddingTop + uni.upx2px(96);
    this.mescroll && this.mescroll.resetUpScroll();
  },
  methods: {
    async upCallback(page) {
      let obj = {pageNum: page.num, pageSize: page.size,merchantId: this.merchantId, type: this.activeType};
      let info = await this.$eatery.getProductList(obj);
      if (page.num == 1) this.list = [];
      this.list = this.list.concat(info.rows)
      this.mescroll.endBySize(info.rows.length, info.total);
    },
    getData(data) {
      this.activeType = data.id
      this.mescroll.resetUpScroll();
    }
  }
}
</script>

<style lang="scss" scoped>
::v-deep .u-tabs__wrapper__nav__line{ border-radius: 13rpx !important; }
.waper {
  width: 100%;
  height: 100vh;
  background-color: #F6F6F6;

  .tabs-box {
	width: 100%;
	position: fixed; left: 0; z-index: 11; box-sizing: border-box; padding: 0 24rpx 16rpx;
	background-color: #fff;

    scroll-view {
      width: 100%;
      white-space: nowrap;
      font-size: 0;
    }

    .tab {
      display: inline-block;
      vertical-align: top;
      height: 70rpx;
      line-height: 70rpx;
      margin: 0 25rpx;
      font-size: 32rpx;
      color: #333333;

      &:first-child {
        margin-left: 32rpx;
      }

      &:last-child {
        margin-right: 32rpx;
      }
    }

    .active {
      position: relative;
      color: #4C90FF;
      &::after{
        content: "";
        position: absolute;
        bottom: 0;
        left: 50%;
        transform: translate(-50%, 0);
        width: 30rpx;
        height: 4rpx;
        background: #4C90FF;
        margin: 0 auto;
      }
    }
  }

  .list-box {
    margin: 22rpx 24rpx;

    .item {
      width: 100%;
      box-sizing: border-box;
      margin-bottom: 22rpx;
      padding: 24rpx;
      border-radius: 10rpx;
      background: #fff;
      display: flex;
      align-items: center;

      .img {
        width: 243rpx;
        min-width: 243rpx;
        height: 182rpx;
        background-color: #ccc;
        border-radius: 10rpx;
        overflow: hidden;

        image {
          width: 100%;
          height: 100%;
        }
      }

      .info {
        height: 180rpx;
        margin-left: 20rpx;
        box-sizing: border-box;
        padding-top: 10rpx;
        padding-bottom: 10rpx;
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: space-between;

        .title {
          line-height: 40rpx;
          color: rgba(0,0,0,0.85);
          font-size: 32rpx;
          font-weight: 500;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }

        .msg {
          display: flex;
          margin-top: 40rpx;
          color: #EE595A;
          font-size: 24rpx;
          align-items: baseline;
          .num{
			font-weight: bold;
            font-size: 40rpx;
          }
        }
      }
    }
  }
}
</style>
