<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>车辆订单明细查询</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <link rel="stylesheet" href="/metrics/css/layui.css">
<!--    <link rel="stylesheet" href="https://www.layuicdn.com/layui/css/layui.css">-->
    <script src="/metrics/jquery.js"></script>
</head>
<body>

<form class="layui-form">
    <table class="layui-table">

        <thead>
        <tr>
            <th colspan="8">车辆订单明细查询</th>
        </tr>
        </thead>
        <tbody>
        <tr>
            <td align="right">开始时间</td>
            <td>
                <input type="text" class="layui-input" id="beginTime">

            </td>


            <td align="right">订单状态</td>
            <td>
                <select id="status" name="status" lay-verify="required">
                    <option value="">请选择</option>
                    <option value="1">未处理</option>
                    <option value="2">检测中</option>
                    <option value="4">检测完成</option>
                </select>
            </td>
        </tr>
        <tr>
            <td align="right">结束时间</td>
            <td>
                <input type="text" class="layui-input" id="endTime">
            </td>

            <td align="right">车牌号</td>
            <td>
                <input type="text" class="layui-input" id="platenumber">
            </td>
<!--            <td colspan="2"></td>-->
            <td align="right"  >
                <button type="button" class="layui-btn layui-btn layui-btn-radius layui-btn-normal"
                        onclick="doSearch()">查询
                </button>
                <!--<button type="button" class="layui-btn layui-btn ">导出excel</button>-->
<!--                <a href="javascript:void(0);" class="layui-btn layui-btn" plain="true" onclick="exportLog()">导出</a>-->
                <!--<a href="javascript:void(0);" class="layui-btn layui-btn" plain="true" onclick="exportLog()">导出</a>-->
            </td>

        </tr>


        </tbody>
    </table>
</form>

<table class="layui-hide" id="testtable" lay-filter="test"></table>


<script src="/metrics/layui.js?v=20241120003"></script>

