Browse Source

Merge branch 'master' of http://git.cc-lotus.info/pointToNetwork/point-app

zs 2 years ago
parent
commit
616bd20db4
2 changed files with 233 additions and 170 deletions
  1. 229 166
      pages/login/index.vue
  2. 4 4
      pagesHome/order/detail.vue

+ 229 - 166
pages/login/index.vue

@@ -20,7 +20,7 @@
 					<text class="iconfont icon-weixin"></text>
 				</view>
 				<view class="btn">
-					<button type="default" size="mini" @tap="wxLogin()" :open-type="openType" @getphonenumber="getUserPhone">微信信任登录</button>
+					<button type="default" size="mini" @tap="wxLogin()">微信信任登录</button>
 				</view>
 			</view>
 			<view class="thr">
@@ -34,6 +34,36 @@
 				</view>
 			</view>
 		</view>
+		<uni-popup ref="dialogShow" type="dialog">
+			<uni-popup-dialog :title="dialog.title" mode="base" :before-close="true" @confirm="diaSubmit(dialog)" @close="diaReset(dialog)">
+				<view class="dialog dialog_1" v-if="dialog.type=='1'">
+					<uni-forms ref="phoneForm" :model="phoneForm" label-width="auto">
+						<uni-forms-item label="方式">
+							<uni-data-checkbox v-model="phoneForm.type" :localdata="typeList" />
+						</uni-forms-item>
+						<uni-forms-item label="微信" v-if="phoneForm.type==0">
+							<button type="default" size="mini" open-type="getPhoneNumber" @getphonenumber="getUserPhone">获取微信绑定手机</button>
+						</uni-forms-item>
+						<uni-forms-item label="手机号" v-if="phoneForm.type==0">
+							<uni-easyinput type="number" v-model="phoneForm.phone" disabled />
+						</uni-forms-item>
+						<uni-forms-item label="手机号" v-if="phoneForm.type==1">
+							<view class="yzm">
+								<view class="l">
+									<uni-easyinput type="number" v-model="phoneForm.phone" placeholder="请输入手机号" />
+								</view>
+								<view class="r">
+									<button type="default" size="mini" @tap="sendCount">{{time_count==0?'验证码':time_count}}</button>
+								</view>
+							</view>
+						</uni-forms-item>
+						<uni-forms-item label="验证码" v-if="phoneForm.type==1">
+							<uni-easyinput type="number" v-model="phoneForm.code" placeholder="请输入验证码" />
+						</uni-forms-item>
+					</uni-forms>
+				</view>
+			</uni-popup-dialog>
+		</uni-popup>
 	</mobile-frame>
 </template>
 
@@ -71,7 +101,28 @@
 				// 微信登陆
 				// 无账号
 				is_user: false,
