<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <LINK rel="Bookmark" href="/favicon.ico">
    <LINK rel="Shortcut Icon" href="/favicon.ico" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <script type="text/javascript" src="lib/PIE_IE678.js"></script>
    <![endif]-->
    <link href="${pageContext.request.contextPath }/common/admin/css/H-ui.min.css" rel="stylesheet" type="text/css" />
    <link href="${pageContext.request.contextPath }/common/admin/css/H-ui.admin.css" rel="stylesheet" type="text/css" />
    <link href="${pageContext.request.contextPath }/common/admin/skin/default/skin.css" rel="stylesheet" type="text/css" id="skin" />
    <link href="${pageContext.request.contextPath }/common/admin/lib/Hui-iconfont/1.0.1/iconfont.css" rel="stylesheet" type="text/css" />
    <link href="${pageContext.request.contextPath }/common/admin/css/style.css" rel="stylesheet" type="text/css" />

    <!--[if IE 6]>
    <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>代理商列表</title>
</head>
<body>
<nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span>
    商城管理 <span class="c-gray en">&gt;</span>代理商列表 <a
        class="btn btn-success radius r mr-20"
        style="line-height: 1.6em; margin-top: 3px"
        href="javascript:location.replace(location.href);" title="刷新"><i
        class="Hui-iconfont">&#xe68f;</i></a>
</nav>
<div class="pd-20">
    <div class="cl pd-5 bg-1 bk-gray mt-20">
        <form action="${pageContext.request.contextPath }/admin/agentTooth/select_agentInfo_list" method="post" id="searchForm">
            <div class="text-c">
                <button type="button" style="float:left;" class="btn btn-success radius" onclick="add_Agent();" id="addAgent" name=""><i class="Hui-iconfont">&#xe665;</i> 添加代理商</button>
                <select name="agentStatus" style="height: 30px;">
                    <option value="">状态</option>
                    <option <c:if test="${agentStatus == 1}">selected = "selected"</c:if> value="1">启用</option>
                    <option <c:if test="${agentStatus == 2}">selected = "selected"</c:if> value="2">停用</option>
                  </select>
                <input type="text" class="input-text" style="width:130px" placeholder="请输入代理商姓名" value="${agentName}" name="agentName">
                <input type="text" class="input-text" style="width:130px" placeholder="请输入代理商电话" value="${agentTel}" name="agentTel">
               <button type="submit" class="btn btn-success radius" id="searchButton" name=""><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
            </div>
        </form>
    </div>
    <form id="configform" >
        <table class="table table-border table-bordered table-bg" id="example">
            <thead>
            <tr>
                <th scope="col" colspan="11">代理商列表</th>
            </tr>
            <tr class="text-c">
                <th width="100">名称</th>
                <th width="100">地址</th>
                <th width="100">电话</th>
                <th width="100">状态</th>
                <th width="100">创建时间</th>
                <th width="100">操作</th>
            </tr>
            </thead>
            <tbody>
            <c:if test="${! (empty agentToothList) }">
            <c:forEach items="${agentToothList }" var="list">
            <tr class="text-c">
                <td>${list.agentName }</td>
                <td>${list.agentAddr }</td>
                <td>${fn:substring(list.agentTel,0,3)}****${fn:substring(list.agentTel,7,11)}</td>
                <td id="agent_status${list.agentId }">
                    <c:if test="${list.agentStatus == 1}">
                        启用
                    </c:if>
                    <c:if test="${list.agentStatus == 2}">
                        停用
                    </c:if>
                </td>
                <td><fmt:formatDate value="${list.agentCreateDate }" pattern="yyyy-MM-dd HH:mm:ss"/></td>
                <td class="td-manage">
                    <input id="agentStatus" type="hidden" value="${list.agentStatus }">
                    <select id="goodstatus" name="" onchange="updateGiftState(this,${list.agentId },${list.agentTel})">
                        <option value="1" ${list.agentStatus==1?'selected':''}>启用</option>
                        <option value="2" ${list.agentStatus==2?'selected':''}>停用</option>
                    </select>
                    <c:if test="${list.agentStatus == 1}">
                    <a onclick="updateAgent('${list.agentId}')"
                       title="编辑" href="javascript:;"  class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>
                    </c:if>
                </td>
        </c:forEach>
        </c:if>
        </tbody>
        </table>
        <div align="right" class="mt-10 mb-10 mr-10">
            <%@include file="/common/other/paper/pager.jsp"%>
        </div>
    </form>
</div>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/layer/1.9.3/layer.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/js/H-ui.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/js/H-ui.admin.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/js/tips.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/js/page/jqPaginator.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/goods/js/utils.js"></script>
<script type="text/javascript">

    function updateGiftState(_this,id,tel){
        var obj = $(_this);
        layer.confirm('确认要修改状态吗？',function(index){
                $.ajax({
                    url: '${pageContext.request.contextPath }/admin/agentTooth/update_agentInfo',
                    type: "POST",
                    dataType: "json",
                    data: {agentId : id,agentStatus : obj.val(),agentTel:tel},
                    error:function(data){
                        layer.msg("修改失败</br>",{icon: 5,time:2000});
                    },
                    success:  function(data){
                        if (data.status) {
                            layer.msg("修改成功</br>",{icon: 1,time:2000});
                            var message = '';
                            switch (obj.val()) {
                                case "1":
                                    message = '启用';
                                    break;
                                case "2":
                                    message = '停用';
                                    break;
                            }
                            $('#agent_status'+id).html(message);
                        } else {
                            layer.alert(data.message, {icon: 5});
                        }
                    }
                });
            }, function () {
                window.location.reload(location.href);
            }
        );

    }

    function updateAgent(id){
        window.location.href = '${pageContext.request.contextPath }/admin/agentTooth/_update_agentInfo?agentId='+id;
    }
    function add_Agent(){
        window.location.href = '${pageContext.request.contextPath }/admin/agentTooth/_add_agentInfo';
    }
</script>
</body>
</html>