<script>

    var load = 0;
    var date = new Date();

    var option = {};
    option.appid = "<option value=''>请选择</option>";
    option.sp = "<option value=''>请选择</option>";
    option.spec = "<option value=''>请选择</option>";

    layui.use('form', function () {
        var form = layui.form;
        $(function () {
            getappid();
            getsp();
        });

        //appid列表
        function getappid() {

            var optionstr = option.appid;
            $.ajax({
                type: 'post',
                url: "/mis/down/getappId",
                dataType: "json",
                success: function (data) {

                    $.each(data.data, function (i, obj) {

                        optionstr += "<option value='" + obj.appid + "'>" + obj.remark + "</option>";

                    });
                    $('#appid').empty()
                    $('#appid').append(optionstr)
                    form.render("select");
                }
            });
        }


        //appid列表
        function getsp() {

            var optionstr = option.appid;
            $.ajax({
                type: 'post',
                url: "/mis/down/getsp",
                dataType: "json",
                success: function (data) {
                    // console.log(data)
                    $.each(data.data, function (i, obj) {

                        optionstr += "<option value='" + obj.sp + "'>" + obj.name + "(" + obj.sp + ")" + "</option>";

                    });
                    // console.log(optionstr)
                    $('#sp').empty()
                    $('#sp').append(optionstr)
                    form.render("select");

                }
            });
        }

        //各种基于事件的操作，下面会有进一步介绍
    });


    function exportLog() {
        var param = "appid=" + $('#appid').val() +
            "&beginTime=" + $('#beginTime').val() +
            "&endTime=" + $('#endTime').val() +
            "&sp=" + $('#sp').val() +
            "&message=" + $('#message').val() +
            "&mobile=" + $('#mobile').val() +
            "&sendStatus=" + $('#sendStatus').val()
        window.location.href = "/mis/down/exportSms?" + param;
    }


    function tableinit() {
        layui.use('table', function () {
            var table = layui.table;

            table.render({
                elem: '#testtable'
                ,
                height: 'full-250'
                ,
                url: '/mis/down/list/'
                ,
                page: true
                ,
                dataType: 'json'
                ,
                limit: 1000
                ,
                limits: [1000, 2000, 3000, 4000, 5000]
                ,
                where: {
                    appid: $('#appid').val(),
                    endTime: $('#endTime').val(),
                    beginTime: $('#beginTime').val(),
                    sendStatus: $('#sendStatus').val(),
                    sp: $('#sp').val(),
                    message: $('#message').val(),
                    mobile: $('#mobile').val()
                }
                // ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
                ,
                cols: [
                    [ //标题栏
                        {title: '明细列表', colspan: 8}
                    ],
                    [
                        // {field:'msgid',  title: '序号', sort: true}
                        // ,
                        {field: 'id', title: 'ID', width: 105}
                        , {field: 'orderno', title: '订单编号', sort: true, width: 150}
                        , {
                        field: 'mname', title: '施工单位名称', width: 220 }
                        , {field: 'orderuserid', title: '订单创建人id', width: 105} //minWidth：局部定义当前单元格的最小宽度，layui 2.2.1 新增
                        , {field: 'orderusername', title: '订单创建人姓名', width: 150, sort: true}
                        , {field: 'platenumber', title: '车牌号', sort: true}
                        , {fixed: 'right', title: '同步', toolbar: '#barDemo', width: '5%', edit: 'text'}

                    ]]



            });
            //工具栏事件
            table.on('tool(test)', function (obj) {
                var data = obj.data;
                switch (obj.event) {
                    case 'edit':
                        layer.alert(JSON.stringify(data));
                        break;
                    case 'del':

                        layer.confirm('确认同步么？', function (index) {
                            $.ajax({
                                url: '/mis/down/tb?id=' + data.id,
                                success: function (data) {
                                    var code = data.code;
                                    if (code == "-1") {
                                        layer.alert("删除失败！");
                                    } else {
                                        layer.alert("删除成功！");
                                    }
                                    doSearch();
                                }
                            });
                        });
                        break;
                }
            });

        });
    }


    /**
     * 设置时间
     */
    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#beginTime' //指定元素
            , format: 'yyyy-MM-dd HH:mm:ss' //可任意组合
            , type: 'datetime'
            ,change: function(value, date, endDate){
                $("#beginTime").val(value);
                if($(".layui-laydate").length){
                    $(".layui-laydate").remove();
                }
            }
            , value: new Date(new Date(new Date().toLocaleDateString()).getTime())
        }); //执行一个laydate实例
        laydate.render({
            elem: '#endTime' //指定元素
            , format: 'yyyy-MM-dd HH:mm:ss' //可任意组合
            , type: 'datetime'
            ,change: function(value, date, endDate){
                $("#endTime").val(value);
                if($(".layui-laydate").length){
                    $(".layui-laydate").remove();
                }
            }
            , value: new Date(new Date(new Date().toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 - 1)
        });
    });


    /**
     * 设置时间
     */
    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#beginTime' //指定元素
            , format: 'yyyy-MM-dd HH:mm:ss' //可任意组合
            , type: 'datetime'
            , value: new Date(new Date(new Date().toLocaleDateString()).getTime())
        }); //执行一个laydate实例
        laydate.render({
            elem: '#endTime' //指定元素
            , format: 'yyyy-MM-dd HH:mm:ss' //可任意组合
            , type: 'datetime'
            , value: new Date(new Date(new Date().toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 - 1)
        });
    });

    function doSearch() {


        var beginTime = $("#beginTime").val();
        var endTime = $("#endTime").val();

        if (beginTime.length == 0 || endTime.length == 0) {
            alert("开始时间和结束时间是必填项，请选择查询时间段")
            return
        }

        var d1 = new Date(beginTime);
        var d2 = new Date(endTime);
        var diffday = parseInt(d2 - d1) / 1000 / 60 / 60 / 24
        if (diffday < 0) {
            alert("结束时间不能小于开始时间，请重新选择查询时间")
            return
        }
        // if (diffday > 90) {
        //     alert("开始时间到结束时间不能超过90天，请修改查询时间")
        //     return
        // }

        var table = layui.table;

        if (load == 0) {
            tableinit();
            load = 1;
        } else {
            table.reload('testtable', {
                url: '/mis/down/list/'
                ,
                page:{
                  curr:1
                },

                where: {
                    id: $('#id').val(),
                    endTime: $('#endTime').val(),
                    beginTime: $('#beginTime').val(),
                    status: $('#status').val(),
                    platenumber: $('#platenumber').val()
                }
            });
        }


    }


</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">同步</a>
</script>

</body>
</html>