提交 | 用户 | 时间
|
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 |
// {fixed: 'right',width: 125, minWidth: 125, align: 'center', toolbar: '#tableBar', title: '操作'} |
|
49 |
]]; |
|
50 |
}; |
|
51 |
|
|
52 |
/** |
|
53 |
* 点击查询按钮 |
|
54 |
*/ |
|
55 |
WorkOrder.search = function () { |
|
56 |
var queryData = {}; |
|
57 |
|
|
58 |
queryData['workOrderCode'] = $('#workOrderCode').val(); |
|
59 |
queryData['salesOrderCode'] = $('#salesOrderCode').val(); |
|
60 |
queryData['productCode'] = $('#productCode').val(); |
|
61 |
queryData['productName'] = $('#productName').val(); |
|
62 |
queryData['workshopCode'] = $('#workshopCode').val(); |
|
63 |
queryData['lineCode'] = $('#lineCode').val(); |
|
64 |
queryData['state'] = $('#state').val(); |
|
65 |
|
|
66 |
table.reload(WorkOrder.tableId, { |
|
67 |
where: queryData, page: {curr: 1} |
|
68 |
}); |
|
69 |
}; |
|
70 |
|
|
71 |
/** |
|
72 |
* 跳转到添加页面 |
|
73 |
*/ |
|
74 |
WorkOrder.jumpAddPage = function () { |
|
75 |
window.location.href = Feng.ctxPath + '/workOrder/add' |
|
76 |
}; |
|
77 |
|
|
78 |
/** |
|
79 |
* 跳转到编辑页面 |
|
80 |
* |
|
81 |
* @param data 点击按钮时候的行数据 |
|
82 |
*/ |
|
83 |
WorkOrder.jumpEditPage = function (data) { |
|
84 |
window.location.href = Feng.ctxPath + '/workOrder/edit?id=' + data.id |
|
85 |
}; |
|
86 |
|
|
87 |
/** |
|
88 |
* 导出excel按钮 |
|
89 |
*/ |
|
90 |
WorkOrder.exportExcel = function () { |
|
91 |
var checkRows = table.checkStatus(WorkOrder.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 |
WorkOrder.onDeleteItem = function (data) { |
|
105 |
var operation = function () { |
|
106 |
var ajax = new $ax(Feng.ctxPath + "/workOrder/delete", function (data) { |
|
107 |
Feng.success("删除成功!"); |
|
108 |
table.reload(WorkOrder.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: '#' + WorkOrder.tableId, |
|
121 |
url: Feng.ctxPath + '/workOrder/list', |
|
122 |
page: true, |
|
123 |
height: "full-158", |
|
124 |
cellMinWidth: 100, |
|
125 |
cols: WorkOrder.initColumn() |
|
126 |
}); |
|
127 |
|
|
128 |
// 搜索按钮点击事件 |
|
129 |
$('#btnSearch').click(function () { |
|
130 |
WorkOrder.search(); |
|
131 |
}); |
|
132 |
|
|
133 |
// 添加按钮点击事件 |
|
134 |
$('#btnAdd').click(function () { |
|
135 |
|
|
136 |
WorkOrder.jumpAddPage(); |
|
137 |
|
|
138 |
}); |
|
139 |
|
|
140 |
// 导出excel |
|
141 |
$('#btnExp').click(function () { |
|
142 |
WorkOrder.exportExcel(); |
|
143 |
}); |
|
144 |
|
|
145 |
//操作栏编辑 |
|
146 |
/** |
|
147 |
* 点击开始工单 |
|
148 |
*/ |
|
149 |
WorkOrder.startOrder = function (data) { |
|
150 |
var ajax = new $ax(Feng.ctxPath + "/workOrder/list?state=3"); |
|
151 |
var result = ajax.start(); |
|
152 |
if(result.data.length === 0) { |
|
153 |
var operation = function () { |
258083
|
154 |
var ajax = new $ax(Feng.ctxPath + "/workOrder/editItem", function (data) { |
1ac2bc
|
155 |
Feng.success("开始工单成功!"); |
258083
|
156 |
table.reload(WorkOrder.tableId); |
1ac2bc
|
157 |
}, function (data) { |
懒 |
158 |
Feng.error("开始工单失败!" + data.responseJSON.message + "!"); |
|
159 |
}); |
|
160 |
ajax.set(data); |
|
161 |
ajax.start(); |
|
162 |
}; |
|
163 |
Feng.confirm("是否开始生产?", operation); |
|
164 |
}else { |
|
165 |
layer.open({ |
|
166 |
title: "操作提示", |
|
167 |
icon: 0, |
|
168 |
closeBtn: 2, |
|
169 |
area: ['450px', '200px'], |
|
170 |
time: 5000, |
|
171 |
content: '<span style="font-size: 30px;color: red">开始失败,只能有一条生产中的工单进行生产!</span>' |
|
172 |
}); |
|
173 |
} |
|
174 |
}; |
|
175 |
|
258083
|
176 |
/** |
懒 |
177 |
* 冻结工单 |
|
178 |
*/ |
|
179 |
WorkOrder.freezeOrder = function (data) { |
|
180 |
console.log(data) |
|
181 |
var operation = function () { |
|
182 |
var ajax = new $ax(Feng.ctxPath + "/workOrder/editOrderState", function (data) { |
|
183 |
Feng.success("冻结工单成功!"); |
|
184 |
table.reload(WorkOrder.tableId); |
|
185 |
}, function (data) { |
|
186 |
Feng.error("冻结工单失败!" + data.responseJSON.message + "!"); |
|
187 |
}); |
|
188 |
ajax.set(data); |
|
189 |
console.log(data) |
|
190 |
ajax.start(); |
|
191 |
}; |
|
192 |
Feng.confirm("是否冻结工单?", operation); |
|
193 |
}; |
|
194 |
|
|
195 |
/** |
|
196 |
* 点击解冻工单 |
|
197 |
*/ |
|
198 |
WorkOrder.thawOrder = function (data) { |
|
199 |
var ajax = new $ax(Feng.ctxPath + "/workOrder/list?state=3"); |
|
200 |
var result = ajax.start(); |
|
201 |
if(result.data.length === 0) { |
|
202 |
var operation = function () { |
|
203 |
var ajax = new $ax(Feng.ctxPath + "/workOrder/editItem", function (data) { |
|
204 |
Feng.success("解冻工单成功!"); |
|
205 |
table.reload(WorkOrder.tableId); |
|
206 |
}, function (data) { |
|
207 |
Feng.error("解冻工单失败!" + data.responseJSON.message + "!"); |
|
208 |
}); |
|
209 |
ajax.set(data); |
|
210 |
ajax.start(); |
|
211 |
}; |
|
212 |
Feng.confirm("是否解冻工单?", operation); |
|
213 |
}else { |
|
214 |
layer.open({ |
|
215 |
title: "操作提示", |
|
216 |
icon: 0, |
|
217 |
closeBtn: 2, |
|
218 |
area: ['450px', '200px'], |
|
219 |
time: 5000, |
|
220 |
content: '<span style="font-size: 30px;color: red">解冻失败,只能有一条生产中的工单进行生产!</span>' |
|
221 |
}); |
|
222 |
} |
|
223 |
}; |
|
224 |
|
|
225 |
/** |
|
226 |
* 关闭工单 |
|
227 |
*/ |
|
228 |
WorkOrder.closeOrder = function (data) { |
|
229 |
var operation = function () { |
|
230 |
var ajax = new $ax(Feng.ctxPath + "/workOrder/editOrderState", function (data) { |
|
231 |
Feng.success("关闭工单成功!"); |
|
232 |
table.reload(WorkOrder.tableId); |
|
233 |
}, function (data) { |
|
234 |
Feng.error("关闭工单失败!" + data.responseJSON.message + "!"); |
|
235 |
}); |
|
236 |
ajax.set(data); |
|
237 |
console.log(data) |
|
238 |
ajax.start(); |
|
239 |
}; |
|
240 |
Feng.confirm("是否关闭工单?", operation); |
|
241 |
}; |
|
242 |
|
|
243 |
/** |
|
244 |
* 点击启用工单 |
|
245 |
*/ |
|
246 |
WorkOrder.enableOrder = function (data) { |
|
247 |
var operation = function () { |
|
248 |
var ajax = new $ax(Feng.ctxPath + "/workOrder/editItem", function (data) { |
|
249 |
Feng.success("启用工单成功!"); |
|
250 |
table.reload(WorkOrder.tableId); |
|
251 |
}, function (data) { |
|
252 |
Feng.error("启用工单失败!" + data.responseJSON.message + "!"); |
|
253 |
}); |
|
254 |
ajax.set(data); |
|
255 |
ajax.start(); |
|
256 |
}; |
|
257 |
Feng.confirm("是否启用工单?", operation); |
|
258 |
}; |
|
259 |
|
|
260 |
/** |
|
261 |
* 点击完成 |
|
262 |
* |
|
263 |
* @param data 点击按钮时候的行数据 |
|
264 |
*/ |
|
265 |
WorkOrder.finish = function (data) { |
|
266 |
var operation = function () { |
|
267 |
var ajax = new $ax(Feng.ctxPath + "/workOrder/editItem", function (data) { |
|
268 |
Feng.success("已完成!"); |
|
269 |
table.reload(WorkOrder.tableId); |
|
270 |
}, function (data) { |
|
271 |
Feng.error("删除失败!" + data.responseJSON.message + "!"); |
|
272 |
}); |
|
273 |
ajax.set(data); |
|
274 |
ajax.start(); |
|
275 |
}; |
|
276 |
Feng.confirm("是否完成?", operation); |
|
277 |
}; |
|
278 |
|
1ac2bc
|
279 |
// 工具条点击事件 |
懒 |
280 |
table.on('tool(' + WorkOrder.tableId + ')', function (obj) { |
|
281 |
var data = obj.data; |
|
282 |
var layEvent = obj.event; |
258083
|
283 |
console.log(data) |
1ac2bc
|
284 |
|
懒 |
285 |
// if (layEvent === 'edit') { |
|
286 |
// WorkOrder.jumpEditPage(data); |
|
287 |
// } else if (layEvent === 'delete') { |
|
288 |
// WorkOrder.onDeleteItem(data); |
|
289 |
// } |
|
290 |
if (layEvent === 'edit') {//编辑 |
|
291 |
WorkOrder.jumpEditPage(data); |
|
292 |
} |
|
293 |
else if (layEvent === 'start') {//开始 |
258083
|
294 |
data.state = '3'; |
懒 |
295 |
data.produceStartTime = getDateTime(); |
1ac2bc
|
296 |
WorkOrder.startOrder(data); |
懒 |
297 |
}else if (layEvent === 'freeze') {//冻结 |
258083
|
298 |
data.state = '4'; |
1ac2bc
|
299 |
WorkOrder.freezeOrder(data); |
懒 |
300 |
}else if (layEvent === 'thaw') {//解冻 |
258083
|
301 |
data.state = '3'; |
1ac2bc
|
302 |
WorkOrder.thawOrder(data); |
懒 |
303 |
}else if (layEvent === 'close') {//关闭 |
258083
|
304 |
data.state = '6'; |
1ac2bc
|
305 |
WorkOrder.closeOrder(data); |
懒 |
306 |
}else if (layEvent === 'enable') {//启用 |
258083
|
307 |
data.state = '1'; |
1ac2bc
|
308 |
WorkOrder.enableOrder(data); |
懒 |
309 |
}else if (layEvent === 'delete') { |
|
310 |
WorkOrder.onDeleteItem(data); |
|
311 |
}else if (layEvent === 'finish') {//完成 |
258083
|
312 |
data.state = '5'; |
懒 |
313 |
data.produceEndTime = getDateTime(); |
1ac2bc
|
314 |
WorkOrder.finish(data); |
懒 |
315 |
} |
|
316 |
}); |
|
317 |
|
|
318 |
//获取当前日期 |
|
319 |
function getDateTime(){ |
|
320 |
let date = new Date(); |
|
321 |
let year = date.getFullYear(); |
|
322 |
let month = date.getMonth() + 1; |
|
323 |
let day = date.getDate(); |
|
324 |
let time = date.toLocaleTimeString(); |
|
325 |
// 对月份进行处理,1-9月在前面添加一个“0” |
|
326 |
if (month >= 1 && month <= 9) { |
|
327 |
month = "0" + month; |
|
328 |
} |
|
329 |
//对日期进行处理,1-9日在前面添加一个“0” |
|
330 |
if (day >= 0 && day <= 9) { |
|
331 |
day = "0" + day; |
|
332 |
} |
|
333 |
let separator = "-"; //添加分隔符“-” |
|
334 |
this.dateTime = year + separator + month + separator + day + " " + time; |
|
335 |
return this.dateTime; |
|
336 |
} |
|
337 |
}); |