he il y a 5 mois
Parent
commit
82b0098cb5

+ 86 - 9
components/auth-login-popup/auth-login-popup.vue

@@ -5,12 +5,19 @@
 				<uni-icons type="close" size="24" color="#999"></uni-icons>
 			</view>
 			<view>
-				<button class="login-btn" @tap="handleLogin">授权登录</button>
-				<view class="agreement-text">
-					登录即代表您已同意
-					<text class="agreement-link" @tap="goToPrivacy">《隐私政策》</text>
-					和
-					<text class="agreement-link" @tap="goToService">《服务协议》</text>
+				<button class="login-btn" @tap="handleLoginClick">授权登录</button>
+				<view class="agreement-wrapper">
+					<view class="checkbox-wrapper" @tap="toggleAgreement">
+						<view class="zen-checkbox" :class="{ 'checked': isAgree }">
+							<view class="zen-circle-inner" v-if="isAgree"></view>
+						</view>
+					</view>
+					<view class="agreement-text">
+						登录即代表您已同意
+						<text class="agreement-link" @tap.stop="goToPrivacy">《隐私政策》</text>
+						和
+						<text class="agreement-link" @tap.stop="goToService">《服务协议》</text>
+					</view>
 				</view>
 			</view>
 		</view>
@@ -29,10 +36,42 @@
 				// 默认用户信息
 				defaultUser: {
 
-				}
+				},
+				// 是否同意协议
+				isAgree: false
 			};
 		},
 		methods: {
+			// 切换协议同意状态
+			toggleAgreement() {
+				this.isAgree = !this.isAgree;
+			},
+
+			// 处理登录按钮点击
+			handleLoginClick() {
+				if (!this.isAgree) {
+					// 未勾选协议,弹出确认框
+					let that = this;
+					uni.showModal({
+						title: '提示',
+						content: '登录需要您同意《隐私政策》和《服务协议》,是否同意?',
+						confirmText: '同意',
+						cancelText: '取消',
+						success: function(res) {
+							if (res.confirm) {
+								// 用户点击同意,自动勾选协议并执行登录
+								that.isAgree = true;
+								that.handleLogin();
+							} else if (res.cancel) {
+								console.log('用户点击取消');
+							}
+						}
+					});
+				} else {
+					// 已勾选协议,直接登录
+					this.handleLogin();
+				}
+			},
 			// 打开弹窗
 			open() {
 				this.$refs.authPopup.open();
@@ -240,15 +279,53 @@
 		border: none;
 	}
 
+	.agreement-wrapper {
+		display: flex;
+		align-items: flex-start;
+		justify-content: center;
+		gap: 16rpx;
+		padding: 0 20rpx;
+	}
+
+	.checkbox-wrapper {
+		flex-shrink: 0;
+		padding-top: 4rpx;
+	}
+
+	.zen-checkbox {
+		width: 36rpx;
+		height: 36rpx;
+		border: 2rpx solid rgba(255, 91, 5, 0.4);
+		border-radius: 18rpx;
+		display: flex;
+		align-items: center;
+		justify-content: center;
+		transition: all 0.3s ease;
+		background: rgba(255, 255, 255, 0.9);
+
+		&.checked {
+			background: #FF5B05;
+			border-color: #FF5B05;
+		}
+
+		.zen-circle-inner {
+			width: 16rpx;
+			height: 16rpx;
+			border-radius: 50%;
+			background: #fff;
+		}
+	}
+
 	.agreement-text {
 		font-size: 24rpx;
 		color: rgba(41, 44, 53, 0.6);
 		line-height: 36rpx;
-		text-align: center;
+		flex: 1;
+		text-align: left;
 	}
 
 	.agreement-link {
 		color: #FF5B05;
 		text-decoration: none;
 	}
-</style>
+</style>

+ 1 - 0
config/api.js

@@ -43,6 +43,7 @@ export const selectUser = (data) => http.get(prefix + '/system/info/selectUser?d
 export const addVisit = (data) => http.post(prefix + '/system/info/addVisit', data) // 提交访客申请
 export const getVisitList = (data) => http.get(prefix + '/system/info/list?visitStatus=' + data.visitStatus +
 	'&userId=' + data.userId) // 获取访客记录列表
+export const updateVisitInfo = (data) => http.post(prefix + '/system/info/updateVisitInfo', data) // 更新访客状态(通过/拒绝)
 // export const getFeedback = (data) => http.get(prefix + '/blade-feedback/getFeedback')
 // export const feedbackSave = (params) => http.post(prefix + '//blade-feedback/save', params) // 意见反馈
 /**

+ 22 - 10
pages/index/index.vue

@@ -549,30 +549,42 @@
 				try {
 					// 调用后端接口提交数据
 					const response = await addVisit(submitData);
-					console.log('提交成功:', response);
+					console.log('提交响应:', response);
 
-					// 检查返回结果
-					if (response && response.code === 200) {
+					// 检查返回结果(支持 code === 200 或 code === "200")
+					if (response && (response.code === 200 || response.code === "200")) {
 						uni.showToast({
-							title: response.msg || '提交成功',
+							title: response.msg || '操作成功',
 							icon: 'success',
 							duration: 2000
 						});
 						// 延迟返回上一页
 						setTimeout(() => {
-							uni.navigateBack();
+							uni.navigateBack({
+								fail: () => {
+									// 如果返回失败,跳转到访客页面
+									uni.switchTab({
+										url: '/pages/tabbar/visitor'
+									});
+								}
+							});
 						}, 2000);
 					} else {
+						// 提交失败
 						uni.showToast({
-							title: response.msg || '提交失败,请重试',
-							icon: 'none'
+							title: response.msg || response.message || '提交失败,请重试',
+							icon: 'none',
+							duration: 2000
 						});
 					}
 				} catch (error) {
-					console.error('提交失败:', error);
+					console.error('提交异常:', error);
+					// 优先使用后端返回的错误信息
+					const errorMsg = error.data?.msg || error.msg || error.message || '提交失败,请重试';
 					uni.showToast({
-						title: error.msg || '提交失败,请重试',
-						icon: 'none'
+						title: errorMsg,
+						icon: 'none',
+						duration: 2000
 					});
 				}
 			},

+ 3 - 1
pages/tabbar/visitor.vue

@@ -200,8 +200,10 @@
 
 			// 跳转到详情页面
 			goToDetail(item) {
+				// 将完整对象数据存储到缓存,用于详情页读取
+				uni.setStorageSync('visitDetailData', item);
 				uni.navigateTo({
-					url: `/pagesA/task/detail?id=${item.id}&status=${item.status}`
+					url: `/pagesA/task/detail?id=${item.id}`
 				});
 			},
 

+ 106 - 51
pagesA/task/detail.vue

@@ -136,6 +136,10 @@
 </template>
 
 <script>
+	import {
+		updateVisitInfo
+	} from '@/config/api.js';
+
 	export default {
 		data() {
 			return {
@@ -165,40 +169,53 @@
 		onLoad(options) {
 			if (options.id) {
 				this.visitId = options.id;
-				this.visitDetail.status = options.status || '待审核';
 				this.getVisitDetail();
 			}
 		},
 		methods: {
 			// 获取访问详情
 			getVisitDetail() {
-				// 模拟数据,实际应该调用接口
-				const mockDetail = {
-					id: this.visitId,
-					department: '技术部',
-					employeeName: '张河嘉',
-					visitReason: '参加业务研究计划',
-					visitTime: '2025-08-09',
-					visitorName: '安晓伟',
-					visitorCompany: '某某某公司',
-					visitorPhone: '13012345678',
-					status: this.visitDetail.status, // 从上一页传来的状态
-					useVehicle: true,
-					vehicleNumber: '冀A·12345',
-					pickupTime: '2025-08-09 16:30',
-					pickupLocation: '石家庄新华区',
-					accompanyPersons: [{
-							name: '李四',
-							phone: '13987654321'
-						},
-						{
-							name: '王五',
-							phone: '13876543210'
+				// 从缓存中获取数据
+				const visitData = uni.getStorageSync('visitDetailData');
+				
+				if (visitData) {
+					// 解析随行人员数据
+					let accompanyPersons = [];
+					if (visitData.accPerson) {
+						try {
+							const accPersonData = typeof visitData.accPerson === 'string' ? JSON.parse(visitData.accPerson) : visitData.accPerson;
+							if (Array.isArray(accPersonData)) {
+								accompanyPersons = accPersonData.map(person => ({
+									name: person.name || person.accName || '',
+									phone: person.phone || person.accTel || ''
+								}));
+							}
+						} catch (error) {
+							console.error('解析随行人员数据失败:', error);
 						}
-					]
-				};
-
-				this.visitDetail = mockDetail;
+					}
+					
+					// 设置详情数据
+					this.visitDetail = {
+						id: visitData.id,
+						department: visitData.visDept || '', // 访客单位作为部门
+						employeeName: visitData.employeeName,
+						visitReason: visitData.visitReason,
+						visitTime: visitData.visitDate,
+						visitorName: visitData.visitorName,
+						visitorCompany: visitData.visitorCompany,
+						visitorPhone: visitData.visitorPhone,
+						status: visitData.status,
+						useVehicle: visitData.useVehicle || false,
+						vehicleNumber: visitData.vehicleNumber || '',
+						pickupTime: visitData.pickupTime || '',
+						pickupLocation: visitData.pickupLocation || '',
+						accompanyPersons: accompanyPersons
+					};
+					
+					// 清除缓存
+					uni.removeStorageSync('visitDetailData');
+				}
 			},
 
 			// 处理拒绝
@@ -220,49 +237,87 @@
 			},
 
 			// 确认通过
-			approveVisit() {
+			async approveVisit() {
 				this.$refs.confirmPopup.close();
 
-				// 模拟接口调用
 				uni.showLoading({
 					title: '处理中...'
 				});
 
-				setTimeout(() => {
-					uni.hideLoading();
+				try {
+					// 调用接口,状态改为 1=已访问(通过)
+					const response = await updateVisitInfo({
+						id: this.visitDetail.id,
+						visitStatus: '1'
+					});
 
-					// 更新状态
-					this.visitDetail.status = '待访问';
+					uni.hideLoading();
 
-					// 显示成功提示
-					this.resultType = 'success';
-					this.resultTitle = '审核通过';
-					this.resultMessage = '访问申请已通过,访客将收到通知';
-					this.$refs.resultPopup.open();
-				}, 1000);
+					if (response && response.code === 200) {
+						// 更新本地状态
+						this.visitDetail.status = '已访问';
+
+						// 显示成功提示
+						this.resultType = 'success';
+						this.resultTitle = '审核通过';
+						this.resultMessage = '访问申请已通过,访客将收到通知';
+						this.$refs.resultPopup.open();
+					} else {
+						uni.showToast({
+							title: response.msg || '操作失败',
+							icon: 'none'
+						});
+					}
+				} catch (error) {
+					uni.hideLoading();
+					console.error('审核通过失败:', error);
+					uni.showToast({
+						title: '操作失败,请重试',
+						icon: 'none'
+					});
+				}
 			},
 
 			// 确认拒绝
-			rejectVisit() {
+			async rejectVisit() {
 				this.$refs.confirmPopup.close();
 
-				// 模拟接口调用
 				uni.showLoading({
 					title: '处理中...'
 				});
 
-				setTimeout(() => {
-					uni.hideLoading();
+				try {
+					// 调用接口,状态改为 3=已拒绝
+					const response = await updateVisitInfo({
+						id: this.visitDetail.id,
+						visitStatus: '3'
+					});
 
-					// 更新状态
-					this.visitDetail.status = '已拒绝';
+					uni.hideLoading();
 
-					// 显示成功提示
-					this.resultType = 'success';
-					this.resultTitle = '审核完成';
-					this.resultMessage = '访问申请已拒绝,访客将收到通知';
-					this.$refs.resultPopup.open();
-				}, 1000);
+					if (response && response.code === 200) {
+						// 更新本地状态
+						this.visitDetail.status = '已拒绝';
+
+						// 显示成功提示
+						this.resultType = 'success';
+						this.resultTitle = '审核完成';
+						this.resultMessage = '访问申请已拒绝,访客将收到通知';
+						this.$refs.resultPopup.open();
+					} else {
+						uni.showToast({
+							title: response.msg || '操作失败',
+							icon: 'none'
+						});
+					}
+				} catch (error) {
+					uni.hideLoading();
+					console.error('拒绝访问失败:', error);
+					uni.showToast({
+						title: '操作失败,请重试',
+						icon: 'none'
+					});
+				}
 			},
 
 			// 关闭结果弹框