<!--components/add_purchase/add_purchase.wxml-->
<wxs module="filters" src="../../utils/filter.wxs"></wxs>

<view class="add_purchase">
  <view  class="cover-layer"></view>
  <view class="spec-model">
    <view class="pding">
      <icon bindtap="closeSpecModal" class="modal-close" color="black" size="22" type="cancel"></icon>
      <view class="spec-goods">
        <image class="wh100 spec-img xc-distance-bottom" bindtap="previewImage" src="{{sele_g.original_img}}" binderror="pop_err_img" data-errorimg="sele_g.original_img"></image>
        <view class="spec-goods-info">
          <view class="spec-goods-name ellipsis-2">{{sele_g.goods_name}}</view>
          <view class="flex ai_end xc-val-money">
            <view class="spec-goods-price" wx:if="{{prom_price==null}}">
              <text class="fs20">￥</text>
              <!-- 如果是等级会员，且有等级价 -->
              <block wx:if="{{card_field && sele_g[card_field]>0}}">{{sele_g[card_field]}}</block>
              <block wx:else>{{sele_g.shop_price}}</block>
            </view>
            <view class="spec-goods-price" wx:else><text class="fs20">￥</text>{{prom_price}}</view>
            <!-- <view class="spec-goods-price" wx:elif="{{prom_type!=2}}"><text class="fs20">￥</text>{{prom_price}}</view> -->
            <!-- 显示线下价格 -->
            <view wx:if="{{sele_g.offline_price}}" class="quan_price flex ai-center jc-center">
              券后￥
              <text class="fs32">{{sele_g.offline_price}}</text>
            </view>
          </view>

          <block wx:if="{{prom_type==0}}">
            <view class="flex">
              <view class="spec-goods-stock">已售：{{sele_g.sales_sum}}</view>
              <!-- 线下门店销售的时候 -->
              <block wx:if="{{sales_rules>=2}}">

                <!-- 如果不是虚拟商品的时候 -->
                <block wx:if="{{!filters.is_virtual_gd(sele_g.is_virtual)}}">
                  <view class="spec-goods-stock" wx:if="{{def_pick_store && def_pick_store.CanOutQty}}">
                    可售：{{def_pick_store.CanOutQty}}
                  </view>
                  <view class="spec-goods-stock" wx:else>可售:0</view>
                </block>

              </block>

              <block wx:else>
                <view class="spec-goods-stock">可售：{{sele_g.store_count}}</view>
              </block>
            </view>
          </block>
          <block wx:if="{{prom_type==1}}">
            <view class="flex">
              <view class="spec-goods-stock" wx:if="{{prom_st>0}}">
                已售：{{prom_act.buy_num+prom_act.virtual}}
              </view>
              <view class="spec-goods-stock" wx:else>已售：{{prom_act.buy_num}}</view>
              <view class="spec-goods-stock">可售：{{(prom_act.is_virtual_count && prom_act.virtual) ? (prom_act.goods_num - prom_act.buy_num - prom_act.virtual) : (prom_act.goods_num-prom_act.buy_num)}}</view>
            </view>
          </block>
          <block wx:if="{{prom_type==2}}">
            <view class="flex">
              <view class="spec-goods-stock" wx:if="{{prom_st>0}}">
                已售：{{prom_act.buy_num+prom_act.virtualNum}}
              </view>
              <view class="spec-goods-stock" wx:else>已售：{{prom_act.buy_num}}</view>
              <view class="spec-goods-stock">可售：{{prom_act.goods_num-prom_act.buy_num}}</view>
            </view>
          </block>
        </view>
        <!-- 选择门店模块 -->
        <view class="flex-space-between address ai_end xc-width ">
          <view class="flex" wx:if="{{def_pick_store && def_pick_store.pickup_name}}">
            <text class="fs30 xc-black3 shop_name bold  {{def_pick_store.distance!=null?'max':''}} ">{{def_pick_store.pickup_name}}</text>
            <view class="distance fs24 xc-ash" wx:if="{{def_pick_store.distance!=null}}">
              距离:{{def_pick_store.distance>1000?filters.toFix(def_pick_store.distance/1000,2)+"km":filters.toFix(def_pick_store.distance,0)+"m"}}
            </view>
          </view>
          <!-- 没有门店的时候 -->
          <view class="flex" bindtap="choice_store" wx:else>
            <image class="stores-img" src="{{iurl}}/miniapp/images/stores.png"></image>
            <view class="fs30" style="color:black;">选择门店</view>
          </view>
          <view hidden="{{has_def && sys_switch.is_pricing_open_store}}" class="red-co fs28" bindtap="choice_store">更多门店<text class="right-arrow"></text></view>
        </view>
        <view wx:if="{{only_pk && !only_pk.length}}">(库存不足)</view>
        <block wx:else>
          <view wx:if="{{def_pickpu_list && !def_pickpu_list.length}}">(库存不足)</view>
          <block wx:else>
            <view class="no_store" wx:if="{{def_pick_store.is_no_dis}}">(配送不匹配)</view>

            <view class="no_store" wx:elif="{{def_pick_store.is_no_dis_nor}}">(该店不可售)</view>
            <view class="no_store" wx:elif="{{def_pick_store.is_no_dis_nor && is_normal}}">(该店不可售)</view>
            <view class="no_store" wx:elif="{{def_pick_store.is_no_dis_act && !is_normal}}">(该店不可售)</view>
            <view wx:elif="{{def_pick_store && !def_pick_store.CanOutQty && !filters.is_virtual_gd(sele_g.is_virtual) && sales_rules>=2 && prom_type==0 &&!sele_g.whsle_id }}">
              (库存不足)
            </view>
          </block>
        </block>
        <view class="fs24 xc-ash-9f xc-distance-top " wx:if="{{def_pick_store && def_pick_store.fulladdress}}">
          地址:{{def_pick_store.fulladdress}}
        </view>
      </view>
      <!-- 商品的属性项目 -->
      <view class="xc-goods-attribute" wx:if="{{goods_type ==1}}">
          <view class="spec-name" style="padding: 0;"></view>
          <view  style="max-height: 120rpx;overflow-y: auto;"></view>
        </view>
      <view class="xc-goods-attribute" wx:else>
        <view hidden="{{ismend==1}}" class="spec-name">商品规格</view>
        <view hidden="{{ismend==1}}" style="max-height: 120rpx;overflow-y: auto;">

          <block wx:if="{{sku_g_pt}}">
            <view class="spec_bt {{gid==item.goods_id?'act':''}}" bindtap="sele_spec" data-gid='{{item.goods_id}}' wx:for="{{sku_g_pt}}" wx:key="sku_g">
              {{item.gg}}
            </view>
          </block>
          <block wx:else>
            <view class="spec_bt {{gid==item.goods_id?'act':''}}" bindtap="sele_spec" data-gid='{{item.goods_id}}' wx:for="{{sku_g}}" wx:key="sku_g">
              {{item.gg}}
            </view>
          </block>
        </view>
      </view>
      <view class="b_num">
        <view>购买数量</view>
        <view class="count">
          <view bindtap="{{goodsInputNum <= 1 ? '': (goods_type==1 ? 'subCartNumser' : 'subCartNum')}}" class="sub {{goodsInputNum <= 1 ? 'active':''}}">
            -
          </view>
          <input bindblur="{{goods_type==1 ? 'inputCartNumser' : 'inputCartNum'}}" type="number" value="{{goodsInputNum}}"></input>
          <view bindtap="{{goods_type==1 ? 'addCartNumser' : 'addCartNum'}}" class="add">+</view>
        </view>
      </view>
      <!-- 提示再买多少优惠 -->
      <view style="margin-top: 35rpx;color:#333;font-size:28rpx;" wx:if="{{hui_condition && openSpecModal_ind==2 && (!hui_condition.limit_num || user_pre_buynum<hui_condition.limit_num)}}">
        再买{{hui_condition.need}}
        <text wx:if="{{hui_condition.money}}">，免{{hui_condition.money}}元</text>
        <text wx:if="{{hui_condition.sale}}">，打{{hui_condition.sale}}折</text>
        <text wx:if="{{hui_condition.past==1}}">，包邮</text>
        <text wx:if="{{hui_condition.intValue>0}}">，送{{hui_condition.intValue}}积分</text>
        <text wx:if="{{hui_condition.couponId>0}}">，送优惠券</text>
        <text wx:if="{{hui_condition.gift_id}}">，送赠品</text>
        <text wx:if="{{hui_condition.lb_id>0}}">，送礼包</text>
        <text wx:if="{{hui_condition.zxlb_id>0}}">，送专享礼包</text>
        <text wx:if="{{hui_condition.monthgiftbag_id>0}}">，送每月礼包</text>
      </view>
    </view>

    <!-- 底部处理按钮 -->
    <view class="spec-cart-btns">
      <view wx:if="{{def_pick_store && def_pick_store.is_no_dis}}" class="spec-cart-btn fs32" data-action="add" style="background-color: #dcdcdc;color: #999;">
        配送不匹配
      </view>
      <view wx:elif="{{def_pick_store && def_pick_store.is_no_dis_nor}}" class="spec-cart-btn fs32" data-action="add" style="background-color: #dcdcdc;color: #999;">
        该店不可售
      </view>
      <view wx:elif="{{def_pick_store && def_pick_store.is_no_dis_nor && is_normal}}" class="spec-cart-btn fs32" data-action="add" style="background-color: #dcdcdc;color: #999;">
        该店不可售
      </view>
      <view wx:elif="{{def_pick_store && def_pick_store.is_no_dis_act && !is_normal}}" class="spec-cart-btn fs32" data-action="add" style="background-color: #dcdcdc;color: #999;">
        该店不可售
      </view>
      <block wx:else>
        <!-- 根本就找不到门店 -->
        <block wx:if="{{!only_pk && !def_pickpu_list}}">
          <view class="spec-cart-btn fs32" data-action="add" style="background-color: #dcdcdc;color: #999;">
            库存不足
          </view>
        </block>
        <block wx:else>
          <block wx:if="{{only_pk && !only_pk.length}}">
            <view class="spec-cart-btn fs32" data-action="add" style="background-color: #dcdcdc;color: #999;">
              库存不足
            </view>
          </block>
          <block wx:else>
            <block wx:if="{{def_pickpu_list && !def_pickpu_list.length}}">
              <view class="spec-cart-btn fs32" data-action="add" style="background-color: #dcdcdc;color: #999">
                库存不足
              </view>
            </block>
            <block wx:else>
              <block wx:if="{{!def_pick_store}}">
                <view class="spec-cart-btn fs32" data-action="add" style="background-color: #dcdcdc;color: #999">
                  请先选择门店
                </view>
              </block>
              <block wx:else>

                <!-- 如果是线下库存购买的时候,且是普通商品购买的时候 -->
                <block wx:if="{{sales_rules>=2 && prom_type==0 && !sele_g.whsle_id}}">

                  <block wx:if="{{!def_pick_store.CanOutQty || def_pick_store.CanOutQty<1 }}">
                    <view class="spec-cart-btn fs32" data-action="add" style="background-color: #dcdcdc;color: #999">
                      库存不足
                    </view>
                  </block>
                  <block wx:else>
                    <view wx:if="{{openSpecModal_ind==1}}" bindtap="{{(goods_type==1 ? 'addCartSer' : 'addCart' )}}" data-openSpecModal_ind="{{openSpecModal_ind}}" class="spec-cart-btn yellow {{sp_seleing?'gray':''}}" data-action="add">
                      加入购物车
                    </view>
                    <view wx:if="{{openSpecModal_ind==2}}" bindtap="{{(goods_type==1 ? 'addCartSer' : 'addCart' )}}" data-openSpecModal_ind="{{openSpecModal_ind}}" class="spec-cart-btn spec-buy {{sp_seleing?'gray':''}}" data-action="buy">
                      {{sele_g.offline_price?"券后购买":"立即购买"}}
                    </view>
                  </block>
                </block>
                <!-- 线上销售 -->
                <block wx:else>

                  <block wx:if="{{prom_type==1  && !is_normal && pro_null}}">
                    <view class="spec-cart-btn fs32" data-action="add" style="background-color: #dcdcdc;color: #999">
                      已抢光
                    </view>
                  </block>
                  <block wx:elif="{{ sele_g.store_count<1  && is_no_new}}">
                    <view class="spec-cart-btn fs32" data-action="add" style="background-color: #dcdcdc;color: #999">
                      库存不足
                    </view>
                  </block>
                  <block wx:else>
                    <view wx:if="{{openSpecModal_ind==1}}" bindtap="{{(goods_type==1 ? 'addCartSer' : 'addCart' )}}" data-openSpecModal_ind="{{openSpecModal_ind}}" class="spec-cart-btn yellow {{sp_seleing?'gray':''}}" data-action="add">
                      加入购物车
                    </view>
                    <view wx:if="{{openSpecModal_ind==2}}" bindtap="{{(goods_type==1 ? 'addCartSer' : 'addCart' )}}" data-openSpecModal_ind="{{openSpecModal_ind}}" class="spec-cart-btn spec-buy {{sp_seleing?'gray':''}}" data-action="buy">
                      {{sele_g.offline_price?"券后购买":"立即购买"}}
                    </view>
                  </block>
                </block>
              </block>
            </block>
          </block>
        </block>
      </block>
    </view>
    <view class="clear"></view>
    <!-- 选择门店的列表 -->
    <view hidden="{{ismend==0}}" class="sto_v">
      <view class="title" hidden="{{is_sec_mend==1}}" bindtap="hidemend">
        <image class="tubiao" src="{{iurl}}/miniapp/images/icon-left.png"></image>
        选择门店
      </view>
      <!-- ---第一级显示---- -->
      <view class="itemlists" hidden="{{is_sec_mend==1}}">
        <block wx:if="{{is_show_sto_cat}}">
          <view wx:for="{{all_sto}}" wx:key="all_sto" class="item" bindtap="show_sec" data-index="{{index}}">
            {{item.name}}
          </view>
        </block>
        <block wx:else>
          <view wx:for="{{only_pk}}" wx:key="only_pk" class="item" bindtap="hidemend" data-p_id="{{item.pickup_id}}" data-p_name="{{item.pickup_name}}" data-p_dis="{{item.distr_type}}">
            {{item.pickup_name}}
          </view>
        </block>
      </view>
      <!-- ---第二级显示---- -->
      <view class="stitle" hidden="{{is_sec_mend==0}}" bindtap="hide_sec_mend">
        <image class="tubiao" src="{{iurl}}/miniapp/images/icon-left.png"></image>
        {{sec_sto.name}}
      </view>
      <view class="itemlists" hidden="{{is_sec_mend==0}}">
        <view wx:for="{{sec_sto.s_arr}}" wx:key="index" class="item" bindtap="hidemend" data-p_id="{{item.pickup_id}}" data-p_name="{{item.pickup_name}}" data-p_dis="{{item.distr_type}}">
          {{item.pickup_name}}
        </view>
      </view>
    </view>
  </view>