-				openType: '',
+				user: {},
+				// 弹框
+				dialog: {
+					title: '绑定手机号',
+					type: '1'
+				},
+				// 绑定手机号
+				phoneForm: {
+					type: 0,
+				},
+				typeList: [ //
+					{
+						text: '微信',
+						value: 0
+					},
+					{
+						text: '短信验证',
+						value: 1
+					}
+				],
+				// 倒计时
+				time_count: 0
 			};
 		},
 		onShow: function() {
@@ -79,18 +130,6 @@
 			that.search();
 		},
 		methods: {
-			// 同意隐私协议
-			changeAgree() {
-				const that = this;
-				if (that.agree) that.$set(that, `agree`, false)
-				else that.$set(that, `agree`, true);
-			},
-			// 查看隐私协议
-			toAgree() {
-				uni.navigateTo({
-					url: `/pages/other/agree`
-				})
-			},
 			search() {
 				const that = this;
 				uni.getStorage({
@@ -127,7 +166,7 @@
 					console.log('to do');
 				}
 			},
-			// 微信登录
+			// 有账号,微信登录,直接返回上一页
 			async openidLogin(e) {
 				const that = this;
 				let res = await that.$api(`/user/wxLogin`, 'POST', {
@@ -166,25 +205,9 @@
 							}
 							const arr = await that.$api(`/user`, 'POST', parmas);
 							if (arr.errcode == '0') {
-								const agg = await that.$api(`/user/wxLogin`, 'POST', {
-									openid: that.openid
-								})
-								if (agg.errcode == '0') {
-									uni.setStorage({
-										data: agg.data,
-										key: 'token',
-										success: function() {
-											uni.navigateBack({
-												delta: 1
-											})
-										}
-									})
-								} else {
-									uni.showToast({
-										title: agg.errmsg,
-										icon: 'none'
-									});
-								}
+								that.$set(that, `user`, arr.data);
+								// 打开弹框
+								that.diaShow();
 							} else {
 								uni.showToast({
 									title: arr.errmsg,
@@ -204,142 +227,138 @@
 					})
 				}
 			},
-			// 获取手机号
-			getUserPhone(e) {
-				console.log('1');
+			// 微信信任登录-1
+			async wxLogins() {
 				const that = this;
+				const agg = await that.$api(`/user/wxLogin`, 'POST', {
+					openid: that.openid
+				})
+				if (agg.errcode == '0') {
+					uni.setStorage({
+						data: agg.data,
+						key: 'token',
+						success: function() {
+							uni.navigateBack({
+								delta: 1
+							})
+						}
+					})
+				} else {
+					uni.showToast({
+						title: agg.errmsg,
+						icon: 'none'
+					});
+				}
 			},
-		}
-		// },
-		// // 微信信任登录
-		// wxLogin() {
-		// 	const that = this;
-		// 	let agree = that.agree;
-		// 	if (agree) {
-		// 		uni.getUserProfile({
-		// 			desc: '用户展示',
-		// 			success: function(res) {
-		// 				uni.login({
-		// 					success: function(resl) {
-
-		// 					},
-		// 					fail: function(errl) {
-		// 						console.log(errl);
-		// 					}
-		// 				})
-		// 			},
-		// 			fail: function(err) {
-		// 				console.log(err);
-		// 			}
-		// 		})
-		// 		// uni.login({
-		// 		// 	success: async function(event) {
-		// 		// 		const res = await that.$api(`/wechat/api/login/app`, 'GET', {
-		// 		// 			js_code: event.code,
-		// 		// 			config: 'pointApp'
-		// 		// 		})
-		// 		// 		if (res.errcode == '0') {
-		// 		// 			// 用openid登录
-		// 		// 			// that.openidLogin(res.data.openid);
-		// 		// 			let arr = await that.$api(`/user/wxLogin`, 'POST', {
-		// 		// 				openid: res.data.openid
-		// 		// 			})
-		// 		// 			if (arr.errcode == '0') {
-		// 		// 				console.log('登录成功');
-		// 		// 			} else {
-		// 		// 				if (arr.errcode == '-5') {
-		// 		// 					// 去注册
-		// 		// 					// that.registerWxuser(e);
-		// 		// 					that.$set(that, `errcode`, arr.errcode)
-		// 		// 				} else {
-		// 		// 					uni.showToast({
-		// 		// 						title: arr.errmsg,
-		// 		// 						icon: 'none'
-		// 		// 					})
-		// 		// 				}
-		// 		// 			}
-		// 		// 		} else {
-		// 		// 			console.log(res);
-		// 		// 		}
-		// 		// 	}
-		// 		// })
-		// 		// console.log(that.errcode);
-		// 		// console.log('1');
-		// 		// if (that.errcode == '-5') {
-		// 		// 	console.log('2');
-		// 		// 	uni.getUserProfile({
-		// 		// 		desc: '用户展示',
-		// 		// 		success: function(res) {
-		// 		// 			console.log(res);
-		// 		// 			console.log(e);
-		// 		// 		},
-		// 		// 		fail: function(err) {
-		// 		// 			console.log(err);
-		// 		// 		}
-		// 		// 	})
-		// 		// }
-
-		// 	} else {
-		// 		uni.showToast({
-		// 			title: '请阅读并同意用户协议和隐私政策',
-		// 			icon: 'none'
-		// 		})
-		// 	}
-		// },
-		// // openid登录
-		// async openidLogin(e) {
-		// 	const that = this;
-		// 	let res = await that.$api(`/user/wxLogin`, 'POST', {
-		// 		openid: e
-		// 	})
-		// 	if (res.errcode == '0') {
-		// 		console.log('登录成功');
-		// 	} else {
-		// 		if (res.errcode == '-5') {
-		// 			// 去注册
-		// 			that.registerWxuser(e);
-		// 		} else {
-		// 			uni.showToast({
-		// 				title: res.errmsg,
-		// 				icon: 'none'
-		// 			})
-		// 		}
-		// 	}
-		// },
-		// // wx注册
-		// registerWxuser(e) {
-		// 	const that = this;
-		// 	console.log(e);
-		// 	uni.getUserProfile({
-		// 		desc: '用户展示',
-		// 		success: function(res) {
-		// 			console.log(res);
-		// 			console.log(e);
-		// 		},
-		// 		fail: function(err) {
-		// 			console.log(err);
-		// 		}
-		// 	})
-		// },
-		// // 账号登录
-		// toSubmit(ref) {
-		// 	const that = this;
-		// 	that.$refs[ref].validate().then(async params => {
-		// 		let agree = that.agree;
-		// 		if (agree) {
-		// 			console.log(params);
-		// 		} else {
-		// 			uni.showToast({
-		// 				title: '请阅读并同意用户协议和隐私政策',
-		// 				icon: 'none'
-		// 			})
-		// 		}
+			// 打开弹框,绑定手机号
+			diaShow() {
+				const that = this;
+				that.$refs.dialogShow.open();
+			},
+			// 获取手机号
+			async getUserPhone(e) {
+				const that = this;
+				let user = that.user;
+				let detail = e.detail;
+				let res = await that.$api(`/wechat/api/login/getPhone`, 'GET', {
+					config: 'pointApp',
+					code: detail.code
+				})
+				if (res.errcode == '0') {
+					let phone = res.data && res.data.phone_info && res.data.phone_info.purePhoneNumber || '';
+					that.$set(that.phoneForm, `phone`, phone);
+				} else {
+					uni.showToast({
+						title: res.errmsg,
+						icon: 'none'
+					})
+				}
 
-		// 	}).catch(err => {
-		// 		console.log(err);
-		// 	})
-		// },
+			},
+			// 短信验证
+			// 获取验证码
+			sendCount() {
+				const that = this;
+				let form = that.phoneForm;
+				if (form && form.phone) {
+					let time_count = 60;
+					that.$set(that, `time_count`, time_count);
+					that.timeDown();
+				} else {
+					uni.showToast({
+						title: '输入错误,请重新输入!',
+						icon: 'none'
+					})
+				}
+			},
+			// 倒计时
+			timeDown() {
+				const that = this;
+				var times = setInterval(() => {
+					that.time_count--;
+					if (that.time_count <= 0) {
+						clearInterval(times);
+					}
+				}, 1000);
+			},
+			// 弹框确认(关闭)
+			async diaSubmit(e) {
+				const that = this;
+				let user = this.user;
+				if (e.type == '1') {
+					const that = this;
+					let form = that.phoneForm;
+					if (form.type == '0') {
+						if (form && form.phone) that.updatePhone(form.phone);
+					} else if (form.type == '1') {
+						let code = '1234';
+						if (form.code == code) {
+							if (form && form.phone) that.updatePhone(form.phone);
+						} else {
+							uni.showToast({
+								title: '短信验证失败,请重新输入!',
+								icon: 'none'
+							})
+						}
+					}
+				}
+			},
+			async updatePhone(e) {
+				const that = this;
+				let user = that.user;
+				let arr = await that.$api(`/user/${user._id}`, 'POST', {
+					phone: e
+				})
+				if (arr.errcode == '0') {
+					that.wxLogins();
+				} else {
+					uni.showToast({
+						title: res.errmsg,
+						icon: 'none'
+					})
+				}
+			},
+			// 弹框取消(关闭)
+			diaReset(e) {
+				const that = this;
+				if (e.type == '1') {
+					that.wxLogins();
+				}
+			},
 
+			// 同意隐私协议
+			changeAgree() {
+				const that = this;
+				if (that.agree) that.$set(that, `agree`, false)
+				else that.$set(that, `agree`, true);
+			},
+			// 查看隐私协议
+			toAgree() {
+				uni.navigateTo({
+					url: `/pages/other/agree`
+				})
+			},
+		}
 	}
 </script>
 
@@ -391,4 +410,48 @@
 			}
 		}
 	}
