7 месяцев назад
Родитель
Сommit
c9effc2dbb
1 измененных файлов с 231 добавлено и 82 удалено
  1. 231 82
      pages/my/VIP/benefits.vue

+ 231 - 82
pages/my/VIP/benefits.vue

@@ -16,25 +16,25 @@
 			<view class="card-content">
 			<view class="card-content">
 				<view class="card-left">
 				<view class="card-left">
 					<view class="card-title">我的权益</view>
 					<view class="card-title">我的权益</view>
-					<view class="card-subtitle">常规版 剩余5天到期</view>
+					<view class="card-subtitle">{{vipStatus}} 剩余{{remainingDays}}天到期</view>
 				</view>
 				</view>
 
 
 				<view class="card-right">
 				<view class="card-right">
 					<view class="benefit-item">
 					<view class="benefit-item">
 						<view class="benefit-label">查看权益</view>
 						<view class="benefit-label">查看权益</view>
-						<view class="benefit-count">10/50</view>
+						<view class="benefit-count">{{browseCount}}/{{50}}</view>
 					</view>
 					</view>
 					<view class="benefit-item">
 					<view class="benefit-item">
 						<view class="benefit-label">沟通权益</view>
 						<view class="benefit-label">沟通权益</view>
-						<view class="benefit-count">10/50</view>
+						<view class="benefit-count">{{chatCount}}/{{50}}</view>
 					</view>
 					</view>
 					<view class="benefit-item">
 					<view class="benefit-item">
 						<view class="benefit-label">普通职位</view>
 						<view class="benefit-label">普通职位</view>
-						<view class="benefit-count">10/50</view>
+						<view class="benefit-count">{{10}}/{{50}}</view>
 					</view>
 					</view>
 					<view class="benefit-item">
 					<view class="benefit-item">
 						<view class="benefit-label">急聘职位</view>
 						<view class="benefit-label">急聘职位</view>
-						<view class="benefit-count">10/50</view>
+						<view class="benefit-count">{{10}}/{{50}}</view>
 					</view>
 					</view>
 				</view>
 				</view>
 			</view>
 			</view>
@@ -132,7 +132,7 @@
 					<text class="note-text">如有问题,请联系我的客服</text>
 					<text class="note-text">如有问题,请联系我的客服</text>
 				</view>
 				</view>
 			</view>
 			</view>
-			
+
 		</view>
 		</view>
 
 
 		<!-- 升级VIP按钮 -->
 		<!-- 升级VIP按钮 -->
@@ -146,9 +146,9 @@
 					</u-checkbox>
 					</u-checkbox>
 				</view>
 				</view>
 			</view>
 			</view>
-		<view class="upgrade-button" @click="showPaymentModal">
-			升级VIP
-		</view>
+			<view class="upgrade-button" @click="showPaymentModal">
+				升级VIP
+			</view>
 		</view>
 		</view>
 
 
 		<!-- 支付弹窗 -->
 		<!-- 支付弹窗 -->
@@ -159,43 +159,16 @@
 				</view>
 				</view>
 
 
 				<view class="picker-content">
 				<view class="picker-content">
-					<view class="plan-option" :class="{ active: selectedPlan === 'regular' }"
-						@click="selectPlan('regular')">
+					<view class="plan-option" :class="{ active: selectedPlan === item.id }" @click="selectPlan(item.id)"
+						v-for="(item,index) in viplist" :key="item.id || index">
 						<view class="option-left">
 						<view class="option-left">
-							<view class="radio-btn" :class="{ checked: selectedPlan === 'regular' }">
-								<u-icon v-if="selectedPlan === 'regular'" name="checkmark" color="#ffffff"
+							<view class="radio-btn" :class="{ checked: selectedPlan === item.id }">
+								<u-icon v-if="selectedPlan === item.id" name="checkmark" color="#ffffff"
 									size="28"></u-icon>
 									size="28"></u-icon>
 							</view>
 							</view>
-							<text class="option-text">常规版</text>
+							<text class="option-text">{{item.vipName}}</text>
 							<view class="price-tag">
 							<view class="price-tag">
