<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>Open Park</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="<%=path%>/static/css/font.css">
    <link rel="stylesheet" href="<%=path%>/static/css/xadmin.css">
    <script type="text/javascript" src="<%=path%>/static/js/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="<%=path%>/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="<%=path%>/static/js/xadmin.js"></script>
</head>

<body>
<div class="x-nav">
    <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">订单管理</a>
        <a><cite>订单列表</cite></a>
    </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i>
    </a>
</div>
<div class="x-body">
    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so" action="<%=path %>/order/list" method="post">
            <input type="text" name="orderName" value="${order.orderName}" placeholder="项目名称" autocomplete="off"
                   class="layui-input">
            <div class="layui-input-inline">
                <select name="orderType" >
                    <option value="">类型</option>
                    <option value="定制" <c:if test="${order.orderType == '定制'}">selected</c:if> >定制</option>
                    <option value="成品" <c:if test="${order.orderType == '成品'}">selected</c:if> >成品</option>
                </select>
            </div>
            <input type="text" name="orderContact" value="${order.orderContact}" placeholder="联系人" autocomplete="off"
                   class="layui-input">
            <input type="text" name="orderWangwang" value="${order.orderWangwang}" placeholder="旺旺名" autocomplete="off"
                   class="layui-input">
            <div class="layui-input-inline">
                <select name="orderStatus" >
                    <option value="">状态</option>
                    <option value="0" <c:if test="${order.orderStatus == 0}">selected</c:if> >进行中</option>
                    <option value="1" <c:if test="${order.orderStatus == 1}">selected</c:if> >已完成</option>
                </select>
            </div>
            <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </form>
    </div>
    <xblock>
        <button class="layui-btn" onclick="x_admin_show('添加','<%=path%>/order/add',500, 600)">
            <i class="layui-icon"></i>添加
        </button>
    </xblock>
    <table class="layui-table">
        <thead>
        <tr>
            <th>
                <div class="layui-unselect header layui-form-checkbox" lay-skin="primary">
                    <i class="layui-icon">&#xe605;</i>
                </div>
            </th>
            <th>
                日期
            </th>
            <th>
                项目名称
            </th>
            <th>
                类型
            </th>
            <th>
                描述
            </th>
            <th>
                金额
            </th>
            <th>
                定金
            </th>
            <th>
                旺旺名
            </th>
            <th>
                联系人
            </th>
            <th>
                负责人
            </th>
            <th>
                淘宝店
            </th>
            <th>
                状态
            </th>
            <th>操作</th>
        </thead>
        <tbody>
        <c:forEach items="${pages.list}" var="item">
            <tr>
                <td>
                    <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'>
                        <i class="layui-icon">&#xe605;</i>
                    </div>
                </td>
                <td>
                        ${item.orderDate}
                </td>
                <td>
                        ${item.orderName}
                </td>
                <td>
                        ${item.orderType}
                </td>
                <td>
                        ${item.orderDetail}
                </td>
                <td>
                        ${item.orderMoney}
                </td>
                <td>
                        ${item.orderDeposit}
                </td>
                <td>
                        ${item.orderWangwang}
                </td>
                <td>
                        ${item.orderContact}
                </td>
                <td>
                        ${item.orderPrincipal}
                </td>
                <td>
                        ${item.orderShop}
                </td>
                <td id="state${item.id}">
                    <c:if test="${item.orderStatus == 0}">
                        进行中
                    </c:if>
                    <c:if test="${item.orderStatus == 1}">
                        已完成
                    </c:if>
                </td>
                <td id="func${item.id}" class="td-manage">
                    <c:if test="${item.orderStatus == 0}">
                    <a title="完成" onclick="order_finish(this,'${item.id}')" href="javascript:;">
                        <i class="layui-icon">&#xe614;</i>
                    </a>
                    <a title="编辑" onclick="x_admin_show('编辑','<%=path %>/order/update?id=${item.id}',500, 600)"
                       href="javascript:;">
                        <i class="layui-icon">&#xe642;</i>
                    </a>
                    <a title="删除" onclick="member_del(this,'${item.id}')" href="javascript:;">
                        <i class="layui-icon">&#xe640;</i>
                    </a>
                    </c:if>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
    <div class="page">
        <div>第&nbsp;${pages.pageNum}&nbsp;页/共&nbsp;${pages.pages}&nbsp;页</div>
        <div>
            <a class="num" href="<%=path %>/order/list?curPage=1">首页</a>
            <c:if test="${pages.hasPreviousPage}">
                <a href="<%=path %>/order/list?curPage=${pages.pageNum-1}" aria-label="Previous"> 上一页</a>
            </c:if>
            <c:if test="${!pages.hasPreviousPage}">
                <a href="javascript:;" aria-label="Previous"> 上一页</a>
            </c:if>
            <c:forEach items="${pages.navigatepageNums}" var="pageNum">
                <a href="<%=path %>/order/list?curPage=${pageNum}">${pageNum}</a>
            </c:forEach>
            <c:if test="${pages.hasNextPage}">
                <a href="<%=path %>/order/list?curPage=${pages.pageNum+1}" aria-label="Next"> 下一页</a>
            </c:if>
            <c:if test="${!pages.hasNextPage}">
                <a href="javascript:;" aria-label="Next"> 下一页</a>
            </c:if>
            <a class="num" href="<%=path %>/order/list?curPage=${pages.pages}">尾页</a>
        </div>
    </div>

</div>
<script>
    function member_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            //发异步删除数据
            $.ajax({
                type: "GET",
                url: "<%=path %>/order/delete",
                data: {
                    id:
                    id
                },
                success: function (data) {
                    $(obj).parents("tr").remove();
                    layer.msg('已删除!', {icon: 1, time: 1000});
                }
            })
            ;
        });
    }


    function order_finish(obj, id) {
        layer.confirm('确认已经完成吗？', function (index) {
            //发异步删除数据
            $.ajax({
                type: "GET",
                url: "<%=path %>/order/finish",
                data: {
                    id: id
                },
                success: function (data) {
                    if(data.state == 0){
                        layer.msg('操作完成!', {icon: 1, time: 1000});
                        if(data.data.orderStatus == 1){
                            $("#state"+id).html("已完成")
                            $("#func"+id).html("")
                        }else{
                            $("#state"+id).html("进行中")
                        }
                    }else{
                        layer.msg('操作失败!原因：'+data.message, {icon: 1, time: 1000});
                    }
                }
            })
            ;
        });
    }
</script>
</body>
</html>