layui 中使用thymeleaf if判断
<table class="layui-hide" id="repairTable" lay-filter="repairTable"></table>
<script type="text/html" id="repairBar" style="display: none;">
{{# if(d.status == 0){ }}
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="confirm">确认维修</a>
{{# }if(d.status == 1) { }}
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="over">完成维修</a>
{{# }if(d.status == 2){ }}
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="cancel">删除</a>
{{# } }}
</script>
<script src="https://www.layuicdn.com/layui-v2.5.5/layui.js"></script>
<script type="text/javascript" th:inline="none">
var tableIns;
layui.use([ 'jquery', 'layer', 'form', 'upload','table'], function() {
var $ = layui.jquery;
var layer = layui.layer;
var form = layui.form;
var table = layui.table;
tableIns=table.render({
elem: '#repairTable'
,url:'repair/queryRepairAllList'
,title: '数据表'
,toolbar:"#repairToolBar"
,height:'full-100'
,cellMinWidth:80
,page: true
,limits: [10, 20, 30]
,limit: 10
,cols: [[
{field:'id', title:'维修管理ID',align:'center'}
,{field:'roomName', title:'维修教室',align:'center'}
,{field:'category', title:'维修种类',align:'center'}
,{field:'damage', title:'维修内容',width:"20%",align:'center'}
,{field:'createTime', title:'报修时间',align:'center'}
,{field:'status', title:'订单',align:'center',templet: function (d) {
if(d.status == 0){
return '<a color=blue>未处理</a>';
}else if (d.status == 1){
return '<a color=blue>维修中</a>';
}else if (d.status == 2){
return '<a color=blue>已维修</a>';
}}}
,{fixed: 'right', title:'操作', width:'16%', toolbar: '#repairBar',align:'center'}
]]
})
$("#doSearch").click(function () {
var params = $("#searchFrm").serialize();
tableIns.reload({
url: "repair/queryRepairAllList?" + params
})
});
table.on('tool(repairTable)', function(obj){
var data = obj.data;
var layEvent = obj.event;
if(layEvent === 'confirm'){
layer.confirm('确认该维修单吗?', function(index){
$.post("repair/updateRepair",{
id:data.id,
status:1
},function(res){
layer.msg(res);
tableIns.reload();
})
});
}
if(layEvent === 'over'){
layer.confirm('确认完成该维修单吗?', function(index){
$.post("repair/updateRepair",{
id:data.id,
status:2
},function(res){
layer.msg(res);
tableIns.reload();
})
});
}
if(layEvent === 'cancel'){
layer.confirm('确认删除该维修单吗?', function(index){
$.post("repair/deleteRepair",{
id:data.id
},function(res){
layer.msg(res);
tableIns.reload();
})
});
}
});
});
</script>
|