-								<text>¥599</text>
-							</view>
-						</view>
-					</view>
-
-					<view class="plan-option" :class="{ active: selectedPlan === 'vip' }" @click="selectPlan('vip')">
-						<view class="option-left">
-							<view class="radio-btn" :class="{ checked: selectedPlan === 'vip' }">
-								<u-icon v-if="selectedPlan === 'vip'" name="checkmark" color="#ffffff"
-									size="28"></u-icon>
-							</view>
-							<text class="option-text">VIP版</text>
-							<view class="price-tag">
-								<text>¥1599</text>
-							</view>
-						</view>
-					</view>
-
-					<view class="plan-option" :class="{ active: selectedPlan === 'flagship' }"
-						@click="selectPlan('flagship')">
-						<view class="option-left">
-							<view class="radio-btn" :class="{ checked: selectedPlan === 'flagship' }">
-								<u-icon v-if="selectedPlan === 'flagship'" name="checkmark" color="#ffffff"
-									size="28"></u-icon>
-							</view>
-							<text class="option-text">旗舰版</text>
-							<view class="price-tag">
-								<text>¥2599</text>
+								<text>¥{{item.money}}</text>
 							</view>
 							</view>
 						</view>
 						</view>
 					</view>
 					</view>
@@ -235,7 +208,12 @@
 				userMonthTime: "", //用户会员到期时间
 				userMonthTime: "", //用户会员到期时间
 				companyMonthTime: "", //企业会员到期时间
 				companyMonthTime: "", //企业会员到期时间
 				vipPrice: "0", //会员价格
 				vipPrice: "0", //会员价格
-				
+				viplist: [],
+				endTime:"",
+				createTime:"",
+				  remainingDays: 0, // 剩余天数
+					vipStatus: "未开通VIP", // VIP状态文字(已过期/剩余x天到期/未开通VIP)
+					totalValidDays: 0, // 总有效期天数(可选)
 				// 权益使用情况
 				// 权益使用情况
 				benefits: {
 				benefits: {
 					view: {
 					view: {
@@ -255,10 +233,10 @@
 						total: 50
 						total: 50
 					}
 					}
 				},
 				},
-					checked: false,
+				checked: false,
 				// 支付弹窗
 				// 支付弹窗
 				showPayment: false,
 				showPayment: false,
-				selectedPlan: 'regular',
+				selectedPlan: '',
 				planPrices: {
 				planPrices: {
 					regular: 599,
 					regular: 599,
 					vip: 1599,
 					vip: 1599,
@@ -270,8 +248,8 @@
 			// 获取状态栏高度
 			// 获取状态栏高度
 			let systemInfo = uni.getSystemInfoSync();
 			let systemInfo = uni.getSystemInfoSync();
 			this.statusBarHeight = systemInfo.statusBarHeight || 0;
 			this.statusBarHeight = systemInfo.statusBarHeight || 0;
-			
-			
+
+
 			this.userType = uni.getStorageSync("userType");
 			this.userType = uni.getStorageSync("userType");
 			if (this.userType == 1) {
 			if (this.userType == 1) {
 				//用户简历的刷新次数
 				//用户简历的刷新次数
@@ -281,7 +259,7 @@
 				this.getVipCom();
 				this.getVipCom();
 				this.getNoVipCom();
 				this.getNoVipCom();
 			}
 			}
-			this.getVipPrice();
+			// this.getVipPrice();
 			// #ifdef APP-PLUS
 			// #ifdef APP-PLUS
 			this.openLists = [{
 			this.openLists = [{
 					image: "../../static/images/my/zhifubao.png",
 					image: "../../static/images/my/zhifubao.png",
@@ -296,7 +274,7 @@
 			];
 			];
 			this.openWay = 1;
 			this.openWay = 1;
 			// #endif
 			// #endif
-			
+
 			// #ifdef MP-WEIXIN
 			// #ifdef MP-WEIXIN
 			this.openLists = [{
 			this.openLists = [{
 				image: "../../static/share/icon_weixin.png",
 				image: "../../static/share/icon_weixin.png",
@@ -305,7 +283,7 @@
 			}, ];
 			}, ];
 			this.openWay = 2;
 			this.openWay = 2;
 			// #endif
 			// #endif
-			
+
 			// #ifdef H5
 			// #ifdef H5
 			let ua = navigator.userAgent.toLowerCase();
 			let ua = navigator.userAgent.toLowerCase();
 			if (ua.indexOf("micromessenger") !== -1) {
 			if (ua.indexOf("micromessenger") !== -1) {
@@ -327,12 +305,16 @@
 					id: 1,
 					id: 1,
 				}, ];
 				}, ];
 			}
 			}
-			
+
 			this.openWay = 1;
 			this.openWay = 1;
 			// #endif
 			// #endif
-			
-			
-			
+
+
+
+		},
+		onShow() {
+			this.selectVipDetails();
+			this.getVipdetile();
 		},
 		},
 		methods: {
 		methods: {
 			// 返回上一页
 			// 返回上一页
@@ -340,44 +322,80 @@
 				uni.navigateBack()
 				uni.navigateBack()
 			},
 			},
 			//支付
 			//支付
