<%inherit file="base.html"/>

<%def name="head()">
<script>
    function release(account_number)
    {
        params = {account_number:account_number};
        $.post("/ops/user/release", params, function (data) {
            alert(data.msg)
        },"json");
    }
    function do_submit(){
        $("#query_form").attr("action", "/ops/user");
        $("#query_form").submit();
    }
    function do_export(){
        $("#query_form").attr("action", "/ops/user/export");
        $("#query_form").submit();
        setTimeout(function(){$("#query_form").attr("action", "/ops/user");}, 0);
    }
</script>
</%def>

<%def name="body()">
<div class="panel panel-default">
    <div class="panel-heading"><span class="glyphicon glyphicon-th"></span> 账号列表</div>
    <div class="panel-body">
        <form id="query_form" class="form-horizontal form-well" role="form" action="/ops/user" method="post">
            <div class="form-group">
                <label for="node_id" class="col-md-2 control-label">区域</label>
                <div class="col-md-3">
                    <select id="node_id" name="node_id" class="form-control" >
                        <option value=""></option>
                        % for node in node_list:
                          <option value="${node.id}" ${str(node.id)==node_id and "selected" or ""}>${node.node_desc}</option>
                        % endfor
                    </select>
                </div>            
                <label for="product_id" class="col-md-2 control-label">资费套餐</label>
                <div class="col-md-3">
                <select id="product_id" name="product_id" class="form-control" >
                    <option value=""></option>
                        % for product in product_list:
                          <option value="${product.id}" ${str(product.id)==product_id and "selected" or ""}>${product.product_name}</option>
                        % endfor
                </select>
                </div>
            </div>
            <div class="form-group">
                <label for="user_name" class="col-md-2 control-label">用户账号</label>

                <div class="col-md-3">
                    <input type="text" id="user_name" name="user_name" class="form-control" placeholder="模糊查询" value=${user_name or ""}>
                </div>
                <label for="state" class="col-md-2 control-label">用户状态</label>

                <div class="col-md-3">
                    <select id="status" name="status" class="form-control">
                        <option></option>
                        % for k,v in {1:u"正常", 2:u"停机" , 3:u"销户", 4:u"到期", 6:u"未激活"}.items():
                        <option value="${k}"  ${str(k)==status and "selected" or ""} >${v}</option>
                        % endfor
                    </select>
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-offset-5 col-md-7">
                    <button type="button" onclick="do_submit();" class="btn btn-primary">查询</button>
                </div>
            </div>
        </form>

        <table class="table table-hover">
            <thead>
            <tr>
                <th>用户账号</th>
                <th>用户姓名</th>
                <th>用户资费</th>
                <th>用户状态</th>
                <th>到期时间</th>
                <th>创建时间</th>
                <th></th>
            </tr>
            </thead>
            <tbody>
            % for user,_realname,_product_name in page_data.result:
            <tr>
                <td>
                    <a href="/ops/user/detail?account_number=${user.account_number}">${user.account_number}</a>
                </td>
                <td>${_realname}</td>
                <td>${_product_name}</td>
                <td>${{1:u"正常",2:u"停机",3:u"销户",4:u"到期",6:u"未激活"}[user.status]}</td>
                <td>${user.expire_date}</td>
                <td>${user.create_time}</td>
                 <td>
                     % if permit.match('/ops/user/release'):
                     <a class="opt-btn btn-default" href="javascript:release('${user.account_number}');">释放绑定</a>
                     % endif
                     % if permit.match('/bus/account/update'):
                     <a class="opt-btn btn-default" href="/bus/account/update?account_number=${user.account_number}">修改策略</a>
                     % endif
                 </td>
            </tr>
            % endfor
            </tbody>
        </table>
        ${page_data.render(form_id="query_form")}
    </div>
</div>


</%def>