// register.js
export const registerRequest = (registerForm) => {
	return new Promise((resolve, reject) => {
		console.log('开始注册，提交数据:', registerForm);
		uni.request({
			url: 'https://api.buzhiyushu.cn/auth/register',
			method: 'POST',
			data: registerForm,
			header: {
				clientId: '1400a724f627ddc73d8f4dd344f80a5e',
				isToken: 'false',
				isEncrypt: 'false',
				repeatSubmit: 'false'
			},
			success: response => {
				console.log('服务器返回的数据：', response.data);
				if (response.data.code === 200) {
					// 注册成功
					uni.showToast({
						title: '注册成功',
						icon: 'success'
					});
					resolve(response.data);
				} else {
					// 注册失败，显示错误信息
					uni.showToast({
						title: response.data.msg || '注册失败',
						icon: 'none'
					});
					reject(response.data);
				}
			},
			fail: err => {
				console.log('请求服务器失败，错误信息：', err);
				uni.showToast({
					title: '请求服务器失败',
					icon: 'none'
				});
				reject(err);
			}
		});
	});
};

// 验证手机号格式
export const validatePhoneNumber = (phoneNumber) => {
	const phoneRegex = /^1[3-9]\d{9}$/;
	return phoneRegex.test(phoneNumber);
};

// 验证密码强度
export const validatePassword = (password) => {
	// 密码至少6位
	if (password.length < 6) {
		return {
			valid: false,
			message: '密码长度不能少于6位'
		};
	}
	return {
		valid: true,
		message: ''
	};
};