+			// 确认支付
 			confirmPayment() {
 			confirmPayment() {
-			
 				let that = this;
 				let that = this;
+
+				// 验证是否选择了会员套餐
+				if (!this.selectedPlan) {
+					uni.showToast({
+						title: "请选择会员套餐",
+						icon: "none"
+					});
+					return;
+				}
+
+				// 验证是否勾选了协议
+				if (!this.checked) {
+					uni.showToast({
+						title: "请阅读并同意《会员开通协议》",
+						icon: "none"
+					});
+					return;
+				}
+
 				if (that.isTrue == false) {
 				if (that.isTrue == false) {
 					return;
 					return;
 				}
 				}
-				let token = uni.getStorageSync('token')
+
+				let token = uni.getStorageSync('token');
 				if (!token) {
 				if (!token) {
 					uni.showToast({
 					uni.showToast({
 						title: "登录过期",
 						title: "登录过期",
-						icon: "none",
+						icon: "none"
 					});
 					});
-					return
+					return;
 				}
 				}
-			
-				console.log('进入支付')
+
+				console.log('进入支付,选择的套餐ID:', this.selectedPlan);
 				that.isTrue = false;
 				that.isTrue = false;
+
+				// 获取选中的套餐详情
+				const selectedPackage = this.viplist.find(item => item.id === this.selectedPlan);
+				const amount = selectedPackage ? selectedPackage.money : 0;
+
+				// 根据不同平台和支付方式调用不同的支付接口
 				if (this.openWay == 2) {
 				if (this.openWay == 2) {
+					// 微信支付
 					// #ifdef APP-PLUS
 					// #ifdef APP-PLUS
-					// 微信APP支付 根据订单id获取支付信息
 					this.$Request
 					this.$Request
 						.post("/app/wxPay/wxPayOrder", {
 						.post("/app/wxPay/wxPayOrder", {
 							classify: 1,
 							classify: 1,
-							money: this.planPrices,
-							type: 2,
+							money: amount,
+							type: this.selectedPlan,
+							//Id: this.selectedPlan, // 传递选中的VIP套餐ID
+							//vipName: selectedPackage ? selectedPackage.vipName : '' // 传递套餐名称
 						})
 						})
 						.then((ret) => {
 						.then((ret) => {
 							this.isCheckPay(ret.code, "wxpay", JSON.stringify(ret.data));
 							this.isCheckPay(ret.code, "wxpay", JSON.stringify(ret.data));
+						})
+						.catch(() => {
+							that.isTrue = true;
+							uni.showToast({
+								title: "请求失败,请重试",
+								icon: "none"
+							});
 						});
 						});
 					// #endif
 					// #endif
-			
+
 					// #ifdef MP-WEIXIN
 					// #ifdef MP-WEIXIN
-					// 微信小程序支付
 					this.$Request
 					this.$Request
 						.post("/app/wxPay/wxPayOrder", {
 						.post("/app/wxPay/wxPayOrder", {
 							classify: 3,
 							classify: 3,
-							money: this.planPrices,
-							type: 2,
+							money: amount,
+							type: this.selectedPlan,
+						//Id: this.selectedPlan, // 传递选中的VIP套餐ID
+						//vipName: selectedPackage ? selectedPackage.vipName : '' // 传递套餐名称
 						})
 						})
 						.then((ret) => {
 						.then((ret) => {
 							uni.hideLoading();
 							uni.hideLoading();
@@ -395,9 +413,11 @@
 										title: "支付成功",
 										title: "支付成功",
 										icon: "success",
 										icon: "success",
 									});
 									});
-									that.show = false;
+									that.showPayment = false;
 									that.isTrue = true;
 									that.isTrue = true;
 									that.getUserInfo();
 									that.getUserInfo();
+									// 支付成功后刷新页面数据
+									that.selectVipDetails();
 								},
 								},
 								fail: function(err) {
 								fail: function(err) {
 									console.log("fail:" + JSON.stringify(err));
 									console.log("fail:" + JSON.stringify(err));
@@ -408,16 +428,25 @@
 									});
 									});
 								},
 								},
 							});
 							});
+						})
+						.catch(() => {
+							that.isTrue = true;
+							uni.showToast({
+								title: "请求失败,请重试",
+								icon: "none"
+							});
 						});
 						});
 					// #endif
 					// #endif
