<!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">
            <div class="layui-inline" style="margin-left: -10px">
              <label class="layui-form-label" style="width: 60px">项目名称</label>
              <div class="layui-input-inline" style="width: 200px">
                <input type="text" id="xmmc" name="xmmc" autocomplete="off" class="layui-input">
              </div>
            </div>
            <div class="layui-inline" style="margin-left: -10px">
              <label class="layui-form-label" style="width: 60px">ERP编号</label>
              <div class="layui-input-inline" style="width: 200px">
                <input type="text" name="erpbh" autocomplete="off" class="layui-input">
              </div>
            </div>
            <div class="layui-inline" style="margin-left: -10px">
              <label class="layui-form-label" style="width: 60px">年份</label>
              <div class="layui-input-inline" style="width: 200px">
                <input type="text" name="nf" autocomplete="off" class="layui-input">
              </div>
            </div>
            <br>
            <div class="layui-inline" style="margin-left: -10px">
              <label class="layui-form-label" style="width: 60px">项目类型</label>
              <div class="layui-input-inline" style="width: 200px">
                <select name="xmlx" id="xmlx" lay-filter="status">
                  <option value="">全部</option>
                  <option th:each="item:${xmlxList}" th:text="${item.name}"
                          th:value="${item.code}"></option>
                </select>
              </div>
            </div>
            <div class="layui-inline">
              <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>
          </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 th:src="@{/lib/jquery-3.4.1/jquery-3.4.1.min.js}" charset="utf-8"></script>
<script th:src="@{/lib/layui-v2.6.3/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 currTable = table.render({
      elem: '#currentTableId',
      url: AjaxUtil.ctx + 'prjAnnualbudget/mylist',
      method: 'post',
      where:{
        add: '1',
      },
      // toolbar: '#toolbarDemo',
      // defaultToolbar: ['filter', 'exports', 'print'],
      cols: [
        [
          {type: 'numbers'},
          {field: 'xmmc', width: '30%', title: '项目名称'},
          {field: 'mc', width: '30%', title: '年度预算名称'},
          {field: 'erpbh', width: '13%', title: 'ERP编号'},
          {field: 'xmlxmc', width: '18%', title: '项目类型'},
          {field: 'ssbmmc', width: '18%', title: '所属部门'},
          {field: 'nf', width: '10%', title: '年份'},
          {field: 'xmfzrxm', width: '10%', title: '项目负责人'},
        ]
      ],
      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"),
          add: '1'
        }
      });
      return false;
    });

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

    //监听行选中
    table.on('row(currentTableFilter)', function (obj) {
      console.log(obj.data)
      annualbudget = obj.data;
      obj.tr.addClass('layui-bg-blue').siblings().removeClass('layui-bg-blue');
      localStorage.setItem("ysid", annualbudget.id);
      localStorage.setItem("xmid", annualbudget.rws);
      localStorage.setItem("nf", annualbudget.nf);
      localStorage.setItem("xmmc", annualbudget.xmmc == null ? '' : annualbudget.xmmc);
      localStorage.setItem("erpbh", annualbudget.erpbh == null ? '' : annualbudget.erpbh);
      localStorage.setItem("xmlx", annualbudget.xmlx == null ? '' : annualbudget.xmlx);
      localStorage.setItem("xmlxmc", annualbudget.xmlxmc == null ? '' : annualbudget.xmlxmc);
      localStorage.setItem("xmfzr", annualbudget.xmfzr == null ? '' : annualbudget.xmfzr);
      localStorage.setItem("xmfzrxm", annualbudget.dkyfzrxm == null ? '' : annualbudget.dkyfzrxm);
      localStorage.setItem("ssbm", annualbudget.ssbm == null ? '' : annualbudget.ssbm);
      localStorage.setItem("ssbmmc", annualbudget.ssbmmc == null ? '' : annualbudget.ssbmmc);
      localStorage.setItem("annualbudget",annualbudget.dkyfzr == null ? '' :  annualbudget.dkyfzr);
    });

    //双击
    table.on('rowDouble(currentTableFilter)', function (obj) {
      project = obj.data;

      obj.tr.addClass('layui-bg-blue').siblings().removeClass('layui-bg-blue');

      localStorage.setItem("ysid", project.id);
      localStorage.setItem("xmid", project.rws);
      localStorage.setItem("nf", project.nf);
      localStorage.setItem("xmmc", project.xmmc == null ? '' : project.xmmc);
      localStorage.setItem("erpbh", project.erpbh == null ? '' : project.erpbh);
      localStorage.setItem("xmlx", project.xmlx == null ? '' : project.xmlx);
      localStorage.setItem("xmlxmc", project.xmlxmc == null ? '' : project.xmlxmc);
      localStorage.setItem("xmfzr", project.xmfzr == null ? '' : project.xmfzr);
      localStorage.setItem("xmfzrxm", project.dkyfzrxm == null ? '' : project.dkyfzrxm);
      localStorage.setItem("ssbm", project.ssbm == null ? '' : project.ssbm);
      localStorage.setItem("ssbmmc", project.ssbmmc == null ? '' : project.ssbmmc);
      localStorage.setItem("annualbudget",project.dkyfzr == null ? '' :  project.dkyfzr);
      localStorage.setItem("updateflag", "1");


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

    // 监听选择按钮
    $("button[lay-filter='selectBtn']").click(function () {
      if (annualbudget == 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>