/*
定义全局api
*/
var api = {
url: "",//接口域名
//loc:"http://test03.efotile.com/",//网站域名
//loc: "http://www.efotile.com/",//网站域名
loc: location.protocol + "//" + location.host + '/',//网站域名
imgsev: '',//图片服务器
//imgsevtest: 'http://122.114.92.80:8090/',//图片服务器
//imgsev: 'http://test01.efotile.net/uploadfiles/',
action: {//api方法列表
'banner': 'getadlist',//广告
'menu': 'getmenulist',//菜单
'tehui': 'getactivityindexlist',//限时特惠
'redpacketlist': "couponconreceive",//可领取
'myredpacketlist': 'getcancoulist',//可使用
'othorredpacket': "couponalready",//其他
'getredpacket': "receivecashcode",//领取
'delredpacket': "delcoupon",//删除
'canshu': 'getproparamlist',//参数
'hotsale': 'gethotsalerlist',//热卖
'notice': 'getnewlist',//文章
'logad': 'advertisementclickcount'//广告点击量
},
fn: {
'banner': 'advertising/advertisinginterface.aspx',
'menu': 'product/productinterface.aspx',
'tehui': 'product/productinfointerface.aspx',
'redpacket': "newhandle.aspx",
'canshu': 'product/productsingleinterface.aspx',
'hotsale': 'product/productinfointerface.aspx',
'notice': 'notice/getnoticeinterface.aspx',
'logad': 'newhandle.aspx'//广告点击量
}
};
$(function () {
//关联错误号和给用户的提示信息
var errmsg = {
'101': '访问连接超时',
'102': '安全验证非法',
'103': '密钥非法',
'104': '未登录',
'105': '无数据'
};
/*
错误提示
--输入参数
err: 错误号(必须),
fn:回调函数(可无)
*/
function showerror(err, fn) {
if (err) {
alert(errmsg['' + err]);
}
if (fn && typeof (fn) == 'function') {
fn();
}
}
//异步数据的dom模板列表,根据返回数据的字段名构建
$.tmpnode = {
'menu': '
' +
'{{categoryname}}' +
'',
'a-01': '' +
'' +
'' +
'' +
'{{adtitle}}' +
'' +
'',
'a-02': '' +
'' +
'' +
'{{adtitle}}' +
'{{adtitle1}}' +
'' +
'',
'a-03': '' +
'' +
'' +
'' +
'',
'a-08': '{{adcode}}
',
'tehui': '' +
'
' +
'
' +
'
' +
'
' +
'
倒计时:0天0小时0分0秒
' +
'
特惠价:
¥{{productprice}}即将开始' +
'
' +
'
',
'canshu': '' +
'
产品型号
' +
'
' +
'' +
'- {{productcode}}
' +
'
' +
'[[procs]]' +
'
',
'hotsale': '' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'¥{{price}}' +
'
' +
'
' +
'
' +
'
',
'notice-01':'' +
'{{summary}}
',
'notice-02': '{{title}}',
'notice-03': '{{title}}',
'getredpacket': '' +
'
' +
'
' +
'
截止日期:
' +
'
{{enddate}}' +
'
使用条件:
' +
'
{{info}}' +
'
' +
'
' +
'
',
'myredpacket': '' +
'
' +
'
截止日期:
' +
'
{{enddate}}' +
'
使用条件:
' +
'
{{info}}' +
'
红包编码:{{code}}
' +
'
' +
'
',
'disredpacket': '' +
'
' +
'
' +
'
截止日期:
' +
'
{{enddate}}' +
'
使用条件:
' +
'
{{info}}' +
'
红包编码:{{code}}
' +
'
' +
'
'
};
/*
异步获取数据,构建广告位
--输入参数
file:api.fn['banner'],//接口文件
tmp:'a-01',//广告位编码
data:{//入参
code:"a-01",//(广告位编码)
readsource:"1"//(限时特惠渠道,1:pc,2:手机)
},
nd:null,//显示内容位置
num:3//显示个数
fn:回调函数(可无);
*/
$.fn.ad = function (parm, fn) {
var defaults = {
action: 'getadlist'//接口的action(必须,默认广告位);
};
var inparm = $.extend(defaults, parm.data || {}, {_t:new date().gettime()});
$.ajax({
url: (parm.url ? parm.url : api.url) + parm.file,//拼接url;
data: inparm,
datatype: parm.datatype || 'jsonp',//返回jsonp;
type: 'get',
success: function (d) {//接口调用成功;
if (d) {//成功获取返回数据;
if (d.status == 100) {//数据正常;
var strhtml = "";//定义初始变量,--广告位代码的字符串拼接;
d.data && $.each(d.data, function (i, v) {//遍历取得的数据
//使用对应的模板
if (typeof parm.num == "number" && i >= parm.num) {
return false;//限制页面显示数据个数
}
var str = $.tmpnode[parm.tmp].replace(/\{\{[\w]+\}\}/ig, function (e) {//将{{字段名}}替换成对应的字段值
var _e = e.substring(2, e.length - 2);//去掉{{字段名}}的{{}};
if (_e in v) {
if (!v[_e] && v[_e] !== 0) {
return '';
}
if (parm.data.action == "getnewlist") {
return v[_e].tostring().replace(/^+/, '').replace(/<\\p>+$/, '');
}
return v[_e].tostring().replace(/^[\s]+/, '').replace(/[\s]+$/, '');//返回对应字段值(如果有值)
} else {
return _e;
}
});
strhtml += str;//拼接字符串
});
if (parm.nd) {
var adhtml = $(strhtml).appendto(parm.nd);//把字符串插入页面对应位置(传入参数)
} else {
var adhtml = $(strhtml).appendto('body');
}
} else {//数据错误
showerror(d.status);//调用错误提示
}
} else {
//console.log('接口错误');
}
if (fn && typeof (fn) == 'function') {
//如果有回调函数,执行回调
if (d === null && d == "undefind") {
fn();
} else {
fn(d);
}
}
},
error: function () {//接口调用失败
//console.log('网络错误');
}
});
};
// $.fn.ad({
// file:api.fn['banner'],//接口文件
// tmp:'a-01',//广告位编码
// data:{code:"a-01"},//入参(广告位编码)
// nd:null,//显示内容位置
// num:3//显示个数
// },function(){});//回调方法
$.fn.productsing = function (parm, fn) {
var defaults = {
action: 'getproparamlist'//接口的action(必须,默认广产品);
};
var inparm = $.extend(defaults, parm.data || {}, {_t:new date().gettime()});
$.ajax({
url: (parm.url ? parm.url : api.url) + parm.file,//拼接url;
data: inparm,
datatype: parm.datatype || 'jsonp',//返回jsonp;
type: 'get',
success: function (d) {//接口调用成功;
if (d) {//成功获取返回数据;
if (d.status == 100) {//数据正常;
//console.log(d.data);
var strhtml = "";//定义初始变量,--代码的字符串拼接;
d.data && $.each(d.data, function (i, v) {//遍历取得的数据
//使用对应的模板
if (typeof parm.num == "number" && i >= parm.num) {
return false;//限制页面显示数据个数
}
var str = $.tmpnode[parm.tmp].replace(/\{\{[\w]+\}\}/ig, function (e) {//将{{字段名}}替换成对应的字段值
var _e = e.substring(2, e.length - 2);//去掉{{字段名}}的{{}};
if (_e in v) {
if (!v[_e] && v[_e] !== 0) {
return '';
}
return v[_e].replace(/^[\s]+/, '').replace(/[\s]+$/, '');//返回对应字段值(如果有值)
} else {
return _e;
}
});
var strlist = '';
$.each(v.paramtypelist, function (x, y) {
strlist += '
' + y.title + '
';
strlist += '';
$.each(y.paraminfolist, function (m, n) {
if (n.info && n.info !== "") {
strlist += '- ' + n.title + '
- ' + n.value + '
- ' + n.info + '
';
} else {
strlist += '- ' + n.title + '
- ' + n.value + '
';
}
});
strlist += '
';
});
str = str.replace(/\[\[procs\]\]/, strlist);
strhtml += str;//拼接字符串
});
if (parm.nd) {
var adhtml = $(strhtml).insertbefore(parm.nd);//把字符串插入页面对应位置(传入参数)
} else {
var adhtml = $(strhtml).appendto('body');
}
} else {//数据错误
showerror(d.status);//调用错误提示
}
} else {
//console.log('接口错误');
}
if (fn && typeof (fn) == 'function') {
//如果有回调函数,执行回调
if (d === null && d == "undefind") {
fn();
} else {
fn(d);
}
}
},
error: function () {//接口调用失败
//console.log('网络错误');
}
});
};
$.fn.getredpacketlist = function (parm, fn) {
var defaults = {
action: 'couponconreceive'//接口的action(必须);
};
var inparm = $.extend(defaults, parm.data || {}, { _t: new date().gettime() });
$.ajax({
url: (parm.url ? parm.url : api.url) + parm.file,//拼接url;
data: inparm,
datatype: parm.datatype || 'jsonp',//返回jsonp;
type: 'get',
success: function (d) {//接口调用成功;
if (d !== null && d != "undefined") {//成功获取返回数据;
if (typeof d == "string" && d === '0') {//未登录
location.href = api.loc + 'login.aspx?refurl=' + location.href.replace('?', '%tf%').replace('&', '%ft%');
} else if (d.length > 0) {//有可以领取的红包
var strhtml = "";
$.each(d, function (i, v) {
if (i % 4 === 0 && inparm.action == "couponconreceive") {
strhtml += '';
}
var strtmp = $.tmpnode[parm.tmp].replace(/{\{[\w]+\}\}/g, function (e) {
var _e = e.substring(2, e.length - 2);//去掉{{字段名}}的{{}};
if (_e in v) {
if (!v[_e] && v[_e] !== 0) {
return '';
}
if (_e == "enddate") {
v[_e] = v[_e].replace('t', ' ');
}
if (_e == "startwords") {
v[_e] = v[_e].substring(0, 1);
}
return v[_e].tostring().replace(/^[\s]+/, '').replace(/[\s]+$/, '');//返回对应字段值(如果有值)
} else {
return _e;
}
});
strhtml += strtmp;
if ((i == d.length || i % 4 == 3) && inparm.action == "couponconreceive") {
strhtml += '
';
}
});
if (parm.nd) {
var adhtml = $(strhtml).appendto(parm.nd);//把字符串插入页面对应位置(传入参数)
} else {
var adhtml = $(strhtml).appendto('body');
}
if (inparm.action == "couponconreceive") {
if ($('.isreceive li').size() === 0) {
$('.dot-navigation').addclass('hide');
$('.arrow-navigation').addclass('hide');
$('.isreceive').hide();
} else if ($('.isreceive li').size() < 2) {
$('.dot-navigation').addclass('hide');
$('.arrow-navigation').addclass('hide');
} else {
$('.isreceive').show();
}
}
}
} else {
//console.log('接口错误');
}
if (fn && typeof (fn) == 'function') {
//如果有回调函数,执行回调
if (d === null && d == "undefind") {
fn();
} else {
fn(d);
}
}
},
error: function () {//接口调用失败
//console.log('网络错误');
}
});
};
});