///
ec.search = {
api: "",
input: null,
init: function () {
this.api = new ec.api("search");
this.isDesign = ke.parm("design") == 1;
try {
this.history.items = JSON.parse(localStorage.getItem("search-history") || "[]");
}
catch (e) {
this.history.items = [];
}
//控件
this.input = $("#wd");
this.btn = $("#search_btn");
this.history.layer = $("#search_history");
this.input.focus(function () { ec.search.history.show(); });
this.input.blur(function () { ec.search.history.hide(); });
this.btn.click(function () { ec.search.go(); });
if (this.input.length > 0)
this.wd(this.parm("q"));
this.input.bind('keypress', function (event) {
var theEvent = window.event || e;
var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
if (code == 13) {
ec.search.btn.click();
}
});
},
wd: function (wd) {
if (wd) {
this.input.val(wd.trim());
}
return this.input.val().trim().substr(0, 100);
},
go: function (e) {
var wd = this.wd();
if (wd) {
this.history.save(wd);
var url = L.route + "/search?q=" + encodeURI(wd);
if (this.isDesign)
url += "&design=1";
window.location.href = url;
}
else
window.location.reload();
},
hot: function (wd) {
this.input.val(wd);
this.go();
},
parm: function (name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return decodeURI(r[2]); return null;
},
history: {
items: [],
layer: null,
show: function () {
var wd = ec.search.wd();
var htm = "
搜索历史";
for (var i = this.items.length - 1; i >= 0; i--) {
var item = this.items[i];
if (item)
htm = htm + ke.format("{this}", item);
}
if (this.items.length > 0)
$("#search_history .fll").html(htm);
$("#search_history").show();
},
hide: function () {
setTimeout("$('#search_history').hide();", 200);
},
save: function (wd) {
if (wd) {
this.items.remove(wd);
this.items.push(wd);
if (this.items.length > 6)
this.items = this.items.slice(this.items.length - 6, this.items.length);
}
localStorage.setItem("search-history", JSON.stringify(this.items));
},
clear: function () {
this.items = [];
this.save();
}
},
structural: {
pn: 1,
type:"",
init: function () {
this.resultCount = $("#search_count");
this.structureBox = $("#structure_box");
this.productsList = $("#products_list");
this.notdata = $("#products_notfind");
},
getKetcher: function () {
var frame = document.getElementById('KetcherPanel_IFrame');
return frame.contentWindow.ketcher;
},
setTargetMol: function () {
var ketcher = this.getKetcher();
if (window.StuctureData != null && window.StuctureData != "") {
ketcher.setMolecule(unescape(window.StuctureData));
}
},
getMolfile: function () {
var ketcher = this.getKetcher();
if (ketcher)
return ketcher.getMolfile();
return "";
},
search: function (t, pn, mode) {
if (pn)
this.pn = pn;
if(t!=null)
this.type = t.trim();
ec.utilities.loading();
ec.search.api.post("structure", { mol: this.getMolfile(), method: this.type, pn: this.pn, mode: mode }, function (r) {
if (r) {
ec.utilities.unLoading();
ec.search.structural.render(r);
}
});
},
render: function (r) {
var hasData = r.Products.length > 0;
var pager = r.Pager;
var html = pager.Total > 50 ? L.G("超过50") : pager.Total;
this.resultCount.show().find("em").html(html);
r.PagerList = [];
for (var i = pager.Start; i <= pager.End; i++) {
r.PagerList.push(i);
}
r.Type = this.type;
this.structureBox.hide();
this.productsList.html(r.dataHtml + window.top.ke.template.get("productsHtm").render(r));
this.productsList.toggle(hasData);
this.notdata.toggle(!hasData);
$(".display").show();
$(".ico-array1").toggleClass("ico-array1-hover", r.mode != 2);
$(".ico-array2").toggleClass("ico-array2-hover", r.mode == 2);
},
back: function () {
this.resultCount.hide();
this.productsList.hide();
this.structureBox.show();
this.notdata.hide();
$(".display").hide();
}
},
batch: {
init: function () {
this.resultCount = $("#search_count");
this.inputBox = $("#input_box");
this.productsList = $("#products_list");
this.notdata = $("#products_notfind");
$(".batch-type div").click(function () {
$(this).addClass("active").find(".ico").addClass("ico-radio-hover");
$(this).siblings().removeClass("active").find(".ico").removeClass("ico-radio-hover")
});
$(".batch-type div").eq(0).addClass("active");
},
pn:1,
search: function (pn, mode) {
if (pn)
this.pn = pn;
var type = $(".batch-type .active").attr("value");
var data = $("#data").val().trim();
if (data == "")
ec.notify(L.G("请输入查询内容"), "question");
else if (data.length <= 1)
ec.notify(L.G("输入内容过短"), "question");
else {
ec.utilities.loading();
ec.search.api.post("batch", { type: type, data: data, pn: this.pn, mode: mode }, function (r) {
if (r) {
ec.utilities.unLoading();
ec.search.batch.render(r);
}
});
}
},
formatTag: function (info) {
var html = "";
$.each(info, function (idx, obj) {
if (obj.url == "thumb")
html += "";
else if (obj.url == "star")
html += "";
else if (obj.url == "sale")
html += "";
else if (obj.url == "hot")
html += "";
else if (obj.url == "new")
html += "";
});
return html;
},
render: function (r) {
var hasData = r.Products.length > 0;
var pager = r.Pager;
this.resultCount.show().find("em").html(pager.Total);
r.PagerList = [];
for (var i = pager.Start; i <= pager.End; i++) {
r.PagerList.push(i);
}
this.inputBox.hide();
this.productsList.html(r.dataHtml + window.top.ke.template.get("productsHtm").render(r));
this.productsList.toggle(hasData);
$(".display").show();
$(".ico-array1").toggleClass("ico-array1-hover", r.mode != 2);
$(".ico-array2").toggleClass("ico-array2-hover", r.mode == 2);
this.notdata.toggle(!hasData);
},
back: function () {
this.resultCount.hide();
this.productsList.hide();
this.inputBox.show();
this.notdata.hide();
$(".display").hide();
},
},
coaSearch: function () {
var num = ItemNumber.get();
var lot = LotNumber.get();
var msg = "";
if (!num)
msg = L.G("请输入产品编号");
else if (!lot)
msg = L.G("请输入批号");
if (!msg)
ec.search.coaDownload(num, lot);
else
ec.notify(msg, "question", 3000);
},
coaDownload: function (num, lot) {
window.open(L.route + "/download-coa/" + num + "?data=" + lot);
},
sdsSearch: function () {
var num = MsdsSearch.get();
if (!num)
ec.notify(L.G("请输入完整的信息,再进行查询"), "question", 3000);
else
ec.search.sdsDownload(num);
},
sdsDownload: function (num) {
window.open(L.route + "/download-sds/" + num);
}
}