Browse Source

兼容非小程序端手机号绑定的功能

master
Gao xiaosong 4 years ago
parent
commit
b706b4f104
  1. 518
      pages/user/User/index.vue

518
pages/user/User/index.vue

@ -18,14 +18,17 @@
<text>ID{{ userInfo.uid || 0}}</text> <text>ID{{ userInfo.uid || 0}}</text>
<text class="iconfont icon-bianji1"></text> <text class="iconfont icon-bianji1"></text>
</view> </view>
<button <!-- #ifdef MP-WEIXIN -->
open-type="getPhoneNumber" <button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" class="binding" v-else>
@getphonenumber="getPhoneNumber"
class="binding"
v-else
>
<text>绑定手机号</text> <text>绑定手机号</text>
</button> </button>
<!-- #endif -->
<!-- #ifndef MP-WEIXIN -->
<button class="binding" @click="goBindPhone()" v-else>
<text>绑定手机号</text>
</button>
<!-- #endif -->
</view> </view>
</view> </view>
<text class="iconfont icon-shezhi" @click="goPersonalData()"></text> <text class="iconfont icon-shezhi" @click="goPersonalData()"></text>
@ -36,11 +39,7 @@
<text>我的余额</text> <text>我的余额</text>
<text class="num">{{ userInfo.nowMoney || 0 }}</text> <text class="num">{{ userInfo.nowMoney || 0 }}</text>
</view> </view>
<view <view @click="goUserPromotion()" class="item" v-if="userInfo.isPromoter === 1 || userInfo.statu === 2">
@click="goUserPromotion()"
class="item"
v-if="userInfo.isPromoter === 1 || userInfo.statu === 2"
>
<text>当前佣金</text> <text>当前佣金</text>
<text class="num">{{ userInfo.brokeragePrice || 0 }}</text> <text class="num">{{ userInfo.brokeragePrice || 0 }}</text>
</view> </view>
@ -65,50 +64,40 @@
<view @click="goMyOrder(0)" class="item"> <view @click="goMyOrder(0)" class="item">
<view class="pictrue"> <view class="pictrue">
<image src="@/static/images/dfk.png" /> <image src="@/static/images/dfk.png" />
<text <text class="order-status-num"
class="order-status-num" v-if="userInfo.orderStatusNum.unpaidCount > 0">{{ userInfo.orderStatusNum.unpaidCount }}</text>
v-if="userInfo.orderStatusNum.unpaidCount > 0"
>{{ userInfo.orderStatusNum.unpaidCount }}</text>
</view> </view>
<view>待付款</view> <view>待付款</view>
</view> </view>
<view @click="goMyOrder(1)" class="item"> <view @click="goMyOrder(1)" class="item">
<view class="pictrue"> <view class="pictrue">
<image src="@/static/images/dfh.png" /> <image src="@/static/images/dfh.png" />
<text <text class="order-status-num"
class="order-status-num" v-if="userInfo.orderStatusNum.unshippedCount > 0">{{ userInfo.orderStatusNum.unshippedCount }}</text>
v-if="userInfo.orderStatusNum.unshippedCount > 0"
>{{ userInfo.orderStatusNum.unshippedCount }}</text>
</view> </view>
<view>待发货</view> <view>待发货</view>
</view> </view>
<view @click="goMyOrder(2)" class="item"> <view @click="goMyOrder(2)" class="item">
<view class="pictrue"> <view class="pictrue">
<image src="@/static/images/dsh.png" /> <image src="@/static/images/dsh.png" />
<text <text class="order-status-num"
class="order-status-num" v-if="userInfo.orderStatusNum.receivedCount > 0">{{ userInfo.orderStatusNum.receivedCount }}</text>
v-if="userInfo.orderStatusNum.receivedCount > 0"
>{{ userInfo.orderStatusNum.receivedCount }}</text>
</view> </view>
<text>待收货</text> <text>待收货</text>
</view> </view>
<view @click="goMyOrder(3)" class="item"> <view @click="goMyOrder(3)" class="item">
<view class="pictrue"> <view class="pictrue">
<image src="@/static/images/dpj.png" /> <image src="@/static/images/dpj.png" />
<text <text class="order-status-num"
class="order-status-num" v-if="userInfo.orderStatusNum.evaluatedCount > 0">{{ userInfo.orderStatusNum.evaluatedCount }}</text>
v-if="userInfo.orderStatusNum.evaluatedCount > 0"
>{{ userInfo.orderStatusNum.evaluatedCount }}</text>
</view> </view>
<text>待评价</text> <text>待评价</text>
</view> </view>
<view @click="goReturnList()" class="item"> <view @click="goReturnList()" class="item">
<view class="pictrue"> <view class="pictrue">
<image src="@/static/images/sh.png" /> <image src="@/static/images/sh.png" />
<text <text class="order-status-num"
class="order-status-num" v-if="userInfo.orderStatusNum.refundCount > 0">{{ userInfo.orderStatusNum.refundCount }}</text>
v-if="userInfo.orderStatusNum.refundCount > 0"
>{{ userInfo.orderStatusNum.refundCount }}</text>
</view> </view>
<text>售后/退款</text> <text>售后/退款</text>
</view> </view>
@ -148,258 +137,275 @@
</view> </view>
</template> </template>
<script> <script>
import { mapState, mapGetters, mapMutations, mapActions } from "vuex"; import {
import { getUserInfo, getMenuUser, bindingPhone } from "@/api/user"; mapState,
import { isWeixin, VUE_APP_RESOURCES_URL } from "@/utils"; mapGetters,
import SwitchWindow from "@/components/SwitchWindow"; mapMutations,
import Authorization from "@/pages/authorization/index"; mapActions
} from "vuex";
import {
getUserInfo,
getMenuUser,
bindingPhone
} from "@/api/user";
import {
isWeixin,
VUE_APP_RESOURCES_URL
} from "@/utils";
import SwitchWindow from "@/components/SwitchWindow";
import Authorization from "@/pages/authorization/index";
const NAME = "User"; const NAME = "User";
export default { export default {
name: NAME, name: NAME,
components: { components: {
SwitchWindow, SwitchWindow,
Authorization Authorization
},
props: {},
data: function() {
return {
MyMenus: [],
switchActive: false,
isWeixin: false
};
},
computed: mapGetters(["userInfo"]),
methods: {
...mapMutations(["updateAuthorizationPage"]),
goReturnList() {
this.$yrouter.push("/pages/order/ReturnList/index");
},
goMyOrder(type) {
this.$yrouter.push({
path: "/pages/order/MyOrder/index",
query: {
type
}
});
},
goUserCoupon() {
this.$yrouter.push("/pages/user/coupon/UserCoupon/index");
},
goIntegral() {
this.$yrouter.push("/pages/user/signIn/Integral/index");
},
goUserPromotion() {
this.$yrouter.push("/pages/user/promotion/UserPromotion/index");
}, },
goUserAccount() { props: {},
this.$yrouter.push({ data: function () {
path: "/pages/user/UserAccount/index" return {
}); MyMenus: [],
switchActive: false,
isWeixin: false
};
}, },
goPersonalData() { computed: mapGetters(["userInfo"]),
this.$yrouter.push("/pages/user/PersonalData/index"); methods: {
}, ...mapMutations(["updateAuthorizationPage"]),
getPhoneNumber: function(e) { goReturnList() {
let thit = this; this.$yrouter.push("/pages/order/ReturnList/index");
// },
if (e.mp.detail.errMsg == "getPhoneNumber:ok") { goMyOrder(type) {
uni.showLoading({ this.$yrouter.push({
title: "绑定中" path: "/pages/order/MyOrder/index",
}); query: {
// type
uni.getProvider({
service: "oauth",
success: function(res) {
// h5
if (res.provider) {
uni.login({
success: loginRes => {
bindingPhone({
code: loginRes.code,
encryptedData: e.mp.detail.encryptedData,
iv: e.mp.detail.iv
})
.then(res => {
console.log(res);
// this.User();
thit.$store.dispatch("userInfo", true);
uni.hideLoading();
uni.showToast({
title: res.msg,
icon: "success",
duration: 2000
});
})
.catch(error => {
uni.hideLoading();
thit.$store.dispatch("userInfo", true);
console.log(error);
uni.showToast({
title:
error.msg ||
error.response.data.msg ||
error.response.data.message,
icon: "none",
duration: 2000
});
});
},
fail() {
reject("绑定失败");
}
});
}
},
fail() {
reject("获取环境服务商失败");
} }
}); });
} else { },
uni.showToast({ goBindPhone(){
title: "已拒绝授权", this.$yrouter.push({
icon: "none", path: "/pages/user/BindingPhone/index",
duration: 2000
}); });
} },
}, goUserCoupon() {
changeswitch: function(data) { this.$yrouter.push("/pages/user/coupon/UserCoupon/index");
this.switchActive = data; },
}, goIntegral() {
User: function() { this.$yrouter.push("/pages/user/signIn/Integral/index");
let that = this; },
getUserInfo().then(res => { goUserPromotion() {
that.user = res.data; this.$yrouter.push("/pages/user/promotion/UserPromotion/index");
that.orderStatusNum = res.data.orderStatusNum; },
}); goUserAccount() {
}, this.$yrouter.push({
MenuUser: function() { path: "/pages/user/UserAccount/index"
let that = this;
getMenuUser()
.then(res => {
uni.hideLoading();
that.MyMenus = res.data.routine_my_menus;
})
.catch(error => {
uni.hideLoading();
console.log(error);
}); });
}, },
goPages: function(index) { goPersonalData() {
let url = this.MyMenus[index].uniapp_url; this.$yrouter.push("/pages/user/PersonalData/index");
if ( },
url === "/pages/user/promotion/UserPromotion/index" && getPhoneNumber: function (e) {
this.userInfo.statu === 1 let thit = this;
) { //
if (!this.userInfo.isPromoter) { if (e.mp.detail.errMsg == "getPhoneNumber:ok") {
uni.showLoading({
title: "绑定中"
});
//
uni.getProvider({
service: "oauth",
success: function (res) {
// h5
if (res.provider) {
uni.login({
success: loginRes => {
bindingPhone({
code: loginRes.code,
encryptedData: e.mp.detail.encryptedData,
iv: e.mp.detail.iv
})
.then(res => {
console.log(res);
// this.User();
thit.$store.dispatch("userInfo", true);
uni.hideLoading();
uni.showToast({
title: res.msg,
icon: "success",
duration: 2000
});
})
.catch(error => {
uni.hideLoading();
thit.$store.dispatch("userInfo", true);
console.log(error);
uni.showToast({
title: error.msg ||
error.response.data.msg ||
error.response.data.message,
icon: "none",
duration: 2000
});
});
},
fail() {
reject("绑定失败");
}
});
}
},
fail() {
reject("获取环境服务商失败");
}
});
} else {
uni.showToast({ uni.showToast({
title: "您还没有推广权限!!", title: "已拒绝授权",
icon: "none",
duration: 2000
});
}
},
changeswitch: function (data) {
this.switchActive = data;
},
User: function () {
let that = this;
getUserInfo().then(res => {
that.user = res.data;
that.orderStatusNum = res.data.orderStatusNum;
});
},
MenuUser: function () {
let that = this;
getMenuUser()
.then(res => {
uni.hideLoading();
that.MyMenus = res.data.routine_my_menus;
})
.catch(error => {
uni.hideLoading();
console.log(error);
});
},
goPages: function (index) {
let url = this.MyMenus[index].uniapp_url;
if (
url === "/pages/user/promotion/UserPromotion/index" &&
this.userInfo.statu === 1
) {
if (!this.userInfo.isPromoter) {
uni.showToast({
title: "您还没有推广权限!!",
icon: "none",
duration: 2000
});
return;
}
}
if (
url === "/pages/orderAdmin/OrderIndex/index" &&
!this.userInfo.adminid
) {
uni.showToast({
title: "您还不是管理员!!",
icon: "none",
duration: 2000
});
return;
}
console.log(this.userInfo)
if (url === "/pages/orderAdmin/OrderCancellation/index" && !this.userInfo.checkStatus) {
uni.showToast({
title: "您没有核销权限,请后台店员设置!!",
icon: "none", icon: "none",
duration: 2000 duration: 2000
}); });
return; return;
} }
}
if ( this.$yrouter.push({
url === "/pages/orderAdmin/OrderIndex/index" && path: this.MyMenus[index].uniapp_url
!this.userInfo.adminid
) {
uni.showToast({
title: "您还不是管理员!!",
icon: "none",
duration: 2000
}); });
return; },
goPages2: function () {
this.$yrouter.push({
path: "/pages/orderAdmin/OrderCancellation/index"
});
}
},
watch: {
userInfo() {
this.MenuUser();
} }
console.log(this.userInfo) },
if (url === "/pages/orderAdmin/OrderCancellation/index" && !this.userInfo.checkStatus) { onShow() {
uni.showToast({ if (this.$store.getters.token) {
title: "您没有核销权限,请后台店员设置!!", //
icon: "none", uni.showLoading({
duration: 2000 title: "加载中"
}); });
return; this.$store.dispatch("getUser", true);
this.MenuUser();
this.isWeixin = isWeixin();
} }
this.$yrouter.push({
path: this.MyMenus[index].uniapp_url
});
}, },
goPages2: function() { onHide() {
this.$yrouter.push({ console.log("离开用户中心");
path: "/pages/orderAdmin/OrderCancellation/index" this.updateAuthorizationPage(false);
});
}
},
watch: {
userInfo() {
this.MenuUser();
} }
}, };
onShow() {
if (this.$store.getters.token) {
//
uni.showLoading({
title: "加载中"
});
this.$store.dispatch("getUser", true);
this.MenuUser();
this.isWeixin = isWeixin();
}
},
onHide() {
console.log("离开用户中心");
this.updateAuthorizationPage(false);
}
};
</script> </script>
<style lang="less"> <style lang="less">
.footer-line-height { .footer-line-height {
height: 1 * 100rpx; height: 1 * 100rpx;
} }
.order-status-num { .order-status-num {
min-width: 0.33 * 100rpx; min-width: 0.33 * 100rpx;
background-color: #fff; background-color: #fff;
color: #eb3729; color: #eb3729;
border-radius: 15px; border-radius: 15px;
position: absolute; position: absolute;
right: -0.14 * 100rpx; right: -0.14 * 100rpx;
top: -0.15 * 100rpx; top: -0.15 * 100rpx;
font-size: 0.2 * 100rpx; font-size: 0.2 * 100rpx;
padding: 0 0.08 * 100rpx; padding: 0 0.08 * 100rpx;
border: 1px solid #eb3729; border: 1px solid #eb3729;
} }
.pictrue { .pictrue {
position: relative; position: relative;
} }
.switch-h5 { .switch-h5 {
margin-left: 0.2 * 100rpx; margin-left: 0.2 * 100rpx;
} }
.binding { .binding {
margin-top: 0.1 * 100rpx; margin-top: 0.1 * 100rpx;
display: inline-block; display: inline-block;
padding: 0.05 * 100rpx 0.2 * 100rpx; padding: 0.05 * 100rpx 0.2 * 100rpx;
background-color: #ca1f10; background-color: #ca1f10;
border-radius: 50px; border-radius: 50px;
font-size: 0.22 * 100rpx; font-size: 0.22 * 100rpx;
line-height: 1.5; line-height: 1.5;
border: 1px solid #e8695e; border: 1px solid #e8695e;
color: #ffffff; color: #ffffff;
} }
.by { .by {
text-align: center; text-align: center;
padding: 30rpx 0; padding: 30rpx 0;
} }
.by-text {
text-align: center; .by-text {
font-size: 24rpx; text-align: center;
} font-size: 24rpx;
}
</style> </style>

Loading…
Cancel
Save