+
+	.dialog {
+		width: 100vw;
+	}
+
+	.dialog_1 {
+		.uni-forms {
+			display: flex;
+
+			form {
+				width: 100%;
+			}
+		}
+	}
+
+	.uni-data-checklist {
+		border: 1px solid #E5E5E5;
+		padding: 1vw;
+		border-radius: 5px;
+	}
+
+	.uni-forms-item {
+		margin-bottom: 2vw !important;
+	}
+
+	.yzm {
+		display: flex;
+		flex-direction: row;
+		justify-content: space-between;
+
+		.l {
+			flex-grow: 1;
+		}
+
+		.r {
+			width: 18vw;
+
+			button {
+				width: 100%;
+				line-height: 2.8;
+				padding: 0 1vw;
+			}
+		}
+	}
 </style>

+ 4 - 4
pagesHome/order/detail.vue

@@ -434,10 +434,10 @@
 						that.searchOther();
 					},
 					fail: function(err) {
-						uni.showToast({
-							title: '无用户登录无法查看收藏信息',
-							icon: 'none'
-						})
+						// uni.showToast({
+						// 	title: '无用户登录无法查看收藏信息',
+						// 	icon: 'none'
+						// })
 					}
 				});
 				let res = await that.$api(`/viewGoods/goodsDetail`, `POST`, {