懒羊羊
2023-08-30 1ac2bc1590406d9babec036e154d8d08f34a6aa1
提交 | 用户 | 时间
1ac2bc 1 layui.use(['form', '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     var form = layui.form;
8
9
10     /**
11      * 工艺路线管理
12      */
13     var ProductRouteInfo = {
14         tableId: "productRouteInfoTable"
15     };
16
17     /**
18      * 初始化表格的列
19      */
20     ProductRouteInfo.initColumn = function () {
21         return [[
22             {type: 'checkbox'},
23             {field: 'id', hide: true, title: '主键id'},
24             // {field: 'routeCode', sort: true, title: '流程编码',width:130},
25             {
26                 field: 'routeCode',width:130, align: "center", sort: true, title: '流程编码', templet: function (d) {
27                     var url = Feng.ctxPath + '/productRouteChildInfo?routeCode=' + d.routeCode;
28                     return '<a style="color: #01AAED;" href="' + url + '">' + d.routeCode + '</a>';
29                 }
30             },
31             {field: 'routeName', sort: true, title: '流程名称',width:160},
32             {field: 'productCode', sort: true, title: '产品编码',width:130},
33             {field: 'productName', sort: true, title: '产品名称',width:160},
34             {field: 'version', sort: true, title: '版本',width:100},
35             {field: 'status', align: "center", sort: true, templet: '#statusTpl', title: '状态'},
36             // {
37             //     field: 'status', align: "center", title: '状态', templet: function (d) {
38             //         if (d.status === 'ENABLE') {
39             //             return "启用";
40             //         } else {
41             //             return "禁用";
42             //         }
43             //     }
44             // },
45             {field: 'remark', sort: true, title: '备注'},
46             {field: 'createUser', sort: true, title: '创建用户',width:130},
47             {field: 'createTime', sort: true, title: '创建时间',width:160},
48             {field: 'updateUser', sort: true, title: '更改用户',width:130},
49             {field: 'updateTime', sort: true, title: '更改时间',width:160},
50             {fixed: 'right',width: 125, minWidth: 125, align: 'center', toolbar: '#tableBar', title: '操作'}
51         ]];
52     };
53
54     /**
55      * 点击查询按钮
56      */
57     ProductRouteInfo.search = function () {
58         var queryData = {};
59
60         queryData['routeCode'] = $('#routeCode').val();
61         queryData['routeName'] = $('#routeName').val();
62         queryData['productCode'] = $('#productCode').val();
63         queryData['productName'] = $('#productName').val();
64         queryData['status'] = $('#status').val();
65
66         table.reload(ProductRouteInfo.tableId, {
67             where: queryData, page: {curr: 1}
68         });
69     };
70
71     form.on('switch(status)', function (obj) {
72         var id = obj.elem.value;
73         var checked = obj.elem.checked ? 'ENABLE' : 'DISABLE';
74         ProductRouteInfo.changeStatus(id, checked);
75     });
76
77     // 修改状态方法
78     ProductRouteInfo.changeStatus = function (id, checked) {
79         var ajax = new $ax(Feng.ctxPath + "/productRouteInfo/editItem", function (data) {
80             Feng.success("修改成功!");
81         }, function (data) {
82             Feng.error("修改失败!" + data.message);
83         });
84         ajax.set("id", id);
85         ajax.set("status", checked);
86         ajax.start();
87     };
88
89     /**
90      * 跳转到添加页面
91      */
92     ProductRouteInfo.jumpAddPage = function () {
93         window.location.href = Feng.ctxPath + '/productRouteInfo/add'
94     };
95
96     /**
97     * 跳转到编辑页面
98     *
99     * @param data 点击按钮时候的行数据
100     */
101     ProductRouteInfo.jumpEditPage = function (data) {
102         window.location.href = Feng.ctxPath + '/productRouteInfo/edit?id=' + data.id
103     };
104
105     /**
106      * 导出excel按钮
107      */
108     ProductRouteInfo.exportExcel = function () {
109         var checkRows = table.checkStatus(ProductRouteInfo.tableId);
110         if (checkRows.data.length === 0) {
111             Feng.error("请选择要导出的数据");
112         } else {
113             table.exportFile(tableResult.config.id, checkRows.data, 'xls');
114         }
115     };
116
117     /**
118      * 点击删除
119      *
120      * @param data 点击按钮时候的行数据
121      */
122     ProductRouteInfo.onDeleteItem = function (data) {
123         var operation = function () {
124             var ajax = new $ax(Feng.ctxPath + "/productRouteInfo/delete", function (data) {
125                 Feng.success("删除成功!");
126                 table.reload(ProductRouteInfo.tableId);
127             }, function (data) {
128                 Feng.error("删除失败!" + data.responseJSON.message + "!");
129             });
130             ajax.set("id", data.id);
131             ajax.set("routeCode", data.routeCode);
132             ajax.start();
133         };
134         Feng.confirm("是否删除?", operation);
135     };
136
137     // 渲染表格
138     var tableResult = table.render({
139         elem: '#' + ProductRouteInfo.tableId,
140         url: Feng.ctxPath + '/productRouteInfo/list',
141         page: true,
142         height: "full-158",
143         cellMinWidth: 100,
144         cols: ProductRouteInfo.initColumn()
145     });
146
147     // 搜索按钮点击事件
148     $('#btnSearch').click(function () {
149         ProductRouteInfo.search();
150     });
151
152     // 添加按钮点击事件
153     $('#btnAdd').click(function () {
154
155     ProductRouteInfo.jumpAddPage();
156
157     });
158
159     // 导出excel
160     $('#btnExp').click(function () {
161         ProductRouteInfo.exportExcel();
162     });
163
164     // 工具条点击事件
165     table.on('tool(' + ProductRouteInfo.tableId + ')', function (obj) {
166         var data = obj.data;
167         var layEvent = obj.event;
168
169         if (layEvent === 'edit') {
170             ProductRouteInfo.jumpEditPage(data);
171         } else if (layEvent === 'delete') {
172             ProductRouteInfo.onDeleteItem(data);
173         }
174     });
175 });