function arrangegoods(gds) {
if (typeof (brandsdata) == "undefined") {
alert("无效的brandsdata");
return false;
}
var brands = brandsdata;
var brandsorts = brandsortsdata;
brandsorts.sort(web960.utils.tools.sort('asc', 'sort'));
//var zi_brandsorts = $.grep(brandsortsdata, function (v) {
// return v["brandtype"] == "1";
//});
////自有品牌
//zi_brandsorts.sort(web960.utils.tools.sort('asc', 'sort'));
//var dl_brandsorts = $.grep(brandsortsdata, function (v) {
// return v["brandtype"] != "1";
//});
////代理品牌
//dl_brandsorts.sort(web960.utils.tools.sort('asc', 'sort'));
for (var i = 0; i < gds.length; i++) {
gds[i]["sort_purity"] = i;
gds[i]["sort_brand"] = i;
gds[i]["sort_standard"] = i;
var extendattrs = {};
if (gds[i].extendattrs != null) {
var extendattrslist = gds[i].extendattrs;
$.each(gds[i].extendattrs, function () {
if (this.field != "purity" && this.field != "brand" && this.field != "packaging") {
extendattrs[this.field] = {
title: this.srctitle,
value: this.keyword
}
}
});
}
gds[i]["extendattrs"] = extendattrs;
var purity = $.trim(web960.utils.tools.getvalfromjson(gds[i].goods_info, "{goodsinfo.purity}"));
var brand = $.trim(web960.utils.tools.getvalfromjson(gds[i].goods_info, "{goodsinfo.brand}"));
var packaging = $.trim(web960.utils.tools.getvalfromjson(gds[i].goods_info, "{goodsinfo.packaging}"));
var msd = $.trim(packaging.tolowercase());
var xmsd = "";
var intpackaging = 0;
if (msd.indexof("ml") != -1) {
xmsd = msd.replace("ml", "");
intpackaging = 1;
}
else if (msd.indexof("μl") != -1) {
xmsd = msd.replace("μl", "");
intpackaging = 0.001;
}
else if (msd.indexof("ul") != -1) {
xmsd = msd.replace("ul", "");
intpackaging = 0.001;
}
else if (msd.indexof("l") != -1) {
xmsd = msd.replace("l", "");
intpackaging = 1000;
}
else if (msd.indexof("kg") != -1) {
xmsd = msd.replace("kg", "");
intpackaging = 1000;
}
else if (msd.indexof("mg") != -1) {
xmsd = msd.replace("mg", "");
intpackaging = 0.001;
}
else if (msd.indexof("ug") != -1) {
xmsd = msd.replace("ug", "");
intpackaging = 0.000001;
}
else if (msd.indexof("μg") != -1) {
xmsd = msd.replace("μg", "");
intpackaging = 0.000001;
}
else if (msd.indexof("g") != -1) {
xmsd = msd.replace("g", "");
intpackaging = 1;
}
var resultsortpack = 0;
try {
resultsortpack = parsefloat(xmsd) * intpackaging;
}
catch (e) { }
if (isnan(resultsortpack)) {
resultsortpack = 0;
}
var bsd = $.grep(brandsortsdata, function (v) {
return v.title == brand;
})
if (brands[brand] != undefined) {
gds[i]["brandsort"] = brands[brand];
}
else {
gds[i]["brandsort"] = 1000;
}
gds[i]["brand"] = brand;
if (bsd.length > 0) {
if (bsd[0]["brandtype"] != null) {
gds[i]["brandtype"] = parseint(bsd[0]["brandtype"]);
}
else {
gds[i]["brandtype"] = 0;
}
}
else {
gds[i]["brandtype"] = 0;
}
gds[i]["purity"] = purity;
gds[i]["packaging"] = resultsortpack;
gds[i]["intpackaging"] = intpackaging;
if (gds[i].sort != "" || gds[i].sort != "0") {
var sort = eval('(' + gds[i].sort + ');');
if (sort.sort_purity != undefined) {
gds[i]["sort_purity"] = sort.sort_purity;
}
if (sort.sort_brand != undefined) {
gds[i]["sort_brand"] = sort.sort_brand;
}
if (sort.sort_standard != undefined) {
gds[i]["sort_standard"] = sort.sort_standard;
}
}
}
// gds.sort(web960.utils.tools.sort('desc', 'brandtype'));//自有品牌
gds.sort(web960.utils.tools.sort('asc', 'brandsort'));
//var gdsitems = {};
//$.each(gds, function () {
// var t = this;
// var s = "x" + "_" + t["brandtype"] + "_" + t["brandsort"];
// if (gdsitems[s] != undefined) {
// gdsitems[s].push(t);
// }
// else {
// gdsitems[s] = [t];
// }
//});
//var finalgd = [];
//for (var i = 0; i < zi_brandsorts.length; i++) {
// var thisar = gdsitems["x" + "_" + zi_brandsorts[i]["brandtype"] + "_" + zi_brandsorts[i].sort];
// if (thisar != undefined) {
// thisar.sort(web960.utils.tools.sort('asc', 'sort_purity'));
// finalgd = $.merge(finalgd, thisar);
// }
//}
//for (var i = 0; i < dl_brandsorts.length; i++) {
// var thisar = gdsitems["x" + "_" + dl_brandsorts[i]["brandtype"] + "_" + dl_brandsorts[i].sort];
// if (thisar != undefined) {
// thisar.sort(web960.utils.tools.sort('asc', 'sort_purity'));
// finalgd = $.merge(finalgd, thisar);
// }
//}
//gds = finalgd;
var cdarr = [];
var fangds = [];
for (var i = 0; i < gds.length; i++) {
var cdstr = gds[i].purity + "|" + gds[i].brand;
var dataar = [];
var idx = jquery.inarray(cdstr, cdarr);
if (idx == -1) {
var item = {};
item["title"] = cdstr;
item["purity"] = gds[i].purity;
item["packaging"] = gds[i].packaging;
item["intpackaging"] = gds[i].intpackaging;
item["brand"] = gds[i].brand;
item["brandtype"] = gds[i].brandtype;
item["items"] = [];
item.items.push(gds[i]);
fangds.push(item);
cdarr.push(cdstr);
}
else {
fangds[idx].items.push(gds[i]);
}
}
return fangds;
}
var goodsconfig = {
whennogoods: function () {
return "";
},
callback: function () {
if (this.nowviewmode == "newlist") {
//如果有默认显示的规格需要显示
//否则选择最小价格
this.initproductitemclick("#progoodslist");
this.initproductitemclick("#kj-buy-select-content");
}
$(".kj-product-prep-item").each(function () {
$(this).parents(".kj-product-item").addclass("kj-product-item-viewbyprepent");
});
},
initproductitemclick: function (el) {
$(".kj-productinfo-fliter dd a", el).click(function () {
if (!$(this).hasclass("disable")) {
var rowidx = parseint($(this).attr("rowidx"));
var nowselectegood = null;
if ($(this).hasclass("active")) {
return;
}
else {
$("a", $(this).parent()).removeclass("active");
$(this).addclass("active");
var text = $.trim($(this).html());
var valtype = $(this).attr("valtype");
var thisinvs = [];
if (valtype == "brand") {
if (goodsconfig.nowproductgoods.invsofbrand[text] != null) {
thisinvs = goodsconfig.nowproductgoods.invsofbrand[text];
}
}
else if (valtype == "purity") {
if (goodsconfig.nowproductgoods.invsofpurity[text] != null) {
thisinvs = goodsconfig.nowproductgoods.invsofpurity[text];
}
}
else if (valtype == "package") {
if (goodsconfig.nowproductgoods.invsofpackage[text] != null) {
thisinvs = goodsconfig.nowproductgoods.invsofpackage[text];
}
}
for (var key in goodsconfig.nowproductgoods.detailarray) {
if ("invsof" + valtype == key) {
if (goodsconfig.nowproductgoods.detailarray[key][text] != null) {
thisinvs = goodsconfig.nowproductgoods.detailarray[key][text];
}
}
}
if (nowselectegood == null) {
nowselectegood = thisinvs;
}
}
//需要设置哪些不可以选择
var checkisable = function (text, valtype) {
var newarrar = [];
if (valtype == "brand") {
newarrar = $.grep(nowselectegood, function (v, i) {
return v.brandname == text;
});
}
else if (valtype == "purity") {
newarrar = $.grep(nowselectegood, function (v, i) {
return v.purity == text;
});
}
else if (valtype == "package") {
newarrar = $.grep(nowselectegood, function (v, i) {
return v.packaging == text;
});
}
for (var key in goodsconfig.nowproductgoods.detailarray) {
if ("invsof" + valtype == key) {
newarrar = $.grep(nowselectegood, function (v, i) {
return v[valtype] == text;
});
}
}
return newarrar.length > 0;
};
var fliterrowidx = -1;
$(".kj-productinfo-fliter dd.kj-productinfo-fliter-dd", el).each(function () {
fliterrowidx++;
var _s = this;
var valtype = $(_s).attr("valtype");
if ($("a.active", _s).length > 0) {
var text = $("a.active", _s).html();
var newarrar = [];
if (valtype == "brand") {
newarrar = $.grep(nowselectegood, function (v, i) {
return v.brandname == text;
});
}
else if (valtype == "purity") {
newarrar = $.grep(nowselectegood, function (v, i) {
return v.purity == text;
});
}
else if (valtype == "package") {
newarrar = $.grep(nowselectegood, function (v, i) {
return v.packaging == text;
});
}
for (var key in goodsconfig.nowproductgoods.detailarray) {
if ("invsof" + valtype == key) {
newarrar = $.grep(nowselectegood, function (v, i) {
return v[valtype] == text;
});
}
}
if (newarrar.length > 0) {
nowselectegood = newarrar;
}
if (!checkisable(text, valtype)) {
$("a.active", _s).removeclass("active");
}
}
if ($("a.active", _s).length == 0) {
$("a", _s).removeclass("disable");
$("a", _s).each(function () {
var text = $(this).html();
if (!checkisable(text, valtype)) {
$(this).addclass("disable");
}
});
}
});
$(".kj-productinfo-fliter a.active", el).each(function () {
var text = $.trim($(this).html());
var valtype = $(this).attr("valtype");
var thisinvs = [];
if (valtype == "brand") {
if (goodsconfig.nowproductgoods.invsofbrand[text] != null) {
thisinvs = goodsconfig.nowproductgoods.invsofbrand[text];
}
}
else if (valtype == "purity") {
if (goodsconfig.nowproductgoods.invsofpurity[text] != null) {
thisinvs = goodsconfig.nowproductgoods.invsofpurity[text];
}
}
else if (valtype == "package") {
if (goodsconfig.nowproductgoods.invsofpackage[text] != null) {
thisinvs = goodsconfig.nowproductgoods.invsofpackage[text];
}
}
for (var key in goodsconfig.nowproductgoods.detailarray) {
if ("invsof" + valtype == key) {
if (goodsconfig.nowproductgoods.detailarray[key][text] != null) {
thisinvs = goodsconfig.nowproductgoods.detailarray[key][text];
}
}
}
if (nowselectegood == null) {
nowselectegood = thisinvs;
}
else {
var newarrar = [];
if (valtype == "brand") {
newarrar = $.grep(nowselectegood, function (v, i) {
return v.brandname == text;
});
}
else if (valtype == "purity") {
newarrar = $.grep(nowselectegood, function (v, i) {
return v.purity == text;
});
}
else if (valtype == "package") {
newarrar = $.grep(nowselectegood, function (v, i) {
return v.packaging == text;
});
}
for (var key in goodsconfig.nowproductgoods.detailarray) {
if ("invsof" + valtype == key) {
newarrar = $.grep(nowselectegood, function (v, i) {
return v[valtype] == text;
});
}
}
nowselectegood = newarrar;
}
});
if ($(".kj-productinfo-fliter dd.kj-productinfo-fliter-dd", el).length == $(".kj-productinfo-fliter a.active", el).length) {
if (nowselectegood.length > 0) {
goodsconfig.nowselectegoods = nowselectegood[0];
$("#kj-addtocart-btn", el).removeclass("disabled").attr("disabled", false);
$("#kj-buy-selected-ok").removeclass("disabled").attr("disabled", false);
$(".kj-nowproduct-price").html(nowselectegood[0].price.moneyunit + nowselectegood[0].price.finalprice);
$(".kj-nowgoods-no").html(nowselectegood[0].goodsno);
}
else {
goodsconfig.nowselectegoods = null;
$("#kj-addtocart-btn", el).addclass("disabled").attr("disabled", true);
$("#kj-buy-selected-ok").removeclass("disabled").attr("disabled", true);
$(".kj-nowproduct-price").html(" ");
$(".kj-nowgoods-no").html(" ");
}
}
else {
goodsconfig.nowselectegoods = null;
$("#kj-addtocart-btn", el).addclass("disabled").attr("disabled", true);
$("#kj-buy-selected-ok").removeclass("disabled").attr("disabled", true);
$(".kj-nowproduct-price").html(" ");
$(".kj-nowgoods-no").html(" ");
}
}
});
},
inventoryitemhtml_productlist: function (goodss, pd_id) {
var html = '';
if ($("#viewbyintegralproduct").length == 0) {
goodss = arrangegoods(goodss);//整理goods
var proinfoview = {};
var skurl = $("#sk1_" + pd_id).attr("href");
if (goodss.length > 0) {
html += '
\
\
\
';
var puritys = [];
var packages = [];
var minprice = -1;
var minpricestr = "";
for (var m = 0; m < goodss.length; m++) {
var purity = goodss[m].purity;
if (puritys.indexof(purity) == -1) {
puritys.push(purity);
}
var brandtype = goodss[m].brandtype;
if (goodss.length == 1) {
//如果只有一个数据默认站看
brandtype = 1;
}
var brand = goodss[m].brand;
//var defdistext = "展开";
//if (brandtype == 1) {
// defdistext = "关闭";
//}
//
品牌 | \
//
纯度 | \
html += '
\
\
\
订货号 | \
品牌 | \
规格 | \
纯度 | \
市场价 | \
会员价 | \
库存 | \
数量 | \
加入购物车 | \
';
var goods = goodss[m].items;
goods.sort(web960.utils.tools.sort("asc", "packaging"));
//goods.sort(web960.utils.tools.sort("asc", "sort_standard"));
for (var i = 0; i < goods.length; i++) {
if (goods[i].extendattrs != null) {
$.each(goods[i].extendattrs, function () {
if (this.field != "purity" && this.field != "brand" && this.field != "packaging" && this.field != "standard" && this.field != "brandname") {
if (this.keyword.length > 0 && proinfoview[this.field] == null) {
proinfoview[this.field] = {
title: this.srctitle,
data: [this.keyword]
};
}
else {
var thisdata = proinfoview[this.field]["data"];
if (this.keyword.length > 0 && thisdata.indexof(this.keyword) == -1) {
thisdata.push(this.keyword);
}
proinfoview[this.field]["data"] = thisdata;
}
}
});
}
var packaging = $.trim(web960.utils.tools.getvalfromjson(goods[i].goods_info, "{goodsinfo.packaging}"));
if (packages.indexof(packaging) == -1) {
packages.push(packaging);
}
var price = this.getgoodsinventoreprice(goods[i], goods[i].inventores[0].preferenttype, goods[i].inventores[0].preferentinfo, goods[i].inventores[0].moneyunit, goods[i].inventores[0].price);
if ($("#pro_ispromotion_" + pd_id).length > 0) {
if (price.ispromotion == 1) {
$("#pro_ispromotion_" + pd_id).replacewith('促销
');
}
}
if (minprice == -1 || price.finalprice < minprice) {
minprice = price.finalprice;
minpricestr = price.moneyunit + price.finalprice;
}
//' + brand + ' | \
// ' + purity + ' | \
html += '\
' + goods[i].goods_no + ' | \
' + brand + ' | \
' + packaging + ' | \
' + purity + ' | \
' + price.finalprice + '' + getsimpmoneyunit(goods[i].inventores[0].moneyunit) + '' + parsefloat(goods[i].inventores[0].price).tofixed(2) + ' ' + goods[i].inventores[0].moneyunit + ' ' + goods[i].inventores[0].unit + '\
' + price.moneyunit + price.orgprice + ' | \
' + price.finalprice + '' + getsimpmoneyunit(goods[i].inventores[0].moneyunit) + '' + parsefloat(goods[i].inventores[0].price).tofixed(2) + ' ' + goods[i].inventores[0].moneyunit + ' ' + goods[i].inventores[0].unit + '\
' + price.html + ' | \
' + initinventorydisplay(goods[i].inventores[0], null, goods[i]) + ' | \
\
\
\
\
\
\
| \
\
\
| \
';
}
html += '
\
';
}
if ($("#product_pur_package_" + pd_id).length > 0) {
if (puritys.length > 0) {
$("#product_pur_package_" + pd_id).html('
' + puritys.join(",") + "
" + packages.join(",") + "
");
}
else {
$("#product_pur_package_" + pd_id).html('
' + packages.join(",") + "
");
}
}
if ($("#kj-item-caption_" + pd_id).length > 0) {
for (var key in proinfoview) {
$("#kj-item-caption_" + pd_id).append('
' + proinfoview[key]["title"] + ":" + proinfoview[key]["data"].join(",") + '
');
}
}
$("#product_small_price_" + pd_id).html(minpricestr);
html += '
\
\
';
}
}
else {
//积分商品
var minintegral = -1;
var maxintegral = -1;
if (goodss.length > 0) {
for (var i = 0; i < goodss.length; i++) {
if (goodss[i].inventores.length > 0) {
var integral = parsefloat(goodss[i].inventores[0].integral);
if (!isnan(integral)) {
if (minintegral == -1 || integral < minintegral) {
minintegral = integral;
}
if (maxintegral == -1 || integral > maxintegral) {
maxintegral = integral;
}
}
}
}
if (minintegral > 0 && maxintegral > 0) {
var integ = minintegral;
if (minintegral != maxintegral) {
integ = minintegral + "-" + maxintegral;
}
html = '积分:' + integ + ' 兑换
';
}
}
}
return html;
},
nowselectegoods: null,
nowproductgoods: {
inventorys: [],
invsofpackage: {},
invsofpurity: {},
invsofbrand: {},
minpriceinv: null
},
inventoryitemhtml_productinfo: function (goodss, pd_id) {
if ($("#nowintegralproductid").length == 0) {
var brands = [];
var puritys = [];
var packages = [];
var inventorys = [];
var minpriceinv = null;
var minprice = -1;
var minpricestr = "";
var invsofbrand = {};
var invsofpurity = {};
var invsofpackage = {};
var invsofdata = {};
var detaildata = {};
var detailarray = {};
var get = $.urlget(); //获取url的get参数
var def_goodsno = get['goodsno']; //取得id的值
var defviewinv = null;
for (var i = 0; i < goodss.length; i++) {
var item = goodss[i];
var goodsno = item["goods_no"];
var extendattrs = {};
if (item.extendattrs != null) {
var extendattrslist = item.extendattrs;
$.each(item.extendattrs, function () {
if (this.field != "purity" && this.field != "brand" && this.field != "packaging" && this.field != "standard" && this.field != "brandname") {
extendattrs[this.field] = {
title: this.srctitle,
value: this.keyword
}
}
});
}
goodss[i]["extendattrs"] = extendattrs;
item["extendattrs"] = extendattrs;
var brandname = $.trim(item["goodsbrand"]);
if (brandname != null && brandname.length > 0 && brands.indexof(brandname) == -1) {
brands.push(brandname);
}
var purity = $.trim(web960.utils.tools.getvalfromjson(item.goods_info, "{goodsinfo.purity}"));
var packaging = $.trim(web960.utils.tools.getvalfromjson(item.goods_info, "{goodsinfo.packaging}"));
if (purity != "" && puritys.indexof(purity) == -1) {
puritys.push(purity);
}
if (packaging != "" && packages.indexof(packaging) == -1) {
packages.push(packaging);
}
detaildata["puritys"] = puritys;
detaildata["packages"] = packages
detaildata["brands"] = brands;
var extendattrdata = {};
for (var key in item["extendattrs"]) {
var dts = [];
if (detaildata[key + "s"] != null) {
dts = detaildata[key + "s"];
}
if (item["extendattrs"][key]["value"] != null && item["extendattrs"][key]["value"] != "" && dts.indexof(item["extendattrs"][key]["value"]) == -1) {
dts.push(item["extendattrs"][key]["value"]);
}
detaildata[key + "s"] = dts;
extendattrdata[key] = item["extendattrs"][key]["value"];
}
if (item.inventores.length > 0) {
var stock = item.inventores[0];
var price = this.getgoodsinventoreprice(item, stock.preferenttype, stock.preferentinfo, stock.moneyunit, stock.price);
if ($("#pro_ispromotion_" + pd_id).length > 0) {
if (price.ispromotion == 1) {
$("#pro_ispromotion_" + pd_id).replacewith('促销
');
}
}
var inv = {
id: stock.inventory_id,
goodsid: stock.goods_id,
goodsno: item.goods_no,
pd_id: item.pd_id,
purity: purity,
brandname: brandname,
packaging: packaging,
price: price,
inv: stock,
goodsinfo: item
};
inv = $.extend(inv, extendattrdata);
if (minprice == -1 || price.finalprice < minprice) {
minprice = price.finalprice;
minpricestr = price.moneyunit + price.finalprice;
minpriceinv = inv;
}
inventorys.push(inv);
//------------
var brandkey = brandname;
if (brandkey == "") {
brandkey = "brand_$$$";
}
var brandinvs = [];
if (invsofbrand[brandkey] != null) {
brandinvs = invsofbrand[brandkey];
}
brandinvs.push(inv);
invsofbrand[brandkey] = brandinvs;
// detailarray["invsofbrand"] = invsofbrand;
//------------
var puritykey = purity;
if (puritykey == "") {
puritykey = "purity_$$$";
}
var purityinvs = [];
if (invsofpurity[puritykey] != null) {
purityinvs = invsofpurity[puritykey];
}
purityinvs.push(inv);
invsofpurity[puritykey] = purityinvs;
// detailarray["invsofpurity"] = invsofpurity;
//------------
var packagekey = packaging;
if (packagekey == "") {
packagekey = "package_$$$";
}
var packagenvs = [];
if (invsofpackage[packagekey] != null) {
packagenvs = invsofpackage[packagekey];
}
packagenvs.push(inv);
invsofpackage[packagekey] = packagenvs;
// detailarray["invsofpackage"] = invsofpackage;
for (var key in extendattrdata) {
var valuekey = extendattrdata[key];
if (valuekey == "") {
valuekey = key + "_$$$";
}
var invs = {};
if (detailarray["invsof" + key] != null) {
invs = detailarray["invsof" + key]
}
var invslist = [];
if (invs[valuekey] != null) {
invslist = invs[valuekey];
}
invslist.push(inv);
invs[valuekey] = invslist;
detailarray["invsof" + key] = invs;
}
if (def_goodsno != null && def_goodsno.length > 0 && def_goodsno == goodsno) {
defviewinv = inv;
}
}
}
if (defviewinv == null && minpriceinv != null) {
defviewinv = minpriceinv;
}
this.nowproductgoods = {
inventorys: inventorys,
invsofpackage: invsofpackage,
invsofpurity: invsofpurity,
invsofbrand: invsofbrand,
minpriceinv: minpriceinv,
defviewinv: defviewinv,
detailarray: detailarray
};
var r = '';
var defbrand = "";
if (brands.length > 0) {
r += '- 品牌
- ';
for (var i = 0; i < brands.length; i++) {
if (defviewinv != null && defviewinv.brandname == brands[i]) {
defbrand = brands[i];
}
r += '' + brands[i] + '';
}
r += '
';
}
var defpurity = "";
var puritytitle = "纯度";
var productstandardcatalog = $("input[name='productstandardcatalog'][productid='" + pd_id + "']").val();
if (productstandardcatalog != null && productstandardcatalog.length > 0) {
if (productstandardcatalog.substr(0, 2) == "12") {
puritytitle = "规格";
}
}
if (puritys.length > 0) {
r += '- ' + puritytitle + '
- ';
for (var i = 0; i < puritys.length; i++) {
if (defviewinv != null && defviewinv.purity == puritys[i]) {
defpurity = puritys[i];
}
// r += '' + puritys[i] + '';
r += '' + puritys[i] + '';
}
r += '
';
}
if (packages.length > 0) {
r += '- 包装
- ';
for (var i = 0; i < packages.length; i++) {
// r += '' + packages[i] + '';
r += '' + packages[i] + '';
}
r += '
';
}
var rowidx = 3;
for (var key in item["extendattrs"]) {
var lists = detaildata[key + "s"];
if (lists.length > 0) {
r += '- ' + item["extendattrs"][key]["title"] + '
- ';
for (var i = 0; i < lists.length; i++) {
var def_value = "";
if (defviewinv != null && defviewinv[key] == lists[i]) {
def_value = lists[i];
}
// r += '' + lists[i] + '';
r += '' + lists[i] + '';
}
r += '
';
}
rowidx++;
}
r += '- 数量
\
- \
\
\
\
\
\
\
\
\
\
\
\
\
';
if (defviewinv != null) {
goodsconfig.nowselectegoods = defviewinv;
$("#kj-addtocart-btn").removeclass("disabled").attr("disabled", false);
$(".kj-nowproduct-price").html(defviewinv.price.moneyunit + defviewinv.price.finalprice);
$(".kj-nowgoods-no").html(defviewinv.goodsno);
}
else {
$("#kj-addtocart-btn").removeclass("disabled").attr("disabled", true);
}
return r;
}
else {
//积分产品展示
var brands = [];
var puritys = [];
var packages = [];
var inventorys = [];
var minpriceinv = null;
var minprice = -1;
var minpricestr = "";
var invsofbrand = {};
var invsofpurity = {};
var invsofpackage = {};
var get = $.urlget(); //获取url的get参数
var def_goodsno = get['goodsno']; //取得id的值
var defviewinv = null;
for (var i = 0; i < goodss.length; i++) {
var item = goodss[i];
var goodsno = item["goods_no"];
var brandname = $.trim(item["goodsbrand"]);
if (brandname != null && brandname.length > 0 && brands.indexof(brandname) == -1) {
brands.push(brandname);
}
var purity = $.trim(web960.utils.tools.getvalfromjson(item.goods_info, "{goodsinfo.purity}"));
var packaging = $.trim(web960.utils.tools.getvalfromjson(item.goods_info, "{goodsinfo.packaging}"));
if (purity != "" && puritys.indexof(purity) == -1) {
puritys.push(purity);
}
if (packaging != "" && packages.indexof(packaging) == -1) {
packages.push(packaging);
}
if (item.inventores.length > 0) {
var stock = item.inventores[0];
var price = { html: "", orgprice: stock.integral, finalprice: stock.integral, moneyunit: "" };
var inv = {
id: stock.inventory_id,
goodsid: stock.goods_id,
goodsno: item.goods_no,
pd_id: item.pd_id,
purity: purity,
brandname: brandname,
packaging: packaging,
price: price,
inv: stock,
goodsinfo: item
};
if (minprice == -1 || price.finalprice < minprice) {
minprice = price.finalprice;
minpricestr = price.moneyunit + price.finalprice;
minpriceinv = inv;
}
inventorys.push(inv);
//------------
var brandkey = brandname;
if (brandkey == "") {
brandkey = "brand_$$$";
}
var brandinvs = [];
if (invsofbrand[brandkey] != null) {
brandinvs = invsofbrand[brandkey];
}
brandinvs.push(inv);
invsofbrand[brandkey] = brandinvs;
//------------
var puritykey = purity;
if (puritykey == "") {
puritykey = "purity_$$$";
}
var purityinvs = [];
if (invsofpurity[puritykey] != null) {
purityinvs = invsofpurity[puritykey];
}
purityinvs.push(inv);
invsofpurity[puritykey] = purityinvs;
//------------
var packagekey = packaging;
if (packagekey == "") {
packagekey = "package_$$$";
}
var packagenvs = [];
if (invsofpackage[packagekey] != null) {
packagenvs = invsofpackage[packagekey];
}
packagenvs.push(inv);
invsofpackage[packagekey] = packagenvs;
if (def_goodsno != null && def_goodsno.length > 0 && def_goodsno == goodsno) {
defviewinv = inv;
}
}
}
if (defviewinv == null && minpriceinv != null) {
defviewinv = minpriceinv;
}
this.nowproductgoods = {
inventorys: inventorys,
invsofpackage: invsofpackage,
invsofpurity: invsofpurity,
invsofbrand: invsofbrand,
minpriceinv: minpriceinv,
defviewinv: defviewinv
};
var r = '';
var defbrand = "";
if (brands.length > 0) {
r += '- 品牌
- ';
for (var i = 0; i < brands.length; i++) {
if (defviewinv != null && defviewinv.brandname == brands[i]) {
defbrand = brands[i];
}
r += '' + brands[i] + '';
}
r += '
';
}
var defpurity = "";
if (puritys.length > 0) {
r += '- 规格
- ';
for (var i = 0; i < puritys.length; i++) {
if (defviewinv != null && defviewinv.purity == puritys[i]) {
defpurity = puritys[i];
}
r += '' + puritys[i] + '';
}
r += '
';
}
if (packages.length > 0) {
r += '- 包装
- ';
for (var i = 0; i < packages.length; i++) {
r += '' + packages[i] + '';
}
r += '
';
}
r += '- 库存
';
r += '- 数量
\
- \
\
\
\
\
\
\
\
- \
\
\
';
if (defviewinv != null) {
goodsconfig.nowselectegoods = defviewinv;
$("#kj-addtocart-btn").removeclass("disabled").attr("disabled", false);
$(".kj-nowproduct-price").html(defviewinv.price.moneyunit + defviewinv.price.finalprice);
$(".kj-nowgoods-no").html(defviewinv.goodsno);
settimeout(function () {
if ($(".nowgoodsinventory").length > 0) {
var keepgo = true;
do {
$(".nowgoodsinventory").html(initinventorydisplay(defviewinv.inv, null, defviewinv.goodsinfo));
if ($(".nowgoodsinventory").length > 0) {
keepgo = false;
}
}
while (keepgo);
}
}, 500);
}
else {
$("#kj-addtocart-btn").removeclass("disabled").attr("disabled", true);
}
return r;
}
},
addtocart: function (o, isintegral) {
if (this.nowselectegoods != null) {
var ordernum = parseint($(".kj-order-num", $(o).parents(".kj-productinfo-fliter")).val());
this.nowselectegoods["ordernum"] = ordernum;
addtocart(this.nowselectegoods.id, o, this.nowselectegoods, isintegral);
}
},
addtocart_mobile: function (o, isintegral) {
if (this.nowselectegoods != null) {
var ordernum = parseint($(".kj-buy-select-content .kj-order-num").val());
this.nowselectegoods["ordernum"] = ordernum;
addtocart(this.nowselectegoods.id, null, this.nowselectegoods, isintegral);
}
},
nowproductviewinfo: {},
inventoryitemhtml: function (goodss, pd_id) {
this.nowproductviewinfo["goodss"] = goodss;
this.nowproductviewinfo["pd_id"] = pd_id;
//if ($("#nowproductid").length > 0) {
// this.nowviewmode = "list";
// return goodsconfig.inventoryitemhtml_productlist(goodss, pd_id);
//}
//else {
// this.nowviewmode = "newlist";
// return goodsconfig.inventoryitemhtml_productlist(goodss, pd_id);
//}
var viewwidth = window.innerwidth;
if ($("#nowintegralproductid").length == 0) {
this.nowviewmode = "list";
}
if (viewwidth < 768) {
this.nowviewmode = "newlist";
}
if ($("#nowproductid").length > 0) {
$("#goods_viewmode_ctrlbox button").removeclass("active");
if (this.nowviewmode == "list") {
$("#goods_viewmode_list").addclass("active");
return goodsconfig.inventoryitemhtml_productlist(goodss, pd_id);
}
else if (this.nowviewmode == "newlist") {
$("#goods_viewmode_newlist").addclass("active");
return goodsconfig.inventoryitemhtml_productinfo(goodss, pd_id);
}
}
else {
this.nowviewmode = "list";
return goodsconfig.inventoryitemhtml_productlist(goodss, pd_id);
}
},
nowviewmode: "list",
toggleviewmode: function (o, el, type) {
this.nowviewmode = type;
$("button", $(o).parent()).removeclass("active");
$(o).addclass("active");
var goodss = this.nowproductviewinfo["goodss"];
var pd_id = this.nowproductviewinfo["pd_id"];
if (type == "list") {
$(el).html(goodsconfig.inventoryitemhtml_productlist(goodss, pd_id));
}
else if (type == "newlist") {
$(el).html(goodsconfig.inventoryitemhtml_productinfo(goodss, pd_id));
}
this.callback();
},
viewmore: function (o) {
$("tr[hidenitem='hideitem']", $(o).parent().parent().parent()).toggle();
},
getgoodsinventoreprice: function (goods, preferenttype, preferentinfo, moneyunit, price) {
var returnv = { html: "", orgprice: price, finalprice: price, moneyunit: getsimpmoneyunit(moneyunit) };
var html = "";
if (preferenttype == "-1") {
returnv.finalprice = price;
}
else {
var brand = $.trim(web960.utils.tools.getvalfromjson(goods.goods_info, "{goodsinfo.brand}"));
if (goodsglobalsettings.preferentsetting != undefined) {
var setting = eval('(' + goodsglobalsettings.preferentsetting + ');');
var preinfo = eval('(' + preferentinfo + ');');
var brandset = setting["preferentsettingbybrand"];//品牌设置优惠
var brandprice = price;
if (brandset != undefined && brand != "") {
for (var x = 0; x < brandset.length; x++) {
var tbrandset = brandset[x];
if (brand == tbrandset.brandname) {
//默认品牌优惠设置
for (var i = 0; i < tbrandset.rolessetting.length; i++) {
if (typeof (nowuserinfo) != "undefined") {
if (nowuserinfo.rolename != undefined && nowuserinfo.rolename != "") {
if (nowuserinfo.rolename == tbrandset.rolessetting[i].rolename) {
brandprice = parsefloat(tbrandset.rolessetting[i].zk) * price;
// html += getsimpmoneyunit(moneyunit) + (parsefloat(tbrandset.rolessetting[i].zk) * price).tofixed(2);
}
} else {
if (tbrandset.rolessetting[i].visible == "all") {
brandprice = parsefloat(tbrandset.rolessetting[i].zk) * price;
// html += getsimpmoneyunit(moneyunit) + (parsefloat(tbrandset.rolessetting[i].zk) * price).tofixed(2);
}
}
}
else {
if (tbrandset.rolessetting[i].visible == "all") {
brandprice = parsefloat(tbrandset.rolessetting[i].zk) * price;
// html += getsimpmoneyunit(moneyunit) + (parsefloat(tbrandset.rolessetting[i].zk) * price).tofixed(2);
}
}
}
break;
}
}
}
var norprice = price;
var exhtml = '';
if (preferenttype == "1" && setting.suspendpromotion == "0") {
//促销
returnv.ispromotion = 1;
if (preinfo.premethod == "1") {
var val = preinfo.val;
if (val == null || val == "") {
val = 10;
}
val = parsefloat(val);
if (isnan(val)) {
val = 10;
}
norprice = (val / 10) * parsefloat(price);
exhtml = '促销';
html = getsimpmoneyunit(moneyunit) + ((val / 10) * parsefloat(price)).tofixed(2) + '促销';
// html = getsimpmoneyunit(moneyunit) + (parsefloat(preinfo.val) * parsefloat(price)).tofixed(2) + '促 ';
}
else {
norprice = parsefloat(preinfo.val);
exhtml = '促销';
html = getsimpmoneyunit(moneyunit) + parsefloat(preinfo.val).tofixed(2) + '促销';
//html = getsimpmoneyunit(moneyunit) + parsefloat(preinfo.val).tofixed(2) + '促';
}
// html = preinfo.val + ' ' + (preinfo.premethod == "1" ? "折" : moneyunit)+'促销 ';
}
else if (preferenttype == "2" && setting.suspendpreferent == "0") {
//优惠
for (var i = 0; i < preinfo.rolessetting.length; i++) {
if (typeof (nowuserinfo) != "undefined") {
if (nowuserinfo.rolename != undefined && nowuserinfo.rolename != "") {
if (nowuserinfo.rolename == preinfo.rolessetting[i].rolename) {
if (preinfo.premethod == "1") {
norprice = parsefloat(preinfo.rolessetting[i].zk) * parsefloat(price);
html += getsimpmoneyunit(moneyunit) + (parsefloat(preinfo.rolessetting[i].zk) * parsefloat(price)).tofixed(2);
}
else {
norprice = parsefloat(preinfo.rolessetting[i].zk);
html += getsimpmoneyunit(moneyunit) + parsefloat(preinfo.rolessetting[i].zk).tofixed(2);
}
}
} else {
if (preinfo.rolessetting[i].visible == "all") {
if (preinfo.premethod == "1") {
norprice = parsefloat(preinfo.rolessetting[i].zk) * parsefloat(price);
html += getsimpmoneyunit(moneyunit) + (parsefloat(preinfo.rolessetting[i].zk) * parsefloat(price)).tofixed(2);
}
else {
norprice = parsefloat(preinfo.rolessetting[i].zk);
html += getsimpmoneyunit(moneyunit) + parsefloat(preinfo.rolessetting[i].zk).tofixed(2);
}
}
}
}
else {
if (preinfo.rolessetting[i].visible == "all") {
if (preinfo.premethod == "1") {
norprice = parsefloat(preinfo.rolessetting[i].zk) * parsefloat(price);
html += getsimpmoneyunit(moneyunit) + (parsefloat(preinfo.rolessetting[i].zk) * parsefloat(price)).tofixed(2);
}
else {
norprice = parsefloat(preinfo.rolessetting[i].zk);
html += getsimpmoneyunit(moneyunit) + parsefloat(preinfo.rolessetting[i].zk).tofixed(2);
}
}
}
}
}
else if (preferenttype == "0" && setting.suspendpreferent == "0" && setting.enable == "1") {
//默认优惠设置
for (var i = 0; i < setting.rolessetting.length; i++) {
if (typeof (nowuserinfo) != "undefined") {
if (nowuserinfo.rolename != undefined && nowuserinfo.rolename != "") {
if (nowuserinfo.rolename == setting.rolessetting[i].rolename) {
norprice = parsefloat(setting.rolessetting[i].zk) * price;
html += getsimpmoneyunit(moneyunit) + (parsefloat(setting.rolessetting[i].zk) * price).tofixed(2);
}
} else {
if (setting.rolessetting[i].visible == "all") {
norprice = parsefloat(setting.rolessetting[i].zk) * price;
html += getsimpmoneyunit(moneyunit) + (parsefloat(setting.rolessetting[i].zk) * price).tofixed(2);
}
}
}
else {
if (setting.rolessetting[i].visible == "all") {
norprice = parsefloat(setting.rolessetting[i].zk) * price;
html += getsimpmoneyunit(moneyunit) + (parsefloat(setting.rolessetting[i].zk) * price).tofixed(2);
}
}
}
}
}
if (norprice > brandprice) {
returnv.finalprice = parsefloat(brandprice).tofixed(2);
html = getsimpmoneyunit(moneyunit) + '' + parsefloat(brandprice).tofixed(2) + "" + exhtml;
}
else {
returnv.finalprice = parsefloat(norprice).tofixed(2);
}
}
returnv.finalprice = parsefloat(returnv.finalprice).tofixed(2);
html = '' + getsimpmoneyunit(moneyunit) + '' + returnv.finalprice + "";
returnv.html = html;
return returnv;
},
guestprice: function (rolessetting, premethod, preinfo, price) {
for (var j = 0; j < rolessetting.length; j++) {
if (rolessetting[j].rolename == "普通会员") {
//if (preinfo.premethod == "2") {
// price = parsefloat(rolessetting[j].zk);
//}
//else {
// price = price * parsefloat(rolessetting[j].zk);
//}
price = price * parsefloat(rolessetting[j].zk);
}
}
return price;
}
};