懒羊羊
2023-08-30 71e81ed1d12e4d69f53c8ad9e066650ad4186293
提交 | 用户 | 时间
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 RecipeManage = {
12         tableId: "recipeManageTable"
13     };
14
15     /**
16      * 初始化表格的列
17      */
18     RecipeManage.initColumn = function () {
19         return [[
20             {type: 'checkbox'},
21             {field: 'id', hide: true, title: 'id'},
22             {field: 'productionLine', sort: true, title: '产线'},
23             {field: 'locationCode', sort: true, title: '工位'},
24             {field: 'productCode', sort: true, title: '产品编号',width:130},
25             {field: 'operationSteps', sort: true, title: '操作内容',width:200},
26             {field: 'techRequirement', sort: true, title: '技术要求',width:300},
27             {field: 'operationType', sort: true, title: '类型',width:130},
28             {field: 'stepSort', sort: true, title: '排序'},
29             {field: 'paramCode', sort: true, title: '参数编码',width:200},
30             {field: 'materialCode', sort: true, title: '物料编码',width:220},
31             {field: 'picture', sort: true, title: '图片',width:200},
32             {field: 'remarks', sort: true, title: '备注'},
33             {align: 'center', toolbar: '#tableBar', title: '操作',width:130}
34         ]];
35     };
36
37     /**
38      * 点击查询按钮
39      */
40     RecipeManage.search = function () {
41         var queryData = {};
42
43         queryData['productionLine'] = $('#productionLine').val();
44         queryData['locationCode'] = $('#locationCode').val();
45         queryData['productCode'] = $('#productCode').val();
46         queryData['paramCode'] = $('#paramCode').val();
47         queryData['materialCode'] = $('#materialCode').val();
48
49         table.reload(RecipeManage.tableId, {
50             where: queryData, page: {curr: 1}
51         });
52     };
53
54     /**
55      * 跳转到添加页面
56      */
57     RecipeManage.jumpAddPage = function () {
58         window.location.href = Feng.ctxPath + '/recipeManage/add'
59     };
60
61     /**
62     * 跳转到编辑页面
63     *
64     * @param data 点击按钮时候的行数据
65     */
66     RecipeManage.jumpEditPage = function (data) {
67         window.location.href = Feng.ctxPath + '/recipeManage/edit?id=' + data.id
68     };
69
70     /**
71      * 导出excel按钮
72      */
73     RecipeManage.exportExcel = function () {
74         var checkRows = table.checkStatus(RecipeManage.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     RecipeManage.onDeleteItem = function (data) {
88         var operation = function () {
89             var ajax = new $ax(Feng.ctxPath + "/recipeManage/delete", function (data) {
90                 Feng.success("删除成功!");
91                 table.reload(RecipeManage.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: '#' + RecipeManage.tableId,
104         url: Feng.ctxPath + '/recipeManage/list',
105         page: true,
106         height: "full-158",
107         cellMinWidth: 100,
108         cols: RecipeManage.initColumn()
109     });
110
111     // 搜索按钮点击事件
112     $('#btnSearch').click(function () {
113         RecipeManage.search();
114     });
115
116     // 添加按钮点击事件
117     $('#btnAdd').click(function () {
118
119     RecipeManage.jumpAddPage();
120
121     });
122
123     // 导出excel
124     $('#btnExp').click(function () {
125         RecipeManage.exportExcel();
126     });
127
128     // 工具条点击事件
129     table.on('tool(' + RecipeManage.tableId + ')', function (obj) {
130         var data = obj.data;
131         var layEvent = obj.event;
132
133         if (layEvent === 'edit') {
134             RecipeManage.jumpEditPage(data);
135         } else if (layEvent === 'delete') {
136             RecipeManage.onDeleteItem(data);
137         }
138     });
139 });