/******************************
用户中心-我的订单
*******************************/
$namespace("iuni.uc.myorder");
/******************************
全局参数配置
*******************************/
iuni.uc.myorder.data={
orderStatus : {
101 : "未支付",
102 : "已审核订单",
103 : "发货中",
104 : "待审核订单",
105 : "发货中",
200 : "已完成",
201 : "已签收",
202 : "已拒收",
203 : "拒收登记中",
204 : "拒收登记中",
300 : "已退款",
301 : "退款中",
302 : "退货中",
303 : "退款中",
404 : "无效订单",
500 : "订单已取消",
505 : "订单异常"
},
cacheList : null,
tempOrderFun : false,
tempLogisticFun : false
};
iuni.uc.myorder.dom={
orderCon : $("#orderCon"),//订单列表容器
hasOrderCon : $("#hasOrderCon"),//有订单时的容器
noOrderCon : $("#noOrderCon"),//无订单时的容器
layerLogistic : $("#layerLogistic")//物流信息容器
};
iuni.uc.myorder.template = {
tempOrder : $getTpl("order")
};
iuni.uc.myorder.cache = {
logistic : {}
};
/******************************
初始化配置
*******************************/
iuni.uc.myorder.init = function(){
//创建订单列表请求对象
this.reqOrderList = (function(){
var req = $Request.create({
url : "http://www.iuni.com/api/user/order_list",
type : "iframe",
timeout : 3000
});
req.done( function( json ){
//处理json结构
var orderList = json.data.dataContext , goodsList;
for (var i = orderList.length - 1; i >= 0; i--) {
goodsList = orderList[i].orderItems;
for (var j = goodsList.length - 1; j >= 0; j--) {
if( goodsList[j].zskuidInfo ){
goodsList[j].zskuidInfo = $evalJSON( goodsList[j].zskuidInfo );
}
}
}
iuni.uc.myorder.cache.orderList = json.data.dataContext;
iuni.uc.myorder.makeOrderList( json );
iuni.uc.myorder.applyService(json);
});
req.error( function(){
iuni.common.ui.fail("获取订单错误,请联系客服");
});
req.timeout(function(){
iuni.common.ui.fail ("请求数据超时,请稍后重试")
});
return req;
})();
//物流信息请求
this.reqLogistic = (function(){
var req = $Request.create({
url : "http://www.iuni.com/api/user/query_ship_status",
type : "iframe",
timeout : 3000
});
req.done( function( json ){
iuni.uc.myorder.makeLogistic( json );
});
req.error( function( json ){
iuni.uc.myorder.makeLogistic( json );
} );
req.timeout(function(){
iuni.common.ui.fail ("请求数据超时,请稍后重试")
});
return req;
})();
//初始化翻页对象
this.pager = $iuni_pagination({
//maxPage : data.data.totalPage,
displayPage : 4,
pageCon : "pagebox",
currPage : 1,
currPageClass : "thispage",
callback : function( page , elem ){
iuni.uc.myorder.getOrderList( page );
}
});
//购物车请求对象
this.reqCart = (function(){
var req = $Request.create({
url : "http://www.iuni.com/api/cart/add",
type : "iframe",
timeout : 3000
});
req.done( function( json ){
window.location = "http://www.iuni.com/cart";
});
req.error( function( json ){
iuni.common.ui.fail( json.msg );
});
req.timeout(function(){
iuni.common.ui.fail ("请求数据超时,请稍后重试")
});
return req;
})();
//获得订单
this.getOrderList( 1 );
};
/******************************
功能实现区
*******************************/
//获得订单数据列表
iuni.uc.myorder.getOrderList = function( page ){
var _t = this,
reqol = _t.reqOrderList,
page = page || 1;
reqol.setParam({
page : page,
psize : 5
});
reqol.start();
}
//跳转到售后服务(event)
iuni.uc.myorder.applyService = function(result){
$('[data-action="applyService"]').off()
.on('click', function(){
var sn = $(this).data('ordersn');
var isOpen = result.data.userApplyOpen;//0关闭,1开启
if(!Boolean(isOpen)){
iuni.common.ui.fail('前端售后功能已关闭,请联系客服,谢谢!');
return;
}
location.href = 'apply_service.shtml?sn='+sn;
});
$('[data-action=orderDesc]').off()
.on('click', function(){
if($(this).siblings('[data-action=applyService]').length){
$setCookie('isApplyService',true);
}else{
$setCookie('isApplyService','');
}
});
};
//生成订单列表html
iuni.uc.myorder.makeOrderList = function(data){
if(data.returnCode !== 0 || !data.data){return}
var _myorder = iuni.uc.myorder,
dom = _myorder.dom , orderList = data.data ,
_tempOrder = _myorder.template.tempOrder ,
tempOrderFun = _myorder.data.tempOrderFun ?
_myorder.data.tempOrderFun : (_myorder.data.tempOrderFun = $formatTpl(_tempOrder["orderList"])),
strOrder;
if( orderList.countRow ){
_myorder.data.cacheList = orderList.dataContext;
//所有订单
strOrder = tempOrderFun( orderList );
dom.hasOrderCon.show();
dom.orderCon.html( strOrder );
}else{
dom.orderCon.hide();
dom.noOrderCon.show();
}
//设置最大页数
_myorder.pager.setMaxPage( orderList.totalPage );
}
//生成物流信息
iuni.uc.myorder.makeLogistic = function(data){
var _myorder = iuni.uc.myorder ,
_elemOf = _myorder.dom.elemLog.offset(),
tempLogisticFun = _myorder.data.tempLogisticFun ?
_myorder.data.tempLogisticFun : (_myorder.data.tempLogisticFun = $formatTpl(_myorder.template.tempOrder["logistic"]));
//缓存数据
_myorder.cache.logistic[data.data.orderSn] = data;
if(!data.data.length)
{
data.data.shipInfoList=[];
}
_myorder.dom.layerLogistic.css({
"left" : _elemOf.left - 260,
"top" : _elemOf.top + 17,
"display" : "block"
}).children("dl").html( tempLogisticFun( data.data.shipInfoList ) );
}
//打开物流信息
function openLogistic(elem){
var elem = $(elem),
_myorder = iuni.uc.myorder,
req = _myorder.reqLogistic,
sn = elem.attr("orderSn"),
data = _myorder.cache.logistic[sn];
//缓存物流追踪按钮
_myorder.dom.elemLog = elem;
if(data){//有缓存取缓存
_myorder.makeLogistic(data);
}else{
req.setParam({"order_sn" : sn});
req.start();
}
}
//关闭物流信息
function closeLogistic(){
setTimeout(function(){
if(iuni.uc.myorder.dom.layerLogistic.isShow){
iuni.uc.myorder.dom.layerLogistic.isShow = false;
return;
}
iuni.uc.myorder.dom.layerLogistic.hide();
},300);
}
//打开物流信息
function showLogistic(){
iuni.uc.myorder.dom.layerLogistic.isShow = true;
iuni.uc.myorder.dom.layerLogistic.show();
}
//重新购买
function reBuy( index ){
var _moudel = iuni.uc.myorder,
orderItems = _moudel.data.cacheList[index].orderItems,
item , _req = _moudel.reqCart , strParam = "";
if( orderItems ){
for( var i = 0 , leni = orderItems.length ; i < leni ; i++ ){
item = orderItems[i];
if( item.goodsType !== "1" && item.goodsType !== "101"){
strParam += "," + item.skuid + ":" + item.goodsNumber;
}
}
strParam = strParam.substring(1);
_req.setParam({
goods : strParam
});
_req.start();
}
}
//单例
iuni.uc.myorder.getSingle = function (fn) {
var ret;
return function () {
return ret || ( ret = fn.apply(this, arguments) );
};
};
//检查预约的定单今日库存
function checkPayStock( index ){
//购物车请求对象
var _moudel = iuni.uc.myorder,
orderItems = _moudel.cache.orderList[ index ],
reqCheck = $Request.create({
url : "http://www.iuni.com/api/order/check_pay_stock",
type : "iframe",
timeout : 3000
}),
childItem = orderItems.childList[1],
orderSn = childItem.orderSn;
reqCheck.setParam({
order_sn : orderSn
});
reqCheck.done( function( json ){
if( json.returnCode === 0 ){
window.location = 'http://www.iuni.com/order/' + ( childItem.deliverId?'submit':'confirm' ) + '/' + childItem.orderSn;
}else{
$iuni_fail( json.msg );
}
});
reqCheck.error( function( json ){
$iuni_fail( json.msg );
});
reqCheck.timeout(function(){
$iuni_fail ("请求数据超时,请稍后重试");
});
reqCheck.start();
return false;
}
iuni.uc.myorder.init();
用户中心-我的订单
*******************************/
$namespace("iuni.uc.myorder");
/******************************
全局参数配置
*******************************/
iuni.uc.myorder.data={
orderStatus : {
101 : "未支付",
102 : "已审核订单",
103 : "发货中",
104 : "待审核订单",
105 : "发货中",
200 : "已完成",
201 : "已签收",
202 : "已拒收",
203 : "拒收登记中",
204 : "拒收登记中",
300 : "已退款",
301 : "退款中",
302 : "退货中",
303 : "退款中",
404 : "无效订单",
500 : "订单已取消",
505 : "订单异常"
},
cacheList : null,
tempOrderFun : false,
tempLogisticFun : false
};
iuni.uc.myorder.dom={
orderCon : $("#orderCon"),//订单列表容器
hasOrderCon : $("#hasOrderCon"),//有订单时的容器
noOrderCon : $("#noOrderCon"),//无订单时的容器
layerLogistic : $("#layerLogistic")//物流信息容器
};
iuni.uc.myorder.template = {
tempOrder : $getTpl("order")
};
iuni.uc.myorder.cache = {
logistic : {}
};
/******************************
初始化配置
*******************************/
iuni.uc.myorder.init = function(){
//创建订单列表请求对象
this.reqOrderList = (function(){
var req = $Request.create({
url : "http://www.iuni.com/api/user/order_list",
type : "iframe",
timeout : 3000
});
req.done( function( json ){
//处理json结构
var orderList = json.data.dataContext , goodsList;
for (var i = orderList.length - 1; i >= 0; i--) {
goodsList = orderList[i].orderItems;
for (var j = goodsList.length - 1; j >= 0; j--) {
if( goodsList[j].zskuidInfo ){
goodsList[j].zskuidInfo = $evalJSON( goodsList[j].zskuidInfo );
}
}
}
iuni.uc.myorder.cache.orderList = json.data.dataContext;
iuni.uc.myorder.makeOrderList( json );
iuni.uc.myorder.applyService(json);
});
req.error( function(){
iuni.common.ui.fail("获取订单错误,请联系客服");
});
req.timeout(function(){
iuni.common.ui.fail ("请求数据超时,请稍后重试")
});
return req;
})();
//物流信息请求
this.reqLogistic = (function(){
var req = $Request.create({
url : "http://www.iuni.com/api/user/query_ship_status",
type : "iframe",
timeout : 3000
});
req.done( function( json ){
iuni.uc.myorder.makeLogistic( json );
});
req.error( function( json ){
iuni.uc.myorder.makeLogistic( json );
} );
req.timeout(function(){
iuni.common.ui.fail ("请求数据超时,请稍后重试")
});
return req;
})();
//初始化翻页对象
this.pager = $iuni_pagination({
//maxPage : data.data.totalPage,
displayPage : 4,
pageCon : "pagebox",
currPage : 1,
currPageClass : "thispage",
callback : function( page , elem ){
iuni.uc.myorder.getOrderList( page );
}
});
//购物车请求对象
this.reqCart = (function(){
var req = $Request.create({
url : "http://www.iuni.com/api/cart/add",
type : "iframe",
timeout : 3000
});
req.done( function( json ){
window.location = "http://www.iuni.com/cart";
});
req.error( function( json ){
iuni.common.ui.fail( json.msg );
});
req.timeout(function(){
iuni.common.ui.fail ("请求数据超时,请稍后重试")
});
return req;
})();
//获得订单
this.getOrderList( 1 );
};
/******************************
功能实现区
*******************************/
//获得订单数据列表
iuni.uc.myorder.getOrderList = function( page ){
var _t = this,
reqol = _t.reqOrderList,
page = page || 1;
reqol.setParam({
page : page,
psize : 5
});
reqol.start();
}
//跳转到售后服务(event)
iuni.uc.myorder.applyService = function(result){
$('[data-action="applyService"]').off()
.on('click', function(){
var sn = $(this).data('ordersn');
var isOpen = result.data.userApplyOpen;//0关闭,1开启
if(!Boolean(isOpen)){
iuni.common.ui.fail('前端售后功能已关闭,请联系客服,谢谢!');
return;
}
location.href = 'apply_service.shtml?sn='+sn;
});
$('[data-action=orderDesc]').off()
.on('click', function(){
if($(this).siblings('[data-action=applyService]').length){
$setCookie('isApplyService',true);
}else{
$setCookie('isApplyService','');
}
});
};
//生成订单列表html
iuni.uc.myorder.makeOrderList = function(data){
if(data.returnCode !== 0 || !data.data){return}
var _myorder = iuni.uc.myorder,
dom = _myorder.dom , orderList = data.data ,
_tempOrder = _myorder.template.tempOrder ,
tempOrderFun = _myorder.data.tempOrderFun ?
_myorder.data.tempOrderFun : (_myorder.data.tempOrderFun = $formatTpl(_tempOrder["orderList"])),
strOrder;
if( orderList.countRow ){
_myorder.data.cacheList = orderList.dataContext;
//所有订单
strOrder = tempOrderFun( orderList );
dom.hasOrderCon.show();
dom.orderCon.html( strOrder );
}else{
dom.orderCon.hide();
dom.noOrderCon.show();
}
//设置最大页数
_myorder.pager.setMaxPage( orderList.totalPage );
}
//生成物流信息
iuni.uc.myorder.makeLogistic = function(data){
var _myorder = iuni.uc.myorder ,
_elemOf = _myorder.dom.elemLog.offset(),
tempLogisticFun = _myorder.data.tempLogisticFun ?
_myorder.data.tempLogisticFun : (_myorder.data.tempLogisticFun = $formatTpl(_myorder.template.tempOrder["logistic"]));
//缓存数据
_myorder.cache.logistic[data.data.orderSn] = data;
if(!data.data.length)
{
data.data.shipInfoList=[];
}
_myorder.dom.layerLogistic.css({
"left" : _elemOf.left - 260,
"top" : _elemOf.top + 17,
"display" : "block"
}).children("dl").html( tempLogisticFun( data.data.shipInfoList ) );
}
//打开物流信息
function openLogistic(elem){
var elem = $(elem),
_myorder = iuni.uc.myorder,
req = _myorder.reqLogistic,
sn = elem.attr("orderSn"),
data = _myorder.cache.logistic[sn];
//缓存物流追踪按钮
_myorder.dom.elemLog = elem;
if(data){//有缓存取缓存
_myorder.makeLogistic(data);
}else{
req.setParam({"order_sn" : sn});
req.start();
}
}
//关闭物流信息
function closeLogistic(){
setTimeout(function(){
if(iuni.uc.myorder.dom.layerLogistic.isShow){
iuni.uc.myorder.dom.layerLogistic.isShow = false;
return;
}
iuni.uc.myorder.dom.layerLogistic.hide();
},300);
}
//打开物流信息
function showLogistic(){
iuni.uc.myorder.dom.layerLogistic.isShow = true;
iuni.uc.myorder.dom.layerLogistic.show();
}
//重新购买
function reBuy( index ){
var _moudel = iuni.uc.myorder,
orderItems = _moudel.data.cacheList[index].orderItems,
item , _req = _moudel.reqCart , strParam = "";
if( orderItems ){
for( var i = 0 , leni = orderItems.length ; i < leni ; i++ ){
item = orderItems[i];
if( item.goodsType !== "1" && item.goodsType !== "101"){
strParam += "," + item.skuid + ":" + item.goodsNumber;
}
}
strParam = strParam.substring(1);
_req.setParam({
goods : strParam
});
_req.start();
}
}
//单例
iuni.uc.myorder.getSingle = function (fn) {
var ret;
return function () {
return ret || ( ret = fn.apply(this, arguments) );
};
};
//检查预约的定单今日库存
function checkPayStock( index ){
//购物车请求对象
var _moudel = iuni.uc.myorder,
orderItems = _moudel.cache.orderList[ index ],
reqCheck = $Request.create({
url : "http://www.iuni.com/api/order/check_pay_stock",
type : "iframe",
timeout : 3000
}),
childItem = orderItems.childList[1],
orderSn = childItem.orderSn;
reqCheck.setParam({
order_sn : orderSn
});
reqCheck.done( function( json ){
if( json.returnCode === 0 ){
window.location = 'http://www.iuni.com/order/' + ( childItem.deliverId?'submit':'confirm' ) + '/' + childItem.orderSn;
}else{
$iuni_fail( json.msg );
}
});
reqCheck.error( function( json ){
$iuni_fail( json.msg );
});
reqCheck.timeout(function(){
$iuni_fail ("请求数据超时,请稍后重试");
});
reqCheck.start();
return false;
}
iuni.uc.myorder.init();