{% extends 'TopxiaWebBundle:MyOrder:layout.html.twig' %}

{% set script_controller = 'my/orders' %}

{% set main_nav = 'orders' %}

{% block main_body %}
  {#search form#}
  <ul class="nav nav-pills" role="tablist">
    <li role="presentation" {% if app.request.query.get('status')=='' %}class="active"{% endif %}><a href="{{path('my_orders',{status:''})}}">全部订单</a></li>
    <li role="presentation" {% if app.request.query.get('status')=='created' %}class="active"{% endif %}><a href="{{path('my_orders',{status:'created'})}}">待付款<span class="badge">{{waitToBePaidCount}}</span></a></li>
    <li role="presentation" {% if app.request.query.get('status')=='paid' %}class="active"{% endif %}><a href="{{path('my_orders',{status:'paid'})}}">已付款</a></li>
  </ul>
  <br>
  <form id="user-search-form" class="form-inline well well-sm" action="" method="get" novalidate>
    <input type="hidden" name="status" value="{{app.request.query.get('status')}}"> 
    <div class="form-group">
      <select class="form-control" name="lastHowManyMonths"  onchange="submit();" >
        {% set options = {'oneWeek':'最近一周','twoWeeks':'最近两周','oneMonth':'最近一个月','twoMonths':'最近两个月','threeMonths':'最近三个月','':'全部记录'} %}
        {{ select_options(options, request.get('lastHowManyMonths')) }}
      </select>
    </div>

    {#<button class="btn btn-primary" >搜索</button>#}

  </form>

  <table class="table table-striped table-hover" id="orders-table">
    <thead>
      <th>名称</th>
      <th>创建时间</th>
      <th>价格</th>
      <th>状态</th>
      <th>操作</th>
    </thead>
    <tbody>
      {% for order in orders %}
        <tr>
          <td>
            {% if order.targetType == 'course' %}
              <a href="{{ path('course_show', {id:order.targetId}) }}" target="_blank">{{ order.title }}</a>
            {% elseif order.targetType == 'vip' %}
              <a href="{{ path('vip', {id:order.targetId}) }}" target="_blank">{{ order.title }}</a>
            {% else %}
              {{ order.title }}
            {% endif %}
            <div class="text-sm text-muted">
              订单号：{{ order.sn }}
            {% if order.payment == 'coin'%}
            <span style="color:#428bca;">
            虚拟币订单
            </span>
            {% endif %}
            </div>
          </td>
          <td>{{ order.createdTime|date('Y-n-d H:i') }}</td>
          {% if order.priceType == 'Coin'%}
          <td>{{ order.totalPrice }}{{setting('coin.coin_name')}}</td>
          {% else %}
          <td>{{ order.totalPrice }}元</td>
          {% endif %}
          <td>
            {{ dict_text('orderStatus:html', order.status) }}
          </td>
          <td>
            <div class="btn-group">
               <a href="javascript:;" class="btn btn-sm btn-default" data-toggle="modal" data-target="#modal" data-url="{{ path('web_user_order_detail', {id:order.id}) }}">详情</a>  
                
               {% if order.status == 'refunding' or  order.status == 'created' %}
               
                <a href="#" type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
                  <span class="caret"></span>
                </a>

                
                <ul class="dropdown-menu pull-right {# text-right #}" style="min-width: 120px;" > 

                   {# <div class="actions"> #}
                    {% if order.status == 'refunding' %}
                      <li><a href="javascript:;" class="cancel-refund" data-url="{{ path('my_order_cancel_refund', {id:order.id}) }}">取消退款</a></li>
                    {% endif %}
                    {% if order.status == 'created' %}

                      <li>
                        <a href="{{path('pay_center_show', {sn:order.sn})}}"  style="display:block" >去支付</a>
                      </li>
                      <li><a href="javascript:;" class=" cancel" style="display:block" data-url="{{ path('my_order_cancel', {id:order.id}) }}">取消订单</a></li>

                    {% endif %}
                   {#  </div> #}
                  </ul>
                {% endif %}
            </div>  
          </td>
        </tr>
      {% else %}
        <tr>
          <td colspan="20" class="empty">无订单记录</td>
        </tr>
      {% endfor %}
    </tbody>
  </table>
{{ web_macro.paginator(paginator) }}
{% endblock %}