123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- $(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 '<span class="label label-success">参数配置</span>';
- }
- return '<span class="label label-primary">目录</span>';
- }
- },
- {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);
- }
- }
- });
|