subjectManage.js
6.77 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
var $ = require('jquery'),
common = require('../common/common'),
util = require('../common/util');
new common.dropDown({el: "#subject-type"});
new common.dropDown({el: "#subject-paltform"});
new common.dropDown({el: "#subject-status"});
var g = new common.grid({
el: "#subject-manage",
parms: function () {
return {
sort: common.util.__input('subject-type'),
plateform: common.util.__input('subject-paltform'),
status: common.util.__input('subject-status')
};
},
columns: [
{display: "ID", name: "id"},
{display: "分类", name: "sort", render: function (item) {
if(item.sort == "1") return "奥莱";
else if(item.sort == "2") return "SALE";
}},
{display: "排序", name: "orderNum"},
{display: "标题", name: "title"},
{display: "封面图", name: "coverUrl", render: function (item) {
return '<img src="'+item.coverUrl+'" height="100px" />';
}},
{display: "促销形式", name: "promotionName"},
{display: "平台", name: "plateform", render: function (item) {
if(item.plateform != null && item.plateform.trim() != "") {
var paltform = item.plateform;
var temp = paltform.replace("1", "WEB").replace("2", "APP").replace("3", "WAP").replace("4", "IPAD");
return temp;
}
}},
{display: "状态", name: "status", render: function (item) {
if(item.status == 1) return "未定时";
else if(item.status == 2) return "未发布";
else if(item.status == 3) return "已发布";
else if(item.status == 4) return "已结束";
}},
{display: "创建时间", name: "createTime", render: function (item) {
if(!item.createTime) return "";
return Bll.getLocalTime(item.createTime);
}},
{display: "活动时间", name: "", render: function (item) {
// return new Date(item.startTime).toStri34ng() + "~" + new Date(item.endTime).tostring();
if(!item.startTime || !item.endTime) return "";
return Bll.getLocalTime(item.startTime) + "~" + Bll.getLocalTime(item.endTime);
}},
{
display: "操作", name: "", render: function (item) {
var arr = [];
arr.push('<a class="btn btn-info add2" data-index="' + item.__index + '">编辑</a>');
arr.push('<a class="btn btn-info delbtn" data-index="' + item.__index + '">删除</a>');
return arr.join("");
}
}
]
});
g.init('/runManage/subjectManage/subjectList');
var Bll = {
getLocalTime:function(nS) {
var date = new Date(parseInt(nS) * 1000);
var mm = date.getMonth() + 1;
var dd = date.getDate();
return date.getFullYear() + "-" + (mm < 10 ? "0" + mm : mm) + "-" + (dd < 10 ? "0" + dd : dd);
},
toast:function(url, item, hint) {
var e = new common.edit("#baseform", {bucket:"activity"});
e.on("validate",function() {
var startTime=$("#startTime").val();
var endTime=$("#endTime").val();
if((startTime==""&&endTime=="") || (startTime!=""&&endTime!="")){}else{
return "开始时间和结束时间必须同时存在";
}
});
e.on("validate", function() {
var temp = $("#productPoolId").val();
if(!temp || temp == -1) {
return "请填写商品池";
}
});
e.on("validate", function() {
if(($("#promotion1").is(":checked") && !$("#promotionName1").val())
|| ($("#promotion2").is(":checked") && (!$("#promotionName2").val() || !$("#promotionName3").val()))
|| ($("#promotion4").is(":checked") && !$("#promotionName4").val())
|| ($("#promotion5").is(":checked") && !$("#promotionName5").val())) {
return "请将折扣形式填写完整";
}
});
var dialog=common.dialog.confirm(hint,
common.util.__template($("#template").html(), item),
function() {
e.submit(url,function(option){
//option.data;
if(typeof option.data.startTime == "string") {
option.data.startTime=new Date(option.data.startTime).getTime() / 1000;
option.data.endTime=new Date(option.data.endTime).getTime() / 1000;
}
var val=$('input:radio[name="promotionName"]:checked').val();
if(val == 1) {
option.data.promotionName = $("#promotionName1").val() + "折起";
}else if(val == 2) {
option.data.promotionName = $("#promotionName2").val() + "~" + $("#promotionName3").val() + "折";
}else if(val == 4) {
option.data.promotionName = $("#promotionName4").val() + "元起";
}else if(val == 5) {
option.data.promotionName = $("#promotionName5").val() + "%Off";
}
option.success=function(res){
dialog.close();
util.__tip(res.data.message, 'success');
g.reload();
};
option.error=function(res){
dialog.close();
util.__tip(res.data.message);
}
});
return false;
});
//提取折扣信息
if(item.promotionName) {
if(item.promotionName.indexOf("折起") != -1) {
$('#promotionName1').val(item.promotionName.replace("折起", ""));
$("#promotion1").attr("checked","checked");
} else if(item.promotionName.indexOf("折") != -1) {
$('#promotionName2').val(item.promotionName.split("~")[0]);
$('#promotionName3').val(item.promotionName.split("~")[1]);
$("#promotion2").attr("checked","checked");
} else if(item.promotionName.indexOf("元起") != -1) {
$('#promotionName4').val(item.promotionName.replace("元起", ""));
$("#promotion4").attr("checked","checked");
} else if(item.promotionName.indexOf("%") != -1) {
var promotionName5 = $("#promotionName5");
var temp = item.promotionName.replace("%", "");
temp = temp.replace(/off/i, "");
promotionName5.val(temp);
$("#promotion5").attr("checked","checked");
}
}
console.log($("#promotion1").val());
e.init();
new common.dropDown({el: "#productPoolId","ajax":"productPool"});
if(hint == "专题编辑") {
common.util.__ajax({
url:'/runManage/subjectManage/queryBaseProductPoolListById',
data:{id:item.productPoolId}
},function(res) {
$("#select2-productPoolId-container").html(res.data[0].text);
},true);
}
}
};
$('#add-subject').on('click', function() {
var item = {};
Bll.toast('/runManage/subjectManage/addSubject', item, "专题添加");
});
$(document).on('click', '.add2', function() {
var item = g.rows[$(this).data("index")];
if(typeof item.startTime == "number") {
item.startTime = Bll.getLocalTime(item.startTime);
item.endTime = Bll.getLocalTime(item.endTime);
}
Bll.toast('/runManage/subjectManage/modify', item, "专题编辑");
});
$(document).on('click', '.delbtn', function() {
var item=g.rows[$(this).data("index")];
common.dialog.confirm("警告",
"确认删除?",
function() {
common.util.__ajax({
url:'/runManage/subjectManage/delSubject',
data:{id:item.id}
},function() {
g.reload();
});
});
});
$(document).on("click","#filter-btn",function () {
g.reload(1);
});