<import-sjs
  name="utils"
  from="../mall-car-popup/index.sjs"
/>
<import-sjs
  name="checkUtils"
  from="../mall-shopcar-button/index.sjs"
/>
<import-sjs
  from="../utils-component/index.sjs"
  name="totalUtils"
/>
<import-sjs
  name="carUtils"
  from="./index.sjs"
/>
<import-sjs
  from="../goods-item/index.sjs"
  name="numUtils"
/>
<wrapper>
  <mas-adc-nav-bar
    zIndex="100"
    onCallback="onReadyHeader"
    background="linear-gradient(138.81deg,#007dff 0%,#75c4ff 73%,#6eddff 100%)"
    a:if="{{header === 'show'}}"
  />
  <!-- 盒子 -->
  <view class="goods-detail-container">
    <!-- 轮播 -->
    <view
      class="swiper-container"
      a:if="{{goodsDetail}}"
    >
      <swiper onChange="onSwiperChange">
        <swiper-item
          key="swiper-item-{{index}}"
          a:for="{{goodsDetail.picList || ['img']}}"
        >
          <stock-img
            width="750rpx"
            height="750rpx"
            borderRadius="0"
            imgSrc="{{item || 'error'}}"
            stockHight="98rpx"
            isNoStock="{{goodsDetail.stockStatus === 'Y' && !goodsDetail.stock}}"
            currentIndex="{{index+1}}"
          >{{""}}
          </stock-img>
        </swiper-item>
      </swiper>
      <view
        a:if="{{goodsDetail.stockStatus === 'Y' && !goodsDetail.stock}}"
        class="swiper-stock"
      >补货中</view>
      <view class="swiper-num">
        {{currentIndex}}/{{goodsDetail.picList.length || 1}}
      </view>
    </view>
    <!-- 详情 -->
    <view class="detail-container">
      <!-- 头部板块 -->
      <view
        a:if="{{goodsDetail}}"
        class="head"
      >
        <!-- 标题 -->
        <view class="head-title">{{goodsDetail.name}}</view>
        <!-- 库存 -->
        <view
          a:if="{{goodsDetail.stockStatus === 'Y'}}"
          class="head-stock {{goodsDetail.stock ? '' : 'red'}}"
        >库存:{{goodsDetail.stock || 0}}</view>
        <!-- 限购 -->
        <view class="goods-limit">
          <goods-tag
            a:if="{{goodsDetail.buyLimitType === 'GENERAL'}}"
            text="限{{goodsDetail.buyLimitCount}}份"
            fontSize="20rpx"
            padding="6rpx"
          />
          <goods-tag
            a:if="{{goodsDetail.userLimitType === 'BESPEAK'}}"
            text="{{goodsDetail.isbespeak ? '已预约' : '去预约'}}"
            isbespeak="{{goodsDetail.isbespeak}}"
            clickTip="{{goodsDetail.activity.joinLinkTip}}"
            url="{{goodsDetail.activity.joinLink}}"
            linkType="{{goodsDetail.activity.joinLinkType}}"
            fontSize="20rpx"
            padding="6rpx"
          />
          <goods-tag
            a:if="{{goodsDetail.deliverType.indexOf('AUTO') > -1 || goodsDetail.deliverType.indexOf('MANUAL') > -1}}"
            text="到店自提"
            fontSize="20rpx"
            padding="6rpx"
          />
          <goods-tag
            a:if="{{goodsDetail.deliverType.indexOf('DELIVERY') > -1}}"
            text="可配送"
            fontSize="20rpx"
            padding="6rpx"
          />
        </view>
        <view style="margin-top: 12rpx">
          <price-tag
            a:if="{{isMember}}"
            price="{{memberPrice}}"
            fontSize="28rpx"
            padding="2px 4px"
          />
        </view>
        <!-- monety and 添加购物车按钮 -->
        <view class="head-money-car">
          <!-- 价格 -->
          <view class="price">
            <view class="price-icon">¥</view>
            <view class="price-text">
              {{goodsDetail.sellPrice}}
            </view>
            <view
              class="pre-price"
              a:if="{{goodsDetail.price !== goodsDetail.sellPrice}}"
            >¥{{goodsDetail.price}}</view>
          </view>
          <!-- car -->
          <view
            hidden="{{carUtils.getQuantity(globalCar.carts, skuId)}}"
            class="car {{carUtils.isActive(goodsDetail) ? '' : 'inactive'}}"
            onTap="handleAddCarClick"
          >
            加入购物车
          </view>
          <!-- 步进器 -->
          <view
            class="step {{carUtils.isActive(goodsDetail) ? '' : 'disable'}}"
            hidden="{{!carUtils.getQuantity(globalCar.carts, skuId)}}"
          >
            <stepper
              catchChange="changeNum"
              defaultNum="{{carUtils.getQuantity(globalCar.carts, skuId)}}"
              maxNum="{{numUtils.getMaxBuyNum(goodsDetail)}}"
              targetId="{{targetId}}"
              numType="{{numUtils.getNumType(goodsItem)}}"
            />
          </view>
        </view>
      </view>
      <block a:if="{{jumpStoreId}}">
        <!-- 商店store -->
        <view class="detail-title">当前门店</view>
        <store
          jumpStoreId="{{jumpStoreId}}"
          productId="{{productId}}"
        />
      </block>
      <block a:if="{{goodsDetail}}">
        <!-- 详情板块 -->
        <view class="detail-title">商品详情</view>
        <!-- 详情内容 -->
        <view class="detail-info">
          <!-- 规格 -->
          <view class="detail-info-title">商品规格：
            <view class="detail-info-title-text">{{goodsDetail.specDesc}}</view>
          </view>
          <!-- 描述 -->
          <view class="detail-info-title">商品描述：</view>
          <mas-adc-rich-pro
            errorImg="{{errorImg}}"
            content="{{goodsDetail.content || '暂无描述'}}"
          />
        </view>
      </block>
    </view>
    <!-- 底部按钮 -->
    <mall-car-popup
      a:if="{{goodsDetail}}"
      ref="saveCarRef"
      startDeliveryAmount="{{startDeliveryAmount}}"
      showFlag="{{showFlag}}"
      text="立刻去商城领取会员卡"
      type="detail"
    >
      <mall-footer-button
        a:if="{{goodsDetail && showFlag && checkUtils.isOnlyDeliver(globalCar.carts)}}"
        selectNum="{{utils.getCheckedNum(globalCar.carts)}}"
        showIcon="{{true}}"
        discountShow="{{true}}"
        totalPrice="{{globalCar.totalPrice}}"
        showColorBtn="{{!!globalCar.carts.length}}"
        position="fixed"
        onCarClick="handleCarClick"
        disCountTotalPrice="{{globalCar.disCountTotalPrice}}"
        showTip="{{true}}"
        startDeliveryAmount="{{startDeliveryAmount}}"
        showColorCar="{{totalUtils.calcNumber(globalCar.disCountTotalPrice, globalCar.deliveryPackingFee || 0) >= startDeliveryAmount}}"
        buttonText="{{totalUtils.calcNumber(globalCar.disCountTotalPrice, globalCar.deliveryPackingFee || 0) >= startDeliveryAmount ? '去结算' : `差${totalUtils.calcNumber(startDeliveryAmount, totalUtils.calcNumber(globalCar.disCountTotalPrice, globalCar.deliveryPackingFee || 0), 'sub')}起送`}}"
        onConfirmClick="{{totalUtils.calcNumber(globalCar.disCountTotalPrice, globalCar.deliveryPackingFee || 0) >= startDeliveryAmount ? 'handleConfirm' : ''}}"
      />
      <mall-footer-button
        a:else
        selectNum="{{utils.getCheckedNum(globalCar.carts)}}"
        showIcon="{{true}}"
        discountShow="{{true}}"
        buttonText="{{btnText}}"
        totalPrice="{{globalCar.totalPrice}}"
        disCountTotalPrice="{{globalCar.disCountTotalPrice}}"
        showColorBtn="{{!!globalCar.carts.length}}"
        position="fixed"
        onConfirmClick="handleConfirm"
        onCarClick="handleCarClick"
      />
    </mall-car-popup>

  </view>
</wrapper>