{{:ModuleInclude('public/header')}}

{{if empty($goods)}}
    {{:ModuleInclude('public/not_data')}}
{{else /}}
    <form class="am-form form-validation am-form-popup-fixed" method="post" action="{{:MyUrl('index/cart/save')}}" request-type="ajax-fun" request-value="GoodsCartInfoSubmitBack">
        <div class="goods-spec-container am-padding-sm">
            <h2>
                <img src="{{$goods.images}}" width="24" height="24" class="am-radius" />
                <span class="am-margin-left-xs">{{$goods.title}}</span>
            </h2>
            <hr data-am-widget="divider" class="am-divider am-divider-default" />
            {{if $goods.inventory gt 0}}
                {{if $goods.inventory egt $goods.buy_min_number}}
                    <div class="goods-spec-content" data-id="{{$goods.id}}">
                        {{if !empty($goods['specifications']['choose'])}}
                            {{foreach $goods.specifications.choose as $key=>$spec}}
                                {{if !empty($spec['value'])}}
                                    <div class="spec-options sku-items am-radius">
                                        <div class="spec-title">{{$spec.name}}</div>
                                        <ul>
                                            {{foreach $spec.value as $keys=>$specs}}
                                                <li class="am-radius sku-line {{if !empty($specs['images'])}} sku-line-images{{/if}} {{if $key gt 0}} sku-dont-choose{{/if}} {{if isset($specs['is_only_level_one']) and isset($specs['inventory']) and $specs['inventory'] elt 0}} sku-items-disabled{{/if}}" data-type-value="{{$spec.name}}" data-value="{{$specs.name}}" {{if !empty($specs['images'])}} data-type-images="{{$specs.images}}"{{/if}}>
                                                    {{if !empty($specs['images'])}}
                                                        <img src="{{$specs.images}}" class="am-radius" />
                                                    {{/if}}
                                                    <span>{{$specs.name}}</span>
                                                </li>
                                            {{/foreach}}
                                        </ul>
                                    </div>
                                {{/if}}
                            {{/foreach}}
                        {{/if}}
                        <div class="spec-options">
                            <div class="spec-title">{{:MyLang('goods_sales_price_title')}}</div>
                            <div class="am-margin-top-xs am-margin-bottom-sm">
                                <strong class="price am-text-lg" data-default-price="{{$goods.price}}" data-is-clearout="0">{{$goods.show_price_symbol}}{{$goods.price}}</strong>
                                {{if !empty($goods['original_price']) and $goods['original_price'] gt 0}}
                                    <span class="am-margin-left-sm original-price" data-default-price="{{$goods.original_price}}" data-price="{{$goods.original_price}}">{{$goods.show_price_symbol}}{{$goods.original_price}}</span>
                                {{/if}}
                            </div>
                        </div>

                        <div class="spec-options am-margin-top-sm">
                            <div class="am-input-group am-input-group-sm number-operate">
                                <span class="am-input-group-label am-radius stock-submit" data-type="min">-</span>
                                <input type="number" name="stock" class="am-form-field am-text-center" value="{{$goods.buy_min_number}}" min="{{$goods.buy_min_number}}" max="{{if empty($goods['buy_max_number'])}}{{$goods.inventory}}{{else /}}{{$goods.buy_max_number}}{{/if}}" data-original-buy-min-number="{{$goods.buy_min_number}}" data-original-buy-max-number="{{$goods.buy_max_number}}" data-is-clearout="0" />
                                <span class="am-input-group-label am-radius stock-submit" data-type="add">+</span>
                            </div>
                            <div class="am-margin-top-xs stock-tips">
                                <span>{{:MyLang('inventory_title')}}</span>
                                <span class="stock" data-original-max="{{if empty($goods['buy_max_number'])}}{{$goods.inventory}}{{else /}}{{$goods.buy_max_number}}{{/if}}" data-original-inventory="{{$goods.inventory}}" data-min-limit="{{$goods.buy_min_number}}" data-max-limit="{{$goods.buy_max_number}}">{{$goods.inventory}}</span>
                                <span class="unit" data-value="{{$goods.inventory_unit}}">{{$goods.inventory_unit}}</span>
                            </div>
                        </div>
                    </div>
                {{else /}}
                    <p class="am-text-danger error-msg">{{:MyLang('goods_inventory_insufficient_min_number_tips')}}({{$goods.inventory}}<{{$goods.buy_min_number}})</p>
                {{/if}}
            {{else /}}
                <p class="am-text-danger">{{:MyLang('goods_no_inventory_title')}}</p>
            {{/if}}
        </div>

        <div class="am-form-popup-submit">
            <input type="hidden" name="goods_id" value="{{$goods.id}}" />
            <input type="hidden" name="spec" value="" />
            <button type="button" class="am-btn am-btn-warning am-radius am-btn-xs" data-am-modal-close>
                <i class="am-icon-paint-brush"></i>
                <span>{{:MyLang('cancel_title')}}</span>
            </button>
            {{if empty($user) or $buy_button['is_cart'] eq 0}}
                <button type="submit" class="am-btn am-btn-primary am-radius am-btn-xs btn-loading-example" disabled>
                    <i class="am-icon-opencart"></i>
                    <span>{{if empty($user)}}{{:MyLang('user_no_login_tips')}}{{else /}}{{if empty($buy_button['error'])}}{{:MyLang('goods_stop_sale_title')}}{{else /}}{{$buy_button.error}}{{/if}}{{/if}}</span>
                </button>
            {{else /}}
                <button type="submit" class="am-btn am-btn-primary am-radius am-btn-xs btn-loading-example" data-am-loading="{spinner: 'circle-o-notch', loadingText:'{{:MyLang('goods_cart_title')}}'}">
                    <i class="am-icon-opencart"></i>
                    <span>{{:MyLang('goods_cart_title')}}</span>
                </button>
            {{/if}}
        </div>
    </form>
{{/if}}

{{:ModuleInclude('public/footer')}}
<script type="text/javascript">
// 购物车回调
function GoodsCartInfoSubmitBack(e)
{
    $.AMUI.progress.done();
    if(e.code == 0)
    {
        Prompt(e.msg, 'success');
        setTimeout(function()
        {
            parent.IframePopupHomeCartNumberTotalUpdate(e.data.buy_number, '.common-goods-cart-popup');
        }, 1500);
    } else {
        Prompt(e.msg);
        $('form.form-validation').find('button[type="submit"]').button('reset');
    }
}
</script>