懒羊羊
2023-11-14 abb175b29054b9708af27136c035b1b7351dcd20
提交 | 用户 | 时间
1ac2bc 1 layui.use(['upload', '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 upload = layui.upload;
8
9     /**
10      * 生产订单管理
11      */
12     var SalesOrder = {
13         tableId: "salesOrderTable"
14     };
15
16     /**
17      * 初始化表格的列
18      */
19     SalesOrder.initColumn = function () {
20         return [[
21             {type: 'checkbox'},
22             {field: 'id', hide: true, title: '主键id'},
23             {field: 'salesOrderCode', sort: true, title: '订单编号',width: 160},
24             {field: 'customerNo', sort: true, title: '客户编号',width: 120},
25             {field: 'cargoNo', sort: true, title: '货号',width: 120},
26             {field: 'productCode', sort: true, title: '产品编号',width: 160},
27             {field: 'productName', sort: true, title: '产品名称',width: 160},
28             {field: 'planNumber', sort: true, title: '计划数量',width: 120},
29             {
30                 field: 'state', align: "center", title: '状态', templet: function (d) {
31                     switch(d.state){
32                         case "1" :
33                             return "<span style=\"color: #130c0e;\">未开始</span>";
34                             break;
35                         case "2" :
36                             return "<span style=\"color: #00cc33;\">已拆分</span>";
37                             break;
38                         case "3" :
39                             return "<span style=\"color: #ff9933;\">已下发</span>";
40                             break;
41                         case "4" :
42                             return "<span style=\"color: #cc0000;\">已关闭</span>";
43                             break;
44                         default :
45                     }
46                 }
47             },
48             {field: 'planStartTime', sort: true, title: '计划开始时间',width: 160},
49             {field: 'planEndTime', sort: true, title: '计划结束时间',width: 160},
50             {field: 'workshopCode', sort: true, title: '车间编码',width: 120},
51             {field: 'lineCode', sort: true, title: '产线编码',width: 120},
52             {field: 'deliveryTime', sort: true, title: '交货时间',width: 160},
53             {field: 'orderSource', sort: true, title: '订单来源',width: 120},
54             {field: 'createUser', sort: true, title: '创建用户',width: 120},
55             {field: 'createTime', sort: true, title: '创建时间',width: 160},
56             {field: 'updateUser', sort: true, title: '更改用户',width: 120},
57             {field: 'updateTime', sort: true, title: '更改时间',width: 160},
58             {field: 'remark', sort: true, title: '备注'},
59             {fixed: 'right',width: 125, minWidth: 125, align: 'center', toolbar: '#tableBar', title: '操作'}
60         ]];
61     };
62
63     /**
64      * 点击查询按钮
65      */
66     SalesOrder.search = function () {
67         var queryData = {};
68         queryData['salesOrderCode'] = $('#salesOrderCode').val();
69         queryData['customerNo'] = $('#customerNo').val();
70         queryData['cargoNo'] = $('#cargoNo').val();
71         queryData['productCode'] = $('#productCode').val();
72         queryData['productName'] = $('#productName').val();
73         queryData['workshopCode'] = $('#workshopCode').val();
74         queryData['lineCode'] = $('#lineCode').val();
75         queryData['state'] = $('#state').val();
76         table.reload(SalesOrder.tableId, {
77             where: queryData, page: {curr: 1}
78         });
79     };
80
81     //下载模板
82     $("#btnTemp").click(function () {
83         window.location.href = Feng.ctxPath + "/salesOrder/exportOut"
84     });
85
86     // 导入excel
87     var uploadInst = upload.render({
88         elem: '#import'
89         ,url: Feng.ctxPath + '/salesOrder/importIn'
90         ,accept: 'file'
91         ,done: function (res) {
92             table.reload(SalesOrder.tableId, {url: Feng.ctxPath + "/salesOrder/list"});
93             Feng.success("上传成功")
94         }
95         ,error: function () {
96             Feng.error("上传失败")
97         }
98     });
99
100     $('#split').click(function (){
101         var checkRows = table.checkStatus(SalesOrder.tableId);
abb175 102         console.log(checkRows.data);
103         console.log(checkRows);
104         console.log(checkRows.data.state);
105
1ac2bc 106         if (checkRows.data.length !== 1) {
107             Feng.error("请选择一条要拆分的订单");
abb175 108             return;
1ac2bc 109         }
abb175 110         if (checkRows.data[0].state === "1") {
111             window.location.href = Feng.ctxPath + '/salesOrder/split?id=' + checkRows.data[0].id
112         }else {
113             Feng.error("已拆分下发订单禁止重复拆分");
114             return;
115         }
116         // if (checkRows.data.state !== "1") {
117         //     Feng.error("已拆分下发订单禁止重复拆分");
118         //     return;
119         // }
120         // window.location.href = Feng.ctxPath + '/salesOrder/split?id=' + checkRows.data[0].id
1ac2bc 121
122     });
123
124     /**
125      * 跳转到添加页面
126      */
127     SalesOrder.jumpAddPage = function () {
128         window.location.href = Feng.ctxPath + '/salesOrder/add'
129     };
130
131     /**
132     * 跳转到编辑页面
133     *
134     * @param data 点击按钮时候的行数据
135     */
136     SalesOrder.jumpEditPage = function (data) {
137         window.location.href = Feng.ctxPath + '/salesOrder/edit?id=' + data.id
138     };
139
140     /**
141      * 导出excel按钮
142      */
143     SalesOrder.exportExcel = function () {
144         var checkRows = table.checkStatus(SalesOrder.tableId);
145         if (checkRows.data.length === 0) {
146             Feng.error("请选择要导出的数据");
147         } else {
148             table.exportFile(tableResult.config.id, checkRows.data, 'xls');
149         }
150     };
151
152     /**
153      * 下发订单
154      */
155     SalesOrder.distribute = function (data) {
156         layer.alert(data);
157
158     };
159
160     /**
161      * 点击删除
162      *
163      * @param data 点击按钮时候的行数据
164      */
165     SalesOrder.onDeleteItem = function (data) {
166         var operation = function () {
167             var ajax = new $ax(Feng.ctxPath + "/salesOrder/delete", function (data) {
168                 Feng.success("删除成功!");
169                 table.reload(SalesOrder.tableId);
170             }, function (data) {
171                 Feng.error("删除失败!" + data.responseJSON.message + "!");
172             });
173             ajax.set("id", data.id);
174             ajax.start();
175         };
176         Feng.confirm("是否删除?", operation);
177     };
178
179     // 渲染表格
180     var tableResult = table.render({
181         elem: '#' + SalesOrder.tableId,
182         url: Feng.ctxPath + '/salesOrder/list',
183         page: true,
184         height: "full-158",
185         cellMinWidth: 100,
186         cols: SalesOrder.initColumn()
187     });
188
189     // 搜索按钮点击事件
190     $('#btnSearch').click(function () {
191         SalesOrder.search();
192     });
193
194     // 添加按钮点击事件
195     $('#btnAdd').click(function () {
196
197     SalesOrder.jumpAddPage();
198
199     });
200
201     // 导出excel
202     $('#btnExp').click(function () {
203         SalesOrder.exportExcel();
204     });
205
206     let salesId = [];
207
208     // 绑定下发
209     $('#distribute').click(function () {
210         var checkRows = table.checkStatus(SalesOrder.tableId);
abb175 211         console.log(checkRows);
212         console.log("checkRows.length=========="+checkRows.data.length)
213         if(checkRows.data.length === 1){
214             if(checkRows.data[0].state === "3"){
215                 Feng.error("该工单已下发完毕!");
216                 return;
217             }
1ac2bc 218         }
219         if (checkRows.data.length !== 1) {
220             Feng.error("请选择一条要下发的订单");
221             return;
222         }
223         var checkRows = table.checkStatus(SalesOrder.tableId);
224         console.log(checkRows.data);
225         window.location.href = Feng.ctxPath + '/salesOrder/bindParam?id=' + checkRows.data[0].id
226     });
227
228     // 工具条点击事件
229     table.on('tool(' + SalesOrder.tableId + ')', function (obj) {
230         var data = obj.data;
231         var layEvent = obj.event;
232         if (layEvent === 'edit') {
233             SalesOrder.jumpEditPage(data);
234         } else if (layEvent === 'delete') {
235             SalesOrder.onDeleteItem(data);
236         }
237     });
238 });