From 00fa7d3b67223806b660d0e2d67b78ea3ebc1e3f Mon Sep 17 00:00:00 2001 From: huliyong <2783385703@qq.com> Date: Sun, 20 Apr 2025 23:03:21 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E8=AE=A2=E5=8D=95=E6=B5=81=E7=A8=8B):=20?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=94=A8=E6=88=B7=E9=80=89=E6=8B=A9=E8=80=81?= =?UTF-8?q?=E5=B8=88=E5=8A=9F=E8=83=BD=E5=B9=B6=E4=BC=98=E5=8C=96=E8=B7=9D?= =?UTF-8?q?=E7=A6=BB=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 Vuex 中新增 `buyInfo` 和 `position` 状态,用于存储用户选择的老师和位置信息 - 新增 `position.js` 工具类,用于计算两点之间的距离 - 在 `companionPetList.vue` 和 `companionPetInfo.vue` 中集成距离计算功能,显示老师与用户的距离 - 优化订单流程,支持用户选择指定老师下单,并在页面中显示相关信息 --- mixins/configList.js | 2 +- mixins/position.js | 38 +++++++++++++++++++++++++++++ pages/companionPetList/companionPetInfo.vue | 20 +++++++++++---- pages/companionPetList/companionPetList.vue | 24 ++++++++++++++---- pages/index.vue | 17 ++++++++++--- pages/newOrder/serviceNew.vue | 16 ++---------- pages/newOrder/serviceNew2.vue | 17 +++---------- store/index.js | 7 ++++++ utils/position.js | 30 +++++++++++++++++++++++ 9 files changed, 130 insertions(+), 41 deletions(-) create mode 100644 mixins/position.js create mode 100644 utils/position.js diff --git a/mixins/configList.js b/mixins/configList.js index d987275..e0316b8 100644 --- a/mixins/configList.js +++ b/mixins/configList.js @@ -13,7 +13,7 @@ export default { } }, computed: { - ...mapState(['configList', 'userInfo']), + ...mapState(['configList', 'userInfo', 'buyInfo']), // currentPagePath() { // const pages = getCurrentPages(); // const currentPage = pages[pages.length - 1]; diff --git a/mixins/position.js b/mixins/position.js new file mode 100644 index 0000000..238a316 --- /dev/null +++ b/mixins/position.js @@ -0,0 +1,38 @@ + + +import { mapState } from 'vuex' +import { calculateDistance } from '@/utils/position' +export default { + data() { + return { + } + }, + computed: { + ...mapState(['position']), + }, + methods: { + calculateDistanceAddress(teacherAddress) { + if (!teacherAddress || + teacherAddress.length == 0 || + !this.position || + !this.position.latitude || + !this.position.longitude) { + return 0 + } + + let minDistance = 0 + + teacherAddress.forEach(item => { + let distance = calculateDistance( + this.position.latitude, + this.position.longitude, + item.latitude, + item.longitude, + ) + minDistance = Math.min(minDistance, distance) + }) + + return minDistance + } + } +} \ No newline at end of file diff --git a/pages/companionPetList/companionPetInfo.vue b/pages/companionPetList/companionPetInfo.vue index 4da3ab3..dc2a520 100644 --- a/pages/companionPetList/companionPetInfo.vue +++ b/pages/companionPetList/companionPetInfo.vue @@ -10,7 +10,7 @@ - {{companionInfo.name}} + {{companionInfo.userName}} sex - + @@ -272,7 +272,7 @@ - {{companionInfo.name}} + {{companionInfo.userName}} @@ -312,7 +312,8 @@ - + @@ -356,7 +357,9 @@ getTeacherServiceLogList, } from "@/api/order/order" import uniRate from '@/uni_modules/uni-rate/components/uni-rate/uni-rate.vue'; + import positionMixin from '../../mixins/position'; export default { + mixins: [positionMixin], data() { return { currentCompanionPetId: '', @@ -475,6 +478,12 @@ this.getCurrentCompanionPetInfo(this.currentCompanionPetId) }, methods: { + toBuy(){ + this.buyInfo.teacher = this.companionInfo + uni.navigateTo({ + url: '/pages/newOrder/serviceNew?type=teacher' + }) + }, onClickFav() { this.collect = !this.collect this.$forceUpdate() @@ -483,6 +492,7 @@ getTeacherDetail({userId}).then(response => { if (response) { this.companionInfo = response + this.companionInfo.distanceText = this.calculateDistanceAddress(response.appletAddresseList) } console.log('getCurrentCompanionPetInfo', response); }) diff --git a/pages/companionPetList/companionPetList.vue b/pages/companionPetList/companionPetList.vue index abd72c7..867aa68 100644 --- a/pages/companionPetList/companionPetList.vue +++ b/pages/companionPetList/companionPetList.vue @@ -18,7 +18,7 @@ + src="https://catmdogf.oss-cn-shanghai.aliyuncs.com/CMDF/front/petServiceOrder/Calendar.png"/> {{selectedDateShowText}}共{{selectedDate.length}}天 选择时间 @@ -128,8 +128,8 @@ - - 距离{{ item.id }}km + + 距离{{ item.distanceText }}km 暂无距离估测 @@ -152,7 +152,9 @@ + style=" + color: #AAAAAA; + display: flex; justify-content: center; align-items: center; height: 100px; font-size: 16px; font-weight: bold;"> 暂无数据 @@ -164,6 +166,7 @@ import uniPopup from '@/uni_modules/uni-popup/components/uni-popup/uni-popup.vue'; import uniFab from '@/uni_modules/uni-fab/components/uni-fab/uni-fab.vue' import FilterPopup from '@/components/FilterPopup/FilterPopup.vue' + import positionMixin from '../../mixins/position'; // import { // getCompanionList, // getCompanionInfo @@ -172,6 +175,7 @@ getTeacherList, } from "@/api/order/order" export default { + mixins: [positionMixin], data() { return { allInfo: { @@ -300,11 +304,16 @@ getTeacherList(data).then(response => { if (response.code == 200) { this.companionList = response.rows - console.log(response); + this.calculateTeacherListDistance() } console.log(response); }) }, + calculateTeacherListDistance(){ + this.companionList.forEach(item => { + item.distanceText = this.calculateDistanceAddress(item.appletAddresseList) + }) + }, iconClick() {}, changeSelectedPet(type) { console.log('changeSelectedPet type', type); @@ -407,6 +416,11 @@ this.locationLatitude = res.latitude this.locationAddress = res.address console.log('选择的位置:', res); + + this.position.address = this.locationAddress + this.position.longitude = this.locationLongitude + this.position.latitude = this.locationLatitude + }, fail: (err) => { // 失败回调 diff --git a/pages/index.vue b/pages/index.vue index e4fb641..0207841 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -616,16 +616,27 @@ icon: "none" }) } else { + + this.$store.commit('setPosition', { + address: this.locationAddress, + longitude: this.locationLongitude, + latitude: this.locationLatitude, + date: this.selectedDateShowText + }) + uni.navigateTo({ // url: '/pages/companionPetList/companionPetList', - url: `/pages/companionPetList/companionPetList?info=` + encodeURIComponent(JSON + url: `/pages/companionPetList/companionPetList?info=` + + encodeURIComponent(JSON .stringify(this.allInfo)) }); } } else { + this.$store.commit('setPosition', {}) + this.buyInfo.teacher = null uni.navigateTo({ - url: '/pages_order/order/payOrderSuccessful', - // url: '/pages/newOrder/serviceNew', + // url: '/pages_order/order/payOrderSuccessful', + url: '/pages/newOrder/serviceNew', // url: '/pages/newOrder/serviceNew2', }); } diff --git a/pages/newOrder/serviceNew.vue b/pages/newOrder/serviceNew.vue index 5e8d5a1..e1f647d 100644 --- a/pages/newOrder/serviceNew.vue +++ b/pages/newOrder/serviceNew.vue @@ -1,8 +1,7 @@