Skip to content

Commit

Permalink
Merge pull request #15 from coolhwm/dev
Browse files Browse the repository at this point in the history
BUG 修订
  • Loading branch information
coolhwm committed Nov 22, 2017
2 parents 4df30d6 + 45beeb6 commit 2f6f3d5
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/api/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class auth extends base {
return true;
}
// 重新登录
await this.login();
await this.doLogin();
// 获取用户信息
const rawUser = userInfo != null ? userInfo : await wepy.getUserInfo();
// 检查是否通过
Expand Down
4 changes: 2 additions & 2 deletions src/app.wpy
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ export default class extends wepy.app {
scene: '',
shopType: null,
app_code: null,
// baseUrl: 'https://api.leshare.shop/v2/customer'
baseUrl: 'https://api.leshare.shop/v2/customer'
// baseUrl: 'http://192.168.31.124:9999/v2/customer',
baseUrl: 'http://106.14.195.68:9999/v2/customer'
// baseUrl: 'http://106.14.195.68:9999/v2/customer'
}
}
</script>
14 changes: 8 additions & 6 deletions src/components/customer/vip_card.wpy
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@

<!--用户信息-->
<view class="info-box column">
<view class="row">
<text class="xxl">{{userInfo.nickName ? userInfo.nickName : '微信用户'}}</text>
<text class="ml10 xs">{{levelName}}</text>
</view>
<text class="user-name">{{userInfo.nickName ? userInfo.nickName : '微信用户'}}</text>
<text class="sm">{{levelName}}</text>
<view class="cost-box row">
<text class="xs">累计消费: {{member.totalCost}}元</text>
<text class="ml20 xs" wx:if="{{vipCard.supplyBonus == 1}}">积分: {{member.bonus}}</text>
<text class="sm">累计消费: {{member.totalCost}}元</text>
<text class="ml20 sm" wx:if="{{vipCard.supplyBonus == 1}}">积分: {{member.bonus}}</text>
</view>
</view>
</view>
Expand Down Expand Up @@ -146,6 +144,10 @@
}
.info-box {
margin-left: 30rpx;

.user-name{
font-size: 36rpx;
}
}
.cost-box{
margin-top: 10rpx;
Expand Down
18 changes: 13 additions & 5 deletions src/pages/customer/index.wpy
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
import base from '../../mixins/base';
import order from '../../api/order';
import auth from '../../api/auth';
import vip from '../../api/member_card';
import member from '../../api/member';
import pagination from '../../mixins/pagination';
import Placeholder from '../../components/common/placeholder';
Expand Down Expand Up @@ -111,8 +110,9 @@
const result = await auth.user({block: true, redirect: true});
if (!result) return;
this.loadUserInfo();
this.member = await member.info();
this.vipCard = await vip.info();
const {card, member} = await Cache.vip();
this.member = member;
this.vipCard = card;
// 加载店铺信息
this.shop = await Cache.shop();
this.shop.notices = await Cache.notices();
Expand All @@ -124,6 +124,12 @@
Event.listen(Event.REGISTE_MEMBER_UPDATE, this.updataCustomerInfo.bind(this), this);
Event.listen(Event.MEMBER_CARD_UPDATE, this.updateMemberCard.bind(this), this);
};
async onPullDownRefresh() {
const {card, member} = await Cache.vip(true);
this.member = member;
this.vipCard = card;
this.loaded();
}
loadUserInfo() {
try {
const value = wepy.getStorageSync('user');
Expand All @@ -134,8 +140,10 @@
console.log(e)
}
}
async updateMemberCard (memberInfo) {
this.member = memberInfo;
async updateMemberCard () {
const {card, member} = await Cache.vip();
this.member = member;
this.vipCard = card;
this.$apply();
}
async updateOrderList() {
Expand Down
75 changes: 67 additions & 8 deletions src/pages/customer/registe_member.wpy
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<template>
<Tips/>
<view class="mt20"></view>
<view class="container registe-box" wx:if="{{init}}">
<view class="weui-cells weui-cells-form">
<view class="container " wx:if="{{init}}">
<view class="weui-cells weui-cells-form registe-box">
<view class="weui-cell weui-cell_input weui-cell_vcode">
<view class="weui-cell__hd">
<view class="weui-label">手机号码</view>
Expand Down Expand Up @@ -50,9 +50,24 @@
</view>
</view>
</view>

<view class="tips-box column">
<text>加入会员可享受下列特权:</text>
<block wx:if="{{discountRuleText.length > 0}}">
<text>• 会员折扣</text>
<text wx:for="{{discountRuleText}}" class="ml20">- {{item}}</text>
</block>
<block wx:if="{{bonusRuleText.length > 0}}">
<text>• 会员积分</text>
<text wx:for="{{bonusRuleText}}" class="ml20">- {{item}}</text>
</block>
</view>

<!--操作栏-->
<ActionBar @tap.user="add" okText="注册" cancelText="返回"/>

</view>

</template>
<script>
import wepy from 'wepy';
Expand All @@ -64,20 +79,25 @@
import VCode from '../../components/weui/vcode';
import Tips from '../../utils/Tips';
import Event from '../../utils/Event';
import WxUtils from '../../utils/WxUtils';
import Cache from '../../utils/Cache';

export default class RegisteMember extends wepy.page {
def = {
item: [
{id: 0, name: 'man', value: '男'},
{id: 1, name: 'wman', value: '女'}
],
vipCard: null,
registeInfo: {},
init: false
};
data = {...this.def};

onLoad () {
this.init = true;
async onLoad () {
const {card} = await Cache.vip();
this.vipCard = card;
this.loaded();
};

methods = {
Expand Down Expand Up @@ -113,21 +133,53 @@
}
},
async add () {
if (!this.validate()) {
return;
}
if (!this.validate()) return;
this.registeInfo = this.input;
try {
await member.create(this.registeInfo, this.input.code);
await Tips.success('注册成功');
await Cache.vip(true);
Event.emit(Event.REGISTE_MEMBER_UPDATE);
wepy.navigateBack();
WxUtils.backOrRedirect('/pages/customer/index');
} catch (error) {
this.tips(error.message);
Tips.loaded();
}
}
};
computed = {
bonusRuleText() {
if (this.vipCard == null) return;
const rule = this.vipCard.bonusRule;
let describes = [];
// 开启积分规则
if (this.vipCard.supplyBonus == 1 && this.vipCard.bonusRule != null) {
// 有初始积分的情况
if (rule.initIncreaseBonus > 0) {
describes.push(`注册绑定手机开卡即送 ${rule.initIncreaseBonus} 积分`);
}
describes.push(`每消费 ${rule.costMoneyUnit} 元可获得 ${rule.increaseBonus} 积分`);
describes.push(`每使用 ${rule.costBonusUnit} 积分,抵扣 ${rule.reduceMoney} 元现金,每笔订单最多使用 ${rule.maxReduceBonus} 积分,订单需满 ${rule.limitMoney} 元`);
}
return describes;
},
discountRuleText() {
if (this.vipCard == null) return;
const rules = this.vipCard.discountRules;
if (this.vipCard.supplyDiscount == 0 || rules == null) return;
const describes = [];
// 有折扣的情况
for (let rule of rules) {
const {upgradeFee, discount, levelName} = rule;
if (discount == 100) continue;
const upgradeText = upgradeFee == 0 ? '完成注册' : `消费满${upgradeFee}元`;
const discountText = (discount / 10).toFixed(1);
const describe = `${levelName}:${upgradeText},部分商品${discountText}折优惠`;
describes.push(describe);
}
return describes;
}
};
components = {
ActionBar: ActionBar,
Tips: FormTips,
Expand Down Expand Up @@ -180,4 +232,11 @@
.registe-box {
background-color: white;
}
.tips-box{
margin-top: 20rpx;
padding: 20rpx;
text{
color: $color-muted;
}
}
</style>
59 changes: 47 additions & 12 deletions src/pages/customer/vip_info.wpy
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@
</template>
<script>
import wepy from 'wepy';
import auth from '../../api/auth';
import base from '../../mixins/base';
import shopInfo from '../../api/shop'
import member from '../../api/member'
import Tips from '../../utils/Tips'
import Event from '../../utils/Event'
import vip from '../../api/member_card';
import shopInfo from '../../api/shop';
import member from '../../api/member';
import Tips from '../../utils/Tips';
import Event from '../../utils/Event';
import WxUtils from '../../utils/WxUtils';
import Cache from '../../utils/Cache';
let interval = null;
export default class VipInfo extends wepy.page {
def = {
Expand All @@ -46,11 +50,31 @@
data = {...this.def};

async onLoad (options, {preload}) {
this.shopInfo = await shopInfo.info();
const param = preload.param;
this.userInfo = param.userInfo;
this.cardInfo = param.vipCard;
this.member = param.member;
// 要求会员授权
const result = await auth.user({block: true, redirect: true});
if (!result) return;
this.shopInfo = await Cache.shop();
// 加载数据
if (preload && preload.param) {
// preload 情况
const param = preload.param;
this.userInfo = param.userInfo;
this.cardInfo = param.vipCard;
this.member = param.member;
} else {
// 直接进入页面的情况
const {card, member} = await Cache.vip();
this.member = member;
this.vipCard = card;
this.userInfo = this.loadUserInfo();
}
// 没注册的会员引导注册
if (this.member == null) {
await Tips.alert('请先注册会员');
this.$redirect('/pages/customer/registe_member');
return;
}
// 增加定时器扫描
interval = setInterval(async () => {
Tips.setLoading();
await this.getTotalCost();
Expand All @@ -65,6 +89,16 @@
// 清理定时器
clearInterval(interval);
}
loadUserInfo() {
try {
const value = wepy.getStorageSync('user');
if (value) {
return value;
}
} catch (e) {
console.log(e)
}
}
async getTotalCost() {
const memberInfo = await member.info();
if (this.member.totalCost != memberInfo.totalCost) {
Expand All @@ -81,10 +115,11 @@
}
this.scanning = true;
Tips.success('扫描成功!');
Event.emit(Event.MEMBER_CARD_UPDATE, memberInfo);
await Cache.vip(true);
Event.emit(Event.MEMBER_CARD_UPDATE);
clearInterval(interval);
this.$apply();
setTimeout(async () => wepy.navigateBack(), 3000);
this.loaded();
setTimeout(async () => WxUtils.backOrRedirect('/pages/customer/index'), 3000);
}
};
computed = {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/login.wpy
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
await auth.user({block: false, redirect: false}, detail);
Tips.success('授权成功');
if (this.redirect == 'true') {
this.$redirect('/pages/shop/index');
this.$redirect('/pages/customer/index');
} else {
wepy.navigateBack();
}
Expand Down
1 change: 0 additions & 1 deletion src/pages/order/detail.wpy
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@
};
data = {...this.def};
async onLoad ({orderId}) {
console.log(orderId)
const result = await auth.user({block: true, redirect: true});
if (!result) return;
// 订单信息
Expand Down

0 comments on commit 2f6f3d5

Please sign in to comment.