$(function () {
initialPage();
getGrid();
});
function initialPage() {
$(window).resize(function () {
TreeGrid.table.resetHeight({height: $(window).height() - 100});
});
}
function getGrid() {
var colunms = TreeGrid.initColumn();
var table = new TreeTable(TreeGrid.id, '../sys/macro/queryAll', colunms);
table.setExpandColumn(1);
table.setIdField("id");
table.setCodeField("id");
table.setParentCodeField("parentId");
table.setExpandAll(false);
table.setHeight($(window).height() - 100);
table.init();
TreeGrid.table = table;
}
var TreeGrid = {
id: "jqGrid",
table: null,
layerIndex: -1
};
/**
* 初始化表格的列
*/
TreeGrid.initColumn = function () {
var columns = [
{field: 'selectItem', radio: true},
// {title: 'id', field: 'id', align: 'center', valign: 'middle', width: '50px', hidden: true},
{title: '名称', field: 'name', align: 'center', valign: 'middle', width: '50px'},
{title: '值', field: 'value', align: 'center', valign: 'middle', width: '50px'},
{
title: '状态',
field: 'status',
align: 'center',
valign: 'middle',
width: '50px',
formatter: function (item) {
if (item.status == 1) {
return '显示';
} else {
return '隐藏';
}
}
},
{
title: '类型', field: 'type', align: 'center', valign: 'middle', width: '50px',
formatter: function (item, index) {
if (item.type === 1) {
return '参数配置';
}
return '目录';
}
},
{title: '排序', field: 'orderNum', align: 'center', valign: 'middle', width: '50px'},
{title: '备注', field: 'remark', align: 'center', valign: 'middle', width: '50px'},
{
title: '创建时间',
field: 'gmtCreate',
align: 'center',
valign: 'middle',
width: '80px',
formatter: function (item) {
return transDate(item.gmtCreate);
}
},
{
title: '修改时间', field: 'gmtModified', align: 'center', valign: 'middle', width: '80px',
formatter: function (item) {
return transDate(item.gmtCreate);
}
}
];
return columns;
};
var vm = new Vue({
el: '#rrapp',
data: {
showList: true,
title: null,
macro: {type: 0, status: 1},
ruleValidate: {
name: [
{required: true, message: '名称不能为空', trigger: 'blur'}
]
},
q: {
name: ''
},
macros: []
},
methods: {
query: function () {
vm.reload();
},
getMacros: function () {
$.get("../sys/macro/queryAll?type=0", function (r) {
vm.macros = r.list;
});
},
add: function () {
vm.showList = false;
vm.title = "新增";
vm.macro = {type: 0, status: 1};
vm.macros = [];
vm.getMacros();
},
update: function (event) {
var id = TreeGrid.table.getSelectedRow();
if (id.length == 0) {
iview.Message.error("请选择一条记录");
return;
}
vm.showList = false;
vm.title = "修改";
$.get("../sys/macro/info/" + id[0].id, function (r) {
vm.macro = r.macro;
});
vm.getMacros();
},
saveOrUpdate: function (event) {
var url = vm.macro.id == null ? "../sys/macro/save" : "../sys/macro/update";
$.ajax({
type: "POST",
url: url,
contentType: "application/json",
data: JSON.stringify(vm.macro),
success: function (r) {
if (r.code === 0) {
alert('操作成功', function (index) {
vm.reload();
});
} else {
alert(r.msg);
}
}
});
},
del: function (event) {
var id = TreeGrid.table.getSelectedRow(), ids = [];
if (id.length == 0) {
iview.Message.error("请选择一条记录");
return;
}
confirm('确定要删除选中的记录?', function () {
$.each(id, function (idx, item) {
ids[idx] = item.id;
});
$.ajax({
type: "POST",
url: "../sys/macro/delete",
contentType: "application/json",
data: JSON.stringify(ids),
success: function (r) {
if (r.code == 0) {
alert('操作成功', function (index) {
vm.reload();
});
} else {
alert(r.msg);
}
}
});
});
},
reload: function (event) {
vm.showList = true;
TreeGrid.table.refresh();
},
handleSubmit: function (name) {
handleSubmitValidate(this, name, function () {
vm.saveOrUpdate()
});
},
handleReset: function (name) {
handleResetForm(this, name);
}
}
});