<%--
  Created by IntelliJ IDEA.
  User: DJH
  Date: 2022/5/30
  Time: 11:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <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"/>
</head>
<body>
<div class="mb50 mt10">
    <div class="wrapper wrapper-content mt5 right-content ml5 mr5">
        <div class="toolbar-panel bdd">
            <div class="toolbar-box">
                <div class="toolbar-head clearfix lgraybg pt5 pl10 bdbd">
                    <!-- 顶部按钮 -->
                    <div class="fl">
                        查询条件
                    </div>
                    <div class="tools fr">
                        <a href="javascript:void(0);" class="collapse dblock f14 dgray mr5">
                            <i class="fa-2x fa fa-angle-double-up"></i>
                        </a>
                    </div>
                </div>
            </div>
            <!--搜索条件 -->
            <div class="toolbar-body">
                <form class="layui-form" lay-filter="formCondition" id="form1" action="" style="margin-top: 10px;">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">用户ID</label>
                            <div class="layui-input-block">
                                <input type="text" name="userId" id="userId" placeholder="用户ID"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <div class="whitebg pl10 pr10">
        <table class="layui-hide" id="table" lay-filter="table"></table>
    </div>
</div>

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

<script type="text/html" id="toolBar">
    {{# if (d.status == '1') { }}
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="cancel">
        <i class="layui-icon layui-icon-delete"></i>取消该任务
    </a>
    {{# } }}
</script>

<script>
    layui.use(['table', 'layer', 'laydate', 'form'], function () {
        var table = layui.table;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var form = layui.form;

        laydate.render({
            elem: '#date1', //指定元素
            format: 'yyyy-MM-dd 00:00:00'
        });
        laydate.render({
            elem: '#date2', //指定元素
            format: 'yyyy-MM-dd 23:59:59'
        });

        var tableIns = table.render({
            elem: '#table'
            , id: 'idTest'
            , url: ctx + '/userTask/page'
            , response: {
                statusName: 'code' //数据状态的字段名称，默认：code
                , countName: 'count' //数据总数的字段名称，默认：count
                , dataName: 'data' //默数据列表的字段名称，认：data
                , statusCode: 200
            }
            , parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.records //解析数据列表
                };
            }
            , where: {
                column: "createTime"
                , asc: false,
            }
            , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            , defaultToolbar: ['filter', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                , layEvent: 'LAYTABLE_TIPS'
                , icon: 'layui-icon-tips'
            }]
            , title: '系统客服信息表'
            , cols: [[
                {type: 'checkbox', fixed: 'left', hidden: true}
                , {field: 'numbers', title: '序号', fixed: 'left', unresize: true, width: 80, sort: true, type: 'numbers'}
                , {field: 'userId', title: '用户id'}
                , {field: 'taskCodeDesc', title: '任务描述'}
                , {field: 'typeDesc', title: '任务类型(执行时间早上10点)'}
                , {field: 'statusDesc', title: '状态'}
                , {field: 'arg0', title: '参数一'}
                , {field: 'arg1', title: '参数二'}
                , {field: 'createTime', title: "创建时间"}
                , {fixed: 'right', title: '操作', width: 220, toolbar: '#toolBar'}
            ]]
            , request: {
                pageName: 'current' //页码的参数名称，默认：page
                , limitName: 'size' //每页数据量的参数名，默认：limit
            }
            , page: true
        });

        //监听头工具栏事件
        table.on('toolbar(table)', function (obj) {
            // var checkStatus = table.checkStatus(obj.config.id);
            //获取选中的数据
            switch (obj.event) {
                case 'search':
                    table.reload('idTest', {
                        page: {
                            curr: 1
                        },
                        initSort: obj,
                        where: form.val('formCondition')
                    });
                    break;
            }
        });

        //监听行工具事件
        table.on('tool(table)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                , layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent === 'cancel') {
                layer.confirm('是否取消该任务？', function (index) {
                    $.ajax({
                        async: false
                        , url: ctx + "/userTask/cancel"
                        , data: {
                            id: data.id
                        }
                        , type: 'POST'
                        , dataType: 'json'
                        , contentType: 'application/x-www-form-urlencoded'
                        , success: function (res) {
                            if (res.code == '200') {
                                table.reload('demo');
                                layer.msg(res.message);
                                layer.close(index);
                            } else {
                                layer.msg(res.message);
                                layer.close(index);
                            }
                        }
                        , error: function (obj, error) {
                            layer.msg(error);
                            layer.close(index);
                        }
                    });
                });
            }
        });
    });
</script>
</body>
</html>
