addbatch.html
23.9 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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
<th:block th:include="include :: header('下拉框')"/>
<th:block th:include="include :: select2-css"/>
<th:block th:include="include :: bootstrap-select-css"/>
<th:block th:include="include :: jasny-bootstrap-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
<form class="form-horizontal m" id="form-menu-add">
<!-- <input id="treeId" name="parentId" type="hidden" th:value="${menu.menuId}" />-->
<!-- 部门id-->
<input name="orgId" type="hidden" id="treeId"/>
<div class="form-group">
<label class="col-sm-3 control-label"><span style="color: red; ">*</span>代下单用户部门:</label>
<div class="col-sm-8">
<div class="input-group">
<input name="deptName" onclick="selectDeptTree()" id="treeName" type="text" placeholder="请选择归属部门" class="form-control" required>
<span class="input-group-addon"><i class="fa fa-search"></i></span>
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label"><span style="color: red; ">*</span>代下单用户名:</label>
<div class="col-sm-8">
<select id="userId" name="userId" class="form-control m-b" required>
<option value="">请选择</option>
<!-- <option value="menuItem">页签</option>-->
<!-- <option value="menuBlank">新窗口</option>-->
</select>
<!-- <span id="userWarm" style="color: red; display: none"> 请先选择用户部门</span>-->
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label"><span style="color: red; ">*</span>报告类型:</label>
<div class="col-sm-8">
<!--<select id="reportType" name="reportType" th:with="type=${@dict.getType('background_report_type')}"
class="form-control m-b" required>
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
</select>-->
<select id="reportType" name="reportType" class="form-control m-b" required>
</select>
</div>
</div>
<div class="form-group" id="clientIdDiv" style="display: none">
<label class="col-sm-3 control-label"><span style="color: red; ">*</span>定制模版:</label>
<div class="col-sm-8">
<select id="clientId" name="clientId" class="form-control m-b" required>
</select>
</div>
</div>
<!--上传文件-->
<div class="form-group">
<label class="col-sm-3 control-label"><span style="color: red; ">*</span>报告下单公司:</label>
<div class="col-sm-8">
<div class="fileinput fileinput-new input-group" data-provides="fileinput">
<div class="form-control" data-trigger="fileinput"><i class="glyphicon glyphicon-file fileinput-exists"></i> <span class="fileinput-filename" id="fileName"></span></div>
<span class="input-group-addon btn btn-white btn-file"><span class="fileinput-new">选择文件</span><span class="fileinput-exists">更改</span><input type="file" name="file" id="file"></span>
<a href="#" class="input-group-addon btn btn-white fileinput-exists" data-dismiss="fileinput">清除</a>
</div>
</div>
</div>
<input id="createImmediate" name="createImmediate" class="form-control" type="hidden" disabled>
<div class="form-group" id="entrustTypeDiv" style="display: none">
<label class="col-sm-3 control-label"><span style="color: red; ">*</span>委托类型:</label>
<div class="col-sm-8">
<!--<select id="entrustType" name="entrustType" th:with="type=${@dict.getType('entrust_type')}" class="form-control m-b" required>
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
</select>-->
<select id="entrustType" name="entrustType" class="form-control m-b" required>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">下单时间: </label>
<div class="col-sm-8">
<input type="text" class="form-control m-b time-input" id="webCreateTime" placeholder="请选择下单时间" name="webCreateTime"/>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label"><span style="color: red; ">*</span>是否需要翻译:</label>
<div class="col-sm-8">
<select id="translateType" name="translateType" class="form-control m-b" required>
<option value="NO">无</option>
<option value="CN">英译中</option>
<option value="ON">中译日</option>
<option value="EN">中译英</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">备注:</label>
<div class="col-sm-8">
<input id="remark" name="remark" class="form-control" type="text">
</div>
</div>
</form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<th:block th:include="include :: bootstrap-select-js"/>
<th:block th:include="include :: jasny-bootstrap-js" />
<script>
var prefix = ctx + "web/report";
let contractReportBusinessTypeList = []
let entrustTypeList = []
let reportTableList = []
/**
* 提交表单,保存用户下单信息
*/
function submitHandler() {
//报告下单公司
let enterpriseName = "";
//报告下单公司code
let enterpriseCode = "";
//代下单用户名
let userName = $("#userId").find(":selected").text();
//代下单用户id
let userId = $("#userId").val();
//代下单用户部门id
let orgId = $("#treeId").val();
//代下单用户部门名称
let orgName = $("#treeName").val();
//报告类型
let reportType = $("#reportType").val();
let country = $("#country").val();
if (reportType == "-10") {
//报告下单公司
enterpriseName = $("#hwName").val();
//报告下单公司code
enterpriseCode = $("#hwCode").val();
} else {
//报告下单公司
enterpriseName = $("#enterpriseName").find(":selected").text();
//报告下单公司code
enterpriseCode = $("#enterpriseName").val();
}
//报告名称
let reportName = $("#reportType").find(":selected").text();
//委托类型
let entrustType = $("#entrustType").val();
//备注
let remark = $("#remark").val();
//下单时间(已确保格式正确)
let webCreateTime = $("#webCreateTime").val();
let city = $("#city").val();
let address = $("#address").val();
let postCode = $("#postCode").val();
let email = $("#email").val();
let phone = $("#phone").val();
let regNo = $("#regNo").val();
let translateType = $("#translateType").val();
let createImmediate = $("#createImmediate").val();
//初始化请求参数
const data = {
"enterpriseName": enterpriseName,
"enterpriseCode": enterpriseCode,
"userName": userName,
"userId": userId,
"orgId": orgId,
"orgName": orgName,
"reportType": reportType,
"reportName": reportName,
"entrustType": entrustType,
"remark": remark,
"webCreateTime": webCreateTime,
country: country,
city: city,
address: address,
postCode: postCode,
email: email,
phone: phone,
regNo: regNo,
translateType: translateType,
createImmediate: createImmediate,
}
var formData = new FormData();
formData.append("file", $('#file')[0].files[0]);
formData.append("userName",userName);
formData.append("userId",userId);
formData.append("orgId",orgId);
formData.append("orgName",orgName);
formData.append("reportType",reportType);
formData.append("reportName",reportName);
formData.append("entrustType",entrustType);
formData.append("remark",remark);
formData.append("translateType",translateType);
formData.append("createImmediate",createImmediate);
//需要校验 报告下单公司 ,其余字段 由jQuery Validation使用 $.validate.form() 校验
// let others = validateOthers(enterpriseCode);
if ($.validate.form() ) {
reportTableList.forEach(item => {
if (item.typeId == $("#reportType").val()) {
if (item.typeId == "-11") {
item.templateConfigurationParametersList.forEach(template => {
if (template.clientId == $("#clientId").val()) {
if ($("#createImmediate").val() == "Y") {
// data.templateParamId = template.templateConfigurationParametersList[0].id
formData.append("templateParamId",template.templateConfigurationParametersList[0].id)
} else {
template.templateConfigurationParametersList.forEach(template2 => {
if (template2.clientType == $("#entrustType").val()) {
// data.templateParamId = template2.id
formData.append("templateParamId",template2.id)
}
})
}
}
})
} else {
if ($("#createImmediate").val() == "Y") {
// data.templateParamId = item.templateConfigurationParametersList[0].id
formData.append("templateParamId",item.templateConfigurationParametersList[0].id)
} else {
item.templateConfigurationParametersList.forEach(template => {
if (template.clientType == $("#entrustType").val()) {
// data.templateParamId = template.id
formData.append("templateParamId",template.id)
}
})
}
}
}
})
// const jsonData = JSON.stringify(data);
// console.log(jsonData)
fetch(prefix + '/backgroundBatchOrder', {
method: 'POST',
body: formData
})
.then(response => {
if (!response.ok) {
throw new Error('接口返回错误' + response.statusText);
}
return response.json();
})
.then(data => {
console.log(data);
if (data.code === 2000) {
$.modal.msgReload("保存成功", modal_status.SUCCESS);
// $.modal.alertSuccess("保存成功")
// $.modal.close();
} else {
$.modal.alertError(data.msg)
}
})
.catch(error => {
console.log('请求出错', error);
})
}
}
function validateOthers(property) {
if (property === '' || property === null) {
$.modal.alertError("请填写报告下单公司")
return false;
}
return true;
}
/**
* 委托类型,报告类型 销毁select2 直接下拉即可
*/
$(document).ready(function () {
$("#entrustType").select2('destroy');
$("#reportType").select2('destroy');
// $("#entrustType").select2({
// // placeholder: "请输入需要下单的公司",
// searchable: false
// });
});
/**
* 报告下单公司,select 模糊搜索(select2 + jQuery)
*/
$(document).ready(function () {
})
function selectInit () {
$("#enterpriseName").select2({
ajax: {
url: ctx + "web/monitorCompany/getEnterpraseInfo",
dataType: 'json',
delay: 1500, //延时500毫秒调用接口
data: function (params) {
let name = encodeURIComponent(params.term);
return {
name: name,
countryCode: $("#country").val(),
//目前 pageNum,pageSize 后台没有接这两个参数, 天眼查接口默认返回20条数据
pageNum: 1,
pageSize: 10
};
},
// 返回数据的回调函数
processResults: function (data, params) {
//解析返回数据
let code = data.code;
let content = data.data;
// console.log(code)
//定义一个空数组,用于保存 转换后的接口数据
var result = [];
//code为2000 数据正常返回
if (code == '2000') {
let items = content.items;
//循环接口返回的数组,并创建一个新的对象,将数据转换成select2能识别的数据格式
for (var item of items) {
var option = {
id: item.creditCode,
text: item.name
}
result.push(option);
}
//code为2010 接口查无数据
} else if (code == '2010') {
$.modal.alert("暂无数据");
} else {
$.modal.alertError("接口查询出错");
}
// 返回查询结果给selet2 ,注意:results为固定参数名
return {
results: result
};
},
cache: true
},
placeholder: "请输入需要下单的公司",
minimumInputLength: 1, //至少输入1个字符 触发搜索
allowClear: true,
//允许在结果中显示 html标签,
escapeMarkup: function (markup) {
// console.log(markup);
return markup;
},
// 自定义结果显示样式(可选),其中data为上面自定的option对象,text是option的属性值
templateResult: function (data) {
return data.text;
},
// 自定义选择后显示的样式(可选),data.text表示:选中之后 select框中的显示的数据为 上面定义的option对象的text属性
templateSelection: function (data) {
return data.text;
}
});
}
/*用户管理-新增-选择部门树*/
function selectDeptTree() {
var treeId = $("#treeId").val();
var deptId = $.common.isEmpty(treeId) ? "23" : $("#treeId").val();
var url = ctx + "business/frontDept/selectDeptTree/" + deptId;
console.log(url)
var options = {
title: '选择部门',
width: "380",
url: url,
expandLevel: 2,
callBack: doSubmit
};
$.modal.openOptions(options);
}
function doSubmit(index, layero) {
var body = layer.getChildFrame('body', index);
$("#treeId").val(body.find('#treeId').val());
$("#treeName").val(body.find('#treeName').val());
layer.close(index);
//部门树回调结束,调用接口获取用户信息
updateDept();
getUserReportType();
}
function getHwFun () {
var options = {
title: '查询企业信息',
width: "800",
height: "600",
url: ctx + "business/bCreditReport/getHwList",
callBack: doSelect
};
$.modal.openOptions(options);
}
function doSelect(index, layero) {
var body = layer.getChildFrame('body', index);
$("#hwName").val(body.find('#ent_name').val());
$("#hwCode").val(body.find('#ent_code').val());
$("#country").val(body.find('#ent_country').val());
layer.close(index);
}
/**
* 代下单用户校验
*/
$('#userId').on('select2:open', function () {
let deptId = $("#treeId").val();
if (deptId === null || deptId === '') {
// console.log(111111111111)
// $("#userWarm").show();
$.modal.alertError("请先选择部门")
return;
}
});
/**
* 根据 选定的部门id 查询对应部门下的用户,并设置 代下单用户的 option
*/
function updateDept() {
let deptId = $("#treeId").val();
// console.log(ctx + '/business/frontUser/getFrontUserByOrgId/')
//调用后端接口,获取用户
fetch(ctx + 'business/frontUser/getFrontUserByOrgId/' + deptId).then(response => response.json()).then(data => {
//先将 select标签置空,防止多次点击 累加option
const userSelect = document.getElementById('userId');
userSelect.innerHTML = '';
data.data.forEach(option => {
//拼接对应的 option
//'<option value="'+ option.id+'"> '+ option.userName +' </option>'
let optionElement = document.createElement('option');
optionElement.textContent = option.userName;
optionElement.value = option.id
userSelect.appendChild(optionElement);
});
}).catch(error => console.error("Error fetching options:" + error));
}
function getUserReportType () {
let deptId = $("#treeId").val();
fetch(ctx + 'business/bCreditReport/getUserReportType?orgId='+ deptId).then(response => response.json()).then(res => {
reportTableList = res.data.reportTableList
// contractReportBusinessTypeList = res.data.contractReportBusinessTypeList
// entrustTypeList = res.data.entrustTypeList
//先将 select标签置空,防止多次点击 累加option
const reportTypeSelect = document.getElementById('reportType');
reportTypeSelect.innerHTML = '';
reportTableList.forEach(option => {
//拼接对应的 option
//'<option value="'+ option.id+'"> '+ option.userName +' </option>'
let optionElement = document.createElement('option');
optionElement.textContent = option.typeName;
optionElement.value = option.typeId
reportTypeSelect.appendChild(optionElement);
})
handleChangeReportType(1) // 自动执行一次
}).catch(error => console.error("Error fetching options:" + error));
}
$("#reportType").on("change", function () {
handleChangeReportType(1);
})
// 处理报告类型的变化
function handleChangeReportType (type) {
let reportType = $("#reportType").val();
$("#createImmediate").val("N");
const entrustTypeSelect = $("#entrustType")
entrustTypeSelect.empty();
$("#translateType").empty();
if (reportType != '-10') {
if (reportType == '-11') {
// 定制
reportTableList.forEach(item => {
if (item.typeId == reportType) {
$("#clientIdDiv").show()
if (type == 1) {
$("#clientId").empty();
item.templateConfigurationParametersList.forEach(option => {
//拼接对应的 option
let optionElement = document.createElement('option');
optionElement.textContent = option.typeName;
optionElement.value = option.clientId
$("#clientId").append(optionElement);
})
}
item.templateConfigurationParametersList.forEach(option => {
if (option.clientId == $("#clientId").val()) {
option.templateConfigurationParametersList.forEach(option2 => {
if (option2.clientType == "3") {
$("#createImmediate").val("Y")
$("#entrustTypeDiv").hide();
}
})
if ($("#createImmediate").val() == "N") {
$("#entrustTypeDiv").show();
option.templateConfigurationParametersList.forEach(option2 => {
let optionElement = document.createElement('option');
optionElement.textContent = getClientTypeStr(option2.clientType)
optionElement.value = option2.clientType
entrustTypeSelect.append(optionElement);
})
}
}
})
}
})
} else {
// 除了定制
$("#clientIdDiv").hide()
reportTableList.forEach(item => {
if (item.typeId == reportType) {
item.templateConfigurationParametersList.forEach(option => {
if (option.clientType == "3") {
$("#createImmediate").val("Y")
$("#entrustTypeDiv").hide();
}
})
if ($("#createImmediate").val() == "N") {
$("#entrustTypeDiv").show();
item.templateConfigurationParametersList.forEach(option => {
let optionElement = document.createElement('option');
optionElement.textContent = getClientTypeStr(option.clientType)
optionElement.value = option.clientType
entrustTypeSelect.append(optionElement);
})
}
}
})
}
$("#enterpriseNameDiv").show();
// $("#hwName").hide();
$("#country").val("CN");
$("#hwEntDiv").hide();
selectInit()
} else {
// $("#hwName").show();
$("#hwEntDiv").show();
$("#enterpriseNameDiv").hide();
$("#clientIdDiv").hide()
reportTableList.forEach(item => {
if (item.typeId == reportType) {
item.templateConfigurationParametersList.forEach(option => {
if (option.clientType == "3") {
$("#createImmediate").val("Y")
$("#entrustTypeDiv").hide();
}
})
if ($("#createImmediate").val() == "N") {
$("#entrustTypeDiv").show();
item.templateConfigurationParametersList.forEach(option => {
let optionElement = document.createElement('option');
optionElement.textContent = getClientTypeStr(option.clientType)
optionElement.value = option.clientType
entrustTypeSelect.append(optionElement);
})
}
}
})
}
// 赋值报告翻译
reportTableList.forEach(item => {
if (item.typeId == reportType) {
if (item.typeId != "-11") {
// 除了定制
item.templateConfigurationParametersList.forEach(option => {
if (option.clientType === null) {
let optionElement = document.createElement('option');
optionElement.textContent = '无'
optionElement.value = "NO"
$("#translateType").append(optionElement)
let optionElement2 = document.createElement('option');
optionElement2.textContent = getReportTranslationTypeStr(option.reportTranslationType);
optionElement2.value = option.reportTranslationType
$("#translateType").append(optionElement2)
}
})
} else {
// 定制
item.templateConfigurationParametersList.forEach(option => {
if (option.clientId == $("#clientId").val()) {
option.templateConfigurationParametersList.forEach(option2 => {
if (option2.reportTranslationType === null) {
let optionElement = document.createElement('option');
optionElement.textContent = '无'
optionElement.value = "NO"
$("#translateType").append(optionElement)
let optionElement2 = document.createElement('option');
optionElement2.textContent = getReportTranslationTypeStr(option2.reportTranslationType);
optionElement2.value = option2.reportTranslationType
$("#translateType").append(optionElement2)
}
})
}
})
}
}
})
/*if ($("#createImmediate").val() == "Y") {
let optionElement = document.createElement('option');
optionElement.textContent = "特急";
optionElement.value = "2"
entrustTypeSelect.appendChild(optionElement);
} else {
$("#createImmediate").val("N");
entrustTypeList[reportType].forEach(item => {
let optionElement = document.createElement('option');
optionElement.textContent = item.clientTypeStr;
optionElement.value = item.clientType
entrustTypeSelect.appendChild(optionElement);
})
}*/
}
$("body").on("change", "#clientId", function () {
handleChangeReportType(2);
})
function getClientTypeStr (type) {
let str = ""
switch (type) {
case "0":
str = "普通"
break;
case "1":
str = "加急"
break;
case "2":
str = "特急"
break;
case "4":
str = "其他"
break;
}
return str
}
function getReportTranslationTypeStr (type) {
let str = ""
switch (type) {
case "ON":
str = "中译日"
break;
case "CN":
str = "英译中"
break;
case "EN":
str = "中译英"
break;
}
return str
}
</script>
</body>
</html>