269 lines
5.0 KiB
Vue
269 lines
5.0 KiB
Vue
<template>
|
||
<view class="page">
|
||
<view class="header">
|
||
<text class="title">编辑个人信息</text>
|
||
<text class="subtitle">完善资料便于我们为您提供更贴心的服务</text>
|
||
</view>
|
||
|
||
<view class="form-card">
|
||
<view class="form-item">
|
||
<text class="form-label">姓名</text>
|
||
<input
|
||
class="form-input"
|
||
v-model="form.name"
|
||
type="text"
|
||
placeholder="请输入您的姓名"
|
||
placeholder-class="form-placeholder"
|
||
/>
|
||
</view>
|
||
<view class="form-item">
|
||
<text class="form-label">手机号</text>
|
||
<input
|
||
class="form-input"
|
||
v-model="form.phone"
|
||
type="number"
|
||
maxlength="11"
|
||
placeholder="请输入常用手机号"
|
||
placeholder-class="form-placeholder"
|
||
/>
|
||
</view>
|
||
<view class="form-item">
|
||
<text class="form-label">邮箱</text>
|
||
<input
|
||
class="form-input"
|
||
v-model="form.email"
|
||
type="text"
|
||
placeholder="请输入联系邮箱"
|
||
placeholder-class="form-placeholder"
|
||
/>
|
||
</view>
|
||
<view class="form-item">
|
||
<text class="form-label">地址</text>
|
||
<textarea
|
||
class="form-textarea"
|
||
v-model="form.address"
|
||
placeholder="请输入联系地址"
|
||
placeholder-class="form-placeholder"
|
||
auto-height="true"
|
||
/>
|
||
</view>
|
||
</view>
|
||
|
||
<view class="tips-card">
|
||
<text class="tips-title">信息使用说明</text>
|
||
<text class="tips-text">
|
||
姓名和联系方式仅用于订单通知及售后服务,我们会严格保护您的隐私信息。
|
||
</text>
|
||
</view>
|
||
|
||
<view class="actions">
|
||
<button class="btn cancel" @click="handleCancel">取消</button>
|
||
<button class="btn submit" type="primary" @click="handleSubmit">保存信息</button>
|
||
</view>
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
export default {
|
||
data() {
|
||
return {
|
||
form: {
|
||
name: '',
|
||
phone: '',
|
||
email: '',
|
||
address: ''
|
||
}
|
||
};
|
||
},
|
||
onLoad() {
|
||
this.loadProfile();
|
||
},
|
||
methods: {
|
||
loadProfile() {
|
||
try {
|
||
const stored = uni.getStorageSync('userProfile');
|
||
if (stored) {
|
||
this.form = {
|
||
...this.form,
|
||
...stored
|
||
};
|
||
}
|
||
} catch (error) {
|
||
console.warn('加载个人信息失败', error);
|
||
}
|
||
},
|
||
validatePhone(phone) {
|
||
const phoneReg = /^(?:(?:\+|00)86)?1[3-9]\d{9}$/;
|
||
return phoneReg.test(phone);
|
||
},
|
||
validateEmail(email) {
|
||
const emailReg =
|
||
/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@(([^<>()[\]\.,;:\s@"]+\.)+[^<>()[\]\.,;:\s@"]{2,})$/i;
|
||
return emailReg.test(email);
|
||
},
|
||
handleCancel() {
|
||
uni.navigateBack({
|
||
delta: 1
|
||
});
|
||
},
|
||
handleSubmit() {
|
||
if (!this.form.name.trim()) {
|
||
return this.showToast('请填写姓名');
|
||
}
|
||
if (!this.form.phone.trim() || !this.validatePhone(this.form.phone.trim())) {
|
||
return this.showToast('请填写有效的手机号');
|
||
}
|
||
if (this.form.email.trim() && !this.validateEmail(this.form.email.trim())) {
|
||
return this.showToast('请填写有效的邮箱');
|
||
}
|
||
if (!this.form.address.trim()) {
|
||
return this.showToast('请填写联系地址');
|
||
}
|
||
|
||
try {
|
||
uni.setStorageSync('userProfile', { ...this.form });
|
||
this.showToast('保存成功', 'success');
|
||
setTimeout(() => {
|
||
uni.navigateBack({
|
||
delta: 1
|
||
});
|
||
}, 800);
|
||
} catch (error) {
|
||
this.showToast('信息保存失败,请稍后重试');
|
||
console.error('保存个人信息失败', error);
|
||
}
|
||
},
|
||
showToast(title, icon = 'none') {
|
||
uni.showToast({
|
||
title,
|
||
icon,
|
||
duration: 2000
|
||
});
|
||
}
|
||
}
|
||
};
|
||
</script>
|
||
|
||
<style scoped>
|
||
.page {
|
||
background: #f7f8fa;
|
||
padding: 40rpx 32rpx 80rpx;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 32rpx;
|
||
}
|
||
|
||
.header {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 12rpx;
|
||
}
|
||
|
||
.title {
|
||
font-size: 36rpx;
|
||
color: #1a1a1a;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.subtitle {
|
||
font-size: 26rpx;
|
||
color: #8c8c8c;
|
||
line-height: 1.6;
|
||
}
|
||
|
||
.form-card {
|
||
background: #ffffff;
|
||
border-radius: 24rpx;
|
||
padding: 32rpx;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 32rpx;
|
||
box-shadow: 0 12rpx 30rpx rgba(16, 30, 54, 0.06);
|
||
}
|
||
|
||
.form-item {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 20rpx;
|
||
}
|
||
|
||
.form-label {
|
||
font-size: 28rpx;
|
||
color: #1a1a1a;
|
||
font-weight: 500;
|
||
}
|
||
.form-input{
|
||
height: 80rpx;
|
||
}
|
||
|
||
.form-input,
|
||
.form-textarea {
|
||
width: 100%;
|
||
background: #f5f7fb;
|
||
border-radius: 16rpx;
|
||
padding: 24rpx 28rpx;
|
||
font-size: 28rpx;
|
||
color: #1a1a1a;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
.form-textarea {
|
||
min-height: 160rpx;
|
||
line-height: 1.6;
|
||
}
|
||
|
||
.form-placeholder {
|
||
color: #b0b3ba;
|
||
font-size: 28rpx;
|
||
}
|
||
|
||
.tips-card {
|
||
background: #fff8f2;
|
||
border-radius: 24rpx;
|
||
padding: 28rpx 32rpx;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 12rpx;
|
||
}
|
||
|
||
.tips-title {
|
||
font-size: 28rpx;
|
||
color: #ff7a00;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.tips-text {
|
||
font-size: 26rpx;
|
||
color: #a66b3a;
|
||
line-height: 1.6;
|
||
}
|
||
|
||
.actions {
|
||
display: flex;
|
||
gap: 24rpx;
|
||
padding: 0 4rpx;
|
||
}
|
||
|
||
.btn {
|
||
flex: 1;
|
||
height: 92rpx;
|
||
border-radius: 46rpx;
|
||
font-size: 30rpx;
|
||
font-weight: 500;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
}
|
||
|
||
.cancel {
|
||
color: #1a1a1a;
|
||
background: #e9ecf1;
|
||
}
|
||
|
||
.submit {
|
||
color: #ffffff;
|
||
background: linear-gradient(135deg, #8b40ff 0%, #ff3c8d 100%);
|
||
border: none;
|
||
}
|
||
</style>
|