Authored by baoss

Merge branch 'feature/group-buy' of git.yoho.cn:fe/yohobuywap-node into feature/group-buy

... ... @@ -5,6 +5,7 @@ const headerModel = require('../../../doraemon/models/header'); // 头部model
const _ = require('lodash');
const utils = '../../../utils';
const detailProcess = require(`${utils}/detail-process`);
const helpers = global.yoho.helpers;
function index(req, res, next) {
req.ctx(GroupService).groupIndex().then(result => {
... ... @@ -133,6 +134,7 @@ function goodsDetail(req, res, next) {
req.ctx(GroupService).goodsDetail({
activityId: param.activityId,
productSkn: param.productSkn,
groupNo: param.groupNo
}).then((result) => {
if (_.isEmpty(result)) {
return next();
... ... @@ -145,6 +147,9 @@ function goodsDetail(req, res, next) {
finalResult.support = result.support;
finalResult.floor = result.floor;
finalResult.storage_sum = result.storage_sum;
finalResult.groupNo = param.groupNo;
finalResult.activityId = param.activityId;
finalResult.isShowPop = result.activityIdDetail.joinLimit === 1 ? true : false;
return res.render('group/goodsDetail', {
page: 'group-goodsDetail',
nodownload: true,
... ... @@ -161,6 +166,65 @@ function goodsDetail(req, res, next) {
}).catch(next);
}
function delOrder(req, res, next) {
let orderCode = req.query.id;
let uid = req.user.uid;
req.ctx(GroupService).delOrder({ orderCode, uid }).then((result) => {
res.json(result);
}).catch(next);
}
function cancelOrder(req, res, next) {
let orderCode = req.query.id;
let uid = req.user.uid;
req.ctx(GroupService).cancelOrder({ orderCode, uid }).then((result) => {
res.json(result);
}).catch(next);
}
function changeOrderStatus(orderItem) {
const orderBtn = [];
if (!orderItem) {
return {};
}
_.each(orderItem.links, function(val) {
switch (val) {
case 'buyNow':
orderBtn.push({
buyNow: true,
link: helpers.urlFormat('/home/orders/paynew', {order_code: orderItem.order_code}),
});
break;
case 'closeOrder':// 取消订单
orderBtn.push({
closeOrder: true
});
break;
case 'delOrder':// 删除订单
orderBtn.push({
delOrder: true,
});
break;
case 'groupInvite':
orderBtn.push({
groupInvite: true,
link: helpers.urlFormat('/activity/group/progress', {
groupNo: orderItem.group_no,
activityId: orderItem.activity_id
}),
});
break;
default:
break;
}
});
return orderBtn;
}
function order(req, res, next) {
const uid = req.user.uid;
const {
... ... @@ -170,7 +234,7 @@ function order(req, res, next) {
const param = {
page: 1,
limit: 50,
type: type || 1,
type: type || 2,
uid
};
... ... @@ -179,6 +243,11 @@ function order(req, res, next) {
if (_.isEmpty(result)) {
return next();
}
_.each(result.order_list, function(orderItem) {
const orderBtn = changeOrderStatus(orderItem);
orderItem.orderBtn = orderBtn;
});
return res.render('group/order', {
title: '我的拼团',
page: 'group-order',
... ... @@ -188,6 +257,7 @@ function order(req, res, next) {
wechatShare: true,
pageStyle: 'group-order-page',
result,
type: type || 2,
navs: [{
title: '进行中',
src: '/activity/group/order?type=2&selectIndex=0'
... ... @@ -211,5 +281,7 @@ module.exports = {
goodsDetail,
order,
filter,
searchList
searchList,
delOrder,
cancelOrder
};
... ...
... ... @@ -175,6 +175,32 @@ class GroupApi extends global.yoho.BaseModel {
});
}
delOrder({
orderCode,
uid
}) {
return this.get({
data: {
method: 'app.SpaceOrders.delOrderByCode',
uid: uid,
order_code: orderCode
}
});
}
cancelOrder({
orderCode,
uid
}) {
return this.get({
data: {
method: 'app.SpaceOrders.close',
uid: uid,
order_code: orderCode
}
});
}
getRefundApplyReasons(param) {
return this.get({
url: '',
... ...
... ... @@ -278,6 +278,38 @@ class GroupService extends global.yoho.BaseModel {
}
}
async delOrder({
orderCode,
uid
}) {
try {
const result = await this.api.delOrder({
orderCode,
uid
});
return result;
} catch (error) {
throw new Error('Group delOrder fail.');
}
}
async cancelOrder({
orderCode,
uid
}) {
try {
const result = await this.api.cancelOrder({
orderCode,
uid
});
return result;
} catch (error) {
throw new Error('Group cancelOrder fail.');
}
}
add0(m) {
return m < 10 ? '0' + m : m;
}
... ...
... ... @@ -375,5 +375,7 @@ router.get('/group/progress', auth, group.progress); // 拼团状态详情页
router.get('/group/productData', group.productData); // 商品信息
router.get('/group/detail', group.goodsDetail);
router.get('/group/order', auth, group.order); // 我的拼团
router.get('/group/delOrder', auth, group.delOrder); // 删除拼团订单
router.get('/group/cancelOrder', auth, group.cancelOrder); // 取消拼团订单
module.exports = router;
... ...
... ... @@ -61,7 +61,7 @@
data-value="{{leftTime}}">{{formatLeftTime}}</span></div>
</div>
<div class='ibutton'>
<div class='ibutton' data-value="{{groupNo}}">
立即参团
</div>
</div>
... ... @@ -132,6 +132,7 @@
<div data-current="{{activityIdDetail.currentTime}}"
data-begin="{{activityIdDetail.beginTime}}"
data-end="{{activityIdDetail.endTime}}"
id="date"
class="comp-count-dow-by-now">
<span id="label"></span>
<span class="number" id="days"></span>
... ... @@ -141,16 +142,18 @@
</div>
{{/if}}
</div>
{{#unless groupNo}}
<div class='shoppint-cart-icon'>
<img src="//img10.static.yhbimg.com/yhb-img01/2019/02/21/01/016b3f1cbc1b946fa0acbb1523f6386435.png"
class="shoppint-cart-icon-image"/>
</div>
{{/unless}}
{{#if isShowPop}}
<div class='old-customer-tips'>
<div class='old-customer-tips' id="isShowPop">
<img style='width:100%;height:100%' src='/static/images/group/PT_tip@3x.png'/>
</div>
{{/if}}
{{#if storage_sum }}
{{#if storage_sum}}
<button class='shoppint-cart-add'
bindtap="selfBuy" style='border-radius: 0;'>
{{#if groupNo}}
... ... @@ -166,7 +169,7 @@
bindtap="buyAction">
<span class="bottom-title">{{activityIdDetail.formatCollagePrice}}</span>
{{#if groupNo}}
<span class="bottom-title">确认参团{{#if activityIdDetail.joinLimit '==1'}},仅限新人{{/if}}</span>
<span class="bottom-title">确认参团{{#if isShowPop}},仅限新人{{/if}}</span>
{{else}}
<div class="bottom-title">{{activityIdDetail.peopleNum}}人成团</div>
{{/if}}
... ... @@ -191,7 +194,7 @@
{{#if preferenceUrl}}
<input id="preferenceUrl" type="hidden" value="{{preferenceUrl}}">
{{/if}}
<input id="activityId" type="hidden" value="{{activityId}}">
<input id="productSkn" type="hidden" value="{{productSkn}}">
<input id="brand-id" type="hidden" value="{{brandId}}">
<input id="product-limit" type="hidden" value="{{isLimitBuy}}">
... ...
<div class="group-order">
<div id="group-order" class="group-order" data-result={{result}}>
{{#if navs.length}}
<div class="group-order-header">
{{#each navs}}
... ... @@ -13,7 +13,7 @@
{{#if result.order_list}}
<div class="group-order-list">
{{#each result.order_list}}
<div class="group-order-list-cell">
<div class="group-order-list-cell" data-id={{this.order_code}} data-select-index={{../selectIndex}}>
{{#ifcond @index '===' 0 }}
<div class="list-cell-no-top-header">
{{^}}
... ... @@ -50,15 +50,28 @@
<div class="list-cell-footer">
<p class="buy-info">{{this.buy_total}}件商品 实付<span class="sum-cost price-color">¥{{this.amount}}</span>(含运费¥{{this.shipping_cost}})</p>
<div class="links-array">
{{#each this.links}}
{{#ifcond this '==' "buyNow" }}
<div class="invite-btn">立即付款</div>
{{^}}
{{#ifcond this '==' "groupInvite" }}
<div class="invite-btn">查看拼团详情</div>
{{/ifcond}}
{{/ifcond}}
{{/each}}
{{#ifcond this.pay_lefttime '==' 0}}
{{^}}
<div class="links-time">剩余:<span class="left-time"
data-value={{this.pay_lefttime}}>{{formatLeftTime}}</span>
</div>
{{/ifcond}}
<div class="links-link">
{{#each this.orderBtn}}
{{#if this.closeOrder}}
<a class="btn cancel" data-id={{this.order_code}}>取消订单</a>
{{/if}}
{{#if this.delOrder}}
<a class="btn del" data-id={{this.order_code}}>删除订单</a>
{{/if}}
{{#if this.buyNow}}
<a href={{this.link}} class="invite-btn">立即付款</a>
{{/if}}
{{#if this.groupInvite }}
<a href={{this.link}} class="invite-btn">查看拼团详情</a>
{{/if}}
{{/each}}
</div>
</div>
</div>
</div>
... ...
... ... @@ -52,13 +52,19 @@ class Detail extends Page {
lazyLoad($('img.lazy'));
this.selector = {
introUrl: $('#introUrl'),
productDesc: $('#productDesc')
productDesc: $('#productDesc'),
$date: $('#date'),
$days: $('#days'),
$hours: $('#hours'),
$minutes: $('#minutes'),
$seconds: $('#seconds'),
$label: $('#label')
};
this.getIntro();
this.goSwiper();
this.toTop();
this.startTimer();
this.actTimer();
}
getIntro() {
... ... @@ -188,8 +194,37 @@ class Detail extends Page {
}, 1000);
}
stopTimer() {
clearInterval(timer);
actTimer() {
let date = this.selector.$date[0];
const current = Number(date.getAttribute('data-current'));
const begin = Number(date.getAttribute('data-begin'));
const end = Number(date.getAttribute('data-end'));
let label;
let diff = Math.abs(begin - current > 0 ? begin - current : end - current);
if (current && begin && end) {
label = begin - current > 0 ? '距拼团开始还剩:' : '距拼团结束还剩:';
}
console.log(this.selector.$label);
this.selector.$label[0].innerText = label;
let time = setInterval(() => {
let days = Math.floor(diff / (24 * 3600));
let leave1 = diff % (24 * 3600);
let hours = Math.floor(leave1 / (3600));
let leave2 = leave1 % 3600;
let minutes = Math.floor(leave2 / 60);
let seconds = leave2 % 60;
this.selector.$days[0].innerText = days;
this.selector.$hours[0].innerText = hours;
this.selector.$minutes[0].innerText = minutes;
this.selector.$seconds[0].innerText = seconds;
--diff;
if (diff < 0) {
clearInterval(time);
window.reload();
}
}, 1000);
}
}
$(() => {
... ...
import 'scss/activity/group/group-order.page.scss';
import $ from 'yoho-jquery';
import Page from 'js/yoho-page';
const dialog = require('js/plugin/dialog'),
tip = require('js/plugin/tip');
function add0(m) {
return m < 10 ? '0' + m : m;
}
function formatDate(shijianchuo) {
// 秒数
let second = Math.floor(shijianchuo);
// 小时位
let hr = Math.floor(second / 3600);
// 分钟位
let min = Math.floor((second - hr * 3600) / 60);
// 秒位
let sec = (second - hr * 3600 - min * 60);
return add0(hr) + ':' + add0(min) + ':' + add0(sec);
}
let timer;
class GroupOrder extends Page {
constructor() {
super();
this.selector = {
$cancel: $('.cancel'),
$del: $('.del'),
$page: $('.group-order')
};
this.data = {
};
this.init();
this.startTimer();
}
init() {
this.initData();
}
initData() {
let result = this.selector.$page.data('result');
this.data.result = result;
}
startTimer() {
let list = [];
let activityGroupDetailList = document.querySelectorAll('.left-time');
for (let item of activityGroupDetailList) {
list.push(item.getAttribute('data-value'));
}
for (let i = 0; i < activityGroupDetailList.length; i++) {
list[i] = Number(list[i]) - 1;
if (list[i]) {
activityGroupDetailList[i].innerText = formatDate(list[i]);
}
}
timer = setInterval(function() {
for (let i = 0; i < activityGroupDetailList.length; i++) {
list[i] = Number(list[i]) - 1;
if (list[i]) {
activityGroupDetailList[i].innerText = formatDate(list[i]);
} else {
clearInterval(timer);
window.location.reload();
}
}
}, 1000);
}
stopTimer() {
clearInterval(timer);
}
}
$('#group-order').on('click', function(e) {
let $cur = $(e.target),
$order,
id,
selectIndex;
if ($cur.closest('.locHref').length > 0) {
return;
}
$order = $cur.closest('.group-order-list-cell');
id = $order.data('id');
selectIndex = $order.data('selectIndex');
console.log(selectIndex);
// $reaMask.data('orderId', id);
// $refundReaMask.data('orderId', id);
if ($cur.closest('.del').length > 0) {
// Order delete
dialog.showDialog({
dialogText: '确认删除该订单吗?删除了的订单不可恢复!',
hasFooter: {
leftBtnText: '取消',
rightBtnText: '确定'
}
}, function() {
$.ajax({
type: 'GET',
url: '/activity/group/delOrder',
data: {
id: id
},
success: function(data) {
dialog.hideDialog();
if (data.message) {
tip.show(data.message);
}
if (data.code === 200) {
// 删除订单页面刷新
window.location.reload();
}
},
error: function() {
tip.show('删除订单失败');
}
});
});
} else if ($cur.closest('.cancel').length > 0) {
// 取消订单
dialog.showDialog({
dialogText: selectIndex === 1 ? '确认取消该订单吗?' : '确认申请退货该订单吗?',
hasFooter: {
leftBtnText: '返回',
rightBtnText: selectIndex === 1 ? '取消订单' : '申请退款'
}
}, function() {
$.ajax({
type: 'GET',
url: '/activity/group/cancelOrder',
data: {
id: id
},
success: function(data) {
dialog.hideDialog();
if (data.message) {
tip.show(data.message);
}
if (data.code === 200) {
// 删除订单页面刷新
window.location.reload();
}
},
error: function() {
tip.show('取消订单失败');
}
});
// $reaMask.css('visibility', 'visible');
});
}
});
$(() => {
new GroupOrder();
});
... ...
... ... @@ -292,6 +292,7 @@
.shoppint-cart-add {
flex: 1;
align-items: center;
border-radius: 0;
background-color: #444;
vertical-align: center;
... ... @@ -319,6 +320,7 @@
.buynow {
flex: 1;
align-items: center;
vertical-align: center;
justify-content: center;
background-color: #d0021b;
... ...
... ... @@ -138,10 +138,22 @@
.links-array {
display: flex;
flex-direction: row;
justify-content: flex-end;
align-items: center;
padding: 27px;
border-bottom: 1px solid #e0e0e0;
.links-link {
flex-grow: 1;
display: flex;
flex-direction: row;
justify-content: flex-end;
align-items: center;
}
.links-time {
width: 200px;
}
.invite-btn {
border-radius: 10px;
height: 54px;
... ... @@ -155,6 +167,18 @@
margin-left: 10px;
padding: 0 8px 0 8px;
}
.btn {
display: inline-block;
box-sizing: border-box;
height: 54px;
line-height: 54px;
font-size: 25px;
text-align: center;
border: 1px solid #000;
border-radius: 10px;
padding: 0 8px 0 8px;
}
}
.info-title-color {
... ...