<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>项目任务书</title>
    <link rel="stylesheet" th:href="@{/lib/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/css/public.css}" media="all">
    <link rel="stylesheet" th:href="@{/lib/font-awesome-4.7.0/css/font-awesome.min.css}" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main" style="margin-bottom: -30px">
        <fieldset class="table-search-fieldset">
            <legend>搜索信息(<b>收起-展开</b>)</legend>
            <div id="search-div" style="margin: 5px 10px -10px 0px">
                <form class="layui-form" action="" lay-filter="search-form">
                    <div class="layui-form-item" style="display: flex; align-items: center;margin-left: -5%">
                        <label class="layui-form-label" style="width: 10%;">项目名称</label>
                        <div class="layui-input-inline" style="width: 20%;">
                            <input type="text" id="xmmc" name="xmmc" autocomplete="off" class="layui-input" th:value="${xmmc}">
                        </div>
                        <label class="layui-form-label" style="width: 10%;">合同名称</label>
                        <div class="layui-input-inline" style="width: 25%;">
                            <input type="text" id="htmc" name="htmc" autocomplete="off" class="layui-input">
                        </div>
                        <button type="submit" class="layui-btn" lay-submit lay-filter="data-search-btn"><i
                                class="layui-icon"></i> 搜 索
                        </button>
                        <button type="submit" class="layui-btn layui-btn-primary" lay-submit
                                lay-filter="data-reset-btn"><i class="layui-icon layui-icon-refresh"></i> 重 置
                        </button>
                    </div>
                </form>
            </div>
        </fieldset>
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <!-- 右侧悬浮按钮 -->
        <div class="layui-form layuimini-form">
            <div class="right-bottom-btn">
                <button class="layui-btn" lay-filter="selectBtn">
                    <i class="layui-icon layui-icon-ok"></i>选择
                </button>
                <button class="layui-btn" lay-filter="cancleBtn">
                    <i class="layui-icon layui-icon-close"></i>取消
                </button>
            </div>
        </div>
    </div>
</div>

<script>

</script>
<script th:src="@{/lib/jquery-3.4.1/jquery-3.4.1.min.js}" charset="utf-8"></script>
<script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
<script th:src="@{/lib/coco-message/coco-message.js}" charset="utf-8"></script>
<script th:src="@{/js/lay-config.js}" charset="utf-8"></script>
<script th:src="@{/lib/xm-select-v1.2.2/xm-select.js}" charset="utf-8"></script>
<script th:inline="javascript" type="text/javascript">
    AjaxUtil.ctx = /*[[@{/}]]*/'';
    layui.use(['form', 'table'], function () {
        var form = layui.form,
            table = layui.table;
        var project = null;
        var xmmc = document.getElementById('xmmc').value;

        var currTable = table.render({
            elem: '#currentTableId',
            url: AjaxUtil.ctx + 'staPayapproval/getHt',
            method: 'post',
            where:{
              xmmc: xmmc
            },
            // toolbar: '#toolbarDemo',
            // defaultToolbar: ['filter', 'exports', 'print'],
            cols: [
                [
                    {type: 'numbers',title: '序号'},
                    {field: 'htmc', width: '45%', title: '合同名称'},
                    {field: 'htje',title: '合同金额(万元)',width: '13%',align: 'right'},
                    {field: 'yfje',title: '已付金额(万元)',width: '13%',align: 'right'},
                    {field: 'cjrxm', width: '10%', title: '创建人', align: 'center'},
                    {field: 'cjsj', width: '10%', title: '创建时间', align: 'center'},

                ]
            ],
            autoSort: false,
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true,
            skin: 'grid',
            parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.rows //解析数据列表
                };
            },
            done: function (res, curr, count) { // done为数据渲染完的回调
                // 测试打印出后端返回的权限列表
                // let permissionSet = [[${permissionSet}]];
                // console.log(JSON.stringify(permissionSet));
            }
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            // 执行搜索重载
            currTable.reload({
                page: {
                    curr: 1 // 页码从1开始
                },
                where: form.val("search-form")
            });
            return false;
        });

        // 监听重置操作
        form.on('submit(data-reset-btn)', function (data) {
            form.val("search-form", {
                "htmc": '',
                "xmmc": '',
                "erpbh": '',
                "xmlx": ''
            });
            // 执行搜索重载
            currTable.reload({
                page: {
                    curr: 1
                },
                where: form.val("search-form")
            });
            return false;
        });

        //监听行选中
        table.on('row(currentTableFilter)', function (obj) {
            project = obj.data;
            console.log(project);
            obj.tr.addClass('layui-bg-blue').siblings().removeClass('layui-bg-blue');

            localStorage.setItem("id", project.id);
            localStorage.setItem("htmc", project.htmc == null ? '' : project.htmc);
            localStorage.setItem("rwsmc", project.rwsmc == null ? '' : project.rwsmc);
            localStorage.setItem("yszl", project.yszl == null ? '' : project.yszl);
            localStorage.setItem("wj", project.wj == null ? '' : project.wj);
            localStorage.setItem("htje", project.htje == null ? '': project.htje);

        });

        //双击
        table.on('rowDouble(currentTableFilter)', function (obj) {
            project = obj.data;
            obj.tr.addClass('layui-bg-blue').siblings().removeClass('layui-bg-blue');

            localStorage.setItem("id", project.id);
            localStorage.setItem("htmc", project.htmc == null ? '' : project.htmc);
            localStorage.setItem("rwsmc", project.rwsmc == null ? '' : project.rwsmc);
            localStorage.setItem("yszl", project.yszl == null ? '' : project.yszl);
            localStorage.setItem("wj", project.wj == null ? '' : project.wj);
            localStorage.setItem("htje", project.htje == null ? '': project.htje);
            localStorage.setItem("updateflag", "1");


            parent.layer.close(parent.layer.getFrameIndex(window.name));// 关闭子窗口
        });

        // 监听选择按钮
        $("button[lay-filter='selectBtn']").click(function () {
            if (project == null) {
                Message.warning("请选择项目", 1000);
                return;
            }
            localStorage.setItem("updateflag", "1");

            parent.layer.close(parent.layer.getFrameIndex(window.name));// 关闭子窗口
        });

        // 监听取消按钮
        $("button[lay-filter='cancleBtn']").click(function () {
            localStorage.setItem("xmid", '');
            localStorage.setItem("updateflag", "0");
            var iframeIndex = parent.layer.getFrameIndex(window.name);
            parent.layer.close(iframeIndex);
        });
    });
</script>
</body>
</html>