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