提交 | 用户 | 时间
|
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 WorkOrder = { |
|
12 |
tableId: "workOrderTable" |
|
13 |
}; |
|
14 |
|
|
15 |
/** |
|
16 |
* 初始化表格的列 |
|
17 |
*/ |
|
18 |
WorkOrder.initColumn = function () { |
|
19 |
return [[ |
|
20 |
{type: 'checkbox'}, |
|
21 |
{field: 'id', hide: true, title: '主键id'}, |
|
22 |
{align: 'center', toolbar: '#tableBar', title: '操作',minWidth:330}, |
|
23 |
{field: 'workOrderCode', sort: true, title: '工单编号',width: 160}, |
|
24 |
{field: 'salesOrderCode', sort: true, title: '订单编号',width: 160}, |
|
25 |
{field: 'productCode', sort: true, title: '产品编号',width: 160}, |
|
26 |
{field: 'productName', sort: true, title: '产品名称',width: 160}, |
|
27 |
{field: 'planQty', sort: true, title: '计划数量',width: 120}, |
|
28 |
{field: 'produceQty', sort: true, title: '完成数量',width: 120}, |
|
29 |
{field: 'onlineQty', sort: true, title: '上线数量',width: 120}, |
|
30 |
{field: 'planStartTime', sort: true, title: '计划开始时间',width: 160}, |
|
31 |
{field: 'planEndTime', sort: true, title: '计划结束时间',width: 160}, |
|
32 |
{field: 'produceStartTime', sort: true, title: '生产开始时间',width: 160}, |
|
33 |
{field: 'produceEndTime', sort: true, title: '生产结束时间',width: 160}, |
|
34 |
{field: 'workshopCode', sort: true, title: '车间编码',width: 120}, |
|
35 |
{field: 'lineCode', sort: true, title: '产线编码',width: 120}, |
|
36 |
{field: 'state', sort: true, title: '状态',width: 120,templet: '#orderStatusTpl'}, |
|
37 |
{field: 'badQty', sort: true, title: '不良数量',width: 120}, |
|
38 |
{field: 'repairQty', sort: true, title: '返修数量',width: 120}, |
|
39 |
{field: 'scrapQty', sort: true, title: '报废数量',width: 120}, |
|
40 |
{field: 'routeCode', sort: true, title: '工艺流程',width: 120}, |
|
41 |
{field: 'bomCode', sort: true, title: '产品BOM',width: 160}, |
|
42 |
{field: 'recipeCode', sort: true, title: '工艺配方',width: 120}, |
|
43 |
{field: 'createUser', sort: true, title: '创建用户',width: 120}, |
|
44 |
{field: 'createTime', sort: true, title: '创建时间',width: 160}, |
|
45 |
{field: 'updateUser', sort: true, title: '更改用户',width: 120}, |
|
46 |
{field: 'updateTime', sort: true, title: '更改时间',width: 160}, |
|
47 |
{field: 'remark', sort: true, title: '备注',width: 160}, |
|
48 |
]]; |
|
49 |
}; |
|
50 |
|
|
51 |
/** |
|
52 |
* 点击查询按钮 |
|
53 |
*/ |
|
54 |
WorkOrder.search = function () { |
|
55 |
var queryData = {}; |
|
56 |
|
|
57 |
queryData['workOrderCode'] = $('#workOrderCode').val(); |
|
58 |
queryData['salesOrderCode'] = $('#salesOrderCode').val(); |
|
59 |
queryData['productCode'] = $('#productCode').val(); |
|
60 |
queryData['productName'] = $('#productName').val(); |
|
61 |
queryData['workshopCode'] = $('#workshopCode').val(); |
|
62 |
queryData['lineCode'] = $('#lineCode').val(); |
|
63 |
queryData['state'] = $('#state').val(); |
|
64 |
|
|
65 |
table.reload(WorkOrder.tableId, { |
|
66 |
where: queryData, page: {curr: 1} |
|
67 |
}); |
|
68 |
}; |
|
69 |
|
|
70 |
/** |
|
71 |
* 跳转到添加页面 |
|
72 |
*/ |
|
73 |
WorkOrder.jumpAddPage = function () { |
|
74 |
window.location.href = Feng.ctxPath + '/workOrder/add' |
|
75 |
}; |
|
76 |
|
|
77 |
/** |
|
78 |
* 跳转到编辑页面 |
|
79 |
* |
|
80 |
* @param data 点击按钮时候的行数据 |
|
81 |
*/ |
|
82 |
WorkOrder.jumpEditPage = function (data) { |
|
83 |
window.location.href = Feng.ctxPath + '/workOrder/edit?id=' + data.id |
|
84 |
}; |
|
85 |
|
|
86 |
/** |
|
87 |
* 导出excel按钮 |
|
88 |
*/ |
|
89 |
WorkOrder.exportExcel = function () { |
|
90 |
var checkRows = table.checkStatus(WorkOrder.tableId); |
|
91 |
if (checkRows.data.length === 0) { |
|
92 |
Feng.error("请选择要导出的数据"); |
|
93 |
} else { |
|
94 |
table.exportFile(tableResult.config.id, checkRows.data, 'xls'); |
|
95 |
} |
|
96 |
}; |
|
97 |
|
|
98 |
/** |
|
99 |
* 点击删除 |
|
100 |
* |
|
101 |
* @param data 点击按钮时候的行数据 |
|
102 |
*/ |
|
103 |
WorkOrder.onDeleteItem = function (data) { |
|
104 |
var operation = function () { |
|
105 |
var ajax = new $ax(Feng.ctxPath + "/workOrder/delete", function (data) { |
|
106 |
Feng.success("删除成功!"); |
|
107 |
table.reload(WorkOrder.tableId); |
|
108 |
}, function (data) { |
|
109 |
Feng.error("删除失败!" + data.responseJSON.message + "!"); |
|
110 |
}); |
|
111 |
ajax.set("id", data.id); |
|
112 |
ajax.start(); |
|
113 |
}; |
|
114 |
Feng.confirm("是否删除?", operation); |
|
115 |
}; |
|
116 |
|
|
117 |
// 渲染表格 |
|
118 |
var tableResult = table.render({ |
|
119 |
elem: '#' + WorkOrder.tableId, |
|
120 |
url: Feng.ctxPath + '/workOrder/list', |
|
121 |
page: true, |
|
122 |
height: "full-158", |
|
123 |
cellMinWidth: 100, |
|
124 |
cols: WorkOrder.initColumn() |
|
125 |
}); |
|
126 |
|
|
127 |
// 搜索按钮点击事件 |
|
128 |
$('#btnSearch').click(function () { |
|
129 |
WorkOrder.search(); |
|
130 |
}); |
|
131 |
|
|
132 |
// 添加按钮点击事件 |
|
133 |
$('#btnAdd').click(function () { |
|
134 |
|
|
135 |
WorkOrder.jumpAddPage(); |
|
136 |
|
|
137 |
}); |
|
138 |
|
|
139 |
// 导出excel |
|
140 |
$('#btnExp').click(function () { |
|
141 |
WorkOrder.exportExcel(); |
|
142 |
}); |
|
143 |
|
|
144 |
//操作栏编辑 |
|
145 |
/** |
|
146 |
* 点击开始工单 |
|
147 |
*/ |
|
148 |
WorkOrder.startOrder = function (data) { |
|
149 |
var ajax = new $ax(Feng.ctxPath + "/workOrder/list?state=3"); |
|
150 |
var result = ajax.start(); |
|
151 |
if(result.data.length === 0) { |
|
152 |
var operation = function () { |
258083
|
153 |
var ajax = new $ax(Feng.ctxPath + "/workOrder/editItem", function (data) { |
1ac2bc
|
154 |
Feng.success("开始工单成功!"); |
258083
|
155 |
table.reload(WorkOrder.tableId); |
1ac2bc
|
156 |
}, function (data) { |
懒 |
157 |
Feng.error("开始工单失败!" + data.responseJSON.message + "!"); |
|
158 |
}); |
|
159 |
ajax.set(data); |
|
160 |
ajax.start(); |
|
161 |
}; |
|
162 |
Feng.confirm("是否开始生产?", operation); |
|
163 |
}else { |
|
164 |
layer.open({ |
|
165 |
title: "操作提示", |
|
166 |
icon: 0, |
|
167 |
closeBtn: 2, |
|
168 |
area: ['450px', '200px'], |
|
169 |
time: 5000, |
|
170 |
content: '<span style="font-size: 30px;color: red">开始失败,只能有一条生产中的工单进行生产!</span>' |
|
171 |
}); |
|
172 |
} |
|
173 |
}; |
|
174 |
|
258083
|
175 |
/** |
懒 |
176 |
* 冻结工单 |
|
177 |
*/ |
|
178 |
WorkOrder.freezeOrder = function (data) { |
|
179 |
console.log(data) |
|
180 |
var operation = function () { |
|
181 |
var ajax = new $ax(Feng.ctxPath + "/workOrder/editOrderState", function (data) { |
|
182 |
Feng.success("冻结工单成功!"); |
|
183 |
table.reload(WorkOrder.tableId); |
|
184 |
}, function (data) { |
|
185 |
Feng.error("冻结工单失败!" + data.responseJSON.message + "!"); |
|
186 |
}); |
|
187 |
ajax.set(data); |
|
188 |
console.log(data) |
|
189 |
ajax.start(); |
|
190 |
}; |
|
191 |
Feng.confirm("是否冻结工单?", operation); |
|
192 |
}; |
|
193 |
|
|
194 |
/** |
|
195 |
* 点击解冻工单 |
|
196 |
*/ |
|
197 |
WorkOrder.thawOrder = function (data) { |
|
198 |
var ajax = new $ax(Feng.ctxPath + "/workOrder/list?state=3"); |
|
199 |
var result = ajax.start(); |
|
200 |
if(result.data.length === 0) { |
|
201 |
var operation = function () { |
|
202 |
var ajax = new $ax(Feng.ctxPath + "/workOrder/editItem", function (data) { |
|
203 |
Feng.success("解冻工单成功!"); |
|
204 |
table.reload(WorkOrder.tableId); |
|
205 |
}, function (data) { |
|
206 |
Feng.error("解冻工单失败!" + data.responseJSON.message + "!"); |
|
207 |
}); |
|
208 |
ajax.set(data); |
|
209 |
ajax.start(); |
|
210 |
}; |
|
211 |
Feng.confirm("是否解冻工单?", operation); |
|
212 |
}else { |
|
213 |
layer.open({ |
|
214 |
title: "操作提示", |
|
215 |
icon: 0, |
|
216 |
closeBtn: 2, |
|
217 |
area: ['450px', '200px'], |
|
218 |
time: 5000, |
|
219 |
content: '<span style="font-size: 30px;color: red">解冻失败,只能有一条生产中的工单进行生产!</span>' |
|
220 |
}); |
|
221 |
} |
|
222 |
}; |
|
223 |
|
|
224 |
/** |
|
225 |
* 关闭工单 |
|
226 |
*/ |
|
227 |
WorkOrder.closeOrder = function (data) { |
|
228 |
var operation = function () { |
|
229 |
var ajax = new $ax(Feng.ctxPath + "/workOrder/editOrderState", function (data) { |
|
230 |
Feng.success("关闭工单成功!"); |
|
231 |
table.reload(WorkOrder.tableId); |
|
232 |
}, function (data) { |
|
233 |
Feng.error("关闭工单失败!" + data.responseJSON.message + "!"); |
|
234 |
}); |
|
235 |
ajax.set(data); |
|
236 |
console.log(data) |
|
237 |
ajax.start(); |
|
238 |
}; |
|
239 |
Feng.confirm("是否关闭工单?", operation); |
|
240 |
}; |
|
241 |
|
|
242 |
/** |
|
243 |
* 点击启用工单 |
|
244 |
*/ |
|
245 |
WorkOrder.enableOrder = function (data) { |
|
246 |
var operation = function () { |
|
247 |
var ajax = new $ax(Feng.ctxPath + "/workOrder/editItem", function (data) { |
|
248 |
Feng.success("启用工单成功!"); |
|
249 |
table.reload(WorkOrder.tableId); |
|
250 |
}, function (data) { |
|
251 |
Feng.error("启用工单失败!" + data.responseJSON.message + "!"); |
|
252 |
}); |
|
253 |
ajax.set(data); |
|
254 |
ajax.start(); |
|
255 |
}; |
|
256 |
Feng.confirm("是否启用工单?", operation); |
|
257 |
}; |
|
258 |
|
|
259 |
/** |
|
260 |
* 点击完成 |
|
261 |
* |
|
262 |
* @param data 点击按钮时候的行数据 |
|
263 |
*/ |
|
264 |
WorkOrder.finish = function (data) { |
|
265 |
var operation = function () { |
|
266 |
var ajax = new $ax(Feng.ctxPath + "/workOrder/editItem", function (data) { |
|
267 |
Feng.success("已完成!"); |
|
268 |
table.reload(WorkOrder.tableId); |
|
269 |
}, function (data) { |
|
270 |
Feng.error("删除失败!" + data.responseJSON.message + "!"); |
|
271 |
}); |
|
272 |
ajax.set(data); |
|
273 |
ajax.start(); |
|
274 |
}; |
|
275 |
Feng.confirm("是否完成?", operation); |
|
276 |
}; |
|
277 |
|
1ac2bc
|
278 |
// 工具条点击事件 |
懒 |
279 |
table.on('tool(' + WorkOrder.tableId + ')', function (obj) { |
|
280 |
var data = obj.data; |
|
281 |
var layEvent = obj.event; |
258083
|
282 |
console.log(data) |
1ac2bc
|
283 |
|
懒 |
284 |
// if (layEvent === 'edit') { |
|
285 |
// WorkOrder.jumpEditPage(data); |
|
286 |
// } else if (layEvent === 'delete') { |
|
287 |
// WorkOrder.onDeleteItem(data); |
|
288 |
// } |
|
289 |
if (layEvent === 'edit') {//编辑 |
|
290 |
WorkOrder.jumpEditPage(data); |
|
291 |
} |
|
292 |
else if (layEvent === 'start') {//开始 |
258083
|
293 |
data.state = '3'; |
懒 |
294 |
data.produceStartTime = getDateTime(); |
1ac2bc
|
295 |
WorkOrder.startOrder(data); |
懒 |
296 |
}else if (layEvent === 'freeze') {//冻结 |
258083
|
297 |
data.state = '4'; |
1ac2bc
|
298 |
WorkOrder.freezeOrder(data); |
懒 |
299 |
}else if (layEvent === 'thaw') {//解冻 |
258083
|
300 |
data.state = '3'; |
1ac2bc
|
301 |
WorkOrder.thawOrder(data); |
懒 |
302 |
}else if (layEvent === 'close') {//关闭 |
258083
|
303 |
data.state = '6'; |
1ac2bc
|
304 |
WorkOrder.closeOrder(data); |
懒 |
305 |
}else if (layEvent === 'enable') {//启用 |
258083
|
306 |
data.state = '1'; |
1ac2bc
|
307 |
WorkOrder.enableOrder(data); |
懒 |
308 |
}else if (layEvent === 'delete') { |
|
309 |
WorkOrder.onDeleteItem(data); |
|
310 |
}else if (layEvent === 'finish') {//完成 |
258083
|
311 |
data.state = '5'; |
懒 |
312 |
data.produceEndTime = getDateTime(); |
1ac2bc
|
313 |
WorkOrder.finish(data); |
懒 |
314 |
} |
|
315 |
}); |
|
316 |
|
|
317 |
//获取当前日期 |
|
318 |
function getDateTime(){ |
|
319 |
let date = new Date(); |
|
320 |
let year = date.getFullYear(); |
|
321 |
let month = date.getMonth() + 1; |
|
322 |
let day = date.getDate(); |
|
323 |
let time = date.toLocaleTimeString(); |
|
324 |
// 对月份进行处理,1-9月在前面添加一个“0” |
|
325 |
if (month >= 1 && month <= 9) { |
|
326 |
month = "0" + month; |
|
327 |
} |
|
328 |
//对日期进行处理,1-9日在前面添加一个“0” |
|
329 |
if (day >= 0 && day <= 9) { |
|
330 |
day = "0" + day; |
|
331 |
} |
|
332 |
let separator = "-"; //添加分隔符“-” |
|
333 |
this.dateTime = year + separator + month + separator + day + " " + time; |
|
334 |
return this.dateTime; |
|
335 |
} |
|
336 |
}); |