XSXS пре 7 месеци
родитељ
комит
eb8764ba11
1 измењених фајлова са 121 додато и 116 уклоњено
  1. 121 116
      pages/my/step.vue

+ 121 - 116
pages/my/step.vue

@@ -150,6 +150,7 @@
                 'disabled': !selectedInterests.includes(interest.id) && isMaxSelected
               }"
               @click="toggleInterest(interest.id)"
+              :style="getCircleStyle(index)"
             >
               <view class="interest-circle">
                 <view>{{ interest.name }}</view>
@@ -325,6 +326,11 @@
       customTags: [],
       maxTags: 5,
       scrollTop: 0,
+      xinzuo: [
+        "水瓶座", "双鱼座", "白羊座", "金牛座", "双子座", 
+        "巨蟹座", "狮子座", "处女座", "天秤座", "天蝎座", 
+        "射手座", "摩羯座"
+      ],
     };
   },
   computed: {
@@ -354,6 +360,9 @@
     const month = String(now.getMonth() + 1).padStart(2, "0");
     const day = String(now.getDate()).padStart(2, "0");
     this.endDate = `${year}-${month}-${day}`;
+    
+    // 页面加载时获取用户信息
+    this.getInfoData();
 		},
 		onShow() {},
 		methods: {
@@ -448,82 +457,135 @@
 				});
 			},
 			getInfoData() {
-      console.log(this.$apiHost + "/Member/getinfoData");
+        console.log(this.$apiHost + "/Member/getinfoData");
 				uni.request({
-        url: this.$apiHost + "/Member/getinfoData", //仅为示例,并非真实接口地址。
+        url: this.$apiHost + "/Member/getinfoData",
 					data: {
           uuid: getApp().globalData.uuid,
 					},
 					header: {
-          "content-type": "application/json", //自定义请求头信息
+          "content-type": "application/json",
 					},
 					success: (res) => {
           console.log("res", res.data);
-						this.nickname = res.data.nickname;
-						this.wechat = res.data.wechat;
-						this.sex = res.data.sex || 2;
-						this.age = res.data.age || 18;
-						this.height = res.data.height || 160;
-						this.weight = res.data.weight || 50;
-						this.xueli_sel = res.data.xueli;
-						this.xinzuo_sel = res.data.xinzuo;
-						this.ziye = res.data.ziye;
-						this.qianmin = res.data.qianmin;
-						if (res.data.avator != "") {
-							this.avator = res.data.avator;
-						}
-						if (res.data.aihao != null && res.data.aihao != undefined) {
-							if (res.data.aihao.length > 0) {
-								this.sel_tags = res.data.aihao.split(",");
+						if (res.data) {
+							// 根据返回数据设置用户信息
+							this.userInfo = {
+								...this.userInfo,
+								nickname: res.data.nickname || "",
+								gender: res.data.sex ? String(res.data.sex) : "",
+								birthday: res.data.birthday || "",
+								xinzuo: res.data.xinzuo || ""
+							};
+							
+							if (res.data.avator) {
+								this.userInfo.avatar = res.data.avator;
+							}
+							
+							// 如果有兴趣爱好,解析并设置
+							if (res.data.aihao && res.data.aihao.length > 0) {
+								// 解析爱好标签
+								const aihaos = res.data.aihao.split(",");
+								
+								// 处理预设兴趣
+								const presetTags = [];
+								const customTags = [];
+								
+								aihaos.forEach(tag => {
+									// 查找是否是预设兴趣
+									const matchedInterest = this.interests.find(i => i.name === tag);
+									if (matchedInterest) {
+										presetTags.push(matchedInterest.id);
+									} else if (tag.trim()) {
+										customTags.push({
+											name: tag,
+											isCustom: true
+										});
+									}
+								});
+								
+								this.selectedInterests = presetTags;
+								this.customTags = customTags;
 							}
 						}
-        },
+					},
+					fail: (err) => {
+						console.error("获取用户信息失败", err);
+						uni.showToast({
+							title: "获取信息失败,请重试",
+							icon: "none"
+						});
+					}
 				});
 			},
 
-			submitData() {
-      let aihao = this.sel_tags.join(",");
-				let obj2 = {
+			submitUserInfo() {
+				// 收集所有标签
+				let tagStr = this.selectedTags.map(item => item.name).join(',');
+				
+				// 构建提交的数据对象
+				const data = {
 					uuid: getApp().globalData.uuid,
-					avator: this.avator,
-					nickname: this.nickname,
-					wechat: this.wechat,
-					sex: this.sex,
-					age: this.age,
-					height: this.height,
-					weight: this.weight,
-					xueli: this.xueli_sel,
-					xinzuo: this.xinzuo_sel,
-					ziye: this.ziye,
-					qianmin: this.qianmin,
-        aihao: aihao,
-      };
-				// console.log("obj2", obj2);
+					nickname: this.userInfo.nickname,
+					avator: this.userInfo.avatar,
+					sex: this.userInfo.gender,
+					birthday: this.userInfo.birthday,
+					xinzuo: this.userInfo.xinzuo,
+					aihao: tagStr
+				};
+
+				uni.showLoading({
+					title: "保存中...",
+					mask: true
+				});
+				
 				uni.request({
-        url: this.$apiHost + "/Member/setinfoData", //仅为示例,并非真实接口地址。
-					data: obj2,
-        method: "POST",
+					url: this.$apiHost + "/Member/setinfoData",
+					data: data,
+					method: "POST",
 					header: {
-          "Content-Type": "application/x-www-form-urlencoded",
-          sign: getApp().globalData.headerSign,
+						"Content-Type": "application/x-www-form-urlencoded",
+						sign: getApp().globalData.headerSign,
 					},
-        dataType: "json",
-					// header: {
-					// 	'content-type': 'application/json', //自定义请求头信息
-					// 	'Access-Control-Allow-Origin': '*'
-					// },
+					dataType: "json",
 					success: (res) => {
-          console.log("res", res.data);
-          this.$refs["ToastW3"].showToast({
-							title: res.data.str,
-            animation: 0,
-						});
-						if (res.data.success == "yes") {
-							uni.switchTab({
-								url: "/pages/index/index",
+						if (res.data.success === "yes") {
+							// 保存用户信息到全局变量和本地存储
+							if (this.userInfo.nickname) {
+								getApp().globalData.nickname = this.userInfo.nickname;
+								uni.setStorageSync("nickname", this.userInfo.nickname);
+							}
+							
+							if (this.userInfo.avatar) {
+								getApp().globalData.avator = this.userInfo.avatar;
+								uni.setStorageSync("avator", this.userInfo.avatar);
+							}
+							
+							uni.showToast({
+								title: "注册成功",
+								icon: "success",
+							});
+							
+							// 延迟返回上一页面
+							setTimeout(() => {
+								uni.navigateBack();
+							}, 1500);
+						} else {
+							uni.showToast({
+								title: res.data.str || "保存失败",
+								icon: "none",
 							});
 						}
-        },
+					},
+					fail: () => {
+						uni.showToast({
+							title: "网络错误",
+							icon: "none",
+						});
+					},
+					complete: () => {
+						uni.hideLoading();
+					},
 				});
 			},
 			// upload() {
@@ -789,12 +851,12 @@
       let offsetLeft = 0;
       let offsetTop = 0;
 
-      if (row == 0 || row == 2) {
+      if (row % 2== 0 ) {
         offsetLeft = offsetLefts;
       } else {
         offsetLeft = -offsetLefts;
       }
-      if (column == 1 || column == 3) {
+      if (column % 2 == 1 ) {
         offsetTop = offsetTops;
       } else {
         offsetTop = -offsetTops;
@@ -865,62 +927,6 @@
         this.submitUserInfo();
       }
     },
-    submitUserInfo() {
-		let tagStr = this.selectedTags.map(item => item.name).join(',');
-      const data = {
-        ...this.userInfo,
-        interests: this.selectedInterests,
-        tags: tagStr,
-		uuid: getApp().globalData.uuid,
-		
-      };
-
-      uni.showLoading({
-        title: "保存中...",
-      });
-	  uni.request({
-        url: this.$apiHost + "/Member/setinfoData", //仅为示例,并非真实接口地址。
-        data: data,
-        method: "POST",
-        header: {
-          "Content-Type": "application/x-www-form-urlencoded",
-          sign: getApp().globalData.headerSign,
-        },
-        dataType: "json",
-        // header: {
-        // 	'content-type': 'application/json', //自定义请求头信息
-        // 	'Access-Control-Allow-Origin': '*'
-        // },
-        success: (res) => {
-			if (res.data.success === "yes") {
-            uni.showToast({
-              title: "保存成功",
-              icon: "success",
-            });
-            // 延迟跳转
-            setTimeout(() => {
-              uni.switchTab({
-                url: "/pages/index/index",
-              });
-            }, 1500);
-          } else {
-            uni.showToast({
-              title: res.data.msg || "保存失败",
-              icon: "none",
-            });
-          }
-        },      fail: () => {
-          uni.showToast({
-            title: "网络错误",
-            icon: "none",
-          });
-        },
-        complete: () => {
-          uni.hideLoading();
-        },
-      });
-      
-    },
     onScroll(e) {
       this.scrollTop = e.detail.scrollTop;
     }
@@ -1245,8 +1251,7 @@
   .interest-tip {
     font-size: 28rpx;
     color: #666;
-    margin-bottom: 30rpx;
-    padding: 0 20rpx;
+    margin-bottom: 30rpx; 
   }
 
   .interest-circles {