邀请码确认弹窗
This commit is contained in:
parent
b03ffe7225
commit
fc78b157a9
|
|
@ -197,6 +197,29 @@
|
|||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<uni-popup ref="existingInvitePopup" type="center" :mask-click="false">
|
||||
<view class="invite-popup-content">
|
||||
<view class="invite-popup-header">
|
||||
<text class="invite-popup-title">请确认邀请信息</text>
|
||||
</view>
|
||||
<view class="invite-popup-body">
|
||||
<view class="invite-item">
|
||||
<text class="invite-label">邀请码</text>
|
||||
<text class="invite-value">{{ existingInviterInfo && (existingInviterInfo.invite_code || existingInviterInfo.invite_code_other) }}</text>
|
||||
</view>
|
||||
<view class="invite-item">
|
||||
<text class="invite-label">邀请人</text>
|
||||
<text class="invite-value">{{ (existingInviterInfo && (existingInviterInfo.name || existingInviterInfo.nick_name)) || '' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="invite-popup-footer">
|
||||
<view class="invite-btn cancel" @click="cancelInviteConfirm">关闭</view>
|
||||
<view class="invite-btn confirm" @click="useExistingInviteCode">确认</view>
|
||||
</view>
|
||||
</view>
|
||||
</uni-popup>
|
||||
|
||||
</view>
|
||||
</template>
|
||||
|
||||
|
|
@ -213,6 +236,7 @@ export default {
|
|||
|
||||
return {
|
||||
userId: null,
|
||||
userMobile: null, // 保存用户手机号用以查询邀请人
|
||||
formData: loadedData || {
|
||||
name: '',
|
||||
contact_type: '1',
|
||||
|
|
@ -250,6 +274,12 @@ export default {
|
|||
inviterInfo: null,
|
||||
currentValidatingCode: '',
|
||||
inviteValidationTimer: null,
|
||||
|
||||
// 新增邀请码弹窗和替换逻辑需要的状态变量
|
||||
existingInviterInfo: null,
|
||||
hasExistingInviter: false,
|
||||
hasAutoReplacedInvite: false,
|
||||
confirmResolve: null // 存储 saveFormData 的 Promise resolve 方法
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
|
|
@ -289,11 +319,21 @@ export default {
|
|||
onShow() {
|
||||
const localData = this.loadFormDataFromLocal();
|
||||
if (localData) {
|
||||
// 如果已经自动替换了邀请码,不要再覆盖
|
||||
if (this.hasAutoReplacedInvite) {
|
||||
const { invite_code_other, ...otherData } = localData;
|
||||
Object.keys(otherData).forEach(key => {
|
||||
if (this.formData[key] !== undefined && key !== 'invite_code_other') {
|
||||
this.formData[key] = otherData[key];
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.formData = {
|
||||
...this.formData,
|
||||
...localData
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
this.checkGlobalData();
|
||||
this.checkAddressData();
|
||||
|
|
@ -318,11 +358,14 @@ export default {
|
|||
}
|
||||
},
|
||||
|
||||
mounted() {
|
||||
async mounted() {
|
||||
this.locatinCitys = this.ChinaCitys[0].citys;
|
||||
this.locationAreas = this.locatinCitys[0].areas;
|
||||
|
||||
if (this.formData.invite_code_other) {
|
||||
// 先检查绑定邀请人信息
|
||||
await this.forceUseExistingInviter();
|
||||
|
||||
if (!this.hasAutoReplacedInvite && this.formData.invite_code_other) {
|
||||
this.validateInviteCode(this.formData.invite_code_other);
|
||||
}
|
||||
},
|
||||
|
|
@ -332,6 +375,124 @@ export default {
|
|||
},
|
||||
|
||||
methods: {
|
||||
// 强制使用已绑定的邀请人
|
||||
async forceUseExistingInviter() {
|
||||
if (this.hasAutoReplacedInvite) return false;
|
||||
|
||||
// 确保我们有手机号,如果没有则再获取一次
|
||||
if (!this.userMobile) {
|
||||
await this.getUserInfo();
|
||||
}
|
||||
if (!this.userMobile) {
|
||||
console.log('用户手机号未获取,跳过强制替换');
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
// 1. 调用查询已绑定的邀请码
|
||||
const res = await request.post('/sj/User/getBInviteCode', {
|
||||
account: this.userMobile,
|
||||
type: 2 // 商家端类型
|
||||
});
|
||||
|
||||
if (res && (res.code === 200 || res.state === 1) && res.data) {
|
||||
const oldInviteCode = res.data.invite_code || res.data.invite_code_other;
|
||||
|
||||
if (oldInviteCode) {
|
||||
console.log('检测到已绑定邀请码:', oldInviteCode);
|
||||
|
||||
// 2. 用邀请码获取完整的邀请人信息
|
||||
const inviteRes = await request.post('/sj/user/getInvite', {
|
||||
invite_code: oldInviteCode
|
||||
});
|
||||
|
||||
if (inviteRes && (inviteRes.code === 200 || inviteRes.state === 1) && inviteRes.data && inviteRes.data.account) {
|
||||
const fullInviterInfo = inviteRes.data;
|
||||
|
||||
// 强制填充
|
||||
this.formData.invite_code_other = oldInviteCode;
|
||||
this.hasExistingInviter = true;
|
||||
this.hasAutoReplacedInvite = true;
|
||||
this.inviteCodeError = false;
|
||||
this.inviterInfo = fullInviterInfo;
|
||||
this.currentValidatingCode = oldInviteCode;
|
||||
this.existingInviterInfo = fullInviterInfo;
|
||||
|
||||
// 保存状态
|
||||
this.saveInviteStateToLocal();
|
||||
this.saveFormDataToLocal();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('强制替换邀请人失败:', error);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
// 显示邀请码确认弹窗
|
||||
showInviteConfirmPopup(inviterData) {
|
||||
this.$nextTick(() => {
|
||||
if (this.$refs.existingInvitePopup) {
|
||||
this.existingInviterInfo = inviterData;
|
||||
this.$refs.existingInvitePopup.open();
|
||||
} else {
|
||||
uni.showModal({
|
||||
title: '请确认邀请信息',
|
||||
content: `邀请码:${inviterData?.invite_code || inviterData?.invite_code_other}\n邀请人:${inviterData?.name || inviterData?.nick_name}`,
|
||||
confirmText: '确认',
|
||||
cancelText: '取消',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
this.useExistingInviteCode();
|
||||
} else {
|
||||
this.cancelInviteConfirm();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 隐藏邀请码确认弹窗
|
||||
hideExistingInviteTipPopup() {
|
||||
if (this.$refs.existingInvitePopup) {
|
||||
this.$refs.existingInvitePopup.close();
|
||||
}
|
||||
},
|
||||
|
||||
// 用户点击确认按钮使用邀请码
|
||||
useExistingInviteCode() {
|
||||
if (this.existingInviterInfo) {
|
||||
const inviteState = {
|
||||
inviterInfo: this.existingInviterInfo,
|
||||
inviteCodeError: false,
|
||||
currentValidatingCode: this.existingInviterInfo.invite_code || this.existingInviterInfo.invite_code_other
|
||||
};
|
||||
uni.setStorageSync('store_invite_state', inviteState);
|
||||
this.saveFormDataToLocal();
|
||||
}
|
||||
this.hideExistingInviteTipPopup();
|
||||
|
||||
// 触发 Promise 解决,以继续表单提交流程
|
||||
if (this.confirmResolve) {
|
||||
this.confirmResolve(true);
|
||||
this.confirmResolve = null;
|
||||
}
|
||||
},
|
||||
|
||||
// 用户点击关闭/取消按钮
|
||||
cancelInviteConfirm() {
|
||||
this.hideExistingInviteTipPopup();
|
||||
// 触发 Promise 拒绝拦截提交
|
||||
if (this.confirmResolve) {
|
||||
this.confirmResolve(false);
|
||||
this.confirmResolve = null;
|
||||
}
|
||||
},
|
||||
|
||||
loadInviteStateFromLocal() {
|
||||
try {
|
||||
const inviteState = uni.getStorageSync('store_invite_state');
|
||||
|
|
@ -447,6 +608,13 @@ export default {
|
|||
|
||||
// 处理邀请码输入
|
||||
handleInviteCodeInput(e) {
|
||||
// 【改动】如果已经被强制替换为已有邀请人,禁止任何手动修改
|
||||
if (this.hasAutoReplacedInvite) {
|
||||
console.log('已强制使用原邀请人,禁止修改邀请码');
|
||||
this.formData.invite_code_other = this.inviterInfo ? (this.inviterInfo.invite_code || this.inviterInfo.invite_code_other) : '';
|
||||
return;
|
||||
}
|
||||
|
||||
const code = e.detail ? e.detail.value : this.formData.invite_code_other;
|
||||
|
||||
console.log('邀请码输入:', code);
|
||||
|
|
@ -590,7 +758,7 @@ export default {
|
|||
try {
|
||||
// 调用接口验证邀请码
|
||||
const response = await request.post('/sj/user/getInvite', {
|
||||
invite_code_other: code
|
||||
invite_code: code
|
||||
});
|
||||
|
||||
console.log('邀请码验证响应:', response);
|
||||
|
|
@ -696,10 +864,15 @@ export default {
|
|||
},
|
||||
|
||||
getUserInfo() {
|
||||
// 【改动】增加了对手机号的抓取并暴露至 data 内,以供给查询上级分销/邀请人使用
|
||||
return new Promise((resolve, reject) => {
|
||||
request.post('/sj/user/getuser').then(result => {
|
||||
if (result.state === 1) {
|
||||
this.userId = result.data.id;
|
||||
this.userMobile = result.data.mobile || result.data.account; // 记录手机号
|
||||
if (this.userMobile && getApp().globalData) {
|
||||
getApp().globalData.userMobile = this.userMobile;
|
||||
}
|
||||
console.log('用户ID获取成功:', this.userId);
|
||||
resolve(this.userId);
|
||||
} else {
|
||||
|
|
@ -719,58 +892,84 @@ export default {
|
|||
};
|
||||
},
|
||||
|
||||
// 这里改造为了 Promise,以拦截并弹窗等待用户操作
|
||||
saveFormData() {
|
||||
return new Promise((resolve) => {
|
||||
if (!this.formData.name) {
|
||||
uni.showToast({
|
||||
title: '请输入店铺名称',
|
||||
icon: 'none'
|
||||
});
|
||||
return false;
|
||||
return resolve(false);
|
||||
}
|
||||
if (!this.formData.dependency) {
|
||||
uni.showToast({
|
||||
title: '请选择门店所在地',
|
||||
icon: 'none'
|
||||
});
|
||||
return false;
|
||||
return resolve(false);
|
||||
}
|
||||
if (!this.formData.address) {
|
||||
uni.showToast({
|
||||
title: '请选择门店详细地址',
|
||||
icon: 'none'
|
||||
});
|
||||
return false;
|
||||
return resolve(false);
|
||||
}
|
||||
if (!this.formData.contact_name) {
|
||||
uni.showToast({
|
||||
title: '请输入联系人',
|
||||
icon: 'none'
|
||||
});
|
||||
return false;
|
||||
return resolve(false);
|
||||
}
|
||||
if (!this.formData.contact_phone) {
|
||||
uni.showToast({
|
||||
title: '请输入联系人电话',
|
||||
icon: 'none'
|
||||
});
|
||||
return false;
|
||||
return resolve(false);
|
||||
}
|
||||
if (!/^1[3-9]\d{9}$/.test(this.formData.contact_phone)) {
|
||||
uni.showToast({
|
||||
title: '请输入正确的手机号码',
|
||||
icon: 'none'
|
||||
});
|
||||
return false;
|
||||
return resolve(false);
|
||||
}
|
||||
if (!this.formData.invite_code_other) {
|
||||
uni.showToast({
|
||||
title: '请输入邀请码',
|
||||
icon: 'none'
|
||||
});
|
||||
return false;
|
||||
return resolve(false);
|
||||
}
|
||||
|
||||
// 验证邀请码的有效性状态
|
||||
if (this.inviteCodeValidating) {
|
||||
uni.showToast({ title: '邀请码验证中,请稍候', icon: 'none' });
|
||||
return resolve(false);
|
||||
}
|
||||
|
||||
if (this.formData.invite_code_other === '13131313') {
|
||||
// 特殊跳过判断
|
||||
} else if (this.inviteCodeError || !this.inviterInfo) {
|
||||
this.triggerInviteErrorShake();
|
||||
return resolve(false);
|
||||
}
|
||||
|
||||
// 挂载 resolve,在确认弹窗触发后再予以抛出
|
||||
this.confirmResolve = resolve;
|
||||
|
||||
if (this.formData.invite_code_other === '13131313') {
|
||||
this.showInviteConfirmPopup({ invite_code_other: '13131313', name: '暂无邀请人' });
|
||||
} else if (this.inviterInfo && this.formData.invite_code_other) {
|
||||
this.showInviteConfirmPopup(this.inviterInfo);
|
||||
} else {
|
||||
this.saveFormDataToLocal();
|
||||
return true;
|
||||
resolve(true);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
setContactType(type) {
|
||||
|
|
@ -1008,6 +1207,7 @@ export default {
|
|||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* 继承你以前的所有原有样式 */
|
||||
.qualification-page {}
|
||||
|
||||
.section {
|
||||
|
|
@ -1455,4 +1655,97 @@ export default {
|
|||
.inviter-phone {
|
||||
color: #666666;
|
||||
}
|
||||
|
||||
/* 邀请码和禁用样式 */
|
||||
/* 输入框禁用样式 */
|
||||
.input:disabled {
|
||||
color: #999999;
|
||||
background-color: #F5F5F5;
|
||||
}
|
||||
|
||||
/* 邀请码确认弹窗样式 */
|
||||
.invite-popup-content {
|
||||
width: 571rpx;
|
||||
height: 535rpx;
|
||||
background-image: url('https://mrrplus.oss-cn-beijing.aliyuncs.com/photo/system/6f130301-f3df-467c-8a1c-dc49f85e5295.png');
|
||||
background-size: cover;
|
||||
background-position: center;
|
||||
border-radius: 30rpx;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding: 40rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.invite-popup-header {
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
margin-bottom: 40rpx;
|
||||
}
|
||||
|
||||
.invite-popup-title {
|
||||
font-size: 36rpx;
|
||||
font-weight: 500;
|
||||
color: #333333;
|
||||
}
|
||||
|
||||
.invite-popup-body {
|
||||
flex: 1;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 24rpx;
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
|
||||
.invite-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 20rpx;
|
||||
background-color: rgba(255, 255, 255, 0.9);
|
||||
border-radius: 16rpx;
|
||||
}
|
||||
|
||||
.invite-label {
|
||||
font-size: 28rpx;
|
||||
color: #666666;
|
||||
}
|
||||
|
||||
.invite-value {
|
||||
font-size: 28rpx;
|
||||
color: #333333;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.invite-popup-footer {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
margin-top: 40rpx;
|
||||
}
|
||||
|
||||
.invite-btn {
|
||||
flex: 1;
|
||||
height: 88rpx;
|
||||
border-radius: 44rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 32rpx;
|
||||
font-weight: 500;
|
||||
margin: 0 5rpx;
|
||||
}
|
||||
|
||||
.invite-btn.cancel {
|
||||
background-color: #FFFFFF;
|
||||
color: #FC437C;
|
||||
border: 2rpx solid #FC437C;
|
||||
}
|
||||
|
||||
.invite-btn.confirm {
|
||||
background: linear-gradient(90deg, #FC437C 0%, #FF618F 100%);
|
||||
color: #FFFFFF;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -190,7 +190,6 @@
|
|||
"latitude": data.latitude || '',
|
||||
"name": data.name || '',
|
||||
"contact_type": data.contact_type || ''
|
||||
|
||||
}
|
||||
uni.setStorageSync('qualification_form_data', qualification_form_data);
|
||||
let store_info_form_data = {
|
||||
|
|
@ -527,7 +526,9 @@
|
|||
|
||||
async submitApplication() {
|
||||
if (this.$refs.storeInfo) {
|
||||
if (!this.$refs.storeInfo.saveFormData()) {
|
||||
// 增加了 await 进行异步表单验证,等待弹窗确认结果
|
||||
const isValid = await this.$refs.storeInfo.saveFormData();
|
||||
if (!isValid) {
|
||||
return;
|
||||
}
|
||||
this.storeInfoData = this.$refs.storeInfo.getFormData();
|
||||
|
|
@ -626,6 +627,7 @@
|
|||
</script>
|
||||
|
||||
<style>
|
||||
/* ...与原来一致的代码... */
|
||||
.ruzhu-page {
|
||||
background: #f5f5f5;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -135,13 +135,13 @@ const request = async (options, isUpdate) => {
|
|||
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
baseURL = url; // 发布到生产环境时,此处代码会被摇树移除掉。
|
||||
baseURL = 'http://116.63.163.121:93'; // 发布到生产环境时,此处代码会被摇树移除掉。
|
||||
//baseURL = 'http://116.63.163.121:96'; // 发布到生产环境时,此处代码会被摇树移除掉。
|
||||
baseURL = 'http://test.mrrwlkj.top'; // 发布到生产环境时,此处代码会被摇树移除掉。
|
||||
//baseURL = 'http://dev.mrrwlkj.top'; // 发布到生产环境时,此处代码会被摇树移除掉。
|
||||
//baseURL = 'https://app.mrrweb.com.cn';
|
||||
} else {
|
||||
baseURL = url; // 发布到生产环境时,此处代码会被摇树移除掉。
|
||||
baseURL = 'http://116.63.163.121:93'; // 发布到生产环境时,此处代码会被摇树移除掉。
|
||||
//baseURL = 'http://116.63.163.121:96'; // 发布到生产环境时,此处代码会被摇树移除掉。
|
||||
baseURL = 'http://test.mrrwlkj.top'; // 发布到生产环境时,此处代码会被摇树移除掉。
|
||||
//baseURL = 'http://dev.mrrwlkj.top'; // 发布到生产环境时,此处代码会被摇树移除掉。
|
||||
//baseURL = 'https://app.mrrweb.com.cn';
|
||||
|
||||
console.log('生产环境');
|
||||
|
|
|
|||
Loading…
Reference in New Issue