YY 2 år sedan
förälder
incheckning
91e969ee28
1 ändrade filer med 58 tillägg och 34 borttagningar
  1. 58 34
      pagesMy/account/upPassword.vue

+ 58 - 34
pagesMy/account/upPassword.vue

@@ -3,14 +3,14 @@
 		<view class="main">
 			<view class="one">
 				<uni-forms ref="form" :modelValue="form" :rules="rules" label-width="auto">
-					<uni-forms-item label="用户账号" name="name">
-						<uni-easyinput type="text" v-model="form.name" placeholder="请输入用户账号" disabled />
+					<uni-forms-item label="账号" name="phone">
+						<uni-easyinput type="text" v-model="form.phone" placeholder="请输入账号" disabled />
 					</uni-forms-item>
 					<uni-forms-item label="新密码" name="password">
 						<uni-easyinput type="password" v-model="form.password" placeholder="请输入新密码" />
 					</uni-forms-item>
-					<uni-forms-item label="确认密码" name="password">
-						<uni-easyinput type="password" v-model="form.password" placeholder="请输入确认密码" />
+					<uni-forms-item label="确认密码" name="is_password">
+						<uni-easyinput type="is_password" v-model="form.is_password" placeholder="请输入确认密码" />
 					</uni-forms-item>
 				</uni-forms>
 				<view class="btn">
@@ -35,52 +35,76 @@
 					password: {
 						rules: [{
 							required: true,
-							errorMessage: '请输入密码',
+							errorMessage: '请输入密码',
 						}]
 					},
 				},
 			};
 		},
 		onLoad: function(e) {
-			console.log(e);
+			const that = this;
+			that.watchLogin();
 		},
 		onShow: function() {},
 		methods: {
+			watchLogin() {
+				const that = this;
+				uni.getStorage({
+					key: 'token',
+					success: (res) => {
+						let user = that.$jwt(res.data);
+						if (user) {
+							that.$set(that, `form`, {
+								id: user.id,
+								phone: user.phone
+							})
+						}
+
+					},
+					fail: (err) => {}
+				})
+			},
 			toPath(e) {
 				if (e && e.route) uni.redirectTo({
 					url: `/${e.route}`
 				})
 			},
+
 			// 提交保存
-			onSubmit() {
+			onSubmit(ref) {
 				const that = this;
-				let data = that.form;
-				data = {
-					...data,
-				}
-				console.log(data);
-				// this.$refs.form.validate().then(async (res) => {
-				// let arr;
-				// if (data._id) {
-				// 	arr = await that.$api(``, 'POST', data)
-				// } else {
-				// 	arr = await that.$api(``, 'POST', data)
-				// }
-				// if (arr.errcode == '0') {
-				// 	uni.showToast({
-				// 		title: `维护信息成功`,
-				// 		icon: 'success',
-				// 		duration: 2000
-				// 	});
-				// 	that.back()
-				// } else {
-				// 	uni.showToast({
-				// 		title: arr.errmsg,
-				// 		icon: 'error',
-				// 		duration: 2000
-				// 	})
-				// }
-				// })
+				that.$refs[ref].validate().then(async params => {
+					if (params.password == params.is_password) {
+						const arr = that.$api(`/user/resetPwd/${that.form.id}`, 'POST', params);
+						console.log(arr);
+						if (arr.errcode == '0') {
+							uni.showToast({
+								title: `密码修改成功`,
+								icon: 'success',
+							});
+							// uni.clearStorage();
+							// uni.redirectTo({
+							// 	url: '/pages/login/index'
+							// })
+						} else {
+							uni.showToast({
+								title: arr.errmsg,
+							})
+						}
+					} else {
+						uni.showToast({
+							title: `密码不一致`,
+						});
+					}
+
+					// let arr;
+					// if (data._id) {
+					// 	arr = await that.$api(``, 'POST', data)
+					// } else {
+					// 	arr = await that.$api(``, 'POST', data)
+					// }
+
+				})
 			},
 		}
 	}