-			
+
 					// #ifdef H5
 					// #ifdef H5
 					let ua = navigator.userAgent.toLowerCase();
 					let ua = navigator.userAgent.toLowerCase();
 					if (ua.indexOf("micromessenger") !== -1) {
 					if (ua.indexOf("micromessenger") !== -1) {
 						let data = {
 						let data = {
 							classify: 2,
 							classify: 2,
-							money: this.planPrices,
-							type: 2,
+							money: amount,
+							type: this.selectedPlan,
+						//Id: this.selectedPlan, // 传递选中的VIP套餐ID
+						//vipName: selectedPackage ? selectedPackage.vipName : '' // 传递套餐名称
 						};
 						};
 						this.$Request.postJson("/app/wxPay/wxPayOrder", data).then((res) => {
 						this.$Request.postJson("/app/wxPay/wxPayOrder", data).then((res) => {
 							if (res.code == 0) {
 							if (res.code == 0) {
@@ -429,33 +458,50 @@
 									title: "支付失败!",
 									title: "支付失败!",
 								});
 								});
 							}
 							}
+						}).catch(() => {
+							that.isTrue = true;
+							uni.showToast({
+								title: "请求失败,请重试",
+								icon: "none"
+							});
 						});
 						});
 					}
 					}
 					// #endif
 					// #endif
 				} else {
 				} else {
-					// APP支付宝支付
+					// 支付宝支付
 					// #ifdef APP
 					// #ifdef APP
 					console.log("APP进入支付。");
 					console.log("APP进入支付。");
 					const datas = {
 					const datas = {
 						classify: 4,
 						classify: 4,
-						money: this.planPrices,
-						type: 2,
-					}
+						money: amount,
+						type: this.selectedPlan,
+						//Id: this.selectedPlan, // 传递选中的VIP套餐ID
+						//vipName: selectedPackage ? selectedPackage.vipName : '' // 传递套餐名称
+					};
 					this.$Request.postT("/app/aliPay/payMoneyOrder", datas).then((ret) => {
 					this.$Request.postT("/app/aliPay/payMoneyOrder", datas).then((ret) => {
-						this.show = false;
+						this.showPayment = false;
 						console.log(ret);
 						console.log(ret);
 						this.isCheckPay(ret.code, "alipay", ret.data);
 						this.isCheckPay(ret.code, "alipay", ret.data);
+					}).catch(() => {
+						that.isTrue = true;
+						uni.showToast({
+							title: "请求失败,请重试",
+							icon: "none"
+						});
 					});
 					});
 					// #endif
 					// #endif
+
 					// #ifdef H5
 					// #ifdef H5
 					let data = {
 					let data = {
-						classify: 5,//支付方式
-						money:this.planPrices,
-						type: 2,
+						classify: 5, //支付方式
+						money: 0.1,
+						type: this.selectedPlan,
+						//Id: this.selectedPlan, // 传递选中的VIP套餐ID
+						//vipName: selectedPackage ? selectedPackage.vipName : '' // 传递套餐名称
 					};
 					};
 					this.$Request.postT("/app/aliPay/payMoneyOrder", data).then((res) => {
 					this.$Request.postT("/app/aliPay/payMoneyOrder", data).then((res) => {
 						if (res.code === 0) {
 						if (res.code === 0) {
-							this.show = false;
+							this.showPayment = false;
 							that.isTrue = true;
 							that.isTrue = true;
 							const div = document.createElement("div");
 							const div = document.createElement("div");
 							div.innerHTML = res.data; //此处form就是后台返回接收到的数据
 							div.innerHTML = res.data; //此处form就是后台返回接收到的数据
@@ -468,10 +514,17 @@
 								title: "支付失败!",
 								title: "支付失败!",
 							});
 							});
 						}
 						}
+					}).catch(() => {
+						that.isTrue = true;
+						uni.showToast({
+							title: "请求失败,请重试",
+							icon: "none"
+						});
 					});
 					});
 					// #endif
 					// #endif
 				}
 				}
 			},
 			},
+
 			callPay: function(response) {
 			callPay: function(response) {
 				if (typeof WeixinJSBridge === "undefined") {
 				if (typeof WeixinJSBridge === "undefined") {
 					if (document.addEventListener) {
 					if (document.addEventListener) {
@@ -586,6 +639,26 @@
 					});
 					});
 				}
 				}
 			},
 			},
+
+
+
+			//vip 套餐
+			selectVipDetails() {
+				this.$Request.get("/app/VipDetails/selectVipDetails").then((res) => {
+					if (res.code == 0) {
+						this.viplist = res.data
+						if (this.viplist.length > 0) {
+							this.selectedPlan = this.viplist[0].id;
+						}
+					} else {
+						uni.showToast({
+							title: '暂无VIP套餐',
+							icon: 'none'
+						})
+					}
+				});
+			},
+
 			//获取个人信息
 			//获取个人信息
 			getUserInfo() {
 			getUserInfo() {
 				this.$Request.get("/app/user/selectUserById").then((res) => {
 				this.$Request.get("/app/user/selectUserById").then((res) => {
@@ -605,8 +678,80 @@
 					}
 					}
 				});
 				});
 			},
 			},
