{{include file="public/header" /}}

<!-- header top nav -->
{{include file="public/header_top_nav" /}}

<!-- search -->
{{include file="public/nav_search" /}}

<!-- header nav -->
{{include file="public/header_nav" /}}

<!-- goods category -->
{{include file="public/goods_category" /}}

<!-- content -->
<div class="am-container">
    <!-- 地址 -->
    <div class="link-list">
        <div class="address">
            <div class="control">
                <h3>确认收货地址</h3>
                {{if !empty($user_address_list)}}
                    <button class="am-btn am-btn-primary am-btn-xs address-submit-save" type="button" data-url="{{:MyUrl('index/useraddress/saveinfo')}}" data-popup-title="新增地址">使用新地址</button>
                {{/if}}
            </div>
            {{if !empty($user_address_list)}}
                <ul class="address-list">
                    {{foreach $user_address_list as $address}}
                        <li class="{{if isset($address['is_default']) and $address['is_default'] eq 1}}address-default{{/if}}" id="data-list-{{$address.id}}" data-value="{{$address.id}}">
                            <div class="address-left">
                                <div class="user-base">
                                    {{if !empty($address.alias)}}
                                        <span class="am-badge am-badge-danger am-radius">{{$address.alias}}</span>
                                    {{/if}}
                                    {{if isset($address['is_default']) and $address['is_default'] eq 1}}
                                        <span class="am-badge am-badge-success am-radius">默认</span>
                                    {{/if}}
                                    <span class="address-detail">   
                                        <span class="user">{{$address.name}}</span>
                                        <span class="phone">{{$address.tel}}</span>
                                    </span>
                                </div>
                                <div class="region">
                                    <span class="province">{{$address.province_name}}</span>
                                    <span class="city">{{$address.city_name}}</span>
                                    <span class="dist">{{$address.county_name}}</span>
                                    <span class="street">{{$address.address}}</span>
                                </div>
                            </div>
                            <div class="address-right">
                                <span class="am-icon-angle-right am-icon-md"></span>
                            </div>
                            <div class="address-operation-btn">
                                <a href="javascript:;" class="am-icon-check-circle-o address-default-submit" data-url="{{:MyUrl('index/useraddress/setdefault')}}" data-id="{{$address.id}}" data-view="reload"> 设为默认</a>
                                <span class="cut">|</span>
                                <a href="javascript:;" class="am-icon-edit address-submit-save" data-url="{{:MyUrl('index/useraddress/saveinfo', ['id'=>$address['id']])}}" data-popup-title="编辑地址"> 编辑</a>
                                <span class="cut">|</span>
                                <a href="javascript:;" class="am-icon-trash-o address-submit-delete" data-url="{{:MyUrl('index/useraddress/delete')}}" data-id="{{$address.id}}"> 删除</a>
                            </div>
                        </li>
                    {{/foreach}}
                </ul>
            {{/if}}
            {{if empty($user_address_list)}}
                <div class="table-no">
                    <i class="am-icon-warning"></i>
                    没有地址
                    <button class="am-btn am-btn-secondary am-btn-xs address-submit-save" type="button" data-url="{{:MyUrl('index/useraddress/saveinfo')}}" data-popup-title="新增地址">使用新地址</button></div>
            {{/if}}
        </div>

        <!-- 支付方式 -->
        <div class="business-item payment" data-type="payment">
            <h3>选择支付</h3>
            {{if !empty($payment_list)}}
                <ul class="payment-list">
                    {{foreach $payment_list as $payment}}
                        <li data-value="{{$payment.id}}">
                            {{if !empty($payment.logo)}}
                                <img src="{{$payment.logo}}" />
                            {{/if}}
                            <span>{{$payment.name}}</span>
                            <i class="icon-active"></i>
                        </li>
                    {{/foreach}}
                </ul>
            {{/if}}
            {{if empty($payment_list)}}
                <div class="table-no"><i class="am-icon-warning"></i> 没有支付方式</div>
            {{/if}}
        </div>

        <!-- 商品列表 -->
        <div class="order-detail">
            <div class="goods-table">
                <h3>确认订单信息</h3>
                <!-- 商品列表 -->
                {{if !empty($goods_list)}}
                    <table class="am-table">
                        <thead>
                            <tr>
                                <th>商品信息</th>
                                <th class="am-hide-sm-only">单价</th>
                                <th class="am-hide-sm-only">数量</th>
                                <th class="am-hide-sm-only">金额</th>
                            </tr>
                        </thead>
                        <tbody>
                            {{foreach $goods_list as $goods}}
                                <tr id="data-list-{{$goods.id}}" data-id="{{$goods.id}}" data-goods-id="{{$goods.goods_id}}">
                                    <td class="base">
                                        <div class="goods-detail">
                                            <a href="{{$goods.goods_url}}" target="_blank">
                                                <img src="{{$goods.images}}">
                                            </a>
                                            <div class="goods-base">
                                                <a href="{{$goods.goods_url}}" target="_blank" class="goods-title">{{$goods.title}}</a>
                                                {{if !empty($goods.spec)}}
                                                    <ul class="goods-attr">
                                                        {{foreach $goods.spec as $spec}}
                                                            <li>{{$spec.type}}：{{$spec.value}}</li>
                                                        {{/foreach}}
                                                    </ul>
                                                {{/if}}
                                            </div>
                                        </div>
                                        <div class="wap-base am-show-sm-only">
                                            {{if $goods['original_price'] gt 0}}
                                                <span class="original-price">￥{{$goods.original_price}}</span>
                                            {{/if}}
                                            <strong class="total-price-content">￥{{$goods.price}}</strong>
                                            <span class="wap-number">x{{$goods.stock}}</span>
                                        </div>
                                    </td>
                                    <td class="price am-hide-sm-only">
                                        {{if $goods['original_price'] gt 0}}
                                            <p class="original-price">￥{{$goods.original_price}}</p>
                                        {{/if}}
                                        <p class="line-price">￥{{$goods.price}}</p>
                                    </td>
                                    <td class="number am-hide-sm-only">
                                        {{$goods.stock}} {{$goods.inventory_unit}}
                                    </td>
                                    <td class="total-price am-hide-sm-only">
                                        <strong class="total-price-content">￥{{$goods.total_price}}</strong>
                                    </td>
                                </tr>
                            {{/foreach}}
                        </tbody>
                    </table>
                {{/if}}
                {{if empty($goods_list)}}
                    <div class="table-no"><i class="am-icon-warning"></i> 没有商品</div>
                {{/if}}

                <!-- 留言 -->
                <div class="buy-message">
                    <div class="order-extra">
                        <div class="order-user-info">
                            <div class="memo">
                                <label>买家留言：</label>
                                <input type="text" title="选填,对本次交易的说明（建议填写已经和卖家达成一致的说明）" placeholder="选填,建议填写和卖家达成一致的说明" class="memo-input">
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 含运费小计 -->
                <div class="buy-point-discharge">
                    <p>
                        合计（含运费） <span>¥</span><em class="pay-sum">{{$base.total_price}}</em>
                    </p>
                </div>

                <!-- 信息 -->
                <div class="order-nav">
                    <div class="pay-confirm">
                        <div class="box">
                            <div class="base-real-pay">
                                <em>实付款：</em>
                                <span class="price">
                                    <span>¥</span>
                                    <em class="nav-total-price">{{$base.total_price}}</em>
                                </span>
                            </div>

                            <div class="pay-address">
                                <div class="buy-footer-address">
                                    <span class="buy-line-title buy-line-title-type">寄送至：</span>
                                    <span class="buy-address-detail">
                                        {{if !empty($base['address'])}}
                                            {{$base.address.province_name}} {{$base.address.city_name}} {{$base.address.county_name}} {{$base.address.address}}
                                        {{else /}}
                                            ...
                                        {{/if}}
                                    </span>
                                </div>
                                <div class="buy-footer-address">
                                    <span class="buy-line-title">收货人：</span> 
                                    <span class="buy-user">
                                        {{if !empty($base['address'])}}
                                            {{$base.address.name}}
                                        {{else /}}
                                            ...
                                        {{/if}}
                                    </span>
                                    <span class="buy-phone">
                                        {{if !empty($base['address'])}}
                                            {{$base.address.tel}}
                                        {{else /}}
                                            ...
                                        {{/if}}
                                    </span>
                                </div>
                            </div>
                        </div>
                        <form class="am-form form-validation nav-buy" action="{{:MyUrl('index/buy/add')}}" method="post" class="nav-buy" request-type="ajax-fun" request-value="BuySubmitBack">
                            <input type="hidden" name="goods_id" value="{{if isset($params['goods_id'])}}{{$params.goods_id}}{{else /}}0{{/if}}" />
                            <input type="hidden" name="buy_type" value="{{if isset($params['buy_type'])}}{{$params.buy_type}}{{else /}}goods{{/if}}" />
                            <input type="hidden" name="stock" value="{{if isset($params['stock'])}}{{$params.stock}}{{else /}}1{{/if}}" />
                            <input type="hidden" name="spec" value='{{if isset($params['spec'])}}{{$params.spec}}{{/if}}' />
                            <input type="hidden" name="ids" value="{{if isset($params['ids'])}}{{$params.ids}}{{/if}}" />
                            <input type="hidden" name="address_id" value="0" />
                            <input type="hidden" name="payment_id" value="0" />
                            <input type="hidden" name="user_note" value="" />
                            <div class="go-btn-wrap">
                                <button type="submit" class="btn-go btn-loading-example" title="点击此按钮，提交订单" data-am-loading="{loadingText:'处理中...'}">提交订单</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- footer start -->
{{include file="public/footer" /}}
<!-- footer end -->

<script type="text/javascript">
// 提交订单回调
function BuySubmitBack(e)
{
    if(e.code == 0)
    {
        $.AMUI.progress.done();
        if($(window).width() < 640)
        {
            PromptBottom(e.msg, 'success', null, 50);
        } else {
            PromptCenter(e.msg, 'success');
        }
        setTimeout(function()
        {
            window.location.href = e.data.jump_url;
        }, 1500);
    } else {
        $('form.form-validation').find('button[type="submit"]').button('reset');
        $.AMUI.progress.done();
        if($(window).width() < 640)
        {
            PromptBottom(e.msg, null, null, 50);
        } else {
            PromptCenter(e.msg);
        }
    }
}
</script>