懒羊羊
2023-11-14 abb175b29054b9708af27136c035b1b7351dcd20
提交 | 用户 | 时间
1ac2bc 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 MaterialInfo = {
12         tableId: "materialInfoTable"
13     };
14
15     /**
16      * 初始化表格的列
17      */
18     MaterialInfo.initColumn = function () {
19         return [[
20             {type: 'checkbox'},
21             {field: 'id', hide: true, title: '主键id'},
22             {field: 'materialCode', sort: true, title: '物料编号',width:130},
23             {field: 'materialName', sort: true, title: '物料名称',width:180},
abb175 24             // {field: 'materialView', sort: true, title: '视图'},
25             // {field: 'typeZ', sort: true, title: '种类'},
26             {
27                 field: 'typeL', align: "center", title: '类型', templet: function (d) {
28                     console.log(d.typeL)
29                     switch(d.typeL){
30                         case "PRODUCE" :
31                             return "产品";
32                             break;
33                         case "SEMIFINISHEDPRODUCTS" :
34                             return "半成品";
35                             break;
36                         case "COMPONENTSANDPARTS" :
37                             return "零部件";
38                             break;
39                         default :
40                     }
41                 }
42             },
1ac2bc 43             {field: 'unit', sort: true, title: '单位'},
abb175 44             // {field: 'matterVersion', sort: true, title: '版本'},
1ac2bc 45             {field: 'remarks', sort: true, title: '备注'},
46             {field: 'createUser', sort: true, title: '创建用户',width:120},
47             {field: 'createTime', sort: true, title: '创建时间',width:160},
48             {field: 'updateUser', sort: true, title: '更改用户',width:120},
49             {field: 'updateTime', sort: true, title: '更改时间',width:160},
abb175 50             // {field: 'erpSpec', sort: true, title: ''},
1ac2bc 51             {fixed: 'right',width: 125, minWidth: 125, align: 'center', toolbar: '#tableBar', title: '操作'}
52         ]];
53     };
54
55     /**
56      * 点击查询按钮
57      */
58     MaterialInfo.search = function () {
59         var queryData = {};
60
61         queryData['materialCode'] = $('#materialCode').val();
62         queryData['materialName'] = $('#materialName').val();
63         queryData['materialView'] = $('#materialView').val();
64         queryData['typeL'] = $('#typeL').val();
65
66         table.reload(MaterialInfo.tableId, {
67             where: queryData, page: {curr: 1}
68         });
69     };
70
71     /**
72      * 跳转到添加页面
73      */
74     MaterialInfo.jumpAddPage = function () {
75         window.location.href = Feng.ctxPath + '/materialInfo/add'
76     };
77
78     /**
79     * 跳转到编辑页面
80     *
81     * @param data 点击按钮时候的行数据
82     */
83     MaterialInfo.jumpEditPage = function (data) {
84         window.location.href = Feng.ctxPath + '/materialInfo/edit?id=' + data.id
85     };
86
87     /**
88      * 导出excel按钮
89      */
90     MaterialInfo.exportExcel = function () {
91         var checkRows = table.checkStatus(MaterialInfo.tableId);
92         if (checkRows.data.length === 0) {
93             Feng.error("请选择要导出的数据");
94         } else {
95             table.exportFile(tableResult.config.id, checkRows.data, 'xls');
96         }
97     };
98
99     /**
100      * 点击删除
101      *
102      * @param data 点击按钮时候的行数据
103      */
104     MaterialInfo.onDeleteItem = function (data) {
105         var operation = function () {
106             var ajax = new $ax(Feng.ctxPath + "/materialInfo/delete", function (data) {
107                 Feng.success("删除成功!");
108                 table.reload(MaterialInfo.tableId);
109             }, function (data) {
110                 Feng.error("删除失败!" + data.responseJSON.message + "!");
111             });
112             ajax.set("id", data.id);
113             ajax.start();
114         };
115         Feng.confirm("是否删除?", operation);
116     };
117
118     // 渲染表格
119     var tableResult = table.render({
120         elem: '#' + MaterialInfo.tableId,
121         url: Feng.ctxPath + '/materialInfo/list',
122         page: true,
123         height: "full-158",
124         cellMinWidth: 100,
125         cols: MaterialInfo.initColumn()
126     });
127
128     // 搜索按钮点击事件
129     $('#btnSearch').click(function () {
130         MaterialInfo.search();
131     });
132
133     // 添加按钮点击事件
134     $('#btnAdd').click(function () {
135
136     MaterialInfo.jumpAddPage();
137
138     });
139
140     // 导出excel
141     $('#btnExp').click(function () {
142         MaterialInfo.exportExcel();
143     });
144
145     // 工具条点击事件
146     table.on('tool(' + MaterialInfo.tableId + ')', function (obj) {
147         var data = obj.data;
148         var layEvent = obj.event;
149
150         if (layEvent === 'edit') {
151             MaterialInfo.jumpEditPage(data);
152         } else if (layEvent === 'delete') {
153             MaterialInfo.onDeleteItem(data);
154         }
155     });
156 });