Authored by 郭成尧

detail-page

@@ -10,6 +10,7 @@ const helpers = global.yoho.helpers; @@ -10,6 +10,7 @@ const helpers = global.yoho.helpers;
10 const _ = require('lodash'); 10 const _ = require('lodash');
11 const headerModel = require('../../../doraemon/models/header'); // 头部model 11 const headerModel = require('../../../doraemon/models/header'); // 头部model
12 const orderDetailModel = require('../models/orderDetail'); 12 const orderDetailModel = require('../models/orderDetail');
  13 +const orderModel = require('../models/order');
13 const payModel = require('../../cart/models/pay'); 14 const payModel = require('../../cart/models/pay');
14 15
15 const orderDetailData = (req, res, next) => { 16 const orderDetailData = (req, res, next) => {
@@ -26,10 +27,12 @@ const orderDetailData = (req, res, next) => { @@ -26,10 +27,12 @@ const orderDetailData = (req, res, next) => {
26 27
27 Promise.all([ 28 Promise.all([
28 orderDetailModel.orderDetailData(uid, orderCode), 29 orderDetailModel.orderDetailData(uid, orderCode),
29 - orderDetailModel.closeReasons() 30 + orderDetailModel.closeReasons(),
  31 + orderModel.refundReason()
30 ]).then(result => { 32 ]).then(result => {
31 let orderDetail = result[0]; 33 let orderDetail = result[0];
32 let cancelReason = result[1]; 34 let cancelReason = result[1];
  35 + let refundReason = result[2];
33 36
34 Object.assign(orderDetail, { 37 Object.assign(orderDetail, {
35 cancelReason: cancelReason 38 cancelReason: cancelReason
@@ -50,6 +53,7 @@ const orderDetailData = (req, res, next) => { @@ -50,6 +53,7 @@ const orderDetailData = (req, res, next) => {
50 title: '订单详情', 53 title: '订单详情',
51 pageFooter: true, 54 pageFooter: true,
52 orderDetail: orderDetail, 55 orderDetail: orderDetail,
  56 + refundReason: refundReason,
53 localCss: true, 57 localCss: true,
54 }); 58 });
55 }).catch(next); 59 }).catch(next);
@@ -309,6 +309,16 @@ const orderDetailData = (uid, orderCode) => { @@ -309,6 +309,16 @@ const orderDetailData = (uid, orderCode) => {
309 orderDetail.invoice.type = (orderDetail.invoice.type + '' === '2'); 309 orderDetail.invoice.type = (orderDetail.invoice.type + '' === '2');
310 } 310 }
311 311
  312 + /* 申请退款 */
  313 + if (orderDetail.isMultiPackage === 'N' &&
  314 + parseInt(orderDetail.paymentType, 10) === 1 &&
  315 + orderDetail.paymentStatus === 'Y' &&
  316 + 4 <= parseInt(orderDetail.status, 10) <= 5) {
  317 + Object.assign(orderDetail, {
  318 + refundApply: true
  319 + });
  320 + }
  321 +
312 return orderDetail; 322 return orderDetail;
313 } else { 323 } else {
314 logger.error('detail info return no 200'); 324 logger.error('detail info return no 200');
@@ -153,6 +153,11 @@ @@ -153,6 +153,11 @@
153 <span class="btn btn-check-logistics">查看二维码</span> 153 <span class="btn btn-check-logistics">查看二维码</span>
154 </a> 154 </a>
155 {{/if}} 155 {{/if}}
  156 +
  157 + {{!-- 申请退款 --}}
  158 + {{#if refundApply}}
  159 + <span class="btn refund">申请退款</span>
  160 + {{/if}}
156 {{/if}} 161 {{/if}}
157 </div> 162 </div>
158 </div> 163 </div>
@@ -171,6 +176,22 @@ @@ -171,6 +176,22 @@
171 </div> 176 </div>
172 </div> 177 </div>
173 {{/ orderDetail}} 178 {{/ orderDetail}}
  179 +
  180 + {{!-- 申请退款原因 --}}
  181 + <div class="refund-reason-mask">
  182 + <div class="refund-reason-box" >
  183 + <div class="box-head"><span class="box-cmp">完成</span></div>
  184 + <div class="swiper-container refund-box-main">
  185 +
  186 + <ul class="swiper-wrapper">
  187 + {{#refundReason}}
  188 + <li class="swiper-slide" data-reason-id="{{id}}"><span >{{reason}}</span></li>
  189 + {{/refundReason}}
  190 + </ul>
  191 + <div class="refund-active-mask"></div>
  192 + </div>
  193 + </div>
  194 + </div>
174 </div> 195 </div>
175 <script>_ozprm = "orderid={{orderCode}}&ordertotal={{orderTotal}}";</script> 196 <script>_ozprm = "orderid={{orderCode}}&ordertotal={{orderTotal}}";</script>
176 <script type="text/javascript" src="//static.yohobuy.com/m/v1/js/AG_Tracking.js"></script> 197 <script type="text/javascript" src="//static.yohobuy.com/m/v1/js/AG_Tracking.js"></script>
@@ -18,7 +18,9 @@ var orderId = $('#order-detail').data('id'), @@ -18,7 +18,9 @@ var orderId = $('#order-detail').data('id'),
18 Swiper = require('yoho-swiper'), 18 Swiper = require('yoho-swiper'),
19 $ownerInfo = $('.owner-info'), 19 $ownerInfo = $('.owner-info'),
20 $reaMask = $('.reason-mask'), 20 $reaMask = $('.reason-mask'),
  21 + $refundReaMask = $('.refund-reason-mask'),
21 reasonSwiper, 22 reasonSwiper,
  23 + refundReasonSwiper,
22 optHammer, 24 optHammer,
23 $createTime = new Date($('.createTime').text() * 1000); 25 $createTime = new Date($('.createTime').text() * 1000);
24 26
@@ -148,7 +150,7 @@ $(function() { @@ -148,7 +150,7 @@ $(function() {
148 centeredSlides: true, 150 centeredSlides: true,
149 slidesPerView: 5, 151 slidesPerView: 5,
150 direction: 'vertical', 152 direction: 'vertical',
151 - onSlideChangeStart: function(reasonSwiper) { 153 + onSlideChangeStart: function(reasonSwiper) {//eslint-disable-line
152 var activeIndex = reasonSwiper.activeIndex, 154 var activeIndex = reasonSwiper.activeIndex,
153 slides = reasonSwiper.slides, 155 slides = reasonSwiper.slides,
154 i = 0; 156 i = 0;
@@ -174,6 +176,39 @@ $(function() { @@ -174,6 +176,39 @@ $(function() {
174 $(slides[activeIndex]).css('transform', ''); 176 $(slides[activeIndex]).css('transform', '');
175 } 177 }
176 }); 178 });
  179 +
  180 + // 申请退款 Swiper
  181 + refundReasonSwiper = new Swiper('.refund-box-main', {
  182 + direction: 'vertical',
  183 + slidesPerView: 5,
  184 + centeredSlides: true,
  185 + initialSlide: 0,
  186 + onSlideChangeStart: function(refundReasonSwiper) {//eslint-disable-line
  187 + let activeIndex = refundReasonSwiper.activeIndex,
  188 + slides = refundReasonSwiper.slides,
  189 + i = 0;
  190 +
  191 + if (slides.length !== 1) {
  192 + if (activeIndex === 0) {
  193 + for (i = 1; i < slides.length; i++) {
  194 + $(slides[i]).css('transform', '');
  195 + }
  196 + } else if (activeIndex === slides.length - 1) {
  197 + for (i = 0; i < activeIndex; i++) {
  198 + $(slides[i]).css('transform', 'rotateX(' + (30 + (activeIndex - i) * 12) + 'deg)');
  199 + }
  200 + } else {
  201 + for (i = 0; i < activeIndex; i++) {
  202 + $(slides[i]).css('transform', 'rotateX(' + (30 + (activeIndex - i) * 12) + 'deg)');
  203 + }
  204 + for (i = activeIndex + 1; i < slides.length; i++) {
  205 + $(slides[i]).css('transform', '');
  206 + }
  207 + }
  208 + }
  209 + $(slides[activeIndex]).css('transform', '');
  210 + }
  211 + });
177 }); 212 });
178 213
179 $reaMask.find('.box-cmp').on('touchend', function(e) { 214 $reaMask.find('.box-cmp').on('touchend', function(e) {
@@ -205,6 +240,36 @@ $reaMask.find('.box-cmp').on('touchend', function(e) { @@ -205,6 +240,36 @@ $reaMask.find('.box-cmp').on('touchend', function(e) {
205 }); 240 });
206 }); 241 });
207 242
  243 +// 申请退款
  244 +$refundReaMask.find('.box-cmp').on('touchend', function() {
  245 + let selSolid = refundReasonSwiper.slides[refundReasonSwiper.activeIndex],
  246 + reason = $(selSolid).text(),
  247 + reasonId = $(selSolid).data('reasonId');
  248 +
  249 + $.ajax({
  250 + type: 'GET',
  251 + url: '/home/refundApply',
  252 + data: {
  253 + id: $refundReaMask.data('orderId'),
  254 + reason: reason,
  255 + reasonId: reasonId
  256 + }
  257 + }).then(function(res) {
  258 + $refundReaMask.fadeOut();
  259 + if ($.type(res) !== 'object') {
  260 + return;
  261 + }
  262 + if (res.message) {
  263 + tip.show(res.message);
  264 + }
  265 + setTimeout(function() {
  266 + window.location.href = '/home/orders';
  267 + }, 2000);
  268 + }).fail(function() {
  269 + tip.show('网络错误');
  270 + });
  271 +});
  272 +
208 $reaMask.on('touchend', function(event) { 273 $reaMask.on('touchend', function(event) {
209 if (event.target.className !== 'reason-mask') { 274 if (event.target.className !== 'reason-mask') {
210 return false; 275 return false;
@@ -214,6 +279,16 @@ $reaMask.on('touchend', function(event) { @@ -214,6 +279,16 @@ $reaMask.on('touchend', function(event) {
214 event.stopPropagation(); 279 event.stopPropagation();
215 }); 280 });
216 281
  282 +// 申请退款
  283 +$refundReaMask.on('touchend', function(event) {
  284 + if (event.target.className !== 'reason-mask') {
  285 + return false;
  286 + }
  287 +
  288 + $refundReaMask.css('visibility', 'hidden');
  289 + event.stopPropagation();
  290 +});
  291 +
217 function formatDate(objD) { 292 function formatDate(objD) {
218 var str, 293 var str,
219 yy = objD.getYear(), 294 yy = objD.getYear(),
@@ -231,7 +231,8 @@ @@ -231,7 +231,8 @@
231 } 231 }
232 } 232 }
233 233
234 - .reason-mask { 234 + .reason-mask,
  235 + .refund-reason-mask {
235 position: fixed; 236 position: fixed;
236 width: 100%; 237 width: 100%;
237 height: 100%; 238 height: 100%;
@@ -241,7 +242,8 @@ @@ -241,7 +242,8 @@
241 z-index: 1; 242 z-index: 1;
242 visibility: hidden; 243 visibility: hidden;
243 244
244 - .reason-box { 245 + .reason-box,
  246 + .refund-reason-box {
245 border-bottom: 1px solid #ccc; 247 border-bottom: 1px solid #ccc;
246 font: inherit; 248 font: inherit;
247 vertical-align: baseline; 249 vertical-align: baseline;
@@ -262,7 +264,8 @@ @@ -262,7 +264,8 @@
262 padding-right: 30px; 264 padding-right: 30px;
263 } 265 }
264 266
265 - .box-main { 267 + .box-main,
  268 + .refund-box-main {
266 background: #fff; 269 background: #fff;
267 padding: 20px; 270 padding: 20px;
268 height: 300px; 271 height: 300px;