$(document).ready(function() {
$("#productSearch").on("input",
function() {
var str = $(this).val();
$.ajax({
type: "GET",
url: "Searchproduct.php",
dataType: "html",
contentType: "application/json;charset=utf-8",
data: {
"str": str
},
timeout: 20000,
success: function(e) {
$("#productlist").show();
$("#productlist ul").html(e);
}
});
});
$(".productlist li").live("click",
function() {
var id = $(this).data("id");
var unit = $(this).data("unit");
var n = "
" + $(this).find(".name").html() + "
";
var pic = "" + $(this).find(".pic").html() + "
";
var item = "";
$(".prowapper").append(item);
$("#productlist").hide();
$("#productSearch").val("");
})
$(".prodelet").live("click",
function() {
$(this).parent().remove();
})
$(".priceitem .additem").live("click",
function() {
var priceitem = $(this).parent().clone();
var i = $(this).parent().index();
var lastnum = $(".priceitem").eq(i).find(".num").val();
var lastprice = $(".priceitem").eq(i).find(".price").val();
if (lastnum == "" || lastprice == "") //未输入无法继续添加
{
return false
} else {
priceitem.find(".num").val("");
priceitem.find(".price").val("");
$(this).parent().after(priceitem);
}
})
$(".priceitem .delitem").live("click",
function() {
var n = $(this).parent().siblings().length;
if (n > 0) {
priceitem = $(this).parent().remove();
} else {
return false
}
})
$(".priceitem .num").live("blur",
function() {
var pnum; //Pre数量
var cnum = $(this).val(); //当前数量
var i = $(this).parent().index();
var pre = i - 1;
var len = $(".priceitem").length;
if (len > 1) {
pnum = $(".priceitem").eq(pre).find(".num").val();
console.log(pnum);
if (eval(cnum) < eval(pnum)) {
$(this).parent().find(".note").html("当前数量不能小于上一项");
$(this).select();
}
else
{$(this).parent().find(".note").html("");}
}
})
$(".priceitem .price").live("blur",
function() {
var pprice; //Pre数量
var cprice = $(this).val(); //当前数量
var i = $(this).parent().index();
var pre = i - 1;
var len = $(".priceitem").length;
if (len > 1) {
pprice = $(".priceitem").eq(pre).find(".price").val();
if (eval(cprice) > eval(pprice)) {
$(this).parent().find(".note").html("当前售价不能高于上一项");
$(this).select();
}
else
{$(this).parent().find(".note").html("");}
}
})
});