<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>博实结设备列表</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <meta name="renderer" content="webkit">
    <!-- 移动设备 viewport -->
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <jsp:include page="../../../common.jsp"/>

    <style>
        .layui-table th {
            text-align: center;
        }

        .layui-form-label {
            padding: 9px 7px;
            width: 96px;
        }
    </style>
</head>
<body>
<div class="row animated fadeInRight" style="margin: 0;">
    <div class="wrapper wrapper-content mt5 right-content ml5 mr5">
        <div class="toolbar-panel bdd">
            <div class="toolbar-box">
                <div class="toolbar-head lgraybg pt10 pb10 pl10 bdbd pr10"
                     style="display: flex; justify-content: space-between">
                    <!-- 顶部按钮 -->
                    <div class="fl" style="align-items: center; display: flex">
                        <p style="align-items: center;">查询条件</p>
                    </div>

                    <div class="tools" style="align-items: center; display: flex">
                        <a class="layui-btn layui-btn-normal layui-btn-sm import" id="import"
                           style="align-items: center;">
                            <i class="layui-icon layui-icon-upload"></i>导入
                        </a>
                        <a href="javascript:void(0);" class="collapse f14 dgray mr5"
                           style="display: inline-block; align-items: center; margin-left: 30px;">
                            <i class="fa-2x fa fa-angle-double-up"></i>
                        </a>
                    </div>
                </div>
            </div>
            <!--搜索条件 -->
            <div class="toolbar-body">
                <form class="layui-form" action="" style="margin-top: 10px" lay-filter="formCondition">
                    <div class="layui-form-item">

                        <div class="layui-inline">
                            <label class="layui-form-label">厂家编号</label>
                            <div class="layui-input-inline">
                                <input type="text" id="deviceNo" name="deviceNo" placeholder="请输入厂家编号"
                                       class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">设备编号</label>
                            <div class="layui-input-inline">
                                <input type="text" id="snNo" name="snNo" placeholder="请输入设备编号"
                                       class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">IMEI</label>
                            <div class="layui-input-inline">
                                <input type="text" id="imei" name="imei" placeholder="请输入IMEI"
                                       class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">ICCID</label>
                            <div class="layui-input-inline">
                                <input type="text" id="iccid" name="iccid" placeholder="请输入ICCID"
                                       class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">SIM</label>
                            <div class="layui-input-inline">
                                <input type="text" id="sim" name="sim" placeholder="请输入SIM卡号"
                                       class="layui-input">
                            </div>
                        </div>

                    </div>
                </form>
            </div>
        </div>

        <!-- 表单数据 -->
        <table class="layui-hide" id="tableList" lay-filter="tableList"></table>
    </div>
</div>

<script id="toolBar" type="text/html">
    <a class="layui-btn layui-btn-sm" lay-event="search">
        <i class="layui-icon layui-icon-search"></i>查询
    </a>

    <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="sendExpiredNotice">
        <i class="layui-icon layui-icon-release"></i>一键发送流量到期通知
    </a>
</script>

<script type="text/javascript">
    var layer;
    var laytpl;
    var form;
    var table;
    var laydate;
    var dropdown;

    //form表单样式
    layui.use(['table', 'layer', 'form', 'laydate', 'dropdown', 'upload'], function () {
        layer = layui.layer;
        laytpl = layui.laytpl;
        form = layui.form;
        table = layui.table;
        laydate = layui.laydate;
        dropdown = layui.dropdown;
        form.render();

        var upload = layui.upload;

        //执行实例
        var uploadInst = upload.render({
            elem: '.import' //绑定元素
            , url: ctx + '/deivceBsj/importExpiredTime' //上传接口
            , accept: 'file'
            , acceptMime: 'file/xlsx, file/xls'
            , exts: 'xlsx|xls'
            , done: function (res) {
                layer.alert(res.message);
            }
            , error: function () {

            }
        });

        $("#userId").bind("input propertychange", function (event) {
            if ($("#userId").val() == null || $("#userId").val() == "") {
                $("#sameIp").attr("disabled", true);
                $("#sameIp").removeAttr("checked");
                $("#sameIp").prop({checked: false});
            } else {
                $("#sameIp").attr("disabled", false);
            }

            form.render();
        });

        //执行一个 table 实例
        table.render({
            elem: '#tableList'
            , id: 'tableList'
            , url: ctx + '/deivceBsj/page' //数据接口
            , autoSort: false
            , where: form.val("formCondition")
            , response: {
                statusCode: 200
            }
            , parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.records //解析数据列表
                };
            }
            , request: {
                pageName: 'current' //页码的参数名称，默认：page
                , limitName: 'size' //每页数据量的参数名，默认：limit
            }
            , even: true
            , title: '博实结设备列表'
            , page: true //开启分页
            , toolbar: '#toolBar' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
            , defaultToolbar: ['filter']
            , cols: [[ //表头
                {field: 'deviceNo', title: '厂家编号', minWidth: 86, align: "left"}
                , {field: 'imei', title: 'IMEI', minWidth: 86, align: "left"}
                , {field: 'iccid', title: 'ICCID', minWidth: 86, align: "left"}
                , {field: 'sim', title: 'SIM卡号', minWidth: 86, align: "left"}
                , {field: 'snNo', title: '设备编号', minWidth: 86, align: "left"}
                , {
                    field: 'simExpireTime',
                    title: '过期时间',
                    align: "left",
                    minWidth: 160,
                    templet: "<div>{{layui.util.toDateString(d.simExpireTime,'yyyy-MM-dd HH:mm:ss')}}</div>"
                }
            ]]

        });

        table.on('toolbar(tableList)', function (obj) {
            switch (obj.event) {
                case 'search':
                    queryUserApp();
                    break;
                case 'sendExpiredNotice':
                    layer.confirm('是否发送流量卡到期通知', {icon: 3, title: '提示'}, function (index) {
                        var url = ctx + "/deivceBsj/sendExpiredTime";

                        $.ajax({
                            url: url,
                            type: "POST",
                            success: function (d) {
                                layer.alert(d.message);
                            }
                        });

                        layer.close(index);
                    });
                    break;
            }
        });
    });

    //查询
    function queryUserApp() {
        table.reload('tableList', {
            page: {
                curr: 1
            }
            , where: form.val("formCondition")
        });
    }
</script>
</script>
</body>
</html>
