| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- //******************************************项目搜索部分*************************************************
- ///定义全局变量
- var www_domain = 'http://www.58jmw.com/';
- var search_domain = 'http://www.58jmw.com/xm/';
- ///页面初始加载事件
- $(function(){
- get_brand_tips_by_keyword(); //项目搜索框智能提示
-
- //提交搜索
- $('#top_search_button').unbind('click');
- $('#top_search_button').click(function(){
- var keyword = $.trim($("#top_search_input").val());
- if(!keyword) {
- return;
- }
- search_keyword_action(keyword);
- });
- //关键字回车搜索
- $("#top_search_input").keydown(function(){
- if (event.keyCode == 13) {
- $("#top_search_button").click();
- return false;
- }
- return true;
- });
- });
- ///品牌名称输入框下拉事件
- function get_brand_tips_by_keyword() {
- $('#top_search_input').live('keyup focus' ,function(e){
- var keyword = $.trim($('#top_search_input').val());
- if(!keyword) {
- $('.header_l .form_down').hide();
- return;
- }
-
- //ajax提交获取品牌
- $.ajax({
- type: 'post',
- dataType: 'json',
- url: www_domain + 'static/wordsearch.html',
- data: { keyword: keyword },
- success: function(data) {
- if(data.msg != 'error' && !jQuery.isEmptyObject(data)) {
- var string = '';
- $.each(data, function(idx, val){
- string += '<span>' + val.brand_name + '</span>';
- });
- $('.header_l .form_down').html(string);
- $('.header_l .form_down').show();
-
- //品牌项选择事件
- $('.header_l .form_down span').unbind('click');
- $('.header_l .form_down span').click(function() {
- var sword = $.trim($(this).text());
- window.location.href = search_domain + 'list.html?keyword=' + sword;
- });
- }
- else {
- $('.header_l .form_down').html('');
- $('.header_l .form_down').hide();
- }
- }
- });
- });
-
-
- //点击页面上除品牌名称位置的任何位置,品牌层隐藏
- $(document).click(function (event) {
- if($(event.target).parents('.form').attr('id') == 'top_serach') return;
- else $(".header_l .form_down").hide(); //品牌层隐藏
- });
- }
- ///根据关键搜索品牌
- function search_keyword_action(keyword) {
- $.ajax({
- type: 'post',
- url: www_domain + 'static/glosearch.html',
- data:{ keyword: keyword },
- dataType: 'json',
- success: function(data) {
- if(data.status!=0){
- if(data.length >= 1) ourl = search_domain + data[1] + '/';
- else ourl = search_domain + 'list.html?keyword=' + keyword;
- window.location.href = ourl;
- }else{
- layer.alert('请输入正确的品牌名称!', {
- icon: 5,
- btn:false,
- title:false,
- closeBtn:false,
- shadeClose:true
- })
- setTimeout(function () {
- layer.closeAll()
- }, 1000);
- }
- }
- });
- }
- ///获取品牌图库图片
- function get_brand_pic_list(domain, t) {
- if(domain == ''|| $.trim(domain) == '') return ;
- else{
- $.ajax({
- url: www_domain + 'static/smpic.html',
- type: 'post',
- dataType: 'json',
- data:{ domain: domain, num: 4 },
- success:function (data){
- if(data.error_code != 0) create_brand_pic_html(data.list,domain);
- else{
- console.log(data);
- return;
- }
- },
- error:function (XMLHttpRequest, textStatus){
- console.log(XMLHttpRequest);
- console.log(textStatus);
- }
- });
- }
- $(t).removeAttr('onclick');
- }
- ///生成品牌图片html文本
- function create_brand_pic_html(data, domain) {
- var pic = '';
- for(var i=0; i<data.length; i++){
- pic += '<li><a href="'+www_domain+'/brand/'+domain+'/product.html"><img src="' + data[i].thumb_path + '" alt="' + data[i].title + '"></a></li>';
- }
- pic += '<li><a href="'+www_domain+'/brand/'+domain+'/product.html"><img src="http://cdns.58jmw.com/images/web/more.png" alt=""></a></li>';
- $('ul[domain="' + domain + '"]').html(pic);
- }
- /*********************************** 留言js ************************************************/
- ///验证留言表单
- function validator_msg_content() {
-
- var test_str = /[(select |inert |update |delete |script|into |load_file|outfile|or |and |cat |drop)]+/;
- var user_name = $.trim($("#message_name").val());
- if(!user_name) {
- layer.tips('请输入联系人!','#message_name');
- return false;
- }
- if(user_name.length<2 || user_name.length>6){
- layer.tips('联系人姓名长度为2~6位!','#message_name');
- return false;
- }
- if(test_str.test(user_name)){
- layer.tips('请输入正确的联系人!','#message_name');
- return false;
- }
- var mobile = $.trim($("#message_mobile").val());
- var myreg=/^([1][3,4,5,6,7,8,9]\d{9}|0\d{2,3}-?\d{7,8})$/;
- if(!mobile || !myreg.test(mobile) || test_str.test(mobile)) {
- layer.tips('输入您的正确联系方式!', '#message_mobile');
- return false;
- }
- var sub_code = $("#sub_code").val();
- var data = {domain:domain,bname:brand_name,user:user_name,phone:mobile,sub_industry_code:sub_code};
- if($("#message_content").length >0){
- var content_mobile = /([1][3,4,5,6,7,8,9]\d{9}|0\d{2,3}-?\d{7,8})+/;
- var msg_content = $.trim($("#message_content").val());
- if(!msg_content) {
- layer.tips('请输入咨询内容!','#message_content');
- return false;
- }
- if(content_mobile.test(msg_content) || test_str.test(msg_content)){
- layer.tips('请输入正确的咨询内容!','#message_content');
- return false;
- }
- data['content'] = msg_content;
- }else{
- var msg = [
- '请问我所在的区域有加盟商吗?',
- '我想了解'+brand_name+'加盟费多少?',
- '请问'+brand_name+'加盟电话多少?',
- '请问'+brand_name+'门店有多少家?',
- '请问'+brand_name+'加盟有哪些支持?',
- '请问加盟'+brand_name+'有什么要求?',
- '我想了解'+brand_name+'加盟费多少?',
- '请问'+brand_name+'加盟电话多少?',
- '请问'+brand_name+'门店有多少家?',
- '请问'+brand_name+'加盟有哪些支持?',
- '请问加盟'+brand_name+'有什么要求?',
- ];
- var j = Math.round(Math.random()*10);
- data['content'] = msg[j];
- }
- if(!$("#message_ydck").attr('checked')) {
- layer.tips('请选择已阅读并同意!','#message_ydck');
- return false;
- }
- if($("#message_addreess").length>0 && $("#message_addreess").length>0){
- var address = $.trim($("#message_addreess").val());
- var money = $.trim($("#message_money").val());
- if(test_str.test(address)){
- layer.tips('请输入正确的地址!','#message_addreess');
- return false;
- }
- if(test_str.test(money)){
- layer.tips('请输入正确的金额!','#message_money');
- return false;
- }
- data['address'] = address;
- data['money'] = money;
- }
- $.ajax({
- url:www_domain+'webmt.html',
- type:'post',
- dataType:'text',
- data:data,
- success:function(data)
- {
- if(data=='ok'){
- layer_alert_tips('留言成功!',6);
- $("#message_name,#message_mobile,#message_content,#message_addreess,#message_money").val('');
- $('.board li').removeClass('board_red');
- }else{
- layer_alert_tips('留言失败!',3);
- }
- }
- });
- }
- ///layer层alert提示
- function layer_alert_tips(alert_msg, ico_type) {
- if(ico_type == 6) { //成功提示
- layer.msg(alert_msg, {icon: ico_type});
- }
- else { //异常提示
- layer.msg(alert_msg, {icon: ico_type});
- }
- }
|