Edit.js
3.35 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
var $ = require('jquery');
var common = require('../../common/common');
var edit = require('../../common/edit');
require('../../common/umeditor.config');
require('../../common/umeditor');
require('../../common/zh-cn');
var mainData = window.ViewModel;
console.log(mainData);
var authorizeCertList = [];
var e = new edit("#basicForm", {bucket: "brandLogo"});
//brandTonality
e.on("validate", function () {
var certParty_checked=$("input[name='certParty']").is(":checked");
if(!certParty_checked){
return "授权方不能为空!"
}
if (authorizeCertList.length < 1){
return "品牌授权书不能为空!"
}
return true;
});
e.init();
console.log(e);
var Bll = {
//重新渲染图片列表
rendBoList: function (pictureBoList) {
$("#authorizeCerts").empty().html(common.util.__template2($("#template2").html(), {pictureBoList: this.getRendJson(pictureBoList)}));
if(authorizeCertList.length > 9){ //最多上传10张
$("#addPic").find(".fileinput-button").hide();
}else{
$("#addPic").find(".fileinput-button").show();
}
//品牌授权书上传
edit.ajaxfileupload(".picfile", {
params: {
__type: "upload",
bucket: "brandCertificate"
},
valid_extensions: ['png', 'jpg', 'jpeg', 'pdf'],
onComplete: function (response) {
if (response.status && response.code == 200) {
authorizeCertList.push(response.data);
Bll.rendBoList(authorizeCertList);
}
else {
common.util.__tip(response.message, 'warning');
}
}
});
},
//获取编辑时新增的图片
getRendJson: function (pictureBoList) {
var list = [];
$.each(pictureBoList, function (index, item) {
var info = {};
var ext = item.split('.').pop().toLowerCase();
info.type = ext;
info.src = item;
list.push(info);
});
return list;
}
};
if(mainData.id){
authorizeCertList = mainData.authorizeCertList;
}
Bll.rendBoList(authorizeCertList);
//删除单张品牌授权书
$(document).on('click', '.remove-item-btn', function () {
var index = $(this).data("index");
authorizeCertList.splice(index, 1);
Bll.rendBoList(authorizeCertList);
});
//下载pdf证书
$(document).on('click', '.download-btn', function() {
var path = $(this).data("link");
location.href = '/ajax/download?path=' + path;
});
$(document).on('click','#save_brand',function () {
e.submit($("#basicForm").attr("action"), function (option) {
//option.data.authorizeCerts = authorizeCertList;
option.data.countryId = option.data.brandHeadstream;
option.data.authorizeCerts = JSON.stringify(authorizeCertList);
option.success = function (res) {
if (res.code == "200") {
e.$tip("提交成功", function () {
location.href = "/erpproduct/brands/index"
}, 'growl-success');
} else {
e.$tip(res.message);
}
return false;
};
option.error = function (res) {
e.$tip(res.message);
};
console.log(option.data);
});
return false;
});