proPhoto.js
6.67 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
/**
* Created by JiangMin on 2016/3/22.
* 产品图片管理
*/
var $ = require('jquery');
var common = require('../common/common');
//日期插件
$('.hasDatepicker').fdatepicker({
format: 'yyyy-mm-dd'
});
/**
* 列表显示数据
* @type {common.grid}
*/
var g = new common.grid({
el: '#content-list',
hash: false,
parms: function () {
return {
//查询参数
productSkn: common.util.__input('content-filter1'),
productSkc: common.util.__input('content-filter2'),
productSku: common.util.__input('content-filter3'),
startTime: ((new Date($('#starttime').val())).getTime()) / 1000,
endTime: ((new Date($('#endtime').val())).getTime()) / 1000
};
},
//列表显示
columns: [
{display: "SKN", name: "productSkn"},
{
display: "最后上传时间", name: "lastAddTime",
render: function (item) {
var t = new Date(item.lastAddTime * 1000);
var formatted = common.util.__dateFormat(t, "yyyy-MM-dd hh:mm:ss");
return "<p>" + formatted + "</p>";
}
},
{
display: "图片", name: "pictureBoList", render: function (item) {
var a = item.pictureBoList || [];
if (a.length > 0) {
var b;
for (var i = 0; i < a.length; i++) {
b = b + '<img src="' + item.pictureBoList[i].fileName + '?imageView/2/w/100/h/100" width="100" height="60"/>'
}
return b.substr(9);
}
else {
return ""
}
}
},
{
display: "操作", name: "", render: function (item) {
var arr = [];
arr.push('<a class="btn btn-info update" data-index="' + item.__index + '">编辑</a>');
return arr.join('');
}
}
]
});
g.init("/shotManage/proPhoto/index2");
var Bll = {
pictureBoList: [],
selectedBoId: [],
clonePics:[],
//重新渲染图片列表
rendBoList: function (pictureBoList) {
$(".image-list").html('');
$("#addPic").prepend(common.util.__template2($("#template2").html(),
{
pictureBoList: pictureBoList
}
));
},
//获取编辑时新增的图片
getNewPics:function(pictureBoList){
var newPic=[];
if(pictureBoList.length>0){
for (var i = 0; i < pictureBoList.length; i++) {
if (!pictureBoList[i].id) {
newPic.push(pictureBoList[i])
}
}
}
return newPic
},
//模态
toast: function (url, item, datacall) {
Bll.pictureBoList = item.pictureBoList||[];
Bll.selectedBoId = [];
var a = new common.dialog({
title: "图片",
width: '80%',
content: common.util.__template2($("#template1").html(), item),
button: [
{
value: "提交", callback: function () {
var data={};
if(item.__state=='add'){
data = datacall && datacall(Bll.clonePics, Bll.selectedBoId);
}else{
data = datacall && datacall(Bll.getNewPics(Bll.clonePics), Bll.selectedBoId);
}
console.log("最终提交数据data",data);
common.util.__ajax({
url: url,
data: data
}, function (res) {
if (res.code == '200') {
g.reload();
a.close();
}
else{
console.log("res",res);
if(res.data.length>0){
var mess="失败列表:";
for(var i=0;i<res.data.length;i++){
mess=mess+res.data[i].originalName+";"
}
common.util.__tip(mess, 'warning');
}
}
});
return false;
}, css: "btn-primary"
},
{
"value": "取消",
css: "btn-info"
}
]
});
Bll.rendBoList(Bll.pictureBoList);
common.edit.ajaxfileupload(".picfile", {
params: {
__type: "upload",
bucket: "goodsimg"
},
valid_extensions: ['png', 'jpg', 'jpeg'],
onComplete: function (response) {
if (response.status && response.code == 200) {
for(var i=0;i<response.data.length;i++){
Bll.pictureBoList.push({
"fileName": response.data[i],
"originalName": response.names[i]
});
Bll.clonePics.push({
"fileName": response.data[i],
"originalName": response.names[i]
})
}
Bll.rendBoList(Bll.clonePics);
}
else {
common.util.__tip(response.message, 'warning');
}
}
});
}
};
//上传图片--点击事件
$('#upload-btn').on('click', function () {
var item = {
__state: "add"
};
Bll.clonePics=[];
Bll.toast('/shotManage/proPhoto/add', item, function (pictureBoList, selectedBoId) {
return {
productPhotoAddStrList: JSON.stringify(pictureBoList)
}
});
});
//编辑
$(document).on('click', '.update', function () {
var item = g.rows[$(this).data("index")];
item.__state = "update";
Bll.clonePics=[];
Array.prototype.push.apply(Bll.clonePics,item.pictureBoList);
Bll.toast('/shotManage/proPhoto/add', item, function (pictureBoList, selectedBoId) {
return {
productSkn: item.productSkn,
ids: JSON.stringify(selectedBoId),
productPhotoAddStrList: JSON.stringify(pictureBoList)
}
});
});
//删除单张图片
$(document).on('click', '.remove1', function () {
var index = $(this).data("index");
if(Bll.clonePics[index].id){
Bll.selectedBoId.push(Bll.clonePics[index].id);
}
Bll.clonePics.splice(index, 1);
Bll.rendBoList(Bll.clonePics);
});
//查询按钮--点击事件
$(document).on('click', '#filter-btn', function () {
g.reload(1);
});