AddSupplierAttachmentScript.blade.php
4.43 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
{!! Autograph() !!}
<script>
layui.use(['form', 'upload', 'admin', 'laydate'], function () {
const form = layui.form
const upload = layui.upload;
const admin = layui.admin;
//提交数据
form.on('submit(saveSupplierAttachment)', function (data) {
layer.confirm('确定要保存附件信息吗?', function (index) {
admin.showLoading({
type: 3
});
$.ajax({
url: '/api/supplier_attachment/SaveSupplierAttachment',
type: 'GET',
async: true,
data: data.field,
dataType: 'json',
timeout: 20000,
success: function (res) {
if (res.err_code === 0) {
admin.removeLoading();
admin.putTempData("needFreshList", 1);
admin.closeThisDialog();
parent.layer.msg(res.err_msg, {icon: 6});
} else {
admin.removeLoading();
parent.layer.msg(res.err_msg, {icon: 5});
}
},
error: function () {
admin.removeLoading();
parent.layer.msg('网络错误', {icon: 5});
}
});
});
return false;
})
let laydate = layui.laydate;
@if (!empty($attachment['validity_period']))
laydate.render({
elem: 'input[name=validity_period]'
, type: 'date'
, trigger: 'click'
, range: '~' //或 range: '~' 来自定义分割字符
, value: '{{$attachment['validity_period']}}'
});
@else
laydate.render({
elem: 'input[name=validity_period]'
, type: 'date'
, trigger: 'click'
, range: '~' //或 range: '~' 来自定义分割字符
, value: ''
});
@endif
@if (!empty($attachment['validity_type'])&&$attachment['validity_type']==2)
$('#validity_period_div').show();
@else
$('#validity_period_div').hide();
@endif
form.on('submit(cancel)', function (data) {
admin.closeThisDialog();
});
form.on('radio(validity_type)', function (data) {
if (data.value == 1) {
$('#validity_period_div').hide();
} else {
$('#validity_period_div').show();
}
});
let fileName = '';
//图片上传
upload.render({
elem: '.upload-attachment'
, url: UploadImgUrl
, field: 'upload'
, data: {
k1: k1,
k2: k2,
source: 1,
cancel_time_verify: 1,
}
, accept: 'file'
, exts: 'jpg|png|bmp|jpeg|zip|pdf'
, choose: function (obj) {
let files = this.files = obj.pushFile();
let recentFile = files[Object.keys(files)[Object.keys(files).length - 1]]
fileName = recentFile.name;
}
, before: function (obj) {
layer.msg('加载中', {
icon: 16
, shade: 0.01
});
let item = this.item;
//预读本地文件示例,不支持ie8
obj.preview(function (index, file, result) {
});
}
, done: function (res, index, upload) {
if (res.code === 200) {
layer.msg('上传成功', {icon: 6});
let item = this.item;
$('#' + item.attr('data-obj')).val(res.data[0]);
$('#file_url_href').text(fileName);
$('#file_name').val(fileName);
$('#file_url').val(res.data[0]);
delete this.files[index];
return false;
} else {
layer.msg('上传失败:' + res.message, {icon: 5});
return false;
}
}
, error: function (res) {
layer.msg('上传失败:' + res.message, {icon: 5});
return false;
}
});
});
</script>