+
+
+	//会员剩余天数
+			getVipdetile() {
+				 this.$Request.get("/app/UserVip/selectUserVip").then((res) => {
+				        if (res.code == 0) {
+				            const endTimeStr = res.data.endTime; // 到期时间(格式:yyyy-MM-dd HH:mm:ss 或 yyyy-MM-dd)
+				            const createTimeStr = res.data.createTime; // 创建时间(格式同上)
+				            
+				            // 1. 时间字符串转时间戳(兼容不同格式)
+				            const endTime = this.formatTimeToTimestamp(endTimeStr);
+				            const createTime = this.formatTimeToTimestamp(createTimeStr);
+				            const currentTime = new Date().getTime(); // 当前时间戳
+				            
+				            // 2. 验证时间有效性
+				            if (!endTime || !createTime) {
+				                console.error("时间格式错误", { endTimeStr, createTimeStr });
+				                this.remainingDays = 0;
+				                this.vipStatus = "已过期";
+				                return;
+				            }
+				            
+				            // 3. 计算剩余时间(毫秒):到期时间 - 当前时间
+				            const remainingTime = endTime - currentTime;
+				            
+				            // 4. 处理不同情况
+				            if (remainingTime <= 0) {
+				                // 已过期
+				                this.remainingDays = 0;
+				                this.vipStatus = "已过期";
+				            } else {
+				                // 计算剩余天数(向上取整,不足1天按1天算)
+				                const days = Math.ceil(remainingTime / (1000 * 60 * 60 * 24));
+				                this.remainingDays = days;
+				                this.vipStatus = `剩余${days}天到期`;
+				                
+				                // 可选:如果需要显示总有效期(创建到到期的总天数)
+				                this.totalValidDays = Math.ceil((endTime - createTime) / (1000 * 60 * 60 * 24));
+				            }
+				            
+				            console.log("VIP剩余天数:", this.remainingDays);
+				            console.log("VIP状态:", this.vipStatus);
+				        } else {
+				            // 无VIP数据
+				            this.remainingDays = 0;
+				            this.vipStatus = "未开通VIP";
+				            // uni.showToast({
+				            //     title: res.msg || "获取VIP信息失败",
+				            //     icon: "none"
+				            // });
+				        }
+				    }).catch((err) => {
+				        console.error("获取VIP详情失败", err);
+				        this.remainingDays = 0;
+				        this.vipStatus = "未开通VIP";
+				        uni.showToast({
+				            title: "获取VIP信息失败,请重试",
+				            icon: "none"
+				        });
+				    });
+			},
 			
 			
-			
+			// 辅助方法:时间字符串转时间戳(兼容 yyyy-MM-dd HH:mm:ss 和 yyyy-MM-dd 格式)
+			formatTimeToTimestamp(timeStr) {
+			    if (!timeStr) return null;
+			    
+			    // 处理 iOS 不兼容的 "-" 分隔符(替换为 "/")
+			    const formattedTime = timeStr.replace(/-/g, "/");
+			    const timestamp = new Date(formattedTime).getTime();
+			    
+			    // 验证是否为有效时间戳
+			    return isNaN(timestamp) ? null : timestamp;
+			},
+
 			//会员简历刷新次数
 			//会员简历刷新次数
 			getVipPeople() {
 			getVipPeople() {
 				this.$Request.get("/app/common/type/328").then((res) => {
 				this.$Request.get("/app/common/type/328").then((res) => {
@@ -615,6 +760,8 @@
 					}
 					}
 				});
 				});
 			},
 			},
+	
+			
 			//非会员简历刷新次数
 			//非会员简历刷新次数
 			getNoVipPeople() {
 			getNoVipPeople() {
 				this.$Request.get("/app/common/type/327").then((res) => {
 				this.$Request.get("/app/common/type/327").then((res) => {
@@ -671,7 +818,9 @@
 
 
 			// 获取选中计划的价格
 			// 获取选中计划的价格
 			getSelectedPrice() {
 			getSelectedPrice() {
-				return this.planPrices[this.selectedPlan]
+				const selectedItem = this.viplist.find(item => item.id === this.selectedPlan);
+				return selectedItem ? selectedItem.money : 0;
+
 			},
 			},
 
 
 			// 确认支付
 			// 确认支付