...
|
...
|
@@ -10,7 +10,7 @@ var type = $("#basicForm").attr("role"),//类型 新增或修改 |
|
|
action = $("#basicForm").data("action");//路由
|
|
|
var startTimeObj;
|
|
|
var endTimeObj;
|
|
|
var customType=[];
|
|
|
var customType = [];
|
|
|
|
|
|
/**
|
|
|
* 监听输入值的变化
|
...
|
...
|
@@ -26,10 +26,8 @@ $(document).on("change", ".observe", function () { |
|
|
* 全局对象
|
|
|
*/
|
|
|
var Bll = {
|
|
|
Brands: [],
|
|
|
Brands1: {},
|
|
|
Brdata: [],
|
|
|
getBrands: function () {
|
|
|
Brands: [],//品牌数据
|
|
|
getBrands: function () {//获取品牌数据
|
|
|
var Brand = {};
|
|
|
$.get("/ajax/yohosearch", function (res) {
|
|
|
if (!res.data || !res.data.brands) {
|
...
|
...
|
@@ -47,7 +45,6 @@ var Bll = { |
|
|
var item = res.data.brands[key][key2];
|
|
|
Brand[name] = Brand[name] || [];
|
|
|
Brand[name].push(item);
|
|
|
Bll.Brands1[item.id] = item;
|
|
|
}
|
|
|
}
|
|
|
for (var i in Brand) {
|
...
|
...
|
@@ -62,41 +59,16 @@ var Bll = { |
|
|
name: i,
|
|
|
items: Brand[i]
|
|
|
});
|
|
|
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
renderBrandPic: function (Brdata) {
|
|
|
var map2 = {};
|
|
|
Brdata.forEach(function (item) {
|
|
|
map2[item.id] = item;
|
|
|
});
|
|
|
Brdata = [];
|
|
|
for (var key in map2) {
|
|
|
Brdata.push(map2[key]);
|
|
|
}
|
|
|
var Brands2 = [];
|
|
|
Brdata.forEach(function (item, index) {
|
|
|
if (!item.brandIco) {
|
|
|
var a = Bll.Brands1[item.id];
|
|
|
if (a.brandIco) {
|
|
|
a.brandIco = common.util.__joinImg("brandLogo", a.brand_ico);
|
|
|
}
|
|
|
Brands2.push(a);
|
|
|
} else {
|
|
|
item.brandIco = common.util.__template(item.brandIco, {width: 110, height: 150});
|
|
|
Brands2.push(item);
|
|
|
}
|
|
|
|
|
|
});
|
|
|
return Brdata;
|
|
|
},
|
|
|
getTime: function (time) {
|
|
|
getTime: function (time) {//时间格式转换
|
|
|
var t = new Date(time * 1000);
|
|
|
return common.util.__dateFormat(t, "yyyy-MM-dd hh:mm:ss");
|
|
|
|
|
|
},
|
|
|
__render: function (item,type) {
|
|
|
__render: function (item, type) {//渲染界面
|
|
|
$("#basicForm").html(common.util.__template2($("#couponListAdd-template").html(), item));
|
|
|
e.init();
|
|
|
startTimeObj = $("#startTime").fdatepicker({
|
...
|
...
|
@@ -109,12 +81,12 @@ var Bll = { |
|
|
}).data("datepicker");
|
|
|
new common.dropDown({el: '#filter-couponType'});
|
|
|
new common.dropDown({el: '#filter-department'});
|
|
|
if(type=='update'){
|
|
|
if(couponBean.customType){
|
|
|
customType=couponBean.customType.split(',');
|
|
|
for(var i=0;i<customType.length;i++){
|
|
|
if (type == 'update') {
|
|
|
if (couponBean.customType) {
|
|
|
customType = couponBean.customType.split(',');
|
|
|
for (var i = 0; i < customType.length; i++) {
|
|
|
var custom = "custom-" + customType[i];
|
|
|
$("input ." + custom).attr("checked","checked");
|
|
|
$("input ." + custom).attr("checked", "checked");
|
|
|
}
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -132,7 +104,7 @@ var Bll = { |
|
|
* 根据type判断界面
|
|
|
*/
|
|
|
if (type == 'add') {
|
|
|
Bll.__render(couponBean,type);
|
|
|
Bll.__render(couponBean, type);
|
|
|
} else {
|
|
|
var id = location.href.substring(location.href.lastIndexOf("/") + 1);
|
|
|
common.util.__ajax({
|
...
|
...
|
@@ -142,26 +114,65 @@ if (type == 'add') { |
|
|
couponBean = res.data.list[0];
|
|
|
couponBean.startTime = Bll.getTime(couponBean.startTime);
|
|
|
couponBean.endTime = Bll.getTime(couponBean.endTime);
|
|
|
Bll.__render(couponBean,type)
|
|
|
Bll.__render(couponBean, type)
|
|
|
}, true);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 优惠条件
|
|
|
*/
|
|
|
$(document).on("change", "#useLimitType", function () {
|
|
|
Bll.__render(couponBean,type);
|
|
|
Bll.__render(couponBean, type);
|
|
|
});
|
|
|
/**
|
|
|
* 适用范围
|
|
|
*/
|
|
|
$(document).on("change", "#useRange", function () {
|
|
|
couponBean.useRange = $(this).val();
|
|
|
Bll.__render(couponBean,type);
|
|
|
Bll.__render(couponBean, type);
|
|
|
});
|
|
|
|
|
|
/**
|
|
|
* 会员身份
|
|
|
*/
|
|
|
$(document).on("click", "input[name='customType']", function () {
|
|
|
if ($(this).is(':checked')) {
|
|
|
customType.push($(this).val());
|
|
|
} else {
|
|
|
for (var i = 0; i < customType.length; i++) {
|
|
|
if ($(this).val() == customType[i]) {
|
|
|
customType.splice(i, 1)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
couponBean.customType = customType.join(",");
|
|
|
});
|
|
|
|
|
|
//输入限制
|
|
|
$(document).on("keyup", ".number", function () {
|
|
|
$(this).val($(this).val().replace(/\D/g, ''));
|
|
|
});
|
|
|
/**
|
|
|
* 保存
|
|
|
*/
|
|
|
$(document).on("click", "#save_brand", function () {
|
|
|
// console.log(couponBean);
|
|
|
if (e.validate()) {
|
|
|
delete couponBean.useRange;
|
|
|
common.util.__ajax({
|
|
|
url: action,
|
|
|
data: couponBean
|
|
|
}, function (res) {
|
|
|
location.href = "/market/couponList/index";
|
|
|
});
|
|
|
}
|
|
|
return false;
|
|
|
});
|
|
|
var tabTreeArr = [];
|
|
|
var tabTree;
|
|
|
|
|
|
/********************************************************分类相关****************************************/
|
|
|
var tabTreeArr = [], tabTree;
|
|
|
//选择分类
|
|
|
$(document).on('click',"#addSorts",function(){
|
|
|
$(document).on('click', "#addSorts", function () {
|
|
|
var data = {};
|
|
|
common.dialog({
|
|
|
title: "选择分类",
|
...
|
...
|
@@ -212,48 +223,10 @@ $(document).on('click', '.del-sort-btn', function () { |
|
|
tabTreeArr.splice(sortIndex, 1);
|
|
|
Bll.checkSortNum();
|
|
|
});
|
|
|
/**
|
|
|
* 会员身份
|
|
|
*/
|
|
|
$(document).on("click", "input[name='customType']", function () {
|
|
|
if ($(this).is(':checked')) {
|
|
|
customType.push($(this).val());
|
|
|
} else {
|
|
|
for (var i = 0; i < customType.length; i++) {
|
|
|
if ($(this).val() == customType[i]) {
|
|
|
customType.splice(i, 1)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
couponBean.customType = customType.join(",");
|
|
|
});
|
|
|
|
|
|
//输入限制
|
|
|
$(document).on("keyup", ".number", function () {
|
|
|
$(this).val($(this).val().replace(/\D/g, ''));
|
|
|
});
|
|
|
/**
|
|
|
* 保存
|
|
|
*/
|
|
|
$(document).on("click", "#save_brand", function () {
|
|
|
console.log(couponBean);
|
|
|
if (e.validate()) {
|
|
|
delete couponBean.useRange;
|
|
|
common.util.__ajax({
|
|
|
url: action,
|
|
|
data: couponBean
|
|
|
}, function (res) {
|
|
|
location.href = "/market/couponList/index";
|
|
|
});
|
|
|
}
|
|
|
return false;
|
|
|
});
|
|
|
|
|
|
|
|
|
/********************************************************品牌相关****************************************/
|
|
|
//获取品牌
|
|
|
Bll.getBrands();
|
|
|
Bll.renderBrandPic(Bll.Brdata);
|
|
|
/**
|
|
|
* 添加品牌
|
|
|
*/
|
...
|
...
|
@@ -261,16 +234,9 @@ $(document).on("click", "#addBrands", function () { |
|
|
var e = new common.edit("#brandForm");
|
|
|
common.dialog.confirm("选择品牌", common.util.__template2($("#template5").html(), {
|
|
|
Brands: Bll.Brands,
|
|
|
Brdata: Bll.Brdata.join(',')
|
|
|
Brdata: couponBean.brandLimit
|
|
|
}), function () {
|
|
|
$("#brandCheckBox").val().split('|').forEach(function (item) {
|
|
|
Bll.Brdata.push({
|
|
|
"brandCategory": "1",
|
|
|
"id": item
|
|
|
});
|
|
|
});
|
|
|
couponBean.brandLimit = $("#brandCheckBox").val().split('|').join(",");
|
|
|
Bll.Brdata = Bll.renderBrandPic(Bll.Brdata);
|
|
|
});
|
|
|
e.init();
|
|
|
});
|
...
|
...
|
@@ -282,6 +248,7 @@ $(document).on('click', '.brand-index', function () { |
|
|
$(document).on("focus", "#brandsearch", function () {
|
|
|
$('.brand-wrap').find('[name="brandsearch"]').show().siblings().hide();
|
|
|
});
|
|
|
//品牌搜索输入
|
|
|
$(document).on("keyup", "#brandsearch", function () {
|
|
|
var txt = $(this).val();
|
|
|
var regex = new RegExp(txt);
|
...
|
...
|
@@ -296,5 +263,5 @@ $(document).on("keyup", "#brandsearch", function () { |
|
|
$("#brandsearchwrap").html(bs.join(''));
|
|
|
var e = new common.edit("#brandForm");
|
|
|
e.init();
|
|
|
|
|
|
});
|
|
|
|
...
|
...
|
|