</view>
<!-- 选择门店的弹框，1.1版最新的 -->
<block wx:if="{{store==1}}">
  <view class="mongolia-layer" bindtap="close_popup"></view>
  <view class="popup-frame">
    <block wx:if="{{sort_store==0}}">
      <!-- 头部 标题 -->
      <view class="popup-top flex-space-between">
        <text class="fs32 nearby_store">{{choice_sort_store==0?'附近的门店':region_name}}</text>
        <view>
          <view>
            <icon bindtap="close_popup" class="modal-closes" color="black" size="22" type="cancel"></icon>
          </view>
          <view class="felx choose_more" bindtap="more_store" wx:if="{{is_show_sto_cat>0}}">
            <text class="fs26 red-co">{{choice_sort_store==0?'更多门店':'返回'}}</text>
            <view class="bg_rights"></view>
          </view>
        </view>
      </view>
      <view class="searchbar flex-vertical-between storeListpadd">
        <input class="inputstore fs28" placeholder="输入要搜索的门店" value="{{keyword}}" placeholder-class="fs28" maxlength="16" bindinput="input_store" bindconfirm="searchfn" />
        <view class="search flex-center" bindtap="searchfn">
          <view class="fs28">搜索</view>
        </view>
      </view>
      <!-- 门店列表，最外层的门店列表，一开始 -->
      <view class="store-list">
        <!-- 如果还没有点击更多门店的时候 -->
        <block wx:if="{{choice_sort_store==0}}">
          <!-- 需要for循环 -->
          <block wx:if="{{is_show_sto_cat==1}}">
            <view class="store_choose flex" wx:for="{{def_pickpu_list}}" bindtap="choose_for_store_fir" data-ind="{{index}}">
              <view class="store flex-vertical">
                <!-- 需要点击事件 -->
                <block wx:if="{{index==fir_pick_index}}">
                  <view class="circle white xc-hook fs20 red-b">Г</view>
                </block>
                <block wx:else>
                  <view class="circle  xc-hooks"></view>
                </block>
                <view class="address-frame xc-ash">
                  <view class="flex-vertical-between butttem5">
                    <view class="flex xc-ash">
                      <view class="fs30 xc-black3 address_name">{{item.pickup_name}}
                        <text class="c-red22" wx:if="{{item.is_no_qyt}}">(库存不足)</text>
                        <text class="c-red22" wx:elif="{{item.is_no_dis}}">(配送不匹配)</text>
                        <text class="c-red22" wx:elif="{{item.is_no_dis_nor}}">(该店不可售)</text>
                        <text class="c-red22" wx:elif="{{item.is_no_dis_nor && is_normal}}">(该店不可售)</text>
                        <text class="c-red22" wx:elif="{{item.is_no_dis_act && !is_normal}}">(该店不可售)</text>
                      </view>
                    </view>
                    <view>
                      <view class="distance fs24 address-val" wx:if="{{item.distance!=null}}">
                        距离：{{item.distance>1000?filters.toFix(item.distance/1000,2)+'km':filters.toFix(item.distance,0)+"m"}}
                      </view>
                    </view>
                  </view>
                  <view class="fs24 xc-ash-9f">地址:{{item.fulladdress}}</view>
                </view>
              </view>
            </view>
          </block>
          <block wx:else>
            <view class="store_choose flex" wx:for="{{only_pk}}" bindtap="choose_for_store_fir" data-ind="{{index}}">
              <view class="store flex-vertical">
                <!-- 需要点击事件 -->
                <block wx:if="{{index==fir_pick_index}}">
                  <view class="circle white xc-hook fs20 red-b">Г</view>
                </block>
                <block wx:else>
                  <view class="circle  xc-hooks"></view>
                </block>
                <view class="address-frame xc-ash">
                  <view class="flex-vertical-between ">
                    <view class="flex xc-ash">
                      <view class="fs30 xc-black3 address_name">{{item.pickup_name}}
                        <text class="c-red22" wx:if="{{item.is_no_dis}}">(配送不匹配)</text>
                        <text class="c-red22" wx:elif="{{item.is_no_dis_nor}}">(该店不可售)</text>
                        <text class="c-red22" wx:elif="{{item.is_no_dis_nor && is_normal}}">(该店不可售)</text>
                        <text class="c-red22" wx:elif="{{item.is_no_dis_act && !is_normal}}">(该店不可售)</text>
                        <text class="c-red22" wx:elif="{{item.is_no_qyt }}">(库存不足)</text>
                      </view>
                    </view>
                    <view>
                      <view class="distance fs24 address-val" wx:if="{{item.distance!=null}}">
                        距离：{{item.distance>1000?filters.toFix(item.distance/1000,2)+"km":filters.toFix(item.distance,0)+"m"}}
                      </view>
                    </view>
                  </view>
                  <view class="fs24 xc-ash-9f">地址:{{item.fulladdress}}</view>
                </view>
              </view>
            </view>
          </block>
        </block>
        <block wx:else>
          <!-- 如果是点击选择门店分类后显示分类下的门店 -->
          <view class="store_choose flex" wx:for="{{sec_sto.s_arr}}" data-ind="{{index}}" bindtap="choose_for_store">
            <view class="store flex-vertical">
              <!-- 需要点击事件 -->
              <block wx:if="{{index==sec_pick_index}}">
                <view class="circle white xc-hook fs20 red-b">Г</view>
              </block>
              <block wx:else>
                <view class="circle  xc-hooks"></view>
              </block>
              <view class="address-frame xc-ash">
                <view class="flex-vertical-between ">
                  <view class="flex xc-ash">
                    <view class="fs28 xc-black3 address_name">{{item.pickup_name}}
                      <text class="c-red22" wx:if="{{item.is_no_qyt}}">(库存不足)</text>
                    </view>
                  </view>
                  <view>
                    <view class="distance fs24 address-val" wx:if="{{item.distance!=null}}">
                      距离：{{item.distance>1000?filters.toFix(item.distance/1000,2)+"km":filters.toFix(item.distance,0)+"m"}}
                    </view>
                  </view>
                </view>
                <view class="fs24 xc-ash-9f">地址:{{item.fulladdress}}</view>
              </view>
            </view>
          </view>
        </block>
      </view>
      <!-- 门店列表底部 -->
      <view class="store-bottom-frame">
        <view class="store-bottom flex-vertical-between">
          <view class="determine red-b fs28 white t-c" bindtap="sure_pick" data-openindstore="{{open_ind_store}}">
            确定
          </view>
          <view class="default  t-c fs28" bindtap="set_def_pick" data-openindstore="{{open_ind_store}}">
            设为默认
          </view>
        </view>
      </view>
    </block>
    <block wx:else>
      <view class="popup-top flex-space-between">
        <text class="fs32 nearby_store">门店分类选择</text>
        <view>
          <view>
            <icon bindtap="close_popup" class="modal-closes" color="black" size="22" type="cancel"></icon>
          </view>
          <view class="felx choose_mores" bindtap="returns">
            <text class="fs26 red-co">返回</text>
          </view>
        </view>
      </view>
      <view class="sort_store_list">
        <view class="sort-store-frame" wx:for="{{all_sto}}" data-index="{{index}}" bindtap="choice_sort_store" data-region="{{item.name}}">
          <view class="sort-store flex-vertical-between">
            <view class="fs30" di>{{item.name}}</view>
            <view class="black_rights-frame">
              <view class="black_rights"></view>
            </view>
          </view>
        </view>
      </view>
    </block>
  </view>
</block>


<warn id="warn"></warn> 