From c605554faa641739efea5cfb14d27da5e7e789d7 Mon Sep 17 00:00:00 2001 From: huliyong <2783385703@qq.com> Date: Wed, 21 May 2025 22:43:37 +0800 Subject: [PATCH] =?UTF-8?q?refactor(companionList):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=BC=B4=E5=AE=A0=E5=B8=88=E5=88=97=E8=A1=A8=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E5=B9=B6=E8=B0=83=E6=95=B4=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 重构伴宠师列表展示逻辑,使用 `companionList` 数据动态渲染 - 调整伴宠师信息展示样式,包括图片、姓名、性别、点赞数、距离和简介 - 添加无伴宠师时的提示信息 - 删除未使用的代码和注释 --- components/FilterPopup/FilterPopup.vue | 2 +- components/addressMap.vue | 4 +- pages/index.vue | 151 ++++++++++++++++----------------- pages/newOrder/serviceNew.vue | 4 +- pages_order/task/AppletTask.java | 77 ----------------- 5 files changed, 81 insertions(+), 157 deletions(-) delete mode 100644 pages_order/task/AppletTask.java diff --git a/components/FilterPopup/FilterPopup.vue b/components/FilterPopup/FilterPopup.vue index 50e37f8..55295de 100644 --- a/components/FilterPopup/FilterPopup.vue +++ b/components/FilterPopup/FilterPopup.vue @@ -42,7 +42,7 @@ 伴宠师等级 - + 初级伴宠师 diff --git a/components/addressMap.vue b/components/addressMap.vue index f9ac786..9813f7e 100644 --- a/components/addressMap.vue +++ b/components/addressMap.vue @@ -73,9 +73,9 @@ // 根据最大距离设置缩放比例 // 距离越大,缩放比例越小 if (maxDistance > 100) { // - this.scale = 2 - }else if (maxDistance > 50) { // this.scale = 5 + }else if (maxDistance > 50) { // + this.scale = 8 }else if (maxDistance > 10) { // 10公里以上 this.scale = 10 } else if (maxDistance > 5) { // 5-10公里 diff --git a/pages/index.vue b/pages/index.vue index 51ba288..e6f26e6 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -149,36 +149,42 @@ - + + :src="item.userImage"> - {{defaultCompanion.name}} + {{ item.userName || '匿名' }} - sex + sex - 客户点赞数{{defaultCompanion.star}} - + 点赞数{{ item.appletUsersTeacher.thumbsUp || 0 }} + - - 距离{{defaultCompanion.distance}}km + + 距离{{ item.distanceText }}km + + + {{ '<' }}1km - - 简介:{{defaultCompanion.shortDescription}} + + 简介:{{ item.appletUsersTeacher.userBrief || '暂无' }} @@ -186,10 +192,16 @@ - 养宠{{defaultCompanion.year}}年 | 评价{{defaultCompanion.record}}条 | 服务小结{{defaultCompanion.serviceNum}}份 + 养宠{{ item.experience || 0 }}年 | 评价{{ item.commentNum || 0 }}条 | 服务小结{{ item.serviceSummaryNum || 0 }}份 + + + + 您周边没有伴宠师呢 + + @@ -240,7 +252,7 @@ style="width: 100%;" mode="widthFix" alt="service" /> - + { + uni.getLocation({ + type: 'gcj02', + success: (res) => { + resolve(res) + } + }) + }) + }, + async getCompanionList() { // 构建参数,使用当前位置坐标 let data = { - address: this.locationAddress || "上海市浦东新区浦东南路150弄", - latitude: this.locationLatitude || 31.22514, - longitude: this.locationLongitude || 121.49857, - petTypes: ["1", "2"], - staffName: "" + latitude: this.position.latitude, + longitude: this.position.longitude, } - console.log('获取周边伴宠师参数:', data); - - // 保存当前位置到Vuex,让position mixin能使用 - this.$store.commit('setPosition', { - address: this.locationAddress, - longitude: this.locationLongitude, - latitude: this.locationLatitude - }); - - getTeacherListIndex(data).then(response => { - if (response.code == 200 && response.rows && response.rows.length > 0) { - const nearbyTeacher = response.rows[0]; - console.log('伴宠师原始数据:', nearbyTeacher); - - // 如果伴宠师有地址信息,使用mixin的calculateDistanceAddress计算距离 - let distance = 0; - if (nearbyTeacher.addressList && nearbyTeacher.addressList.length > 0) { - distance = this.calculateDistanceAddress(nearbyTeacher.addressList); - } else if (nearbyTeacher.latitude && nearbyTeacher.longitude) { - // 如果没有地址列表但有经纬度信息,则构造地址对象 - const addressList = [{ - latitude: nearbyTeacher.latitude, - longitude: nearbyTeacher.longitude - }]; - distance = this.calculateDistanceAddress(addressList); - } - - // 处理用户图片 - let userImageUrl = ""; - if (typeof nearbyTeacher.userImage === 'string') { - userImageUrl = nearbyTeacher.userImage; - } else if (nearbyTeacher.userImage && Array.isArray(nearbyTeacher.userImage) && nearbyTeacher.userImage.length > 0) { - userImageUrl = nearbyTeacher.userImage[0].url || ""; - } - - // 构建伴宠师信息对象 - this.defaultCompanion = { - name: nearbyTeacher.userName || '宠小二', - gender: nearbyTeacher.gender || '1', // 性别,1-男,2-女 - star: nearbyTeacher.likeNum || 0, - distance: distance.toFixed(1), - shortDescription: nearbyTeacher.shortDescription || '专业伴宠师,用心照顾每一位小宠物', - staffImages: [{ - url: userImageUrl || "https://catmdogf.oss-cn-shanghai.aliyuncs.com/CMDF/front/personal/pet/catdog.png" - }], - year: nearbyTeacher.serviceAge || 1, // 服务年限 - record: nearbyTeacher.commentNum || 0, // 评价数 - serviceNum: nearbyTeacher.serviceSummaryNum || 0 // 服务小结数 - } - - console.log('周边伴宠师信息:', this.defaultCompanion); - } else { - console.log('没有找到周边伴宠师或返回数据有误'); + + if(!data.latitude){ + let res = await this.getLocation() + data.latitude = res.latitude + data.longitude = res.longitude + } + + getTeacherList(data).then(response => { + if (response.code == 200) { + this.companionList = response.rows + this.calculateTeacherListDistance() } - }).catch(err => { - console.error('获取周边伴宠师失败:', err); + console.log(response); + }) + }, + calculateTeacherListDistance(){ + this.companionList.forEach(item => { + item.distanceText = this.calculateDistanceAddress(item.appletAddresseList) }) + + this.companionList.sort((a,b) => a.distanceText - b.distanceText) }, getOrder(value) { if (value) { @@ -975,6 +962,18 @@ background-color: #F5F5F7 !important; } + .no-data{ + width: 100%; + height: 100%; + display: flex; + align-items: center; + justify-content: center; + .no-data-text{ + font-size: 24rpx; + color: #999; + } + } + .home-content { position: relative; diff --git a/pages/newOrder/serviceNew.vue b/pages/newOrder/serviceNew.vue index 4850ad6..3132124 100644 --- a/pages/newOrder/serviceNew.vue +++ b/pages/newOrder/serviceNew.vue @@ -29,7 +29,9 @@ - +