<!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">
    <script type="text/html" id="toolbarDemo">
      <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="view">
          <i class="layui-icon layui-icon-file" style="font-size: 10px;"></i>查看
        </button>
        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="spOption">
          <i class="layui-icon layui-icon-edit" style="font-size: 10px;"></i>审核
        </button>
        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="spList">
          <i class="layui-icon layui-icon-list" style="font-size: 10px;"></i>审批列表
        </button>
        <!--                <button class="layui-btn layui-btn-sm" lay-event="exportList">-->
        <!--                    <i class="layui-icon layui-icon-export" style="font-size: 10px;"></i>导出列表-->
        <!--                </button>-->
      </div>
    </script>

    <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

  </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/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 = /*[[@{/}]]*/'';
  var updateflag = 0;
  var xmApproval = {};
  layui.use(['form', 'table'], function () {
    var form = layui.form,
            table = layui.table;

    var currTable = table.render({
      elem: '#currentTableId',
      url: AjaxUtil.ctx + 'prjApproverecord/htxgsqList',
      method: 'post',
      toolbar: '#toolbarDemo',
      defaultToolbar: ['filter', 'exports', 'print'],
      cols: [
        [
          {type: "checkbox", fixed: 'left'},
          {type: 'numbers', align: 'center'},
          {field: 'spzt', width: '12%', title: '审批状态', sort: true},
          {field: 'xmlxmc', width: '10%', title: '类型', sort: true},
          {field: 'xm', width: '35%', title: '项目/申请', sort: true},
          // {field: 'zt', width: '12%',title: '状态', sort: true},
          {field: 'tjrxm', width: '8%', title: '提交人', align: 'center'},
          {field: 'tjsj', width: '12%', title: '提交时间', align: 'center'}
          // {title: '操作', toolbar: '#currentTableBar', align: 'center', fixed: 'right'}
        ]
      ],
      sortName: 'xm',
      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", {
        "xm": '',
        "erpbh": '',
        "xmlx": '',
        "spzt": '',
        "tablename":''
      });
      // 执行搜索重载
      currTable.reload({
        page: {
          curr: 1
        },
        where: form.val("search-form")
      });
      return false;
    });

    // 监听排序事件
    table.on('sort(currentTableFilter)', function (obj) { //注：sort 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
      currTable.reload({
        initSort: obj, //记录初始排序，如果不设的话，将无法标记表头的排序状态。
        where: { //请求参数（注意：这里面的参数可任意定义，并非下面固定的格式）
          sortName: toLine(obj.field), //排序字段
          sortOrder: toLine(obj.type) //排序方式
        }
      });
    });

    // 监听行工具事件
    table.on('toolbar(currentTableFilter)', function (obj) {
      if (obj.event == 'view') {
        var projects = table.cache["currentTableId"];
        if (projects.length == 0)
          return;

        var checkStatus = table.checkStatus('currentTableId')
                , data = checkStatus.data;
        if (data == null || data.length === 0) {
          Message.warning("请选择要查看的记录！", 1500);
        } else if (data.length > 1) {
          Message.warning("请选择一条记录进行查看！", 1500);
        } else {
          var height = 1090;
          var title = '查看合同修改数据';
          var content = AjaxUtil.ctx;
            content += 'prjContractXg/forView/' + data[0].xmid;

          layer.open({
            title: title,
            type: 2,
            shade: 0.3,
            maxmin: true,
            shadeClose: true,
            area: [height + 'px', layerheight + 'px'],
            content: content,
            end: function (index) {
              layer.close(index);
            }
          });
        }
      } else if (obj.event === 'spOption') {
        var projects = table.cache["currentTableId"];
        if (projects.length == 0)
          return;

        var checkStatus = table.checkStatus('currentTableId')
                , data = checkStatus.data;
        if (data == null || data.length === 0) {
          Message.warning("请选择要审批的记录！", 1500);
        } else if (data.length > 1) {
          Message.warning("请选择一条记录进行审批！", 1500);
        } else {
          var content = oneSP(data)
          layer.open({
            title: '审批意见',
            type: 2,
            shade: 0.3,
            maxmin: true,
            shadeClose: true,
            area: ['1025px', layerheight + 'px'],
            content: content,
            end: function () {
              if (updateflag == 1)
                currTable.reload();
              updateflag = 0;
            }
          });
        }
      } else if (obj.event === 'spList') {
        var projects = table.cache["currentTableId"];
        if (projects.length == 0)
          return;

        var checkStatus = table.checkStatus('currentTableId')
                , data = checkStatus.data;
        if (data == null || data.length === 0) {
          Message.warning("请选择要查看的记录！", 1500);
        } else if (data.length > 1) {
          Message.warning("请选择一条记录进行查看！", 1500);
        } else {
          xmApproval = {
            "xmid": data[0].xmid,
            "xm": data[0].xm
          };

          var content = AjaxUtil.ctx;
          if (data[0].tablename == 'prj_Contract')
            content += 'prjContract';
          content += '/forApproveList?mc=' + data[0].xm;

          var index = layer.open({
            title: '审批列表',
            type: 2,
            shade: 0.3,
            maxmin: true,
            shadeClose: true,
            area: ['1300px', '750px'],
            content: content,
            end: function () {
              layer.close(index);
            }
          });
        }
      }
    });

    //双击
    table.on('rowDouble(currentTableFilter)', function (obj) {
      var projects = table.cache["currentTableId"];
      if (projects.length == 0)
        return;

      var checkStatus = table.checkStatus('currentTableId')
              , data = checkStatus.data;
      if (data == null || data.length === 0) {
        Message.warning("请选择要审批的记录！", 1500);
      } else if (data.length > 1) {
        Message.warning("请选择一条记录进行审核！", 1500);
      } else {
        var content = oneSP(data)
        layer.open({
          title: '审批意见',
          type: 2,
          shade: 0.3,
          maxmin: true,
          shadeClose: true,
          area: ['1025px', layerheight + 'px'],
          content: content,
          end: function () {
            if (updateflag == 1)
              currTable.reload();
            updateflag = 0;
          }
        });
      }
    });
  });

  function oneSP(data) {
    var content = AjaxUtil.ctx;
    if (data[0].tablename == 'prj_Contract') {
      xmApproval = {
        "xmid": data[0].xmid,
        "xm": data[0].xm,
        "zt": data[0].spzt,
        "htje": data[0].htje
      };
      content += 'prjContract/forApproveUpdate/' + data[0].xmid + '?spzt=' + data[0].spzt;
    }
    return content;
  }

  function setUpdateFlag() {
    updateflag = 1;
  }

  function getXmApproval() {
    return xmApproval;
  }
</script>
</body>
</html>