MaterialNew.js
15.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
let action = null,
app = null;
layui.config({
base: "/js/",
version: 22
}).use(['ztree', 'system'], function () {
var form = layui.form,
$ = layui.jquery,
table = layui.table,
system = layui.system,
u = new system.u(),
sendData = {
isok: null,
mtTypeName: null,
mtTypeCode: null,
},
tempSysData = {
btnEditRateTitle: "编辑物料BOM比例",
nowBtnIdentity: "btnEdit",
enumBtnEdit: "btnEdit",
enumBtnEditRate: "btnEditRate",
btnEditRateReturnData: null,
},
treeAllData= null,
areaName = 'material',
tableName = 'Material';
action = {
rowData: null,
addOptions: function () {
var options = {
fromId: "#modifyForm form",
url: `/${areaName}/${tableName}/Ins`,
submit: "submit(fromAdd)"
}
return options;
},
editOptions: function () {
//区分按钮是编辑还是编辑物料BOM比例
var options = {
url: `/${tableName}/Upd`,
submit: "submit(fromUpdate)"
}
switch (tempSysData.nowBtnIdentity) {
case tempSysData.enumBtnEdit:
options.fromId = "#modifyForm form";
options.content = $("#modifyForm");
options.title ="";
options.url = `/${areaName}/${tableName}/Upd`;
break;
case tempSysData.enumBtnEditRate:
options.fromId = "#modifyRateForm form";
options.content = $("#modifyRateForm");
options.title = tempSysData.btnEditRateTitle;
options.url = `/${areaName}/${tableName}/EditRate`;
break;
}
return options;
},
deleteOptions: function () {
var options = {
url: `/${areaName}/${tableName}/DelByIds`,
keyId: "keys"
}
return options;
},
exportOptions: function () {
var options = {
fromId: "listForm",
url: `/${areaName}/${tableName}/Export`,
sendDataWhere: {
mtTypeCode: sendData.mtTypeCode == null ? 0 : sendData.mtTypeCode
},
isDefault: false,
excelCols: {
head: app.data.cols
}
}
return options;
},
queryOptions: function () {
var options = {
resetFrom: "form[lay-filter=listForm]",
fromId: "listForm",
urlExport: `/${areaName}/${tableName}/Export`,
urlQuery: `/${areaName}/${tableName}/Load`,
mainTable: app.data.tableIns
}
return options;
},
uploadOptions: function () {
var options = {
url: `/${areaName}/${tableName}/Import`,
fromFile: "#excelfile",
content: $("#ImportData")
}
return options;
},
//-----------------------------------按钮事件--------------------------------------
editBefore: function (data, callBack) {
if (sendData.mtTypeName != null ) {
data["mtTypeName"] = sendData.mtTypeName;
} else {
treeAllData = app.data.treeObj.getNodes()[0].children;
var arr = treeAllData.GetArrValueRow("mtTypeCode", data.mtTypeCode)
if (arr.length > 0) data["mtTypeName"] = arr[0].name
}
//区分按钮是编辑还是编辑物料BOM比例
switch (tempSysData.nowBtnIdentity) {
case tempSysData.enumBtnEdit:
form.val("modifyForm", data);
break;
case tempSysData.enumBtnEditRate:
form.val("modifyRateForm", tempSysData.btnEditRateReturnData);
break;
}
//callBack是回调函数,如果editBefore有ajax 放在成功之后
if (callBack != null) callBack();
},
editSaveBefore: function (data, callBack) {
if (typeof data.field.isDelete == "undefined") data.field["isDelete"] = "0";
if (callBack != null) callBack();
},
addBefore: function (callBack) {
if (sendData.isok !== "true") {
layer.alert("请选择不是根节点新增物料", { icon: u.config.iconoError, shade: 0.4, time: u.config.errorTime });
return;
}
if (sendData.mtTypeCode == "cp") {
layer.alert("请选择物料类别不是【成品】后,再新增物料信息!", { icon: u.config.iconoError, shade: 0.4, time: u.config.errorTime });
return;
}
form.val("modifyForm", { mtTypeCode: sendData.mtTypeCode, mtTypeName: sendData.mtTypeName });
//callBack是回调函数,如果editBefore有ajax 放在成功之后
if (callBack != null) callBack();
},
addSaveBefore: function (data, callBack) {
if (sendData.isok !== "true") {
layer.alert("请选择物料类别不是根节点后,再新增物料信息!", { icon: u.config.iconoError, shade: 0.4, time: u.config.errorTime });
return;
}
data.field.mtTypeCode = sendData.mtTypeCode;
if (typeof data.field.isDelete == "undefined") data.field["isDelete"] = "0";
if (callBack != null) callBack();
},
//编辑物料BOM比例
btnEditRate: function (sysU, toolbarId, obj) {
var checkStatus = table.checkStatus(toolbarId),
data = checkStatus.data;
if (data.length !== 1) {
layer.alert("请选择一条要编辑【使用比例】的物料",{ icon: u.config.iconoError, shade: 0.4, time: u.config.errorTime });
return false;
}
tempSysData.btnEditRateTitle = "为物料【" + data[0].materialCode + "--" + data[0].materialName + "】设置使用比例";
tempSysData.nowBtnIdentity = obj.event;
var ajaxConfig = {
url: `/${areaName}/${tableName}/GetMaterialRateByCode?materialKeys=` + data[0].keys,
type: "get",
success: function (result) {
if (u.successBefore(result)) return;
tempSysData.btnEditRateReturnData = result.Result[0];
$("a[lay-event=btnEdit]").click();
}
};
u.ajax(ajaxConfig);
},
//同步信科物料
btnSyncMaterial: function (obj) {
var ajaxConfig = {
url: $("#materiaApilUrl").val(),
type: "get",
isDataFilter: false,//不特殊处理调用api返回的数据
success: function (result) {
if (u.successBefore(result)) return false;
layer.msg(result.Message, { icon: 1, time: 3000 })
action.actionSuccess();
}
};
u.ajax(ajaxConfig);
},
//产品明细物料绑定删除
checkboxMethod: function (obj) {
var page = "".GetUrlParam("page"),
proHeadKeys = "".GetUrlParam("proHeadKeys");
if (page == "ProductDesc") {
var checkBoxData = {
materialCodes: null,
proHeadKeys: proHeadKeys,
checkeds: obj.checked,
};
if (obj.type == "all") {
checkBoxData.materialCodes = u.getTableAllData(app.data.tableElem).GetArrValue("materialCode");
} else {
checkBoxData.materialCodes = obj.data.materialCode;
}
if (checkBoxData.materialCodes == null || checkBoxData.materialCodes == "") {
layer.alert("checkboxMethod:物料编码标识【materialCode】为空,请重新关闭后再操作,反复出现请联系管理员", { icon: 2, shadeClose: true, title: "提示" });
return false;
}
var ajaxConfig = {
data: checkBoxData,
url: `/configure/ProductHeader/AssignMaterial`,
success: function (result) {
if (u.successBefore(result)) return false;
layer.msg(result.Message);
}
};
u.ajax(ajaxConfig);
}
},
//所有动作成功之后
actionSuccess: () => {
app.methods.initTable({ mtTypeCode: sendData.mtTypeCode });
},
closeAfter: function (callBack) {
tempSysData.nowBtnIdentity = tempSysData.enumBtnEdit;
if (callBack != null) callBack();
}
}
app = {
data: {
cols: [[
{ checkbox: true, fixed: true },
{ field: "id", width: 80, hide: true, title: "Id" },
{ field: "keys", width: 120, title: "keys", hide: true, },
{ field: "materialCode", width: 120, title: "物料编号" },
{ field: "materialName", width: 150, title: "物料名称" },
{ field: "mtTypeCode", width: 150, title: "物料类别", templet: function (d) { return GetDicLabel("mtTypeCode", "mtTypeCode", "mtTypeName", d.mtTypeCode) } },
{ field: "mtClassify", width: 150, title: "物料分类", templet: function (d) { return GetDicLabel("mtClassify", "DictValue", "DictLabel", d.mtClassify) } },
{ field: "specifications", width: 300, title: "规格" },
{ field: "materialType", width: 100, title: "物料类型" },
{ field: "types", width: 150, title: "材质" },
{ field: "diameter", width: 100, title: "直径" },
{ field: "thickness", width: 150, title: "壁厚" },
{ field: "unitCode", width: 150, title: "单位", templet: function (d) { return GetDicLabel("unitCode", "Code", "Name", d.unitCode) } },//
{ field: 'plmeid', width: 150, title: 'plmeid', hide: true },
{ field: 'otherCode', width: 120, title: '外部编码' },
{ field: 'isDelete', width: 120, title: '是否有效', templet: "#isSysDeleteTemplet" },
{ field: "createTime", width: 150, title: "创建时间" },
{ field: "createBy", width: 150, title: "创建用户" },
//{ field: "updateTime", width: 150, title: "更新时间" },
//{ field: "updateBy", width: 150, title: "更新用户" }
]],
urlTable: `/${areaName}/${tableName}/Load`,
tableIns: null,
tableElem: "mainList",
selectOption: {
unitCode: {
SelType: "FromUrl",
SelFrom: "/HomeRedis/GetBaseInfoByKey?key=base_material_unit",
SelLabel: "Name",
SelValue: "Code",
Dom: [$("[name='unitCode']")]
},
mtClassify: {
SelType: "FromDict",
SelFrom: "mtClassify",
SelLabel: "DictLabel",
SelValue: "DictValue",
Dom: [$("[name='mtClassify']")]
},
mtTypeCode: {
SelType: "FromUrl",
SelFrom: "/HomeRedis/GetBaseInfoByKey?key=base_material_type",
SelLabel: "mtTypeName",
SelValue: "mtTypeCode",
Dom: [$("[name='mtTypeCode']")]
},
oprSequenceCode: {
SelType: "FromUrl",
SelFrom: "/configure/ProcessRoute/GetProcessDetail",
SelLabel: "oprSequenceName",
SelValue: "oprSequenceCode",
Dom: [$("[name='oprSequenceCode']")]
},
//返回的数据 用于后续操作
selectData: {
}
},
tree: $("#tree"),
treeObj: null,
setting: {
view: { selectedMulti: false },
async: {
enable: true,
url: `/${areaName}/${tableName}/GetTreeList`,
type: "get"
},
data: {
simpleData: {
enable: true,
idKey: "keys",
pIdKey: "parentId",
rootPId: ""
}
},
callback: {
onClick: function (event, treeId, treeNode) {
sendData.isok = treeNode.level!=0?"true":"false";
sendData.mtTypeCode = treeNode.mtTypeCode;
sendData.mtTypeName = treeNode.name;
app.methods.initTable({ mtTypeCode: sendData.mtTypeCode });
},
onAsyncSuccess: function (event, treeId, treeNode, msg) {
app.data.treeObj.expandAll(true);
}
}
}
},
methods: {
initTable: function (options) {
var config = {};
if (options != undefined) $.extend(config, options);
let opt = {
cols: u.columnRecord(app.data.tableElem, app.data.cols),
elem: "#" + app.data.tableElem,
url: `/${areaName}/${tableName}/Load`,
toolbar: '#toolbarTable',
where: config,
doneExtend: function (res, obj) {
//产品明细选中
var pageFlag = "".GetUrlParam("page");
if (pageFlag == "ProductDesc") {
var targetArrValue = "".GetUrlParam("materialCode");
var selectColKey = "".GetUrlParam("selectColKeyCustom");
u.SetTableCheck(targetArrValue, res, selectColKey, app.data.tableElem);
}
}
}
var pageFlag = "".GetUrlParam("page");
if (pageFlag == "ProductDesc") {
opt["height"] = "".GetUrlParam("height")-20;
}
app.data.tableIns = u.initTable(opt);
},
initTree: function () {
setTimeout(() => {
app.data.treeObj = $.fn.zTree.init(app.data.tree, app.data.setting);
app.data.tree.height($("div.layui-table-view").height() - 20);
}, 50);
},
initFrom: function () {
u.initSelect(app.data.selectOption);
}
},
registerEvent: function () {
},
init: function () {
app.methods.initFrom();
app.methods.initTree();
app.methods.initTable();
app.registerEvent();
}
};
app.init();
})