<import src="/templates/star-rate.wxml" />
<import src="/templates/load-more.wxml" />
<import src="templates/goods-actions.wxml" />
<import src="templates/cart-box.wxml" />
<import src="templates/sub-goods.wxml" />

<!--pages/shop/show.wxml-->
<view class="shop-show">
  <view class="shop-info weui-panel weui-panel_access">
    <view class="weui-panel__bd">
      <view class="weui-media-box weui-media-box_appmsg">
        <view class="weui-media-box__hd weui-media-box__hd_in-appmsg">
          <image class="weui-media-box__thumb shop-info__pic" src="{{info.pic_url}}" />
        </view>
        <view class="weui-media-box__bd weui-media-box__bd_in-appmsg">
          <view class="weui-media-box__title">{{info.seller_name}}</view>
          <view class="weui-media-box__desc shop-info__desc">
            <view>
              {{info.min_price}}元起送 | {{info.reach_time}}分钟 | 距离{{info.distanceFormat}}km
            </view>
            <view wx:if="{{info.notice}}">
              公告: {{info.notice}}
            </view>
          </view>
        </view>
      </view>
      <view wx:if="{{info.promotion && info.promotion.length > 0}}" class="promotion">
        <swiper class="promotion-swiper" vertical="true" autoplay="true" interval="5000">
          <swiper-item wx:key="index" wx:for="{{info.promotion}}" class="promotion-item">
            <image class="promotion-item__icon" src="{{item.pic_url}}"></image>
            <text>{{item.info}}</text>
          </swiper-item>
        </swiper>
        <view class="promotion-total">
          {{info.promotion.length}}个活动
        </view>
      </view>
    </view>
  </view>
  <view class="shop-content">
    <view class=" weui-tab weui-tab_shop">
      <view class="weui-navbar">
        <view wx:for="{{tabs}}" wx:key="*this" id="{{index}}" class="weui-navbar__item {{activeIndex == index ? 'weui-bar__item_on' : ''}}" bindtap="tabClick">
          <view class="weui-navbar__title">{{item}}</view>
        </view>
      </view>
      <swiper bindchange="swiperChange" current="{{activeIndex}}" autoplay="{{false}}" class="weui-tab__panel">
        <swiper-item class="weui-tab__content menu-tab">
          <view class="menu-content weui-flex">
            <view class="menu-list">
              <view bindtap="menuClick" id="{{index}}" class="menu-item {{index == activeMenuIndex ? 'menu-item_active' : ''}} " wx:for="{{info.menus}}" wx:key="menu_id">
                {{item.menu_name}}
              </view>
            </view>
            <view wx:if="{{info.menus && info.menus[activeMenuIndex]}}" class="goods-list weui-flex__item">
              <view class="goods-list__label">
                {{info.menus[activeMenuIndex].menu_name}}
              </view>
              <view wx:for="{{info.menus[activeMenuIndex].goods2}}" wx:key="goods_id" class="goods-item weui-flex">
                <image class="goods-item__pic" src="{{item.pic_url}}"></image>
                <view class="weui-flex__item">
                  <view class="goods-item__name">{{item.goods_name}}</view>
                  <view class="goods-item__desc text-small grey-color">月售{{item.sales}}份</view>
                  <view class="goods-item__price primary-color text-large">¥{{item.price}}</view>
                  <view class="goods-item__actions">
                    <view data-goods-id="{{item.goods_id}}" bindtap="showSubGoods" wx:if="{{item.sub_goods && item.sub_goods.length > 0}}" class="goods-item__sub-goods">
                      选规格
                      <view wx:if="{{order['goodsNums'][item.goods_id] > 0}}" class="weui-badge goods-item__sub-goods-badge">{{order['goodsNums'][item.goods_id]}}</view>
                    </view>
                    <template is="goods-actions" data="{{goods_id: item.goods_id, num: order['goodsNums'][item.goods_id]}}" wx:else />
                  </view>
                </view>
              </view>
            </view>
          </view>
          <view class="menu-cart weui-flex">
            <view bindtap="toggleCart" class="weui-flex__item menu-cart__content weui-flex">
              <view wx:if="{{!showCart}}" class="menu-cart__badge-wrap">
                <image class="menu-cart__icon" src="{{order.totalNum > 0 ? '/images/cart-full@2x.png': '/images/cart-empty@2x.png'}}"></image>
                <view wx:if="{{order.totalNum > 0}}" class="weui-badge menu-cart__badge">{{order.totalNum}}</view>
              </view>
              <view class="weui-flex__item menu-cart__price-wrap">
                <view class="menu-cart__price" wx:if="{{order.totalPrice > 0}}">¥{{order.totalPrice}}</view>
                <view class="text-small grey-color">另需配送费{{info.delivery_fee}}元</view>
              </view>
            </view>
            <button disabled="{{loading}}" loading="{{loading}}" wx:if="{{order.totalPrice >= info.min_price}}" bindtap="onAddQuasiOrder" class="weui-btn menu-cart__btn" type="primary">
              选好了
            </button>
            <button wx:else class="weui-btn menu-cart__btn" type="primary" disabled>
              <text wx:if="{{order.totalPrice > 0}}">还差{{info.min_price - order.totalPrice}}元起送</text>
              <text wx:else>{{info.min_price}}元起送</text>
            </button>
          </view>
        </swiper-item>
        <swiper-item class="weui-tab__content weui-tab__content_review">
          <scroll-view class="scroll-view_review" enable-back-to-top="true" bindscrolltolower="onScrolltolower" scroll-y="true">
            <view class="shop-rate">
              <view class="shop-rate__overall">
                <view class="shop-rate__overall-num">{{info.overall}}</view>
                <view class="classname">综合评分</view>
              </view>
              <view class="shop-rate__score">
                <view class="shop-rate__score-item">
                  <view class="shop-rate__score-item-label">商家评分</view>
                  <template is="star-rate" data="{{value: info.quality}}"></template>
                  <view class="shop-rate__score-item-num">{{info.quality}}</view>
                </view>
                <view class="shop-rate__score-item">
                  <view class="shop-rate__score-item-label">配送评分</view>
                  <template is="star-rate" data="{{value: info.service}}"></template>
                  <view class="shop-rate__score-item-num">{{info.service}}</view>
                </view>
              </view>
            </view>
            <view class="shop-review">
              <view class="review-list">
                <view wx:for="{{review.list}}" wx:key="{{index}}" class="review-item">
                  <view class="">
                    <image class="review-item__head-img" src="{{item.head_pic || '/images/default-image.png'}}"></image>
                  </view>
                  <view class="review-item__content">
                    <view class="review-item__hd">
                      <view class="review-item__add-time">{{item.timeFormat}}</view>
                      <view class="review-item__nick">{{item.nick}}</view>
                      <view class="weui-flex">
                        <template is="star-rate" data="{{value: item.quality, mini: true}}"></template>
                        <view class="review-item__reach-time text-small grey-color">及时到达</view>
                      </view>
                    </view>
                    <view class="review-item__bd">
                      {{item.content}}
                    </view>
                  </view>
                </view>
              </view>
            </view>
            <template is="load-more" data="{{loading: review.loading, hasMore: review.hasMore}}"></template>
          </scroll-view>
        </swiper-item>
        <swiper-item class="weui-tab__content weui-tab__content_info">
          <block wx:if="{{info.promotion.length > 0}}">
            <view class="weui-cells__title">商家活动</view>
            <view class="weui-cells weui-cells_after-title info__promotion-list">
              <view wx:for="{{info.promotion}}" wx:key="{{index}}" class="weui-cell info__promotion-item">
                <view class="weui-cell__hd">
                  <image src="{{item.pic_url}}" class="info__promotion-img"></image>
                </view>
                <view class="weui-cell__bd">{{item.info}}</view>
              </view>
            </view>
          </block>
          <view class="weui-cells__title">商家信息</view>
          <view class="weui-cells weui-cells_after-title">
            <view data-phone="{{info.phone}}" bindtap="onPhoneTap" class="weui-cell weui-cell_access info-item">
              <view class="weui-cell__hd weui-cell__hd_info">
                商家电话
              </view>
              <view class="weui-cell__bd ">{{info.phone}}</view>
              <view class="weui-cell__ft">
                <image class="info__phone-icon" src="/images/chat_phone_normal.png"></image>
              </view>
            </view>
            <view wx:if="{{info.notice}}" class="weui-cell">
              <view class="weui-cell__hd weui-cell__hd_info">
                商家公告
              </view>
              <view class="weui-cell__bd">{{info.notice}}</view>
            </view>
            <view class="weui-cell">
              <view class="weui-cell__hd weui-cell__hd_info">
                商家地址
              </view>
              <view class="weui-cell__bd">{{info.address}}</view>
            </view>
            <view class="weui-cell">
              <view class="weui-cell__hd weui-cell__hd_info">
                营业时间
              </view>
              <view class="weui-cell__bd">{{info.sell_time}}</view>
            </view>
            <view class="weui-cell">
              <view class="weui-cell__hd weui-cell__hd_info">
                配送服务
              </view>
              <view class="weui-cell__bd">爱跑腿</view>
            </view>
          </view>
        </swiper-item>
      </swiper>
    </view>
  </view>
</view>
<template wx:if="{{showCart}}" is="cart-box" data="{{...order}}" />
<template is="sub-goods" wx:if="{{showSubGoods}}" data="{{...activeSubGoods}}" />