...
|
...
|
@@ -6,6 +6,52 @@ var e = new common.edit2("#basicForm"); |
|
|
var type = $("#basicForm").attr("role"),
|
|
|
action = $("#basicForm").data("action");
|
|
|
|
|
|
var Bll = {
|
|
|
__render:function() {
|
|
|
$("#basicForm").html(common.util.__template2($("#limitcodeEdit-template").html(), editBean));
|
|
|
e.init();
|
|
|
if(type != "add") {
|
|
|
$('input[name="skn_sku"]').prop('disabled', true);
|
|
|
$(".noEdit").prop("disabled", true);
|
|
|
$('input[name="userTypeLimit"]').prop('disabled', true);
|
|
|
if(Bll.getLocalTime(editBean.limitDateFrom) <= Bll.getLocalTime(new Date())) {
|
|
|
$("#limitDateFrom").prop("disabled", true);
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
__checkSkn:function(callback) {
|
|
|
var flag = false;
|
|
|
common.util.__ajax({
|
|
|
async:false,
|
|
|
url: "/limitCode/checkSknValidity",
|
|
|
data: {skn:editBean.limitSkn}
|
|
|
},function(res) {
|
|
|
if(!res.data.isExist) {
|
|
|
flag = true;
|
|
|
common.util.__tip("SKN不存在");
|
|
|
} else if(res.data.isConflict) {
|
|
|
flag = true;
|
|
|
common.util.__tip("SKN与其他限购冲突");
|
|
|
} else if(res.data.isOnSales) {
|
|
|
flag = true;
|
|
|
common.util.__tip("SKN已上架,请先下架");
|
|
|
}
|
|
|
callback && callback(res);
|
|
|
}, true);
|
|
|
return flag;
|
|
|
},
|
|
|
getLocalTime:function(nS) {
|
|
|
var date = new Date(parseInt(nS) * 1000);
|
|
|
var mm = date.getMonth() + 1;
|
|
|
var dd = date.getDate();
|
|
|
var h = date.getHours();
|
|
|
var min = date.getMinutes();
|
|
|
var second = date.getSeconds();
|
|
|
return date.getFullYear() + "-" + (mm < 10 ? "0" + mm : mm) + "-" + (dd < 10 ? "0" + dd : dd) + " " + (h < 10 ? "0" + h : h) + ":"
|
|
|
+ (min < 10 ? "0" + min : min) + ":" + (second < 10 ? "0" + second : second);
|
|
|
},
|
|
|
};
|
|
|
|
|
|
if(type != "add") {
|
|
|
var id = location.href.substring(location.href.lastIndexOf("/") + 1);
|
|
|
common.util.__ajax({
|
...
|
...
|
@@ -20,170 +66,87 @@ if(type != "add") { |
|
|
"营销策划"
|
|
|
];
|
|
|
}
|
|
|
$("#basicForm").html(common.util.__template2($("#limitcodeEdit-template").html(), editBean));
|
|
|
e.init();
|
|
|
if (type == 'edit') {
|
|
|
//$('#name, #limitTimes, #userUseLimit, #department1, #department2, #limitDateFrom, #limitDateTo, #describe, #UID').prop('disabled', true);
|
|
|
$(".noEdit").prop("disabled", true);
|
|
|
$('input[name="userTypeLimit"]').prop('disabled', true);
|
|
|
$("#indetify").hide();
|
|
|
$("#limit-userUseLimit").hide();
|
|
|
}
|
|
|
editBean.selected = editBean.skus ? "SKU" : "SKN";
|
|
|
Bll.__render();
|
|
|
},true);
|
|
|
} else {
|
|
|
$("#basicForm").html(common.util.__template2($("#limitcodeEdit-template").html(), editBean));
|
|
|
e.init();
|
|
|
$("#indetify").hide();
|
|
|
$("#limit-userUseLimit").hide();
|
|
|
Bll.__render();
|
|
|
}
|
|
|
//var e = new edit("#basicForm");
|
|
|
|
|
|
//
|
|
|
|
|
|
$(document).on("change", ".observe", function () {
|
|
|
var val = $(this).val();
|
|
|
var fn = new Function("editBean", "val", "editBean." + $(this).data("field") + "= val;");
|
|
|
fn(editBean, val);
|
|
|
var $this = $(this);
|
|
|
var name = $this.data("field");
|
|
|
editBean = common.util.__buildobj(name, '.', editBean, function (obj, name) {
|
|
|
obj[name] = $this.val();
|
|
|
});
|
|
|
editBean.limitDateFrom = $("#limitDateFrom").val();
|
|
|
editBean.limitDateTo = $("#limitDateTo").val();
|
|
|
console.log(editBean);
|
|
|
});
|
|
|
|
|
|
$(document).on("change", "#limitSkn", function() {
|
|
|
var val = $(this).val();
|
|
|
if($("#sknsku").val() == "SKU" && val && val.length == 8) {
|
|
|
$(document).on("click", ".limitProduct", function() {
|
|
|
editBean.selected = $(this).val();
|
|
|
Bll.__render();
|
|
|
console.log(editBean);
|
|
|
});
|
|
|
|
|
|
}
|
|
|
$(document).on("click", ".delSku", function () {
|
|
|
var index = $(this).data("index");
|
|
|
editBean.skusInfos.splice(index, 1);
|
|
|
Bll.__render();
|
|
|
});
|
|
|
$(document).on("click", ".addSku", function () {
|
|
|
editBean.skusInfo.push({
|
|
|
"sku": "",
|
|
|
"skuTimes": ""
|
|
|
});
|
|
|
Bll.__render();
|
|
|
});
|
|
|
//
|
|
|
//
|
|
|
//e.on("render", function() {
|
|
|
// if ($("#reqDepartment").val()) {
|
|
|
// var departmentArr = String.prototype.split.call($("#reqDepartment").val(), '/'),
|
|
|
// $department1 = $("#department1"),
|
|
|
// $department2 = $("#department2");
|
|
|
//
|
|
|
// $department1.val(departmentArr[0]);
|
|
|
// if (departmentArr[1]) {
|
|
|
// $department2.val(departmentArr[1]).show();
|
|
|
// } else {
|
|
|
// $department2.hide();
|
|
|
// }
|
|
|
// }
|
|
|
//});
|
|
|
//
|
|
|
//e.on("bind", function() {
|
|
|
// if ($("#reqDepartment").val()) {
|
|
|
// var departmentArr = String.prototype.split.call($("#reqDepartment").val(), '/'),
|
|
|
// $department1 = $("#department1"),
|
|
|
// $department2 = $("#department2");
|
|
|
//
|
|
|
// $("select").change(function() {
|
|
|
// if ($(this).is($department1)) {
|
|
|
// departmentArr.length = 0;
|
|
|
// departmentArr[0] = $(this).val();
|
|
|
// if ($(this).val() === "零售部") {
|
|
|
// $department2.show();
|
|
|
// departmentArr[1] = $department2.val();
|
|
|
// } else {
|
|
|
// $department2.hide();
|
|
|
// }
|
|
|
// } else {
|
|
|
// departmentArr[1] = $(this).val();
|
|
|
// }
|
|
|
// $("#reqDepartment").val(departmentArr.join('/'));
|
|
|
// });
|
|
|
// }
|
|
|
//});
|
|
|
//
|
|
|
//e.on("validate", function() {
|
|
|
// var num = $.trim($("#limitTimes").val());
|
|
|
// if (+num > 100000 || +num < 1) {
|
|
|
// return "数量(范围:1-100000)";
|
|
|
// }
|
|
|
// return true;
|
|
|
//});
|
|
|
//e.on("validate", function() {
|
|
|
// var skn = $.trim($("#limitSkn").val());
|
|
|
// if (skn.length > 8) {
|
|
|
// return "skn长度不能超过8位";
|
|
|
// }
|
|
|
// return true;
|
|
|
//});
|
|
|
//
|
|
|
//e.on("validate", function() {
|
|
|
// var startTime = $('#limitDateFrom').val(),
|
|
|
// endTime = $('#limitDateTo').val();
|
|
|
//
|
|
|
// if (startTime > endTime) {
|
|
|
// return '结束时间不能小于开始时间';
|
|
|
// }
|
|
|
//});
|
|
|
//
|
|
|
//e.init();
|
|
|
//
|
|
|
//var submit = function(callback) {
|
|
|
//
|
|
|
// e.submit($("#basicForm").attr("action"), function(option) {
|
|
|
// $("#save_brand").addClass('disabled');
|
|
|
// option.success = function(res) {
|
|
|
// res = res.data;
|
|
|
// if (res.code == "200") {
|
|
|
// e.$tip('提交成功', function() {
|
|
|
// location.href = "/market/limitcode/index";
|
|
|
// }, 'growl-success');
|
|
|
// } else {
|
|
|
// e.$tip(res.message);
|
|
|
// $("#save_brand").removeClass('disabled');
|
|
|
// };
|
|
|
//
|
|
|
// return false;
|
|
|
// };
|
|
|
// option.error = function(res) {
|
|
|
// $("#save_brand").removeClass('disabled');
|
|
|
// e.$tip("提交失败");
|
|
|
// }
|
|
|
// console.log(option.data);
|
|
|
// callback && callback(option.data);
|
|
|
// });
|
|
|
//}
|
|
|
//
|
|
|
//
|
|
|
$("#save_brand").click(function() {
|
|
|
|
|
|
//submit(function(data) {
|
|
|
// // 限购码状态0:待审核 1:审核通过 2:驳回 3:过期 4:作废
|
|
|
// if (+data.status == 1) {
|
|
|
// //不改
|
|
|
// } else {
|
|
|
// data.status = 0;
|
|
|
// }
|
|
|
//});
|
|
|
if(e.validate()) {
|
|
|
editBean.limitDateFrom = $("#limitDateFrom").val();
|
|
|
editBean.limitDateTo = $("#limitDateTo").val();
|
|
|
$(document).on("blur", "#limitSkn", function() {
|
|
|
Bll.__checkSkn(function(res) {
|
|
|
if (res.data.skuList) {
|
|
|
editBean.skusInfo = [];
|
|
|
for (var i = 0; i < res.data.skuList.length; i++) {
|
|
|
editBean.skusInfo.push({
|
|
|
"sku": res.data.skuList[i],
|
|
|
"skuTimes": ""
|
|
|
});
|
|
|
}
|
|
|
$(".addSku").prop("disabled", false);
|
|
|
}
|
|
|
Bll.__render();
|
|
|
});
|
|
|
});
|
|
|
$(document).on("blur", ".skus", function() {
|
|
|
//TODO
|
|
|
});
|
|
|
$(document).on("click","#save_brand", function() {
|
|
|
// 限购码状态0:待审核 1:审核通过 2:驳回 3:过期 4:作废
|
|
|
if(e.validate() && (!editBean.limitSkn || !Bll.__checkSkn())) {
|
|
|
editBean.reqDepartment = editBean.reqDepartment.join("/");
|
|
|
editBean.creatorId = $("#auth_id").val();
|
|
|
editBean.creatorName = $("#auth_name").val();
|
|
|
if (editBean.status != 1) {
|
|
|
editBean.status = 0;
|
|
|
}
|
|
|
console.log(editBean);
|
|
|
if(editBean.selected != "SKN") {
|
|
|
editBean.skus = "";
|
|
|
editBean.skuTimes = "";
|
|
|
for(var item in editBean.skusInfo) {
|
|
|
if(item != 0) {
|
|
|
editBean.skus+=";";
|
|
|
editBean.skuTimes+=";";
|
|
|
}
|
|
|
editBean.skus += editBean.skusInfo[item].sku;
|
|
|
editBean.skuTimes+=editBean.skusInfo[item].skuTimes;
|
|
|
}
|
|
|
}
|
|
|
common.util.__ajax({
|
|
|
url: action,
|
|
|
data: editBean
|
|
|
}, function (res) {
|
|
|
location.href = "/market/limitcode/index";
|
|
|
//editBean = res.data;
|
|
|
//editBean.reqDepartment = editBean.reqDepartment.split("/");
|
|
|
//if(!editBean.reqDepartment.length) {
|
|
|
// editBean.reqDepartment = [
|
|
|
// "零售部",
|
|
|
// "营销策划"
|
|
|
// ];
|
|
|
//}
|
|
|
//$("#basicForm").html(common.util.__template2($("#limitcodeEdit-template").html(), editBean));
|
|
|
//e.init();
|
|
|
},function() {
|
|
|
editBean.reqDepartment = editBean.reqDepartment.split("/");
|
|
|
});
|
|
|
}
|
|
|
return false;
|
...
|
...
|
|