<import-sjs
  name="utils"
  from="./index.sjs"
/>
<import-sjs
  name="checkUtils"
  from="../mall-shopcar-button/index.sjs"
/>
<import-sjs
  from="../utils-component/index.sjs"
  name="totalUtils"
/>
<import-sjs
  from="../mall-index/index.sjs"
  name="carUtils"
/>
<wrapper>
  <!-- 弹框内容 -->
  <popup-container
    show="{{ popUpShow && globalCar.carts.length }}"
    title=""
    onClose="onClosePopup"
    disableScroll="{{globalCar.carts.length <= 4}}"
  >
    <!-- 标题栏 -->
    <view
      class="mall-car-popup-head"
      slot="header"
    >
      <am-checkbox
        ctrlChecked="{{utils.isCheckedAll(globalCar.carts || [])}}"
        onChange="checkedAllChange"
      />
      <view class="head-text">
        全选（已选 {{utils.getCheckedNum(globalCar.carts || [])}} 件）
      </view>
      <view
        class="head-clear"
        onTap="clearCar"
      >
        <am-icon
          type="DeleteOutline"
          size="16"
        />
        <view class="head-clear-text">
          清空
        </view>
      </view>
    </view>
    <view class="mall-car-container">
      <!-- 物品列表栏 -->
      <block a:for="{{globalCar.carts}}">
        <view
          key="{{'car'+item.skuId}}"
          class="car-item-container"
        >
          <view
            class="goods-item-checkbox"
            data-skuId="{{item.skuId}}"
            data-status="{{item.status}}"
            data-checkedState="{{item.checkedState}}"
            onTap="handelItemCheck"
          >
            <am-checkbox ctrlChecked="{{item.checkedState === 'Y'}}" />
          </view>
          <view class="car-goods-item">
            <goods-item
              targetId="#carBottomEnd"
              goodsItem="{{item}}"
              defaultNum="{{item.quantity}}"
              onItemChange="handelItemChange"
              showStock="{{item.stockStatus === 'Y'}}"
              showAuto="{{utils.isShowAuto(globalCar)}}"
              showBooking="{{item.userLimitType === 'BESPEAK' && !item.isbespeak}}"
            ></goods-item>
          </view>
        </view>
      </block>
    </view>
    <!-- 商品页面 购物总价 底部 fixed按钮 -->
    <mall-footer-button
      a:if="{{showFlag && checkUtils.isOnlyDeliver(globalCar.carts)}}"
      selectNum="{{utils.getCheckedNum(globalCar.carts)}}"
      disCountTotalPrice="{{globalCar.disCountTotalPrice}}"
      totalPrice="{{globalCar.totalPrice}}"
      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 ? 'handelCreateOrder' : ''}}"
    />
    <mall-footer-button
      a:else
      selectNum="{{utils.getCheckedNum(globalCar.carts)}}"
      disCountTotalPrice="{{globalCar.disCountTotalPrice}}"
      totalPrice="{{globalCar.totalPrice}}"
      onConfirmClick="handelCreateOrder"
    />
  </popup-container>
  <!-- popup 选择结算商品 -->
  <popup-container
    show="{{ deliveryPopShow }}"
    title="选择结算商品"
    onClose="onClosePopup"
    backGroundColor="#f2f2f2"
    overFlow="unset"
  >
    <view
      class="choose-goods-header"
      slot="header"
    >选择结算商品
      <view class="choose-chancel-icon">
        <am-icon
          type="CloseOutline"
          size="15"
          onTap="cancelClick"
        />
      </view>
    </view>

    <view class="choose-goods-list">
      <deliver-card
        showFlag="{{showFlag}}"
        startDeliveryAmount="{{startDeliveryAmount}}"
        a:for="{{deliverTypeList}}"
        title="{{item.deliverType === 'SELF_PICK_UP_DELIVERY' ? '门店自提' : '发货速配'}}"
        item="{{item}}"
        itemIndex="{{index}}"
        isChecked="{{item.isChecked}}"
        onCheckBoxClick="onCheckBoxClick"
      />
    </view>
    <!-- 商品页面 购物总价 底部 fixed按钮 -->
    <mall-footer-button
      a:if="{{showFlag && deliverTypeList[itemIndex].deliverType === 'DELIVERY_LOGISTICS' }}"
      selectNum="{{utils.getCheckedNum(deliverTypeList[itemIndex].carts)}}"
      disCountTotalPrice="{{deliverTypeList[itemIndex].disCountTotalPrice || 0}}"
      totalPrice="{{deliverTypeList[itemIndex].totalPrice || 0}}"
      packingFee="{{deliverTypeList[itemIndex].packingFee || 0}}"
      item="{{deliverTypeList[itemIndex]}}"
      showColorCar="{{deliverTypeList[itemIndex].canOrder}}"
      onConfirmClick="{{deliverTypeList[itemIndex].canOrder ? 'gotoCreateOrder' : ''}}"
    />
    <mall-footer-button
      a:else
      selectNum="{{utils.getCheckedNum(deliverTypeList[itemIndex].carts)}}"
      packingFee="{{deliverTypeList[itemIndex].packingFee || 0}}"
      disCountTotalPrice="{{deliverTypeList[itemIndex].disCountTotalPrice || 0}}"
      totalPrice="{{deliverTypeList[itemIndex].totalPrice || 0}}"
      onConfirmClick="gotoCreateOrder"
      showColorCar="{{!!deliverTypeList[itemIndex]}}"
      item="{{deliverTypeList[itemIndex]}}"
    />
  </popup-container>
  <member-car-popup
    a:if="{{memberItem && memberPopUpShow}}"
    memberItem="{{memberItem}}"
    onBtnClick="handleMemberBtnClick"
    memberPopUpShow="{{memberPopUpShow}}"
    onPopClose="onMemberPopClose"
    text={{text}}
  />
</wrapper>
<view>
  <slot></slot>
</view>