admin
2024-01-11 4a2c6796c89f6889bbdd3e9630fee40a93c6473e
提交 | 用户 | 时间
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      * bom信息管理
10      */
11     var BomInfo = {
12         tableId: "bomInfoTable"
13     };
14
15     /**
16      * 初始化表格的列
17      */
18     BomInfo.initColumn = function () {
19         return [[
20             {type: 'checkbox'},
21             /*  {type:"numbers" ,title:'序号',width:40,fixed:'left'},*/
22             {field: 'id', hide: true, title: 'ID'},
23             {field: 'materialCode', sort: true, title: '物料编号', width: 125},
24             {field: 'materialName', sort: true, title: '物料名称', width: 200},
25             {field: 'productCode', sort: true, title: '产品编号', width: 125},
26             {field: 'productName', sort: true, title: '产品名称', width: 270},
27             {field: 'locationCode', sort: true, title: '工位编号', width: 110},
28             {field: 'locationName', sort: true, title: '工位名称', width: 270},
29             {field: 'loadingCode', sort: true, title: '扫码工位编号', width: 135},
30             // {field: 'loadingName', sort: true, title: '扫码工位名称'},
31             // {field: 'traceabilityType', sort: true, title: '追溯类型'},
32             {field: 'traceabilityType', title: '追溯类型',width: 100, templet: function (data) {if (data.traceabilityType === '1') return '编号追溯';else if (data.traceabilityType === '2') return '批次追溯'; else return '追溯';}},
33             {field: 'quantity', sort: true, title: '数量',align:'center'},
a55627 34             {field: 'lineCode', sort: true, title: '单位',align:'center'},
71e81e 35             {field: 'remarks', sort: true, title: '备注'},
36             {align: 'center', toolbar: '#tableBar', title: '操作', width: 125}
37         ]];
38     };
39
40     /**
41      * 点击查询按钮
42      */
43     BomInfo.search = function () {
44         var queryData = {};
45         queryData['materialCode'] = $("#materialCode").val();
46         queryData['materialName'] = $("#materialName").val();
47         queryData['productCode'] = $("#productCode").val();
48         queryData['locationCode'] = $("#locationCode").val();
49         table.reload(BomInfo.tableId, {
50             where: queryData, page: {curr: 1}
51         });
52     };
53
54     /**
55      * 跳转到添加页面
56      */
57     BomInfo.jumpAddPage = function () {
58         window.location.href = Feng.ctxPath + '/bomInfo/add'
59     };
60
61     /**
62     * 跳转到编辑页面
63     *
64     * @param data 点击按钮时候的行数据
65     */
66     BomInfo.jumpEditPage = function (data) {
67         window.location.href = Feng.ctxPath + '/bomInfo/edit?id=' + data.id
68     };
69
70     /**
71      * 导出excel按钮
72      */
73     BomInfo.exportExcel = function () {
74         var checkRows = table.checkStatus(BomInfo.tableId);
75         if (checkRows.data.length === 0) {
76             Feng.error("请选择要导出的数据");
77         } else {
78             table.exportFile(tableResult.config.id, checkRows.data, 'xls');
79         }
80     };
81
82     /**
83      * 点击删除
84      *
85      * @param data 点击按钮时候的行数据
86      */
87     BomInfo.onDeleteItem = function (data) {
88         var operation = function () {
89             var ajax = new $ax(Feng.ctxPath + "/bomInfo/delete", function (data) {
90                 Feng.success("删除成功!");
91                 table.reload(BomInfo.tableId);
92             }, function (data) {
93                 Feng.error("删除失败!" + data.responseJSON.message + "!");
94             });
95             ajax.set("id", data.id);
96             ajax.start();
97         };
98         Feng.confirm("是否删除?", operation);
99     };
100
101     // 渲染表格
102     var tableResult = table.render({
103         elem: '#' + BomInfo.tableId,
104         url: Feng.ctxPath + '/bomInfo/list',
105         toolbar: '#toolbarDemo',
106         page: true,
107         height: "full-158",
108         cellMinWidth: 80,
109         cols: BomInfo.initColumn()
110     });
111
112     // 搜索按钮点击事件
113     $('#btnSearch').click(function () {
114         BomInfo.search();
115     });
116
117     // 添加按钮点击事件
118    /* $('body').on('click', '#btnAdd', function() {*/
119     $('#btnAdd').click(function () {
120
121         BomInfo.jumpAddPage();
122
123     });
124
125     // 添加编辑点击事件
126     $('#btnEdit').click(function () {
127         var checkRows = table.checkStatus(BomInfo.tableId);
128         if (checkRows.data.length == 1) {
129             BomInfo.jumpEditPage(checkRows.data[0]);
130         } else {
131             Feng.error("请选择一条要修改的数据");
132         }
133     });
134
135     // 导出excel
136     $('#btnExp').click(function () {
137         BomInfo.exportExcel();
138     });
139
140     // 工具条点击事件
141     table.on('tool(' + BomInfo.tableId + ')', function (obj) {
142         var data = obj.data;
143         var layEvent = obj.event;
144
145         if (layEvent === 'edit') {
146             BomInfo.jumpEditPage(data);
147         } else if (layEvent === 'delete') {
148             BomInfo.onDeleteItem(data);
149         }
150     });
151 });