<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>${metadata.alias!}</title>
</head>
<body>
    <header data-diy="page">
        <h1>${(site.name)!}</h1>
    </header>
    <nav data-diy="category">
        <a href="${site.dynamicPath}">Home</a>
<@cms.categoryList>
    <#list page.list as a>
        <a href="${a.url!}" target="_blank" data-diy-item="${a.id}">${a.name}</a>
    </#list>
</@cms.categoryList>
    </nav>
    <main>
        <#macro message code>${springMacroRequestContext.getMessage(code)}</#macro>
        <#if orderId?has_content>
            <@trade.order id=orderId>
                <p><label>Status:</label>:<@message 'page.status.order.'+object.status/></p>
                <p><label>Confirmed:</label>:${object.confirmed?then('Yes','No')}</p>
                <p><label>Processed:</label>:${object.processed?then('Yes','No')}</p>
                <p><label>Shipping address::</label>${object.address!}</p>
                <p><label>Receiver:</label>:${object.addressee!}</p>
                <p><label>Telephone:</label>:${object.telephone!}</p>
                <p><label>Remark:</label>:${object.remark!}</p>
                <p><label>Amount:</label>:${object.amount!}</p>
                <@trade.orderProductList orderId=orderId>
                    <#list page.list as op>
                    <@cms.content id=op.contentId>
                        <p>
                            <#if object.cover?has_content><img src="${object.cover}" style="max-width:200px;max-height:200px;border:1px solid;"/><br></#if>
                            <a href="${object.url}" target="_blank">${object.title}</a>
                        </p>
                    </@cms.content>
                    <@cms.contentProduct id=op.productId>
    
                        <p>
                            <#if object.cover?has_content><img src="${object.cover}" style="max-width:200px;max-height:200px;border:1px solid;"/><br></#if>
                            product:${object.title} <label>price::</label>:${op.price} Remark:${op.remark!}
                            <label>Quantity:</label>${op.quantity!}
                        </p>
                    </@cms.contentProduct>
                    </#list>
                </@trade.orderProductList>
                <#if 0=object.status>
                    <#if object.paymentId?has_content>
                        <@trade.payment id=object.paymentId>
                            <p><label>Payment status:</label>:<@message 'page.status.payment.'+object.status/></p>
                            <#if 0=object.status>
                                <a href="${site.dynamicPath}tradePayment/pay?paymentId=${object.id}&returnUrl=https:${(site.dynamicPath+'order.html?orderId='+orderId)?url}">Continue to pay</a> 
                                <a href="${site.dynamicPath}tradePayment/cancel?paymentId=${object.id}&returnUrl=https:${(site.dynamicPath+'order.html?orderId='+orderId)?url}&_csrf=<@tools.csrfToken/>">Change payment method</a>
                                <a href="${site.dynamicPath}tradeOrder/close?orderId=${orderId}&returnUrl=https:${(site.dynamicPath+'order.html?orderId='+orderId)?url}&_csrf=<@tools.csrfToken/>">Close order</a>
                            <#elseif 1=object.status>
                                <form action="${site.dynamicPath}tradePayment/refund" method="POST">
                                    <input type="hidden" name="_csrf" value="<@tools.csrfToken/>"/>
                                    <input type="hidden" name="returnUrl" value="${site.dynamicPath}order.html?orderId=${orderId}"/>
                                    <input type="hidden" name="paymentId" value="${object.id}"/>
                                    <label>Amount:</label><input type="text" name="amount" required="required" value="${object.amount}" max="${object.amount}"/>
                                    <label>Reason:</label><input type="text" name="reason" required="required"/>
                                    <input type="submit" value="Apply refund"/>
                                </form>
                            </#if>
                        </@trade.payment>
                    <#else>
                    <a href="${site.dynamicPath}tradeOrder/pay/alipay?orderId=${orderId!}&clientType=FAST_INSTANT_TRADE_PAY&returnUrl=https:${(site.dynamicPath+'order.html?orderId='+orderId)?url}" data-diy="config" data-diy-id="alipay">Alipay</a>
                    <a href="${site.dynamicPath}tradeOrder/pay/wechat?orderId=${orderId!}&clientType=native&returnUrl=https:${(site.dynamicPath+'order.html?orderId='+orderId)?url}" data-diy="config" data-diy-id="wechat">Wechat</a>
                    <@trade.account id=object.userId;account>
                        <#if account.amount gte object.amount>
                            <a href="${site.dynamicPath}tradeOrder/pay/account?orderId=${orderId!}&returnUrl=https:${(site.dynamicPath+'order.html?orderId='+orderId)?url}">Account balance payment(${account.amount!})</a>
                        </#if>
                    </@trade.account>
                    </#if>
                </#if>
            </@trade.order>
        <#else>
            <#if productId?has_content && quantity?has_content && productId?size=quantity?size>
                <form action="${site.dynamicPath}tradeOrder/create" method="POST">
                    <input type="hidden" name="_csrf" value="<@tools.csrfToken/>"/>
                    <input type="hidden" name="returnUrl" value="${site.dynamicPath}order.html"/>
                    <input type="hidden" name="orderIdField" value="orderId"/>
                    <p><label>Shipping address:</label><input type="text" name="address" required="required"></p>
                    <p><label>Receiver:</label><input type="text" name="addressee" required="required"></p>
                    <p><label>Telephone:</label><input type="text" name="telephone" required="required"></p>
                    <p><label>Remark:</label><input type="text" name="remark" required="required"></p>           
                    <#list productId as p>
                        <@cms.contentProduct id=p;product>
                            <@cms.content id=product.contentId>
                                <p>
                                    <#if object.cover?has_content><img src="${object.cover}" style="max-width:200px;max-height:200px;border:1px solid;"/></#if> <a href="${object.url}" target="_blank">${object.title}</a>
                                </p>
                                <#if p?is_first><input type="hidden" name="title" value="${object.title} - ${product.title}"/></#if>
                            </@cms.content>                
                            <p>
                                <#if product.cover?has_content><img src="${product.cover}" style="max-width:200px;max-height:200px;border:1px solid;"/><br></#if>
                                product:${product.title} <label>price::</label>${product.price} <label>inventory::</label>${product.inventory}
                            </p>
                            <input type="hidden" name="tradeOrderProductList[${p?index}].contentId" value="${product.contentId}"/>
                            <input type="hidden" name="tradeOrderProductList[${p?index}].productId" value="${product.id}"/>
                            <label>Quantity:</label><input type="text" name="tradeOrderProductList[${p?index}].quantity" value="${quantity[p?index]}" required="required"/>
                            <label>Remark:</label><input type="text" name="tradeOrderProductList[${p?index}].remark"/>
                        </@cms.contentProduct>
                    </#list>
                    <input type="submit" value="Submit"/>
                </form>
            <#else>
                <h3>Parameter error</h3>
            </#if>
        </#if>
    </main>
    <footer>
        Copyright &copy; ${.now?string('yyyy')}
    </footer>
    <script>
    var templatePath='${.current_template_name?keep_after('/')}';
    </script>
    <script src="${site.dynamicPath}resource/js/cms.support.js"></script>
    <script>
        var ca = cmsAnalytics();
        var url='${site.dynamicPath}api/visit/record';
        if("string" ==typeof itemString){
            url=url+"?"+itemString;
        }
        ca.setDomain('${site.sitePath?keep_after('//')?keep_before('/')?keep_before(':')}');
        ca.setPath('/');
        ca.report(url);
    </script>
</body>
</html>