<%
#include "FormEleLib.js_"

var parentPkgName=GetGParamValue('EZGEN_ROOT_PKGNAME'); //上级包名
if(!parentPkgName)parentPkgName='com.ruoyi.project';
var modelPkgName=AutoCapProc(curModel.name,'JavaPackageName');
var modelCap=curModel.caption?curModel.caption:curModel.name;
var tb=curTable; //当前表
var tbPkgName=AutoCapProc(tb.name,'JavaPackageName');
var ClsName=AutoCapProc(tb.name,'ClassName'); //类名（驼峰命名，首字母大写）
var instName=AutoCapProc(tb.name,'FieldName'); //类名（驼峰命名，首字母小写）
var dispName=tb.UIDisplayName; //逻辑显示名
if(!dispName)dispName=ClsName;

var fds=tb.metaFields;
var idName='id';
var idCol='id';
var idTp='Long';
var pk=tb.getPrimaryKeyField();
if(pk){
    idName=AutoCapProc(pk.name,'FieldName');
    idCol=pk.name;
    if(pk.dataType!='cfdtInteger')
        idTp='String';
}

var hasQueryCfg=false;
for(var k=0; k<fds.count; k++) 
{
    var fd = fds.getItem(k); //取第k个字段
    if(!fd.isPhysicalField()) //判断字段是否物理字段
      continue; 
    if(fd.queryable)hasQueryCfg=true;
}

var _LfKeyL='${';

%><!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('${dispName}列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul><%  //遍历所有字段
  coutIndentSpace="                                ";
  var autoQfCount=0;
  for(var k=0; k<fds.count; k++) 
  {
    var fd = fds.getItem(k); //取第k个字段
    if(!fd.isPhysicalField()) //判断字段是否物理字段
      continue;
    if(!hasQueryCfg)
    {
      if(!fd.canDisplay('grid'))
        continue;
      autoQfCount++;
      if(autoQfCount>8) //自动生成查询项：最多8个
        break;
    } else if(!fd.queryable)
      continue;
    curOut.add('                            <li>');
    curOut.add('                                <label>'+fd.getLabelText()+'：</label>');
    var edt=fd.possibleEditorType();
    if(edt=='ComboBox' || edt=='RadioBox' || edt=='ButtonGroup'){
        couti('<select name="'+AutoCapProc(fd.name,'FieldName')+'">'); 
        couti('  <option value="">所有</option>');
        var opts=getDropdownItems(fd);
        if(opts){
          for(var idx in opts){
            var opt=opts[idx];
            couti('  <option value="'+opt.value+'">'+opt.text+'</option>');
          }
        }
        couti('</select>');
    }
    else if(fd.dataType=='cfdtDate')
      curOut.add('                                <input type="text" class="time-input" name="'+AutoCapProc(fd.name,'FieldName')+'"/>');
    else
      curOut.add('                                <input type="text" name="'+AutoCapProc(fd.name,'FieldName')+'"/>');
    curOut.add('                            </li>');
  }%>

                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="${modelPkgName}:${tbPkgName}:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="${modelPkgName}:${tbPkgName}:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="${modelPkgName}:${tbPkgName}:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="${modelPkgName}:${tbPkgName}:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${_LfKeyL}@permission.hasPermi('${modelPkgName}:${tbPkgName}:edit')}]];
        var removeFlag = [[${_LfKeyL}@permission.hasPermi('${modelPkgName}:${tbPkgName}:remove')}]];
        var typeNameDatas = [[${_LfKeyL}@dict.getType('sys_notice_type')}]];
        var prefix = ctx + "${modelPkgName}/${tbPkgName}";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "${dispName}",
                columns: [{
                    checkbox: true
                },<%  
  if(pk){
    curOut.add('                {');
    curOut.add('                    field: "'+AutoCapProc(pk.name,'FieldName')+'",');
    curOut.add('                    title: "'+pk.getLabelText()+'",');
    if(pk.canDisplay('grid'))
      curOut.add('                    visible: true');
    else
      curOut.add('                    visible: false');
    curOut.add('                },');
  } else {
    curOut.add('                {');
    curOut.add('                    field: "id",');
    curOut.add('                    title: "编号",');
    curOut.add('                    visible: false');
    curOut.add('                },');
  }
                
  //遍历所有字段
  coutIndentSpace="                    ";
  for(var k=0; k<fds.count; k++) 
  {
    var fd = fds.getItem(k); //取第k个字段
    if(!fd.isPhysicalField()) //判断字段是否物理字段
      continue;
    if (fd.name==idCol)
      continue;
    if(!fd.canDisplay('grid'))
      continue;
    curOut.add('                {');
    curOut.add('                    field: "'+AutoCapProc(fd.name,'FieldName')+'",');
    curOut.add('                    title: "'+fd.getLabelText()+'"');
    var edt=fd.possibleEditorType();
    if(edt=='ComboBox' || edt=='RadioBox' || edt=='ButtonGroup')
    if(fd.dataType=='cfdtInteger' || fd.dataType=='cfdtEnum'){
        var opts=getDropdownItems(fd);
        if(opts){
          couti(', formatter: function (value, row, index) {');
          for(var idx in opts){
            var opt=opts[idx];
            couti('  if (value=="'+opt.value+'") return "'+opt.text+'";');
          }
          couti('  return value;');
          couti('}');
        }
    }
    curOut.add('                },');
  }%>

                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.${idName} + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.${idName} + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
    </script>
</body>
</html>