懒羊羊
2024-01-11 be26d5065b4a07123638c220c0792e9250a458e6
提交 | 用户 | 时间
71e81e 1 layui.use(['table', 'admin', 'ax', 'func'], function () {
2     var $ = layui.$;
3     var table = layui.table;
4     var $ax = layui.ax;
5     var admin = layui.admin;
6     var func = layui.func;
7
8     /**
9      * 设备状态管理
10      */
11     var EquipmentStatus = {
12         tableId: "equipmentStatusTable"
13     };
14
15     /**
16      * 初始化表格的列
17      */
18     EquipmentStatus.initColumn = function () {
19         return [[
20             {type: 'checkbox'},
21             {field: 'id', hide: true, title: 'ID'},
22             {field: 'equipmentNo', sort: true, title: '设备编号'},
23             {field: 'equipmentName', sort: true, title: '设备名称'},
24             {field: 'workshopCode', sort: true, title: '车间编号'},
25             {field: 'productionLineCode', sort: true, title: '产线编号'},
26             {field: 'locationCode', sort: true, title: '工位编号'},
27             {field: 'status', sort: true, title: '设备状态'},//(1运转2待机3故障)
28 /*            {field: 'spareField1', sort: true, title: '预留字段1'},
29             {field: 'spareField2', sort: true, title: '预留字段2'},*/
30             {field: 'remarks', sort: true, title: '备注'},
31             {field: 'updateTime', sort: true, title: '更新时间'},
32            /* {align: 'center', toolbar: '#tableBar', title: '操作'}*/
33         ]];
34     };
35
36     /**
37      * 点击查询按钮
38      */
39     EquipmentStatus.search = function () {
40         var queryData = {};
41         queryData['equipmentNo'] = $("#equipmentNo").val();
42         queryData['equipmentName'] = $("#equipmentName").val();
43
44         table.reload(EquipmentStatus.tableId, {
45             where: queryData, page: {curr: 1}
46         });
47     };
48
49     /**
50      * 跳转到添加页面
51      */
52     EquipmentStatus.jumpAddPage = function () {
53         window.location.href = Feng.ctxPath + '/equipmentStatus/add'
54     };
55
56     /**
57     * 跳转到编辑页面
58     *
59     * @param data 点击按钮时候的行数据
60     */
61     EquipmentStatus.jumpEditPage = function (data) {
62         window.location.href = Feng.ctxPath + '/equipmentStatus/edit?id=' + data.id
63     };
64
65     /**
66      * 导出excel按钮
67      */
68     EquipmentStatus.exportExcel = function () {
69         var checkRows = table.checkStatus(EquipmentStatus.tableId);
70         if (checkRows.data.length === 0) {
71             Feng.error("请选择要导出的数据");
72         } else {
73             table.exportFile(tableResult.config.id, checkRows.data, 'xls');
74         }
75     };
76
77     /**
78      * 点击删除
79      *
80      * @param data 点击按钮时候的行数据
81      */
82     EquipmentStatus.onDeleteItem = function (data) {
83         var operation = function () {
84             var ajax = new $ax(Feng.ctxPath + "/equipmentStatus/delete", function (data) {
85                 Feng.success("删除成功!");
86                 table.reload(EquipmentStatus.tableId);
87             }, function (data) {
88                 Feng.error("删除失败!" + data.responseJSON.message + "!");
89             });
90             ajax.set("id", data.id);
91             ajax.start();
92         };
93         Feng.confirm("是否删除?", operation);
94     };
95
96     // 渲染表格
97     var tableResult = table.render({
98         elem: '#' + EquipmentStatus.tableId,
99         url: Feng.ctxPath + '/equipmentStatus/list',
100         toolbar: '#toolbarDemo',
101         page: true,
102         height: "full-158",
103         cellMinWidth: 100,
104         cols: EquipmentStatus.initColumn()
105     });
106
107     // 搜索按钮点击事件
108     $('#btnSearch').click(function () {
109         EquipmentStatus.search();
110     });
111
112     // 添加按钮点击事件
113     $('#btnAdd').click(function () {
114
115     EquipmentStatus.jumpAddPage();
116
117     });
118
119     // 导出excel
120     $('#btnExp').click(function () {
121         EquipmentStatus.exportExcel();
122     });
123
124     // 工具条点击事件
125     table.on('tool(' + EquipmentStatus.tableId + ')', function (obj) {
126         var data = obj.data;
127         var layEvent = obj.event;
128
129         if (layEvent === 'edit') {
130             EquipmentStatus.jumpEditPage(data);
131         } else if (layEvent === 'delete') {
132             EquipmentStatus.onDeleteItem(data);
133         }
134     });
135 });