Authored by 郭成尧

refund-apply

... ... @@ -36,8 +36,12 @@ exports.order = (req, res, next) => {
return Promise.all([
orderModel.order(params),
orderModel.getOrders(initialData)
orderModel.getOrders(initialData),
orderModel.refundReason()
]).then(result => {
// 申请退款原因
let refundReason = result[2];
res.render('order', {
module: 'home',
page: 'order',
... ... @@ -49,6 +53,7 @@ exports.order = (req, res, next) => {
localCss: true,
pageFooter: true,
order: result[0] || [],
refundReason: refundReason,
walkwayUrl: result[1] && result[1].length ? '' : '//m.yohobuy.com/product/new',
firstPageOrdersList: result[1] || []
});
... ...
... ... @@ -81,6 +81,28 @@ const cancelOrder = (req, res, next) => {
};
/**
* 申请退款
*/
const refundApply = (req, res, next) => {
let orderCode = req.query.id;
if (!orderCode) {
return res.json({
code: 404,
msg: '订单号不存在!'
});
}
orderDetailModel.refundApply({
orderCode: req.query.id,
uid: req.user.uid,
reasonId: req.query.reasonId || 1,
reason: req.query.reason
}).then(result => {
res.json(result);
}).catch(next);
};
/**
* 我的订单-查看物流信息
*/
const logistic = (req, res, next) => {
... ... @@ -102,5 +124,6 @@ module.exports = {
delOrder,
readdData,
cancelOrder,
refundApply,
logistic
};
... ...
... ... @@ -263,21 +263,21 @@ const _getNavs = (type) => {
};
/**
* 订单页面数据
* 订单页面导航条和取消订单原因
* @param params
* @returns {*|Promise.<TResult>}
*/
const order = (params) => {
let finalResult = {};
Object.assign(finalResult, {navs: _getNavs(params.type)});
let finalResult = {
navs: _getNavs(params.type)
};
return api.get('', _.assign({
method: 'app.SpaceOrders.closeReasons'
}, params), {
cache: true,
code: 200
}).then((result) => {
}).then(result => {
if (result.data) {
Object.assign(finalResult, {cancelReason: result.data});
... ... @@ -288,6 +288,17 @@ const order = (params) => {
};
/**
* 申请退款原因
*/
const refundReason = () => {
return api.get('', {
method: 'app.SpaceOrders.refundApplyReasons'
}, {code: 200, cache: true}).then(result => {
return _.get(result, 'data', []);
});
};
/**
* 获取订单列表
* @param params
*/
... ... @@ -333,6 +344,15 @@ const getOrders = (params) => {
});
}
/* 申请退款 */
if (parseInt(value.payment_type, 10) === 1 &&
value.payment_status === 'Y' &&
4 <= parseInt(value.status, 10) <= 5) {
Object.assign(perOrder, {
refundApply: true
});
}
finalResult.push(perOrder);
});
}
... ... @@ -343,5 +363,6 @@ const getOrders = (params) => {
module.exports = {
order,
getOrders
getOrders,
refundReason
};
... ...
... ... @@ -373,6 +373,19 @@ const cancelOrder = (orderCode, uid, reasonId, gender, channel, reason) => {
});
};
/**
* 申请退款
*/
const refundApply = (params) => {
return api.get('', {
method: 'app.SpaceOrders.refundApply',
uid: params.uid,
order_code: params.orderCode,
reason_id: params.reasonId,
reason: params.reason
});
};
/*
* 我的订单-查看物流
* @param int $orderCode 订单号
... ... @@ -452,5 +465,6 @@ module.exports = {
delOrder,
readdData,
cancelOrder,
refundApply,
logistics
};
... ...
... ... @@ -55,6 +55,7 @@ router.get('/orders/detail', auth, orderDetailController.orderDetailData); // è®
router.get('/delOrder', auth, orderDetailController.delOrder); // 删除订单
router.get('/readd', auth, orderDetailController.readdData); // 再次购买
router.get('/cancelOrder', auth, orderDetailController.cancelOrder); // 取消订单
router.get('/refundApply', auth, orderDetailController.refundApply); // 申请退款
router.get('/', homeController.index); // 个人中心首页
router.get('/mydetails', auth, homeController.myDetails); // 个人基本资料页面
... ...
... ... @@ -44,5 +44,21 @@
</div>
</div>
{{/ order}}
{{!-- 申请退款原因 --}}
<div class="refund-reason-mask">
<div class="refund-reason-box" >
<div class="box-head"><span class="box-cmp">完成</span></div>
<div class="swiper-container refund-box-main">
<ul class="swiper-wrapper">
{{#refundReason}}
<li class="swiper-slide" data-reason-id="{{id}}"><span >{{reason}}</span></li>
{{/refundReason}}
</ul>
<div class="refund-active-mask"></div>
</div>
</div>
</div>
</div>
... ...
... ... @@ -37,6 +37,11 @@
<span class="btn check-logistics">查看二维码</span>
</a>
{{/if}}
{{!-- 申请退款 --}}
{{#if refundApply}}
<span class="btn refund">申请退款</span>
{{/if}}
</div>
{{/unless}}
{{/unless}}
... ...
... ... @@ -32,7 +32,9 @@ var dialog = require('../plugin/dialog');
var orderHammer,
$reaMask = $('.reason-mask'),
reasonSwiper;
$refundReaMask = $('.refund-reason-mask'),
reasonSwiper,
refundReasonSwiper;
// 首屏加载标志
var firstScreen = $('.firstscreen-orders').children().size() > 0;
... ... @@ -110,14 +112,13 @@ function getOrders(option) {
type: activeType,
page: order.page + 1
};
var show = option && !option.noLoadingMask;
if (firstScreen) {
// 如果首屏加载了,则去掉10条记录
opt.start = 10;
}
var show = option && !option.noLoadingMask;
if (inAjax) {
return;
}
... ... @@ -155,7 +156,8 @@ function getOrders(option) {
if (opt.page > 1) {
return;
}
$curContainer.html('<div class="no-order"><div class="icon"></div><span>你还没有订单!</span><a class="walk-way" href="//m.yohobuy.com/product/new">随便逛逛</a></div>');
$curContainer.html('<div class="no-order"><div class="icon"></div><span>' +
'你还没有订单!</span><a class="walk-way" href="//m.yohobuy.com/product/new">随便逛逛</a></div>');
order.end = true;
}
... ... @@ -203,6 +205,7 @@ orderHammer.on('tap', function(e) {
id = $order.data('id');
$reaMask.data('orderId', id);
$refundReaMask.data('orderId', id);
if ($cur.closest('.del').length > 0) {
... ... @@ -237,7 +240,11 @@ orderHammer.on('tap', function(e) {
});
});
} else if ($cur.closest('.cancel').length > 0) {
// 取消订单
$reaMask.css('visibility', 'visible');
} else if ($cur.closest('.refund').length > 0) {
// 申请退款
$refundReaMask.css('visibility', 'visible');
} else if ($cur.closest('.order-goods').length > 0) {
// Location to order detail
... ... @@ -287,7 +294,7 @@ $(function() {
centeredSlides: true,
initialSlide: 0,
onSlideChangeStart: function(reasonSwiper) {//eslint-disable-line
var activeIndex = reasonSwiper.activeIndex,
let activeIndex = reasonSwiper.activeIndex,
slides = reasonSwiper.slides,
i = 0;
... ... @@ -312,10 +319,43 @@ $(function() {
$(slides[activeIndex]).css('transform', '');
}
});
// 申请退款 Swiper
refundReasonSwiper = new Swiper('.refund-box-main', {
direction: 'vertical',
slidesPerView: 5,
centeredSlides: true,
initialSlide: 0,
onSlideChangeStart: function(refundReasonSwiper) {//eslint-disable-line
let activeIndex = refundReasonSwiper.activeIndex,
slides = refundReasonSwiper.slides,
i = 0;
if (slides.length !== 1) {
if (activeIndex === 0) {
for (i = 1; i < slides.length; i++) {
$(slides[i]).css('transform', '');
}
} else if (activeIndex === slides.length - 1) {
for (i = 0; i < activeIndex; i++) {
$(slides[i]).css('transform', 'rotateX(' + (30 + (activeIndex - i) * 12) + 'deg)');
}
} else {
for (i = 0; i < activeIndex; i++) {
$(slides[i]).css('transform', 'rotateX(' + (30 + (activeIndex - i) * 12) + 'deg)');
}
for (i = activeIndex + 1; i < slides.length; i++) {
$(slides[i]).css('transform', '');
}
}
}
$(slides[activeIndex]).css('transform', '');
}
});
});
$reaMask.find('.box-cmp').on('touchend', function() {
var selSolid = reasonSwiper.slides[reasonSwiper.activeIndex],
let selSolid = reasonSwiper.slides[reasonSwiper.activeIndex],
reason = $(selSolid).text(),
reasonId = $(selSolid).data('reasonId');
... ... @@ -343,6 +383,36 @@ $reaMask.find('.box-cmp').on('touchend', function() {
});
});
// 申请退款
$refundReaMask.find('.box-cmp').on('touchend', function() {
let selSolid = refundReasonSwiper.slides[refundReasonSwiper.activeIndex],
reason = $(selSolid).text(),
reasonId = $(selSolid).data('reasonId');
$.ajax({
type: 'GET',
url: '/home/refundApply',
data: {
id: $refundReaMask.data('orderId'),
reason: reason,
reasonId: reasonId
}
}).then(function(res) {
$refundReaMask.fadeOut();
if ($.type(res) !== 'object') {
return;
}
if (res.message) {
tip.show(res.message);
}
setTimeout(function() {
window.location.href = '/home/orders';
}, 2000);
}).fail(function() {
tip.show('网络错误');
});
});
$reaMask.on('touchend', function(event) {
if (event.target.className !== 'reason-mask') {
return false;
... ... @@ -352,6 +422,16 @@ $reaMask.on('touchend', function(event) {
event.stopPropagation();
});
// 申请退款
$refundReaMask.on('touchend', function(event) {
if (event.target.className !== 'reason-mask') {
return false;
}
$refundReaMask.css('visibility', 'hidden');
event.stopPropagation();
});
$('.nav-tap').on('click', function(e) {
var $cur = $(e.target);
... ...
.order-page {
background: #f0f0f0;
.reason-mask {
.reason-mask,
.refund-reason-mask {
position: fixed;
width: 100%;
height: 100%;
... ... @@ -11,7 +12,8 @@
z-index: 5;
visibility: hidden;
.reason-box {
.reason-box,
.refund-reason-box {
border-bottom: 1px solid #ccc;
font: inherit;
position: absolute;
... ... @@ -32,7 +34,8 @@
padding-right: 30px;
}
.box-main {
.box-main,
.refund-box-main {
background: #fff;
padding: 20px;
height: 300px;
... ...